2022-08-26 09:25:54 +00:00
|
|
|
package protocol
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"crypto/ecdsa"
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
2023-08-09 17:07:28 +00:00
|
|
|
"github.com/golang/protobuf/proto"
|
2022-08-26 09:25:54 +00:00
|
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
|
2022-08-29 14:07:32 +00:00
|
|
|
userimage "github.com/status-im/status-go/images"
|
2024-04-03 14:49:57 +00:00
|
|
|
multiaccountscommon "github.com/status-im/status-go/multiaccounts/common"
|
|
|
|
|
2023-10-25 18:11:04 +00:00
|
|
|
"github.com/status-im/status-go/multiaccounts/settings"
|
2022-08-26 09:25:54 +00:00
|
|
|
"github.com/status-im/status-go/protocol/common"
|
2023-03-07 14:38:09 +00:00
|
|
|
"github.com/status-im/status-go/protocol/protobuf"
|
2022-08-26 09:25:54 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestGroupChatSuite(t *testing.T) {
|
|
|
|
suite.Run(t, new(MessengerGroupChatSuite))
|
|
|
|
}
|
|
|
|
|
|
|
|
type MessengerGroupChatSuite struct {
|
2023-07-13 10:28:34 +00:00
|
|
|
MessengerBaseTestSuite
|
2022-08-26 09:25:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MessengerGroupChatSuite) createGroupChat(creator *Messenger, name string, members []string) *Chat {
|
|
|
|
response, err := creator.CreateGroupChatWithMembers(context.Background(), name, members)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(response.Chats(), 1)
|
|
|
|
|
|
|
|
chat := response.Chats()[0]
|
|
|
|
err = creator.SaveChat(chat)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
return chat
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MessengerGroupChatSuite) createEmptyGroupChat(creator *Messenger, name string) *Chat {
|
|
|
|
return s.createGroupChat(creator, name, []string{})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MessengerGroupChatSuite) verifyGroupChatCreated(member *Messenger, expectedChatActive bool) {
|
|
|
|
response, err := WaitOnMessengerResponse(
|
|
|
|
member,
|
2022-12-09 16:16:21 +00:00
|
|
|
func(r *MessengerResponse) bool {
|
|
|
|
return len(r.Chats()) == 1 && r.Chats()[0].Active == expectedChatActive
|
|
|
|
},
|
2022-08-26 09:25:54 +00:00
|
|
|
"chat invitation not received",
|
|
|
|
)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(response.Chats(), 1)
|
|
|
|
s.Require().True(response.Chats()[0].Active == expectedChatActive)
|
|
|
|
}
|
|
|
|
|
|
|
|
func makeMutualContact(origin *Messenger, contactPubkey *ecdsa.PublicKey) error {
|
|
|
|
contact, err := BuildContactFromPublicKey(contactPubkey)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2023-01-20 14:28:30 +00:00
|
|
|
contact.ContactRequestLocalState = ContactRequestStateSent
|
|
|
|
contact.ContactRequestRemoteState = ContactRequestStateReceived
|
2022-08-26 09:25:54 +00:00
|
|
|
origin.allContacts.Store(contact.ID, contact)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MessengerGroupChatSuite) makeContact(origin *Messenger, toAdd *Messenger) {
|
|
|
|
s.Require().NoError(makeMutualContact(origin, &toAdd.identity.PublicKey))
|
|
|
|
}
|
|
|
|
|
2022-08-29 14:07:32 +00:00
|
|
|
func (s *MessengerGroupChatSuite) makeMutualContacts(lhs *Messenger, rhs *Messenger) {
|
|
|
|
s.makeContact(lhs, rhs)
|
|
|
|
s.makeContact(rhs, lhs)
|
|
|
|
}
|
|
|
|
|
2022-08-26 09:25:54 +00:00
|
|
|
func (s *MessengerGroupChatSuite) TestGroupChatCreation() {
|
|
|
|
testCases := []struct {
|
|
|
|
name string
|
|
|
|
creatorAddedMemberAsContact bool
|
|
|
|
memberAddedCreatorAsContact bool
|
|
|
|
expectedCreationSuccess bool
|
|
|
|
expectedAddedMemberChatActive bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "not added - not added",
|
|
|
|
creatorAddedMemberAsContact: false,
|
|
|
|
memberAddedCreatorAsContact: false,
|
|
|
|
expectedCreationSuccess: false,
|
|
|
|
expectedAddedMemberChatActive: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "added - not added",
|
|
|
|
creatorAddedMemberAsContact: true,
|
|
|
|
memberAddedCreatorAsContact: false,
|
|
|
|
expectedCreationSuccess: true,
|
|
|
|
expectedAddedMemberChatActive: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "not added - added",
|
|
|
|
creatorAddedMemberAsContact: false,
|
|
|
|
memberAddedCreatorAsContact: true,
|
|
|
|
expectedCreationSuccess: false,
|
|
|
|
expectedAddedMemberChatActive: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "added - added",
|
|
|
|
creatorAddedMemberAsContact: true,
|
|
|
|
memberAddedCreatorAsContact: true,
|
|
|
|
expectedCreationSuccess: true,
|
|
|
|
expectedAddedMemberChatActive: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, testCase := range testCases {
|
2024-02-26 09:12:37 +00:00
|
|
|
creator := s.newMessenger()
|
|
|
|
member := s.newMessenger()
|
2022-08-26 09:25:54 +00:00
|
|
|
members := []string{common.PubkeyToHex(&member.identity.PublicKey)}
|
|
|
|
|
|
|
|
if testCase.creatorAddedMemberAsContact {
|
|
|
|
s.makeContact(creator, member)
|
|
|
|
}
|
|
|
|
if testCase.memberAddedCreatorAsContact {
|
|
|
|
s.makeContact(member, creator)
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err := creator.CreateGroupChatWithMembers(context.Background(), fmt.Sprintf("test_group_chat_%d", i), members)
|
|
|
|
if testCase.creatorAddedMemberAsContact {
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.verifyGroupChatCreated(member, testCase.expectedAddedMemberChatActive)
|
|
|
|
} else {
|
|
|
|
s.Require().EqualError(err, "group-chat: can't add members who are not mutual contacts")
|
|
|
|
}
|
|
|
|
|
2022-08-29 14:07:32 +00:00
|
|
|
defer s.NoError(creator.Shutdown())
|
|
|
|
defer s.NoError(member.Shutdown())
|
2022-08-26 09:25:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MessengerGroupChatSuite) TestGroupChatMembersAddition() {
|
|
|
|
testCases := []struct {
|
|
|
|
name string
|
|
|
|
inviterAddedMemberAsContact bool
|
|
|
|
memberAddedInviterAsContact bool
|
|
|
|
expectedAdditionSuccess bool
|
|
|
|
expectedAddedMemberChatActive bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "not added - not added",
|
|
|
|
inviterAddedMemberAsContact: false,
|
|
|
|
memberAddedInviterAsContact: false,
|
|
|
|
expectedAdditionSuccess: false,
|
|
|
|
expectedAddedMemberChatActive: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "added - not added",
|
|
|
|
inviterAddedMemberAsContact: true,
|
|
|
|
memberAddedInviterAsContact: false,
|
|
|
|
expectedAdditionSuccess: true,
|
|
|
|
expectedAddedMemberChatActive: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "not added - added",
|
|
|
|
inviterAddedMemberAsContact: false,
|
|
|
|
memberAddedInviterAsContact: true,
|
|
|
|
expectedAdditionSuccess: false,
|
|
|
|
expectedAddedMemberChatActive: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "added - added",
|
|
|
|
inviterAddedMemberAsContact: true,
|
|
|
|
memberAddedInviterAsContact: true,
|
|
|
|
expectedAdditionSuccess: true,
|
|
|
|
expectedAddedMemberChatActive: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, testCase := range testCases {
|
2024-02-26 09:12:37 +00:00
|
|
|
admin := s.newMessenger()
|
|
|
|
inviter := s.newMessenger()
|
|
|
|
member := s.newMessenger()
|
2022-08-26 09:25:54 +00:00
|
|
|
members := []string{common.PubkeyToHex(&member.identity.PublicKey)}
|
|
|
|
|
|
|
|
if testCase.inviterAddedMemberAsContact {
|
|
|
|
s.makeContact(inviter, member)
|
|
|
|
}
|
|
|
|
if testCase.memberAddedInviterAsContact {
|
|
|
|
s.makeContact(member, inviter)
|
|
|
|
}
|
|
|
|
|
|
|
|
for j, inviterIsAlsoGroupCreator := range []bool{true, false} {
|
|
|
|
var groupChat *Chat
|
|
|
|
if inviterIsAlsoGroupCreator {
|
|
|
|
groupChat = s.createEmptyGroupChat(inviter, fmt.Sprintf("test_group_chat_%d_%d", i, j))
|
|
|
|
} else {
|
|
|
|
s.makeContact(admin, inviter)
|
|
|
|
groupChat = s.createGroupChat(admin, fmt.Sprintf("test_group_chat_%d_%d", i, j), []string{common.PubkeyToHex(&inviter.identity.PublicKey)})
|
|
|
|
err := inviter.SaveChat(groupChat)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err := inviter.AddMembersToGroupChat(context.Background(), groupChat.ID, members)
|
|
|
|
if testCase.inviterAddedMemberAsContact {
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.verifyGroupChatCreated(member, testCase.expectedAddedMemberChatActive)
|
|
|
|
} else {
|
|
|
|
s.Require().EqualError(err, "group-chat: can't add members who are not mutual contacts")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-29 14:07:32 +00:00
|
|
|
defer s.NoError(admin.Shutdown())
|
|
|
|
defer s.NoError(inviter.Shutdown())
|
|
|
|
defer s.NoError(member.Shutdown())
|
2022-08-26 09:25:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-29 14:07:32 +00:00
|
|
|
func (s *MessengerGroupChatSuite) TestGroupChatMembersRemoval() {
|
2024-02-26 09:12:37 +00:00
|
|
|
admin := s.newMessenger()
|
|
|
|
memberA := s.newMessenger()
|
|
|
|
memberB := s.newMessenger()
|
|
|
|
memberC := s.newMessenger()
|
2022-12-10 04:26:51 +00:00
|
|
|
members := []string{common.PubkeyToHex(&memberA.identity.PublicKey), common.PubkeyToHex(&memberB.identity.PublicKey),
|
|
|
|
common.PubkeyToHex(&memberC.identity.PublicKey)}
|
2022-08-29 14:07:32 +00:00
|
|
|
|
|
|
|
s.makeMutualContacts(admin, memberA)
|
|
|
|
s.makeMutualContacts(admin, memberB)
|
2022-12-10 04:26:51 +00:00
|
|
|
s.makeMutualContacts(admin, memberC)
|
2022-08-29 14:07:32 +00:00
|
|
|
|
|
|
|
groupChat := s.createGroupChat(admin, "test_group_chat", members)
|
|
|
|
s.verifyGroupChatCreated(memberA, true)
|
|
|
|
s.verifyGroupChatCreated(memberB, true)
|
2022-12-10 04:26:51 +00:00
|
|
|
s.verifyGroupChatCreated(memberC, true)
|
2022-08-29 14:07:32 +00:00
|
|
|
|
2022-12-10 04:26:51 +00:00
|
|
|
_, err := memberA.RemoveMembersFromGroupChat(context.Background(), groupChat.ID, []string{common.PubkeyToHex(&memberB.identity.PublicKey),
|
|
|
|
common.PubkeyToHex(&memberC.identity.PublicKey)})
|
2022-08-29 14:07:32 +00:00
|
|
|
s.Require().Error(err)
|
|
|
|
|
|
|
|
// only admin can remove members from the group
|
2022-12-10 04:26:51 +00:00
|
|
|
_, err = admin.RemoveMembersFromGroupChat(context.Background(), groupChat.ID, []string{common.PubkeyToHex(&memberB.identity.PublicKey),
|
|
|
|
common.PubkeyToHex(&memberC.identity.PublicKey)})
|
2022-08-29 14:07:32 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
// ensure removal is propagated to other members
|
|
|
|
response, err := WaitOnMessengerResponse(
|
|
|
|
memberA,
|
|
|
|
func(r *MessengerResponse) bool { return len(r.Chats()) > 0 },
|
|
|
|
"chat invitation not received",
|
|
|
|
)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(response.Chats(), 1)
|
|
|
|
s.Require().True(response.Chats()[0].Active)
|
|
|
|
s.Require().Len(response.Chats()[0].Members, 2)
|
|
|
|
|
|
|
|
defer s.NoError(admin.Shutdown())
|
|
|
|
defer s.NoError(memberA.Shutdown())
|
|
|
|
defer s.NoError(memberB.Shutdown())
|
2022-12-10 04:26:51 +00:00
|
|
|
defer s.NoError(memberC.Shutdown())
|
2022-08-29 14:07:32 +00:00
|
|
|
}
|
|
|
|
|
2022-08-26 09:25:54 +00:00
|
|
|
func (s *MessengerGroupChatSuite) TestGroupChatEdit() {
|
2024-02-26 09:12:37 +00:00
|
|
|
admin := s.newMessenger()
|
|
|
|
member := s.newMessenger()
|
2022-08-29 14:07:32 +00:00
|
|
|
s.makeMutualContacts(admin, member)
|
|
|
|
|
|
|
|
groupChat := s.createGroupChat(admin, "test_group_chat", []string{common.PubkeyToHex(&member.identity.PublicKey)})
|
|
|
|
s.verifyGroupChatCreated(member, true)
|
|
|
|
|
|
|
|
response, err := admin.EditGroupChat(context.Background(), groupChat.ID, "test_admin_group", "#FF00FF", userimage.CroppedImage{})
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(response.Chats(), 1)
|
|
|
|
s.Require().Equal("test_admin_group", response.Chats()[0].Name)
|
|
|
|
s.Require().Equal("#FF00FF", response.Chats()[0].Color)
|
|
|
|
// TODO: handle image
|
|
|
|
|
|
|
|
// ensure group edit is propagated to other members
|
|
|
|
response, err = WaitOnMessengerResponse(
|
|
|
|
member,
|
|
|
|
func(r *MessengerResponse) bool { return len(r.Chats()) > 0 },
|
|
|
|
"chat invitation not received",
|
|
|
|
)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(response.Chats(), 1)
|
|
|
|
s.Require().Equal("test_admin_group", response.Chats()[0].Name)
|
|
|
|
s.Require().Equal("#FF00FF", response.Chats()[0].Color)
|
|
|
|
|
|
|
|
response, err = member.EditGroupChat(context.Background(), groupChat.ID, "test_member_group", "#F0F0F0", userimage.CroppedImage{})
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(response.Chats(), 1)
|
|
|
|
s.Require().Equal("test_member_group", response.Chats()[0].Name)
|
|
|
|
s.Require().Equal("#F0F0F0", response.Chats()[0].Color)
|
|
|
|
|
|
|
|
// ensure group edit is propagated to other members
|
|
|
|
response, err = WaitOnMessengerResponse(
|
|
|
|
admin,
|
|
|
|
func(r *MessengerResponse) bool { return len(r.Chats()) > 0 },
|
|
|
|
"chat invitation not received",
|
|
|
|
)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(response.Chats(), 1)
|
|
|
|
s.Require().Equal("test_member_group", response.Chats()[0].Name)
|
|
|
|
s.Require().Equal("#F0F0F0", response.Chats()[0].Color)
|
2022-08-26 09:25:54 +00:00
|
|
|
|
2022-11-17 18:11:07 +00:00
|
|
|
inputMessage := buildTestMessage(*groupChat)
|
|
|
|
|
|
|
|
_, err = admin.SendChatMessage(context.Background(), inputMessage)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
response, err = WaitOnMessengerResponse(
|
|
|
|
member,
|
|
|
|
func(r *MessengerResponse) bool { return len(r.Messages()) > 0 },
|
|
|
|
"chat invitation not received",
|
|
|
|
)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(response.Messages(), 1)
|
|
|
|
s.Require().Equal(inputMessage.Text, response.Messages()[0].Text)
|
|
|
|
|
2022-08-29 14:07:32 +00:00
|
|
|
defer s.NoError(admin.Shutdown())
|
|
|
|
defer s.NoError(member.Shutdown())
|
2022-08-26 09:25:54 +00:00
|
|
|
}
|
2023-03-07 14:38:09 +00:00
|
|
|
|
|
|
|
func (s *MessengerGroupChatSuite) TestGroupChatDeleteMemberMessage() {
|
2024-02-26 09:12:37 +00:00
|
|
|
admin := s.newMessenger()
|
|
|
|
member := s.newMessenger()
|
2023-03-07 14:38:09 +00:00
|
|
|
s.makeMutualContacts(admin, member)
|
|
|
|
|
|
|
|
groupChat := s.createGroupChat(admin, "test_group_chat", []string{common.PubkeyToHex(&member.identity.PublicKey)})
|
|
|
|
s.verifyGroupChatCreated(member, true)
|
|
|
|
|
|
|
|
ctx := context.Background()
|
|
|
|
inputMessage := buildTestMessage(*groupChat)
|
|
|
|
_, err := member.SendChatMessage(ctx, inputMessage)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
response, err := WaitOnMessengerResponse(
|
|
|
|
admin,
|
|
|
|
func(r *MessengerResponse) bool { return len(r.Messages()) > 0 },
|
|
|
|
"messages not received",
|
|
|
|
)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(response.Messages(), 1)
|
|
|
|
s.Require().Equal(inputMessage.Text, response.Messages()[0].Text)
|
|
|
|
|
|
|
|
message := response.Messages()[0]
|
|
|
|
deleteMessageResponse, err := admin.DeleteMessageAndSend(ctx, message.ID)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
_, err = WaitOnMessengerResponse(member, func(response *MessengerResponse) bool {
|
|
|
|
return len(response.RemovedMessages()) > 0
|
|
|
|
}, "removed messages not received")
|
|
|
|
s.Require().Equal(deleteMessageResponse.RemovedMessages()[0].DeletedBy, contactIDFromPublicKey(admin.IdentityPublicKey()))
|
|
|
|
s.Require().NoError(err)
|
|
|
|
message, err = member.MessageByID(message.ID)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().True(message.Deleted)
|
|
|
|
|
|
|
|
defer s.NoError(admin.Shutdown())
|
|
|
|
defer s.NoError(member.Shutdown())
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MessengerGroupChatSuite) TestGroupChatHandleDeleteMemberMessage() {
|
2024-02-26 09:12:37 +00:00
|
|
|
admin := s.newMessenger()
|
|
|
|
member := s.newMessenger()
|
2023-03-07 14:38:09 +00:00
|
|
|
s.makeMutualContacts(admin, member)
|
|
|
|
|
|
|
|
groupChat := s.createGroupChat(admin, "test_group_chat", []string{common.PubkeyToHex(&member.identity.PublicKey)})
|
|
|
|
s.verifyGroupChatCreated(member, true)
|
|
|
|
|
|
|
|
ctx := context.Background()
|
|
|
|
inputMessage := buildTestMessage(*groupChat)
|
|
|
|
_, err := member.SendChatMessage(ctx, inputMessage)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
response, err := WaitOnMessengerResponse(
|
|
|
|
admin,
|
|
|
|
func(r *MessengerResponse) bool { return len(r.Messages()) > 0 },
|
|
|
|
"messages not received",
|
|
|
|
)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(response.Messages(), 1)
|
|
|
|
s.Require().Equal(inputMessage.Text, response.Messages()[0].Text)
|
|
|
|
|
2023-08-18 11:39:59 +00:00
|
|
|
deleteMessage := &DeleteMessage{
|
|
|
|
DeleteMessage: &protobuf.DeleteMessage{
|
2023-03-07 14:38:09 +00:00
|
|
|
Clock: 2,
|
|
|
|
MessageType: protobuf.MessageType_PRIVATE_GROUP,
|
|
|
|
MessageId: inputMessage.ID,
|
|
|
|
ChatId: groupChat.ID,
|
|
|
|
},
|
|
|
|
From: common.PubkeyToHex(&admin.identity.PublicKey),
|
|
|
|
}
|
|
|
|
|
|
|
|
state := &ReceivedMessageState{
|
|
|
|
Response: &MessengerResponse{},
|
|
|
|
}
|
|
|
|
|
2023-08-18 11:39:59 +00:00
|
|
|
err = member.handleDeleteMessage(state, deleteMessage)
|
2023-03-07 14:38:09 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
removedMessages := state.Response.RemovedMessages()
|
|
|
|
s.Require().Len(removedMessages, 1)
|
|
|
|
s.Require().Equal(removedMessages[0].MessageID, inputMessage.ID)
|
|
|
|
|
|
|
|
defer s.NoError(admin.Shutdown())
|
|
|
|
defer s.NoError(member.Shutdown())
|
|
|
|
}
|
2023-08-09 17:07:28 +00:00
|
|
|
|
|
|
|
func (s *MessengerGroupChatSuite) TestGroupChatMembersRemovalOutOfOrder() {
|
2024-02-26 09:12:37 +00:00
|
|
|
admin := s.newMessenger()
|
|
|
|
memberA := s.newMessenger()
|
2023-08-09 17:07:28 +00:00
|
|
|
members := []string{common.PubkeyToHex(&memberA.identity.PublicKey)}
|
|
|
|
|
|
|
|
s.makeMutualContacts(admin, memberA)
|
|
|
|
|
|
|
|
groupChat := s.createGroupChat(admin, "test_group_chat", members)
|
|
|
|
|
|
|
|
removeMembersResponse, err := admin.removeMembersFromGroupChat(context.Background(), groupChat, []string{common.PubkeyToHex(&memberA.identity.PublicKey)})
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
encodedMessage := removeMembersResponse.encodedProtobuf
|
|
|
|
|
|
|
|
message := protobuf.MembershipUpdateMessage{}
|
|
|
|
err = proto.Unmarshal(encodedMessage, &message)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
response := &MessengerResponse{}
|
|
|
|
|
|
|
|
messageState := &ReceivedMessageState{
|
|
|
|
ExistingMessagesMap: make(map[string]bool),
|
|
|
|
Response: response,
|
|
|
|
AllChats: new(chatMap),
|
|
|
|
Timesource: memberA.getTimesource(),
|
|
|
|
}
|
|
|
|
|
|
|
|
c, err := buildContact(admin.myHexIdentity(), &admin.identity.PublicKey)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
messageState.CurrentMessageState = &CurrentMessageState{
|
|
|
|
Contact: c,
|
|
|
|
}
|
|
|
|
|
|
|
|
err = memberA.HandleMembershipUpdate(messageState, nil, &message, memberA.systemMessagesTranslations)
|
|
|
|
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().NotNil(messageState.Response)
|
|
|
|
s.Require().Len(messageState.Response.Chats(), 1)
|
|
|
|
s.Require().Len(messageState.Response.Chats()[0].Members, 1)
|
|
|
|
defer s.NoError(admin.Shutdown())
|
|
|
|
defer s.NoError(memberA.Shutdown())
|
|
|
|
}
|
2023-10-25 18:11:04 +00:00
|
|
|
|
|
|
|
func (s *MessengerGroupChatSuite) TestGroupChatMembersInfoSync() {
|
2024-02-26 09:12:37 +00:00
|
|
|
admin, memberA, memberB := s.newMessenger(), s.newMessenger(), s.newMessenger()
|
2024-04-03 14:49:57 +00:00
|
|
|
memberB.account.CustomizationColor = multiaccountscommon.CustomizationColorBlue
|
2023-10-25 18:11:04 +00:00
|
|
|
s.Require().NoError(admin.settings.SaveSettingField(settings.DisplayName, "admin"))
|
|
|
|
s.Require().NoError(memberA.settings.SaveSettingField(settings.DisplayName, "memberA"))
|
|
|
|
s.Require().NoError(memberB.settings.SaveSettingField(settings.DisplayName, "memberB"))
|
|
|
|
|
|
|
|
members := []string{common.PubkeyToHex(&memberA.identity.PublicKey), common.PubkeyToHex(&memberB.identity.PublicKey)}
|
|
|
|
|
|
|
|
s.makeMutualContacts(admin, memberA)
|
|
|
|
s.makeMutualContacts(admin, memberB)
|
|
|
|
|
|
|
|
s.createGroupChat(admin, "test_group_chat", members)
|
|
|
|
s.verifyGroupChatCreated(memberA, true)
|
|
|
|
s.verifyGroupChatCreated(memberB, true)
|
|
|
|
|
|
|
|
response, err := WaitOnMessengerResponse(
|
|
|
|
memberA,
|
|
|
|
func(r *MessengerResponse) bool { return len(r.Chats()) > 0 },
|
|
|
|
"chat invitation not received",
|
|
|
|
)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(response.Chats(), 1)
|
|
|
|
s.Require().True(response.Chats()[0].Active)
|
|
|
|
s.Require().Len(response.Chats()[0].Members, 3)
|
|
|
|
|
|
|
|
_, err = WaitOnMessengerResponse(
|
|
|
|
memberA,
|
|
|
|
func(r *MessengerResponse) bool {
|
|
|
|
// we republish as we don't have store nodes in tests
|
|
|
|
err := memberB.publishContactCode()
|
|
|
|
if err != nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
contact, ok := memberA.allContacts.Load(common.PubkeyToHex(&memberB.identity.PublicKey))
|
2024-04-03 14:49:57 +00:00
|
|
|
return ok && contact.DisplayName == "memberB" && contact.CustomizationColor == memberB.account.GetCustomizationColor()
|
2023-10-25 18:11:04 +00:00
|
|
|
},
|
|
|
|
"DisplayName is not the same",
|
|
|
|
)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
s.NoError(admin.Shutdown())
|
|
|
|
s.NoError(memberA.Shutdown())
|
|
|
|
s.NoError(memberB.Shutdown())
|
|
|
|
}
|