parent
cee5313e0e
commit
d1a4b53d5c
|
@ -114,10 +114,10 @@ func (m *Messenger) CreateGroupChatFromInvitation(name string, chatID string, ad
|
||||||
return &response, m.saveChat(&chat)
|
return &response, m.saveChat(&chat)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Messenger) RemoveMemberFromGroupChat(ctx context.Context, chatID string, member string) (*MessengerResponse, error) {
|
func (m *Messenger) RemoveMembersFromGroupChat(ctx context.Context, chatID string, members []string) (*MessengerResponse, error) {
|
||||||
var response MessengerResponse
|
var response MessengerResponse
|
||||||
logger := m.logger.With(zap.String("site", "RemoveMemberFromGroupChat"))
|
logger := m.logger.With(zap.String("site", "RemoveMembersFromGroupChat"))
|
||||||
logger.Info("Removing member form group chat", zap.String("chatID", chatID), zap.String("member", member))
|
logger.Info("Removing members form group chat", zap.String("chatID", chatID), zap.Any("members", members))
|
||||||
chat, ok := m.allChats.Load(chatID)
|
chat, ok := m.allChats.Load(chatID)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, ErrChatNotFound
|
return nil, ErrChatNotFound
|
||||||
|
@ -136,17 +136,20 @@ func (m *Messenger) RemoveMemberFromGroupChat(ctx context.Context, chatID string
|
||||||
}
|
}
|
||||||
|
|
||||||
clock, _ := chat.NextClockAndTimestamp(m.getTimesource())
|
clock, _ := chat.NextClockAndTimestamp(m.getTimesource())
|
||||||
// Remove member
|
|
||||||
event := v1protocol.NewMemberRemovedEvent(member, clock)
|
|
||||||
event.ChatID = chat.ID
|
|
||||||
err = event.Sign(m.identity)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = group.ProcessEvent(event)
|
for _, member := range members {
|
||||||
if err != nil {
|
// Remove member
|
||||||
return nil, err
|
event := v1protocol.NewMemberRemovedEvent(member, clock)
|
||||||
|
event.ChatID = chat.ID
|
||||||
|
err = event.Sign(m.identity)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = group.ProcessEvent(event)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
encodedMessage, err := m.sender.EncodeMembershipUpdate(group, nil)
|
encodedMessage, err := m.sender.EncodeMembershipUpdate(group, nil)
|
||||||
|
|
|
@ -255,20 +255,26 @@ func (s *MessengerGroupChatSuite) TestGroupChatMembersRemoval() {
|
||||||
admin := s.startNewMessenger()
|
admin := s.startNewMessenger()
|
||||||
memberA := s.startNewMessenger()
|
memberA := s.startNewMessenger()
|
||||||
memberB := s.startNewMessenger()
|
memberB := s.startNewMessenger()
|
||||||
members := []string{common.PubkeyToHex(&memberA.identity.PublicKey), common.PubkeyToHex(&memberB.identity.PublicKey)}
|
memberC := s.startNewMessenger()
|
||||||
|
members := []string{common.PubkeyToHex(&memberA.identity.PublicKey), common.PubkeyToHex(&memberB.identity.PublicKey),
|
||||||
|
common.PubkeyToHex(&memberC.identity.PublicKey)}
|
||||||
|
|
||||||
s.makeMutualContacts(admin, memberA)
|
s.makeMutualContacts(admin, memberA)
|
||||||
s.makeMutualContacts(admin, memberB)
|
s.makeMutualContacts(admin, memberB)
|
||||||
|
s.makeMutualContacts(admin, memberC)
|
||||||
|
|
||||||
groupChat := s.createGroupChat(admin, "test_group_chat", members)
|
groupChat := s.createGroupChat(admin, "test_group_chat", members)
|
||||||
s.verifyGroupChatCreated(memberA, true)
|
s.verifyGroupChatCreated(memberA, true)
|
||||||
s.verifyGroupChatCreated(memberB, true)
|
s.verifyGroupChatCreated(memberB, true)
|
||||||
|
s.verifyGroupChatCreated(memberC, true)
|
||||||
|
|
||||||
_, err := memberA.RemoveMemberFromGroupChat(context.Background(), groupChat.ID, common.PubkeyToHex(&memberB.identity.PublicKey))
|
_, err := memberA.RemoveMembersFromGroupChat(context.Background(), groupChat.ID, []string{common.PubkeyToHex(&memberB.identity.PublicKey),
|
||||||
|
common.PubkeyToHex(&memberC.identity.PublicKey)})
|
||||||
s.Require().Error(err)
|
s.Require().Error(err)
|
||||||
|
|
||||||
// only admin can remove members from the group
|
// only admin can remove members from the group
|
||||||
_, err = admin.RemoveMemberFromGroupChat(context.Background(), groupChat.ID, common.PubkeyToHex(&memberB.identity.PublicKey))
|
_, err = admin.RemoveMembersFromGroupChat(context.Background(), groupChat.ID, []string{common.PubkeyToHex(&memberB.identity.PublicKey),
|
||||||
|
common.PubkeyToHex(&memberC.identity.PublicKey)})
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
// ensure removal is propagated to other members
|
// ensure removal is propagated to other members
|
||||||
|
@ -285,6 +291,7 @@ func (s *MessengerGroupChatSuite) TestGroupChatMembersRemoval() {
|
||||||
defer s.NoError(admin.Shutdown())
|
defer s.NoError(admin.Shutdown())
|
||||||
defer s.NoError(memberA.Shutdown())
|
defer s.NoError(memberA.Shutdown())
|
||||||
defer s.NoError(memberB.Shutdown())
|
defer s.NoError(memberB.Shutdown())
|
||||||
|
defer s.NoError(memberC.Shutdown())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *MessengerGroupChatSuite) TestGroupChatEdit() {
|
func (s *MessengerGroupChatSuite) TestGroupChatEdit() {
|
||||||
|
|
|
@ -105,7 +105,7 @@ func (api *API) RemoveMember(ctx context.Context, communityID types.HexBytes, ch
|
||||||
}
|
}
|
||||||
|
|
||||||
return api.execAndGetGroupChatResponse(func() (*protocol.MessengerResponse, error) {
|
return api.execAndGetGroupChatResponse(func() (*protocol.MessengerResponse, error) {
|
||||||
return api.s.messenger.RemoveMemberFromGroupChat(ctx, chatID, member)
|
return api.s.messenger.RemoveMembersFromGroupChat(ctx, chatID, []string{member})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -219,7 +219,11 @@ func (api *PublicAPI) AddMembersToGroupChat(ctx Context, chatID string, members
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *PublicAPI) RemoveMemberFromGroupChat(ctx Context, chatID string, member string) (*protocol.MessengerResponse, error) {
|
func (api *PublicAPI) RemoveMemberFromGroupChat(ctx Context, chatID string, member string) (*protocol.MessengerResponse, error) {
|
||||||
return api.service.messenger.RemoveMemberFromGroupChat(ctx, chatID, member)
|
return api.service.messenger.RemoveMembersFromGroupChat(ctx, chatID, []string{member})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (api *PublicAPI) RemoveMembersFromGroupChat(ctx Context, chatID string, members []string) (*protocol.MessengerResponse, error) {
|
||||||
|
return api.service.messenger.RemoveMembersFromGroupChat(ctx, chatID, members)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *PublicAPI) AddAdminsToGroupChat(ctx Context, chatID string, members []string) (*protocol.MessengerResponse, error) {
|
func (api *PublicAPI) AddAdminsToGroupChat(ctx Context, chatID string, members []string) (*protocol.MessengerResponse, error) {
|
||||||
|
|
|
@ -289,7 +289,7 @@ func (api *NimbusPublicAPI) AddMembersToGroupChat(ctx Context, chatID string, me
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *NimbusPublicAPI) RemoveMemberFromGroupChat(ctx Context, chatID string, member string) (*protocol.MessengerResponse, error) {
|
func (api *NimbusPublicAPI) RemoveMemberFromGroupChat(ctx Context, chatID string, member string) (*protocol.MessengerResponse, error) {
|
||||||
return api.service.messenger.RemoveMemberFromGroupChat(ctx, chatID, member)
|
return api.service.messenger.RemoveMembersFromGroupChat(ctx, chatID, []string{member})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *NimbusPublicAPI) AddAdminsToGroupChat(ctx Context, chatID string, members []string) (*protocol.MessengerResponse, error) {
|
func (api *NimbusPublicAPI) AddAdminsToGroupChat(ctx Context, chatID string, members []string) (*protocol.MessengerResponse, error) {
|
||||||
|
|
Loading…
Reference in New Issue