fix TestGroupChatMembersRemoval sometimes failed (#3037)
This commit is contained in:
parent
7d04be3613
commit
fe2270540e
|
@ -121,8 +121,10 @@ func (m *Messenger) HandleMembershipUpdate(messageState *ReceivedMessageState, c
|
||||||
wasUserAdded = true
|
wasUserAdded = true
|
||||||
newChat := CreateGroupChat(messageState.Timesource)
|
newChat := CreateGroupChat(messageState.Timesource)
|
||||||
// We set group chat inactive and create a notification instead
|
// We set group chat inactive and create a notification instead
|
||||||
// unless is coming from us or a contact or were waiting for approval
|
// unless is coming from us or a contact or were waiting for approval.
|
||||||
newChat.Active = isActive
|
// 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
|
newChat.ReceivedInvitationAdmin = senderID
|
||||||
chat = &newChat
|
chat = &newChat
|
||||||
|
|
||||||
|
@ -213,6 +215,16 @@ func (m *Messenger) HandleMembershipUpdate(messageState *ReceivedMessageState, c
|
||||||
return nil
|
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) {
|
func (m *Messenger) createMessageNotification(chat *Chat, messageState *ReceivedMessageState) {
|
||||||
|
|
||||||
var notificationType ActivityCenterType
|
var notificationType ActivityCenterType
|
||||||
|
|
|
@ -479,7 +479,7 @@ func (g Group) LastClockValue() uint64 {
|
||||||
return g.events[len(g.events)-1].ClockValue
|
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 {
|
if len(g.events) == 0 {
|
||||||
return "", errors.New("no events in the group")
|
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 {
|
func (g Group) validateChatID(chatID string) bool {
|
||||||
creator, err := g.creator()
|
creator, err := g.Creator()
|
||||||
if err != nil || creator == "" {
|
if err != nil || creator == "" {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,7 +67,7 @@ func TestGroupCreator(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
g, err := NewGroupWithCreator("abc", "#fa6565", 20, key)
|
g, err := NewGroupWithCreator("abc", "#fa6565", 20, key)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
creator, err := g.creator()
|
creator, err := g.Creator()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, publicKeyToString(&key.PublicKey), creator)
|
require.Equal(t, publicKeyToString(&key.PublicKey), creator)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue