Remove user from community
This commit is contained in:
parent
a0d5f66c8f
commit
3be6d86326
|
@ -317,6 +317,30 @@ func (m *Manager) InviteUserToCommunity(idString string, pk *ecdsa.PublicKey) (*
|
||||||
return community, nil
|
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) {
|
func (m *Manager) GetByIDString(idString string) (*Community, error) {
|
||||||
id, err := types.DecodeHex(idString)
|
id, err := types.DecodeHex(idString)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -2043,6 +2043,22 @@ func (m *Messenger) InviteUserToCommunity(orgID, pkString string) (*MessengerRes
|
||||||
}, nil
|
}, 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 {
|
func (m *Messenger) DeleteChat(chatID string) error {
|
||||||
m.mutex.Lock()
|
m.mutex.Lock()
|
||||||
defer m.mutex.Unlock()
|
defer m.mutex.Unlock()
|
||||||
|
|
|
@ -368,11 +368,16 @@ func (api *PublicAPI) CreateCommunityChat(orgID string, c *protobuf.CommunityCha
|
||||||
return api.service.messenger.CreateCommunityChat(orgID, c)
|
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) {
|
func (api *PublicAPI) InviteUserToCommunity(orgID, userPublicKey string) (*protocol.MessengerResponse, error) {
|
||||||
return api.service.messenger.InviteUserToCommunity(orgID, userPublicKey)
|
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 {
|
type ApplicationMessagesResponse struct {
|
||||||
Messages []*common.Message `json:"messages"`
|
Messages []*common.Message `json:"messages"`
|
||||||
Cursor string `json:"cursor"`
|
Cursor string `json:"cursor"`
|
||||||
|
|
Loading…
Reference in New Issue