Skip to content

Commit

Permalink
Workaround ordering returned by GetPostThread API call
Browse files Browse the repository at this point in the history
  • Loading branch information
hloeung committed Apr 22, 2023
1 parent a69a19f commit 7eb2917
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions mm-go-irckit/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ func getChannelName(u *User, channelID string) string {
channelMembers := strings.Split(channelName, "__")

if len(channelMembers) != 2 {
return fmt.Sprintf("#%s", channelName)
return channelName
}

if channelMembers[0] == u.br.GetMe().User {
Expand Down Expand Up @@ -342,12 +342,27 @@ func scrollback(u *User, toUser *User, args []string, service string) {

postlist, _ := list.(*model.PostList)

for i := len(postlist.Order) - 1; i >= 0; i-- {
if limit != 0 && len(postlist.Order) > limit && i < len(postlist.Order)-limit {
// Workaround https://github.com/mattermost/mattermost-server/issues/23081
plOrder := postlist.Order
if searchPostID != "" {
plOrder = append(plOrder, searchPostID)
}
skipRoot := false

for i := len(plOrder) - 1; i >= 0; i-- {
if limit != 0 && len(plOrder) > limit && i < len(plOrder)-limit {
continue
}

p := postlist.Posts[postlist.Order[i]]
p := postlist.Posts[plOrder[i]]

// Workaround https://github.com/mattermost/mattermost-server/issues/23081
if searchPostID != "" && p.Id == searchPostID {
if skipRoot {
continue
}
skipRoot = true
}

props := p.GetProps()
botname, override := props["override_username"].(string)
Expand Down Expand Up @@ -387,6 +402,8 @@ func scrollback(u *User, toUser *User, args []string, service string) {
formatScrollbackMsg(u, channelID, search, scrollbackUser, nick, p, fileMsg)
}
}

u.MsgUser(toUser, fmt.Sprintf("scrollback results shown in %s", search))
}

func formatScrollbackMsg(u *User, channelID string, channel string, user *User, nick string, p *model.Post, msgText string) {
Expand Down

0 comments on commit 7eb2917

Please # to comment.