fix: error reordering chats when destination category position is the same as original chatId position (#2448)
This commit is contained in:
parent
73c7ea57d1
commit
51a6d8ee7c
|
@ -254,7 +254,7 @@ func (o *Community) ReorderChat(categoryID string, chatID string, newPosition in
|
|||
changes := o.emptyCommunityChanges()
|
||||
|
||||
o.SortCategoryChats(changes, oldCategoryID)
|
||||
o.insertAndSort(changes, categoryID, chat, newPosition)
|
||||
o.insertAndSort(changes, oldCategoryID, categoryID, chatID, chat, newPosition)
|
||||
|
||||
o.increaseClock()
|
||||
|
||||
|
@ -295,7 +295,7 @@ func (o *Community) SortCategoryChats(changes *CommunityChanges, categoryID stri
|
|||
}
|
||||
}
|
||||
|
||||
func (o *Community) insertAndSort(changes *CommunityChanges, categoryID string, chat *protobuf.CommunityChat, newPosition int) {
|
||||
func (o *Community) insertAndSort(changes *CommunityChanges, oldCategoryID string, categoryID string, chatID string, chat *protobuf.CommunityChat, newPosition int) {
|
||||
// We sort the chats here because maps are not guaranteed to keep order
|
||||
var catChats []string
|
||||
sortedChats := make(sortSlice, 0, len(o.config.CommunityDescription.Chats))
|
||||
|
@ -318,15 +318,25 @@ func (o *Community) insertAndSort(changes *CommunityChanges, categoryID string,
|
|||
newPosition = 0
|
||||
}
|
||||
|
||||
if int32(newPosition) == chat.Position {
|
||||
return
|
||||
}
|
||||
|
||||
decrease := false
|
||||
if chat.Position > int32(newPosition) {
|
||||
decrease = true
|
||||
}
|
||||
|
||||
for k, v := range o.config.CommunityDescription.Chats {
|
||||
if k != chatID && newPosition == int(v.Position) && v.CategoryId == categoryID {
|
||||
if oldCategoryID == categoryID {
|
||||
if decrease {
|
||||
v.Position++
|
||||
} else {
|
||||
v.Position--
|
||||
}
|
||||
} else {
|
||||
v.Position++
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
idx := -1
|
||||
currChatID := ""
|
||||
var sortedChatIDs []string
|
||||
|
|
Loading…
Reference in New Issue