Skip to content
Snippets Groups Projects

Add group chat MessageReceive documentation

Merged Josh Brooks requested to merge XX-4193/GroupChatMessageCallback into release
1 file
+ 42
1
Compare changes
  • Side-by-side
  • Inline
+ 42
1
@@ -410,6 +410,7 @@ type GroupRequest interface {
}
// GroupChatProcessor manages the handling of received group chat messages.
// The decryptedMessage field will be a JSON marshalled GroupChatMessage.
type GroupChatProcessor interface {
Process(decryptedMessage, msg, receptionId []byte, ephemeralId,
roundId int64, err error)
@@ -422,13 +423,53 @@ type groupChatProcessor struct {
bindingsCb GroupChatProcessor
}
// GroupChatMessage is the bindings layer representation of the
// [groupChat.MessageReceive].
//
// GroupChatMessage Example JSON:
// {
// "GroupId": "AAAAAAAJlasAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAE",
// "SenderId": "AAAAAAAAB8gAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD",
// "MessageId": "Zm9ydHkgZml2ZQAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=",
// "Payload": "Zm9ydHkgZml2ZQ==",
// "Timestamp": 1663009269474079000
// }
type GroupChatMessage struct {
// GroupId is the ID of the group that this message was sent on.
GroupId []byte
// SenderId is the ID of the sender of this message.
SenderId []byte
// MessageId is the ID of this group message.
MessageId []byte
// Payload is the content of the message.
Payload []byte
// Timestamp is the time this message was sent on.
Timestamp int64
}
// convertMessageReceive is a helper function which converts a
// [groupChat.MessageReceive] to the bindings-layer representation GroupChatMessage.
func convertMessageReceive(decryptedMsg gc.MessageReceive) GroupChatMessage {
return GroupChatMessage{
GroupId: decryptedMsg.GroupID.Bytes(),
SenderId: decryptedMsg.SenderID.Bytes(),
MessageId: decryptedMsg.ID.Bytes(),
Payload: decryptedMsg.Payload,
Timestamp: decryptedMsg.Timestamp.UnixNano(),
}
}
// convertProcessor turns the input of a groupChat.Processor to the
// binding-layer primitives equivalents within the GroupChatProcessor.Process.
func convertGroupChatProcessor(decryptedMsg gc.MessageReceive, msg format.Message,
receptionID receptionID.EphemeralIdentity, round rounds.Round) (
decryptedMessage, message, receptionId []byte, ephemeralId, roundId int64, err error) {
decryptedMessage, err = json.Marshal(decryptedMsg)
decryptedMessage, err = json.Marshal(convertMessageReceive(decryptedMsg))
message = msg.Marshal()
receptionId = receptionID.Source.Marshal()
ephemeralId = receptionID.EphId.Int64()
Loading