Skip to content

Commit

Permalink
Show scrollback in same channel/query window. Fixes #391
Browse files Browse the repository at this point in the history
  • Loading branch information
hloeung committed Feb 13, 2021
1 parent f7b5b63 commit f389ec5
Showing 1 changed file with 31 additions and 8 deletions.
39 changes: 31 additions & 8 deletions mm-go-irckit/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,22 +276,30 @@ func scrollback(u *User, toUser *User, args []string, service string) {
return
}

var spoof func(string, string)
scrollbackUser, exists := u.Srv.HasUser(args[0])

var channelName string
if strings.HasPrefix(args[0], "#") {
var channelID string
switch {
case strings.HasPrefix(args[0], "#"):
channelName = strings.ReplaceAll(args[0], "#", "")
} else if scrollbackUser, exists := u.Srv.HasUser(args[0]); exists && scrollbackUser.Ghost {
channelID = u.br.GetChannelID(channelName, u.br.GetMe().TeamID)
spoof = u.Srv.Channel(channelID).SpoofMessage
case exists && scrollbackUser.Ghost:
// We need to sort the two user IDs to construct the DM
// channel name.
userIDs := []string{u.User, scrollbackUser.User}
sort.Strings(userIDs)
channelName = userIDs[0] + "__" + userIDs[1]
} else {
channelID = u.br.GetChannelID(channelName, u.br.GetMe().TeamID)
default:
u.MsgUser(toUser, "need SCROLLBACK (#<channel>|<user>) <lines>")
u.MsgUser(toUser, "e.g. SCROLLBACK #bugs 10 (show last 10 lines from #bugs)")
return
}

list := u.br.GetPosts(u.br.GetChannelID(channelName, u.br.GetMe().TeamID), limit)
list := u.br.GetPosts(channelID, limit)
if list == nil || list.(*model.PostList) == nil || len(list.(*model.PostList).Order) == 0 {
u.MsgUser(toUser, "no results")
return
Expand All @@ -303,17 +311,32 @@ func scrollback(u *User, toUser *User, args []string, service string) {
p := postlist.Posts[postlist.Order[i]]
ts := time.Unix(0, p.CreateAt*int64(time.Millisecond))

nick := u.br.GetUser(p.UserId).Nick
props := p.GetProps()
botname, override := props["override_username"].(string)
user := u.br.GetUser(p.UserId)
nick := user.Nick
if override {
nick = botname
}

for _, post := range strings.Split(p.Message, "\n") {
if post != "" {
u.MsgUser(toUser, "["+ts.Format("2006-01-02 15:04")+"]"+" <"+nick+"> "+post)
if post == "" {
continue
}
if strings.HasPrefix(args[0], "#") {
spoof(nick, "["+ts.Format("2006-01-02 15:04")+"] "+post)
continue
}
u.MsgSpoofUser(scrollbackUser, nick, "["+ts.Format("2006-01-02 15:04")+"]"+" <"+nick+"> "+post)
}

if len(p.FileIds) > 0 {
for _, fname := range u.br.GetFileLinks(p.FileIds) {
u.MsgUser(toUser, "["+ts.Format("2006-01-02 15:04")+"]"+" <"+nick+"> download file - "+fname)
if strings.HasPrefix(args[0], "#") {
spoof(nick, "["+ts.Format("2006-01-02 15:04")+"] download file - "+fname)
continue
}
u.MsgSpoofUser(scrollbackUser, nick, "["+ts.Format("2006-01-02 15:04")+"]"+" <"+nick+"> download file - "+fname)
}
}
}
Expand Down

0 comments on commit f389ec5

Please sign in to comment.