Updated MembershipUpdateMessage to use interfaced ChatEntity
Replaces ChatMessage only field
This commit is contained in:
parent
b6d24e950c
commit
45c1e5ba1c
|
@ -18,6 +18,7 @@ import (
|
|||
"github.com/status-im/status-go/protocol/datasync"
|
||||
datasyncpeer "github.com/status-im/status-go/protocol/datasync/peer"
|
||||
"github.com/status-im/status-go/protocol/encryption"
|
||||
"github.com/status-im/status-go/protocol/protobuf"
|
||||
"github.com/status-im/status-go/protocol/transport"
|
||||
v1protocol "github.com/status-im/status-go/protocol/v1"
|
||||
)
|
||||
|
@ -262,13 +263,20 @@ func (p *MessageProcessor) SendPairInstallation(
|
|||
// All the events in a group are encoded and added to the payload
|
||||
func (p *MessageProcessor) EncodeMembershipUpdate(
|
||||
group *v1protocol.Group,
|
||||
chatEntity proto.Message,
|
||||
chatEntity ChatEntity,
|
||||
) ([]byte, error) {
|
||||
m := chatEntity.GetProtobuf().(*protobuf.ChatMessage)
|
||||
e := chatEntity.GetProtobuf().(*protobuf.EmojiReaction)
|
||||
|
||||
if m == nil && e == nil {
|
||||
return nil, errors.New("chat entity must be of type protobuf.ChatMessage or protobuf.EmojiReaction")
|
||||
}
|
||||
|
||||
message := v1protocol.MembershipUpdateMessage{
|
||||
ChatID: group.ChatID(),
|
||||
Events: group.Events(),
|
||||
Message: chatEntity,
|
||||
Message: m,
|
||||
EmojiReaction: e,
|
||||
}
|
||||
encodedMessage, err := v1protocol.EncodeMembershipUpdateMessage(message)
|
||||
if err != nil {
|
||||
|
|
|
@ -3401,7 +3401,7 @@ func (m *Messenger) encodeChatEntity(chat *Chat, message ChatEntity) ([]byte, er
|
|||
return nil, err
|
||||
}
|
||||
|
||||
encodedMessage, err = m.processor.EncodeMembershipUpdate(group, message.GetProtobuf())
|
||||
encodedMessage, err = m.processor.EncodeMembershipUpdate(group, message)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -20,9 +20,10 @@ import (
|
|||
// about group membership changes.
|
||||
// For more information, see https://github.com/status-im/specs/blob/master/status-group-chats-spec.md.
|
||||
type MembershipUpdateMessage struct {
|
||||
ChatID string `json:"chatId"` // UUID concatenated with hex-encoded public key of the creator for the chat
|
||||
Events []MembershipUpdateEvent `json:"events"`
|
||||
Message proto.Message `json:"-"`
|
||||
ChatID string `json:"chatId"` // UUID concatenated with hex-encoded public key of the creator for the chat
|
||||
Events []MembershipUpdateEvent `json:"events"`
|
||||
Message *protobuf.ChatMessage `json:"-"`
|
||||
EmojiReaction *protobuf.EmojiReaction `json:"-"`
|
||||
}
|
||||
|
||||
const signatureLength = 65
|
||||
|
@ -59,7 +60,7 @@ func MembershipUpdateEventFromProtobuf(chatID string, raw []byte) (*MembershipUp
|
|||
}, nil
|
||||
}
|
||||
|
||||
func (m *MembershipUpdateMessage) ToProtobuf() *protobuf.MembershipUpdateMessage {
|
||||
func (m *MembershipUpdateMessage) ToProtobuf() (*protobuf.MembershipUpdateMessage, error) {
|
||||
var rawEvents [][]byte
|
||||
for _, e := range m.Events {
|
||||
var encodedEvent []byte
|
||||
|
@ -67,13 +68,22 @@ func (m *MembershipUpdateMessage) ToProtobuf() *protobuf.MembershipUpdateMessage
|
|||
encodedEvent = append(encodedEvent, e.RawPayload...)
|
||||
rawEvents = append(rawEvents, encodedEvent)
|
||||
}
|
||||
return &protobuf.MembershipUpdateMessage{
|
||||
ChatId: m.ChatID,
|
||||
Events: rawEvents,
|
||||
|
||||
// TODO handle this
|
||||
Message: m.Message,
|
||||
mUM := &protobuf.MembershipUpdateMessage{
|
||||
ChatId: m.ChatID,
|
||||
Events: rawEvents,
|
||||
}
|
||||
|
||||
switch {
|
||||
case m.Message != nil:
|
||||
mUM.ChatEntity = &protobuf.MembershipUpdateMessage_Message{Message: m.Message}
|
||||
case m.EmojiReaction != nil:
|
||||
mUM.ChatEntity = &protobuf.MembershipUpdateMessage_EmojiReaction{EmojiReaction: m.EmojiReaction}
|
||||
default:
|
||||
return nil, errors.New("neither Message or EmojiReaction is set")
|
||||
}
|
||||
|
||||
return mUM, nil
|
||||
}
|
||||
|
||||
func MembershipUpdateMessageFromProtobuf(raw *protobuf.MembershipUpdateMessage) (*MembershipUpdateMessage, error) {
|
||||
|
@ -88,13 +98,18 @@ func MembershipUpdateMessageFromProtobuf(raw *protobuf.MembershipUpdateMessage)
|
|||
return &MembershipUpdateMessage{
|
||||
ChatID: raw.ChatId,
|
||||
Events: events,
|
||||
Message: raw.Message,
|
||||
Message: raw.GetMessage(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// EncodeMembershipUpdateMessage encodes a MembershipUpdateMessage using protobuf serialization.
|
||||
func EncodeMembershipUpdateMessage(value MembershipUpdateMessage) ([]byte, error) {
|
||||
return proto.Marshal(value.ToProtobuf())
|
||||
pb, err := value.ToProtobuf()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return proto.Marshal(pb)
|
||||
}
|
||||
|
||||
// MembershipUpdateEvent contains an event information.
|
||||
|
|
Loading…
Reference in New Issue