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 (
"context"
"encoding/base64"
"encoding/json"
"syscall/js"
"time"
"github.com/hack-pad/go-indexeddb/idb"
"github.com/pkg/errors"
jww "github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/xxdk-wasm/utils"
"syscall/js"
"time"
"gitlab.com/elixxir/client/channels"
"gitlab.com/elixxir/client/cmix/rounds"
......@@ -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
// user of the API to filter such called by message ID.
func (w *wasmModel) ReceiveMessage(channelID *id.ID,
messageID cryptoChannel.MessageID, senderUsername string, text string,
timestamp time.Time, lease time.Duration, _ rounds.Round,
messageID cryptoChannel.MessageID,
nickname, text string, identity cryptoChannel.Identity,
timestamp time.Time, lease time.Duration, round rounds.Round,
status channels.SentStatus) {
parentErr := errors.New("failed to ReceiveMessage")
err := w.receiveHelper(buildMessage(channelID.Marshal(), messageID.Bytes(),
nil, senderUsername, text, timestamp, lease, status))
err := w.receiveHelper(buildMessage(channelID.Marshal(),
messageID.Bytes(), nil, nickname, text, identity,
timestamp, lease, status))
if err != nil {
jww.ERROR.Printf("%+v", errors.Wrap(parentErr, err.Error()))
}
......@@ -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
// the initial message. As a result, it may be important to buffer replies.
func (w *wasmModel) ReceiveReply(channelID *id.ID,
messageID cryptoChannel.MessageID, replyTo cryptoChannel.MessageID,
senderUsername string, text string, timestamp time.Time,
lease time.Duration, _ rounds.Round, status channels.SentStatus) {
messageID cryptoChannel.MessageID,
reactionTo cryptoChannel.MessageID, nickname, text string,
identity cryptoChannel.Identity, timestamp time.Time,
lease time.Duration, round rounds.Round, status SentStatus) uint64 {
parentErr := errors.New("failed to ReceiveReply")
err := w.receiveHelper(buildMessage(channelID.Marshal(), messageID.Bytes(),
replyTo.Bytes(), senderUsername, text, timestamp, lease, status))
err := w.receiveHelper(buildMessage(channelID.Marshal(),
messageID.Bytes(), replyTo.Bytes(), nickname, text, identity,
timestamp, lease, status))
if err != nil {
jww.ERROR.Printf("%+v", errors.Wrap(parentErr, err.Error()))
}
......@@ -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
// the initial message. As a result, it may be important to buffer reactions.
func (w *wasmModel) ReceiveReaction(channelID *id.ID,
messageID cryptoChannel.MessageID, reactionTo cryptoChannel.MessageID,
senderUsername string, reaction string, timestamp time.Time,
lease time.Duration, _ rounds.Round, status channels.SentStatus) {
func (w *wasmModel) ReceiveReaction(channelID *id.ID, messageID cryptoChannel.MessageID,
reactionTo cryptoChannel.MessageID, nickname, reaction string,
identity cryptoChannel.Identity, timestamp time.Time,
lease time.Duration, round rounds.Round, status SentStatus) uint64 {
parentErr := errors.New("failed to ReceiveReaction")
err := w.receiveHelper(buildMessage(channelID.Marshal(), messageID.Bytes(),
reactionTo.Bytes(), senderUsername, reaction, timestamp, lease, status))
err := w.receiveHelper(buildMessage(channelID.Marshal(),
messageID.Bytes(), reactionTo.Bytes(), nickname, reaction,
identity, timestamp, lease, status))
if err != nil {
jww.ERROR.Printf("%+v", errors.Wrap(parentErr, err.Error()))
}
......@@ -198,8 +204,8 @@ func (w *wasmModel) ReceiveReaction(channelID *id.ID,
// UpdateSentStatus is called whenever the [channels.SentStatus] of a message
// has changed.
// TODO: Potential race condition due to separate get/update operations.
func (w *wasmModel) UpdateSentStatus(messageID cryptoChannel.MessageID,
status channels.SentStatus) {
func (w *wasmModel) UpdateSentStatus(uuid uint64, messageID cryptoChannel.MessageID,
timestamp time.Time, round rounds.Round, status SentStatus) {
parentErr := errors.New("failed to UpdateSentStatus")
// Convert messageID to the key generated by json.Marshal
......@@ -228,12 +234,13 @@ func (w *wasmModel) UpdateSentStatus(messageID cryptoChannel.MessageID,
// buildMessage is a private helper that converts typical [channels.EventModel]
// inputs into a basic Message structure for insertion into storage.
func buildMessage(channelID, messageID, parentId []byte, senderUsername,
text string, timestamp time.Time, lease time.Duration,
func buildMessage(channelID, messageID, parentId []byte, nickname,
text string, timestamp time.Time, identity cryptoChannel.Identity,
lease time.Duration,
status channels.SentStatus) *Message {
return &Message{
Id: messageID,
SenderUsername: senderUsername,
Nickname: nickname,
ChannelId: channelID,
ParentMessageId: parentId,
Timestamp: timestamp,
......@@ -242,6 +249,15 @@ func buildMessage(channelID, messageID, parentId []byte, senderUsername,
Hidden: false,
Pinned: false,
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