feat: add api to delete a community channel (#2266)
This commit is contained in:
parent
e4038df1ed
commit
151edb3607
|
@ -341,6 +341,35 @@ func (m *Manager) EditChat(communityID types.HexBytes, chatID string, chat *prot
|
|||
return community, changes, nil
|
||||
}
|
||||
|
||||
func (m *Manager) DeleteChat(communityID types.HexBytes, chatID string) (*Community, *protobuf.CommunityDescription, error) {
|
||||
community, err := m.GetByID(communityID)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
if community == nil {
|
||||
return nil, nil, ErrOrgNotFound
|
||||
}
|
||||
|
||||
// Remove communityID prefix from chatID if exists
|
||||
if strings.HasPrefix(chatID, communityID.String()) {
|
||||
chatID = strings.TrimPrefix(chatID, communityID.String())
|
||||
}
|
||||
description, err := community.DeleteChat(chatID)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
err = m.persistence.SaveCommunity(community)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
// Advertise changes
|
||||
m.publish(&Subscription{Community: community})
|
||||
|
||||
return community, description, nil
|
||||
}
|
||||
|
||||
func (m *Manager) CreateCategory(request *requests.CreateCommunityCategory) (*Community, *CommunityChanges, error) {
|
||||
community, err := m.GetByID(request.CommunityID)
|
||||
if err != nil {
|
||||
|
|
|
@ -454,6 +454,28 @@ func (m *Messenger) EditCommunityChat(communityID types.HexBytes, chatID string,
|
|||
return &response, m.saveChats(chats)
|
||||
}
|
||||
|
||||
func (m *Messenger) DeleteCommunityChat(communityID types.HexBytes, chatID string) (*MessengerResponse, error) {
|
||||
response := &MessengerResponse{}
|
||||
|
||||
community, _, err := m.communitiesManager.DeleteChat(communityID, chatID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = m.deleteChat(chatID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
response.AddRemovedChat(chatID)
|
||||
|
||||
_, err = m.transport.RemoveFilterByChatID(chatID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
response.AddCommunity(community)
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (m *Messenger) CreateCommunity(request *requests.CreateCommunity) (*MessengerResponse, error) {
|
||||
if err := request.Validate(); err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -379,11 +379,16 @@ func (api *PublicAPI) CreateCommunityChat(communityID types.HexBytes, c *protobu
|
|||
return api.service.messenger.CreateCommunityChat(communityID, c)
|
||||
}
|
||||
|
||||
// CreateCommunityChat creates a community chat in the given community
|
||||
// EditCommunityChat edits a community chat in the given community
|
||||
func (api *PublicAPI) EditCommunityChat(communityID types.HexBytes, chatID string, c *protobuf.CommunityChat) (*protocol.MessengerResponse, error) {
|
||||
return api.service.messenger.EditCommunityChat(communityID, chatID, c)
|
||||
}
|
||||
|
||||
// DeleteCommunityChat deletes a community chat in the given community
|
||||
func (api *PublicAPI) DeleteCommunityChat(communityID types.HexBytes, chatID string) (*protocol.MessengerResponse, error) {
|
||||
return api.service.messenger.DeleteCommunityChat(communityID, chatID)
|
||||
}
|
||||
|
||||
// InviteUsersToCommunity invites the users with pks to the community with ID
|
||||
func (api *PublicAPI) InviteUsersToCommunity(request *requests.InviteUsersToCommunity) (*protocol.MessengerResponse, error) {
|
||||
return api.service.messenger.InviteUsersToCommunity(request)
|
||||
|
|
Loading…
Reference in a new issue