diff --git a/protocol/communities/manager.go b/protocol/communities/manager.go index e31e170c8..788de4c36 100644 --- a/protocol/communities/manager.go +++ b/protocol/communities/manager.go @@ -317,6 +317,30 @@ func (m *Manager) InviteUserToCommunity(idString string, pk *ecdsa.PublicKey) (* return community, nil } +func (m *Manager) RemoveUserFromCommunity(idString string, pk *ecdsa.PublicKey) (*Community, error) { + community, err := m.GetByIDString(idString) + if err != nil { + return nil, err + } + if community == nil { + return nil, ErrOrgNotFound + } + + _, err = community.RemoveUserFromOrg(pk) + if err != nil { + return nil, err + } + + err = m.persistence.SaveCommunity(community) + if err != nil { + return nil, err + } + + m.publish(&Subscription{Community: community}) + + return community, nil +} + func (m *Manager) GetByIDString(idString string) (*Community, error) { id, err := types.DecodeHex(idString) if err != nil { diff --git a/protocol/messenger.go b/protocol/messenger.go index 91e19e2d0..ab7d75946 100644 --- a/protocol/messenger.go +++ b/protocol/messenger.go @@ -2043,6 +2043,22 @@ func (m *Messenger) InviteUserToCommunity(orgID, pkString string) (*MessengerRes }, nil } +func (m *Messenger) RemoveUserFromCommunity(orgID, pkString string) (*MessengerResponse, error) { + publicKey, err := common.HexToPubkey(pkString) + if err != nil { + return nil, err + } + + org, err := m.communitiesManager.RemoveUserFromCommunity(orgID, publicKey) + if err != nil { + return nil, err + } + + return &MessengerResponse{ + Communities: []*communities.Community{org}, + }, nil +} + func (m *Messenger) DeleteChat(chatID string) error { m.mutex.Lock() defer m.mutex.Unlock() diff --git a/services/ext/api.go b/services/ext/api.go index 0f8cb65ac..0347df96a 100644 --- a/services/ext/api.go +++ b/services/ext/api.go @@ -368,11 +368,16 @@ func (api *PublicAPI) CreateCommunityChat(orgID string, c *protobuf.CommunityCha return api.service.messenger.CreateCommunityChat(orgID, c) } -// InviteUserToCommunity invites the used with pk to the community with ID +// InviteUserToCommunity invites the user with pk to the community with ID func (api *PublicAPI) InviteUserToCommunity(orgID, userPublicKey string) (*protocol.MessengerResponse, error) { return api.service.messenger.InviteUserToCommunity(orgID, userPublicKey) } +// RemoveUserFromCommunity removes the user with pk from the community with ID +func (api *PublicAPI) RemoveUserFromCommunity(orgID, userPublicKey string) (*protocol.MessengerResponse, error) { + return api.service.messenger.RemoveUserFromCommunity(orgID, userPublicKey) +} + type ApplicationMessagesResponse struct { Messages []*common.Message `json:"messages"` Cursor string `json:"cursor"`