fix: make the community id prefix optional in chat ids (#2273)

This commit is contained in:
RichΛrd 2021-07-02 14:07:49 -04:00 committed by GitHub
parent c799e5eb6b
commit 44fe606155
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 27 additions and 0 deletions

View File

@ -4,6 +4,7 @@ import (
"crypto/ecdsa" "crypto/ecdsa"
"database/sql" "database/sql"
"fmt" "fmt"
"strings"
"time" "time"
"github.com/golang/protobuf/proto" "github.com/golang/protobuf/proto"
@ -318,6 +319,12 @@ func (m *Manager) EditChat(communityID types.HexBytes, chatID string, chat *prot
if community == nil { if community == nil {
return nil, nil, ErrOrgNotFound return nil, nil, ErrOrgNotFound
} }
// Remove communityID prefix from chatID if exists
if strings.HasPrefix(chatID, communityID.String()) {
chatID = strings.TrimPrefix(chatID, communityID.String())
}
changes, err := community.EditChat(chatID, chat) changes, err := community.EditChat(chatID, chat)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
@ -343,6 +350,14 @@ func (m *Manager) CreateCategory(request *requests.CreateCommunityCategory) (*Co
return nil, nil, ErrOrgNotFound return nil, nil, ErrOrgNotFound
} }
categoryID := uuid.New().String() categoryID := uuid.New().String()
// Remove communityID prefix from chatID if exists
for i, cid := range request.ChatIDs {
if strings.HasPrefix(cid, request.CommunityID.String()) {
request.ChatIDs[i] = strings.TrimPrefix(cid, request.CommunityID.String())
}
}
changes, err := community.CreateCategory(categoryID, request.CategoryName, request.ChatIDs) changes, err := community.CreateCategory(categoryID, request.CategoryName, request.ChatIDs)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
@ -368,6 +383,13 @@ func (m *Manager) EditCategory(request *requests.EditCommunityCategory) (*Commun
return nil, nil, ErrOrgNotFound return nil, nil, ErrOrgNotFound
} }
// Remove communityID prefix from chatID if exists
for i, cid := range request.ChatIDs {
if strings.HasPrefix(cid, request.CommunityID.String()) {
request.ChatIDs[i] = strings.TrimPrefix(cid, request.CommunityID.String())
}
}
changes, err := community.EditCategory(request.CategoryID, request.CategoryName, request.ChatIDs) changes, err := community.EditCategory(request.CategoryID, request.CategoryName, request.ChatIDs)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
@ -418,6 +440,11 @@ func (m *Manager) ReorderChat(request *requests.ReorderCommunityChat) (*Communit
return nil, nil, ErrOrgNotFound return nil, nil, ErrOrgNotFound
} }
// Remove communityID prefix from chatID if exists
if strings.HasPrefix(request.ChatID, request.CommunityID.String()) {
request.ChatID = strings.TrimPrefix(request.ChatID, request.CommunityID.String())
}
changes, err := community.ReorderChat(request.CategoryID, request.ChatID, request.Position) changes, err := community.ReorderChat(request.CategoryID, request.ChatID, request.Position)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err