From 17f91b3141d36156390323514cfc8717d407dbc8 Mon Sep 17 00:00:00 2001 From: Adam Babik Date: Mon, 9 Mar 2020 07:19:23 +0100 Subject: [PATCH] Clean up protocol package (#1890) --- protocol/chat_group_proxy.go | 2 +- protocol/message_handler.go | 2 +- protocol/messenger.go | 4 ++-- protocol/v1/membership_update_message.go | 12 ++++-------- 4 files changed, 8 insertions(+), 12 deletions(-) diff --git a/protocol/chat_group_proxy.go b/protocol/chat_group_proxy.go index 5e2c44964..a63cdb8e8 100644 --- a/protocol/chat_group_proxy.go +++ b/protocol/chat_group_proxy.go @@ -5,5 +5,5 @@ import ( ) func newProtocolGroupFromChat(chat *Chat) (*v1protocol.Group, error) { - return v1protocol.NewGroup(chat.ID, chat.MembershipUpdates) + return v1protocol.NewGroupWithEvents(chat.ID, chat.MembershipUpdates) } diff --git a/protocol/message_handler.go b/protocol/message_handler.go index 214712956..0d292a03b 100644 --- a/protocol/message_handler.go +++ b/protocol/message_handler.go @@ -79,7 +79,7 @@ func (m *MessageHandler) HandleMembershipUpdate(messageState *ReceivedMessageSta return errors.Wrap(err, "invalid membership update") } merged := v1protocol.MergeMembershipUpdateEvents(existingGroup.Events(), updateGroup.Events()) - group, err = v1protocol.NewGroup(chat.ID, merged) + group, err = v1protocol.NewGroupWithEvents(chat.ID, merged) if err != nil { return errors.Wrap(err, "failed to create a group with new membership updates") } diff --git a/protocol/messenger.go b/protocol/messenger.go index 57b6b1a64..1b6984835 100644 --- a/protocol/messenger.go +++ b/protocol/messenger.go @@ -1736,6 +1736,8 @@ func (m *Messenger) handleRetrievedMessages(chatWithMessages map[transport.Filte continue } + logger.Debug("processing messages further", zap.Int("count", len(statusMessages))) + for _, msg := range statusMessages { publicKey := msg.SigPubKey() @@ -1896,11 +1898,9 @@ func (m *Messenger) handleRetrievedMessages(chatWithMessages map[transport.Filte logger.Warn("failed to handle ContactUpdate", zap.Error(err)) continue } - default: // RawMessage, not processed here, pass straight to the client rawMessages[chat] = append(rawMessages[chat], msg) - } } else { logger.Debug("Adding raw message", zap.Any("msg", msg)) diff --git a/protocol/v1/membership_update_message.go b/protocol/v1/membership_update_message.go index 1e44da7e2..c688a8ea3 100644 --- a/protocol/v1/membership_update_message.go +++ b/protocol/v1/membership_update_message.go @@ -242,10 +242,6 @@ func NewGroupWithCreator(name string, clock uint64, creator *ecdsa.PrivateKey) ( return newGroup(chatID, []MembershipUpdateEvent{chatCreated}) } -func NewGroup(chatID string, events []MembershipUpdateEvent) (*Group, error) { - return newGroup(chatID, events) -} - func newGroup(chatID string, events []MembershipUpdateEvent) (*Group, error) { g := Group{ chatID: chatID, @@ -293,14 +289,14 @@ func (g Group) ChatID() string { return g.chatID } -func (g Group) Events() []MembershipUpdateEvent { - return g.events -} - func (g Group) Name() string { return g.name } +func (g Group) Events() []MembershipUpdateEvent { + return g.events +} + func (g Group) Members() []string { return g.members.List() }