From 7eb291772b8117b6de5af124934af2b273d8c72c Mon Sep 17 00:00:00 2001 From: Haw Loeung Date: Sun, 23 Apr 2023 09:02:03 +1000 Subject: [PATCH] Workaround ordering returned by GetPostThread API call --- mm-go-irckit/service.go | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/mm-go-irckit/service.go b/mm-go-irckit/service.go index 1b3bbcef..5b1e2ddd 100644 --- a/mm-go-irckit/service.go +++ b/mm-go-irckit/service.go @@ -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 { @@ -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) @@ -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) {