diff --git a/protocol/messenger_handler.go b/protocol/messenger_handler.go index 4180af5ec..6e860cc9e 100644 --- a/protocol/messenger_handler.go +++ b/protocol/messenger_handler.go @@ -121,8 +121,10 @@ func (m *Messenger) HandleMembershipUpdate(messageState *ReceivedMessageState, c wasUserAdded = true newChat := CreateGroupChat(messageState.Timesource) // We set group chat inactive and create a notification instead - // unless is coming from us or a contact or were waiting for approval - newChat.Active = isActive + // unless is coming from us or a contact or were waiting for approval. + // Also, as message MEMBER_JOINED may come from member(not creator, not our contact) + // reach earlier than CHAT_CREATED from creator, we need check if creator is our contact + newChat.Active = isActive || m.checkIfCreatorIsOurContact(group) newChat.ReceivedInvitationAdmin = senderID chat = &newChat @@ -213,6 +215,16 @@ func (m *Messenger) HandleMembershipUpdate(messageState *ReceivedMessageState, c return nil } +func (m *Messenger) checkIfCreatorIsOurContact(group *v1protocol.Group) bool { + creator, err := group.Creator() + if err == nil { + contact, _ := m.allContacts.Load(creator) + return contact != nil && contact.Added && contact.HasAddedUs + } + m.logger.Warn("failed to get creator from group", zap.String("group name", group.Name()), zap.String("group chat id", group.ChatID()), zap.Error(err)) + return false +} + func (m *Messenger) createMessageNotification(chat *Chat, messageState *ReceivedMessageState) { var notificationType ActivityCenterType diff --git a/protocol/v1/membership_update_message.go b/protocol/v1/membership_update_message.go index 5b1932755..40e3bc396 100644 --- a/protocol/v1/membership_update_message.go +++ b/protocol/v1/membership_update_message.go @@ -479,7 +479,7 @@ func (g Group) LastClockValue() uint64 { return g.events[len(g.events)-1].ClockValue } -func (g Group) creator() (string, error) { +func (g Group) Creator() (string, error) { if len(g.events) == 0 { return "", errors.New("no events in the group") } @@ -491,7 +491,7 @@ func (g Group) creator() (string, error) { } func (g Group) validateChatID(chatID string) bool { - creator, err := g.creator() + creator, err := g.Creator() if err != nil || creator == "" { return false } diff --git a/protocol/v1/membership_update_message_test.go b/protocol/v1/membership_update_message_test.go index e97b98a17..54a77a3a2 100644 --- a/protocol/v1/membership_update_message_test.go +++ b/protocol/v1/membership_update_message_test.go @@ -67,7 +67,7 @@ func TestGroupCreator(t *testing.T) { require.NoError(t, err) g, err := NewGroupWithCreator("abc", "#fa6565", 20, key) require.NoError(t, err) - creator, err := g.creator() + creator, err := g.Creator() require.NoError(t, err) require.Equal(t, publicKeyToString(&key.PublicKey), creator) }