fix: make the community id prefix optional in chat ids (#2273)
This commit is contained in:
parent
c799e5eb6b
commit
44fe606155
|
@ -4,6 +4,7 @@ import (
|
|||
"crypto/ecdsa"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/golang/protobuf/proto"
|
||||
|
@ -318,6 +319,12 @@ func (m *Manager) EditChat(communityID types.HexBytes, chatID string, chat *prot
|
|||
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())
|
||||
}
|
||||
|
||||
changes, err := community.EditChat(chatID, chat)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
|
@ -343,6 +350,14 @@ func (m *Manager) CreateCategory(request *requests.CreateCommunityCategory) (*Co
|
|||
return nil, nil, ErrOrgNotFound
|
||||
}
|
||||
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)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
|
@ -368,6 +383,13 @@ func (m *Manager) EditCategory(request *requests.EditCommunityCategory) (*Commun
|
|||
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)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
|
@ -418,6 +440,11 @@ func (m *Manager) ReorderChat(request *requests.ReorderCommunityChat) (*Communit
|
|||
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)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
|
|
Loading…
Reference in New Issue