Skip to content
Snippets Groups Projects
Commit 492b1a40 authored by Josh Brooks's avatar Josh Brooks
Browse files

Add group chat MessageReceive documentation

parent 6011849a
No related branches found
No related tags found
2 merge requests!510Release,!375Add group chat MessageReceive documentation
......@@ -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()
......
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