Skip to content
Snippets Groups Projects
Commit b274d09f authored by Richard T. Carback III's avatar Richard T. Carback III Committed by Jono Wenger
Browse files

Update implementation to insert the user identity to each message

parent f40f71c7
No related branches found
No related tags found
2 merge requests!60Revert "Fail a test to be sure it works",!8Updates to match the client fullyDecentrilizedChannels branch
...@@ -13,12 +13,13 @@ import ( ...@@ -13,12 +13,13 @@ import (
"context" "context"
"encoding/base64" "encoding/base64"
"encoding/json" "encoding/json"
"syscall/js"
"time"
"github.com/hack-pad/go-indexeddb/idb" "github.com/hack-pad/go-indexeddb/idb"
"github.com/pkg/errors" "github.com/pkg/errors"
jww "github.com/spf13/jwalterweatherman" jww "github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/xxdk-wasm/utils" "gitlab.com/elixxir/xxdk-wasm/utils"
"syscall/js"
"time"
"gitlab.com/elixxir/client/channels" "gitlab.com/elixxir/client/channels"
"gitlab.com/elixxir/client/cmix/rounds" "gitlab.com/elixxir/client/cmix/rounds"
...@@ -145,13 +146,15 @@ func (w *wasmModel) LeaveChannel(channelID *id.ID) { ...@@ -145,13 +146,15 @@ func (w *wasmModel) LeaveChannel(channelID *id.ID) {
// It may be called multiple times on the same message; it is incumbent on the // It may be called multiple times on the same message; it is incumbent on the
// user of the API to filter such called by message ID. // user of the API to filter such called by message ID.
func (w *wasmModel) ReceiveMessage(channelID *id.ID, func (w *wasmModel) ReceiveMessage(channelID *id.ID,
messageID cryptoChannel.MessageID, senderUsername string, text string, messageID cryptoChannel.MessageID,
timestamp time.Time, lease time.Duration, _ rounds.Round, nickname, text string, identity cryptoChannel.Identity,
timestamp time.Time, lease time.Duration, round rounds.Round,
status channels.SentStatus) { status channels.SentStatus) {
parentErr := errors.New("failed to ReceiveMessage") parentErr := errors.New("failed to ReceiveMessage")
err := w.receiveHelper(buildMessage(channelID.Marshal(), messageID.Bytes(), err := w.receiveHelper(buildMessage(channelID.Marshal(),
nil, senderUsername, text, timestamp, lease, status)) messageID.Bytes(), nil, nickname, text, identity,
timestamp, lease, status))
if err != nil { if err != nil {
jww.ERROR.Printf("%+v", errors.Wrap(parentErr, err.Error())) jww.ERROR.Printf("%+v", errors.Wrap(parentErr, err.Error()))
} }
...@@ -164,13 +167,15 @@ func (w *wasmModel) ReceiveMessage(channelID *id.ID, ...@@ -164,13 +167,15 @@ func (w *wasmModel) ReceiveMessage(channelID *id.ID,
// Messages may arrive our of order, so a reply, in theory, can arrive before // Messages may arrive our of order, so a reply, in theory, can arrive before
// the initial message. As a result, it may be important to buffer replies. // the initial message. As a result, it may be important to buffer replies.
func (w *wasmModel) ReceiveReply(channelID *id.ID, func (w *wasmModel) ReceiveReply(channelID *id.ID,
messageID cryptoChannel.MessageID, replyTo cryptoChannel.MessageID, messageID cryptoChannel.MessageID,
senderUsername string, text string, timestamp time.Time, reactionTo cryptoChannel.MessageID, nickname, text string,
lease time.Duration, _ rounds.Round, status channels.SentStatus) { identity cryptoChannel.Identity, timestamp time.Time,
lease time.Duration, round rounds.Round, status SentStatus) uint64 {
parentErr := errors.New("failed to ReceiveReply") parentErr := errors.New("failed to ReceiveReply")
err := w.receiveHelper(buildMessage(channelID.Marshal(), messageID.Bytes(), err := w.receiveHelper(buildMessage(channelID.Marshal(),
replyTo.Bytes(), senderUsername, text, timestamp, lease, status)) messageID.Bytes(), replyTo.Bytes(), nickname, text, identity,
timestamp, lease, status))
if err != nil { if err != nil {
jww.ERROR.Printf("%+v", errors.Wrap(parentErr, err.Error())) jww.ERROR.Printf("%+v", errors.Wrap(parentErr, err.Error()))
} }
...@@ -182,14 +187,15 @@ func (w *wasmModel) ReceiveReply(channelID *id.ID, ...@@ -182,14 +187,15 @@ func (w *wasmModel) ReceiveReply(channelID *id.ID,
// //
// Messages may arrive our of order, so a reply, in theory, can arrive before // Messages may arrive our of order, so a reply, in theory, can arrive before
// the initial message. As a result, it may be important to buffer reactions. // the initial message. As a result, it may be important to buffer reactions.
func (w *wasmModel) ReceiveReaction(channelID *id.ID, func (w *wasmModel) ReceiveReaction(channelID *id.ID, messageID cryptoChannel.MessageID,
messageID cryptoChannel.MessageID, reactionTo cryptoChannel.MessageID, reactionTo cryptoChannel.MessageID, nickname, reaction string,
senderUsername string, reaction string, timestamp time.Time, identity cryptoChannel.Identity, timestamp time.Time,
lease time.Duration, _ rounds.Round, status channels.SentStatus) { lease time.Duration, round rounds.Round, status SentStatus) uint64 {
parentErr := errors.New("failed to ReceiveReaction") parentErr := errors.New("failed to ReceiveReaction")
err := w.receiveHelper(buildMessage(channelID.Marshal(), messageID.Bytes(), err := w.receiveHelper(buildMessage(channelID.Marshal(),
reactionTo.Bytes(), senderUsername, reaction, timestamp, lease, status)) messageID.Bytes(), reactionTo.Bytes(), nickname, reaction,
identity, timestamp, lease, status))
if err != nil { if err != nil {
jww.ERROR.Printf("%+v", errors.Wrap(parentErr, err.Error())) jww.ERROR.Printf("%+v", errors.Wrap(parentErr, err.Error()))
} }
...@@ -198,8 +204,8 @@ func (w *wasmModel) ReceiveReaction(channelID *id.ID, ...@@ -198,8 +204,8 @@ func (w *wasmModel) ReceiveReaction(channelID *id.ID,
// UpdateSentStatus is called whenever the [channels.SentStatus] of a message // UpdateSentStatus is called whenever the [channels.SentStatus] of a message
// has changed. // has changed.
// TODO: Potential race condition due to separate get/update operations. // TODO: Potential race condition due to separate get/update operations.
func (w *wasmModel) UpdateSentStatus(messageID cryptoChannel.MessageID, func (w *wasmModel) UpdateSentStatus(uuid uint64, messageID cryptoChannel.MessageID,
status channels.SentStatus) { timestamp time.Time, round rounds.Round, status SentStatus) {
parentErr := errors.New("failed to UpdateSentStatus") parentErr := errors.New("failed to UpdateSentStatus")
// Convert messageID to the key generated by json.Marshal // Convert messageID to the key generated by json.Marshal
...@@ -228,12 +234,13 @@ func (w *wasmModel) UpdateSentStatus(messageID cryptoChannel.MessageID, ...@@ -228,12 +234,13 @@ func (w *wasmModel) UpdateSentStatus(messageID cryptoChannel.MessageID,
// buildMessage is a private helper that converts typical [channels.EventModel] // buildMessage is a private helper that converts typical [channels.EventModel]
// inputs into a basic Message structure for insertion into storage. // inputs into a basic Message structure for insertion into storage.
func buildMessage(channelID, messageID, parentId []byte, senderUsername, func buildMessage(channelID, messageID, parentId []byte, nickname,
text string, timestamp time.Time, lease time.Duration, text string, timestamp time.Time, identity cryptoChannel.Identity,
lease time.Duration,
status channels.SentStatus) *Message { status channels.SentStatus) *Message {
return &Message{ return &Message{
Id: messageID, Id: messageID,
SenderUsername: senderUsername, Nickname: nickname,
ChannelId: channelID, ChannelId: channelID,
ParentMessageId: parentId, ParentMessageId: parentId,
Timestamp: timestamp, Timestamp: timestamp,
...@@ -242,6 +249,15 @@ func buildMessage(channelID, messageID, parentId []byte, senderUsername, ...@@ -242,6 +249,15 @@ func buildMessage(channelID, messageID, parentId []byte, senderUsername,
Hidden: false, Hidden: false,
Pinned: false, Pinned: false,
Text: text, Text: text,
// User Identity Info
Pubkey: identity.PubKey.Bytes(),
Honorific: identity.Honorific.String(),
Adjective: identity.Adjective.String(),
Noun: identity.Noun.String(),
Codename: identity.Codename,
Color: identity.Color,
Extension: identity.Extension,
CodesetVersion: identity.CodesetVersion,
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment