diff --git a/bridge/bridge.go b/bridge/bridge.go index 10e52c16..a133fb01 100644 --- a/bridge/bridge.go +++ b/bridge/bridge.go @@ -150,6 +150,8 @@ type FileEvent struct { ChannelID string ChannelType string Files []*File + MessageID string + ParentID string } type ReactionAddEvent struct { diff --git a/bridge/mattermost/mattermost.go b/bridge/mattermost/mattermost.go index df7a15ea..8eeed9ad 100644 --- a/bridge/mattermost/mattermost.go +++ b/bridge/mattermost/mattermost.go @@ -959,6 +959,8 @@ func (m *Mattermost) handleFileEvent(channelType string, ghost *bridge.UserInfo, Receiver: ghost, ChannelType: channelType, ChannelID: data.ChannelId, + MessageID: data.Id, + ParentID: data.ParentId, } event.Data = fileEvent diff --git a/mm-go-irckit/service.go b/mm-go-irckit/service.go index 73bc15e0..04ced682 100644 --- a/mm-go-irckit/service.go +++ b/mm-go-irckit/service.go @@ -323,7 +323,7 @@ func scrollback(u *User, toUser *User, args []string, service string) { continue } - switch { + switch { // nolint:dupl case u.v.GetString(u.br.Protocol()+".threadcontext") == "mattermost" && strings.HasPrefix(args[0], "#"): threadMsgID := u.prefixContext("", p.Id, p.ParentId, "") scrollbackMsg := u.formatContextMessage(ts.Format("2006-01-02 15:04"), threadMsgID, post) @@ -341,13 +341,27 @@ func scrollback(u *User, toUser *User, args []string, service string) { } } - if len(p.FileIds) > 0 { - for _, fname := range u.br.GetFileLinks(p.FileIds) { - 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) + if len(p.FileIds) == 0 { + continue + } + + for _, fname := range u.br.GetFileLinks(p.FileIds) { + fileMsg := "download file - " + fname + switch { // nolint:dupl + case u.v.GetString(u.br.Protocol()+".threadcontext") == "mattermost" && strings.HasPrefix(args[0], "#"): + threadMsgID := u.prefixContext("", p.Id, p.ParentId, "") + scrollbackMsg := u.formatContextMessage(ts.Format("2006-01-02 15:04"), threadMsgID, fileMsg) + spoof(nick, scrollbackMsg) + case u.v.GetString(u.br.Protocol()+".threadcontext") == "mattermost": + threadMsgID := u.prefixContext("", p.Id, p.ParentId, "") + scrollbackMsg := u.formatContextMessage(ts.Format("2006-01-02 15:04"), threadMsgID, fileMsg) + u.MsgSpoofUser(scrollbackUser, nick, scrollbackMsg) + case strings.HasPrefix(args[0], "#"): + scrollbackMsg := "[" + ts.Format("2006-01-02 15:04") + "] " + fileMsg + spoof(nick, scrollbackMsg) + default: + scrollbackMsg := "[" + ts.Format("2006-01-02 15:04") + "]" + " <" + nick + "> " + fileMsg + u.MsgSpoofUser(scrollbackUser, nick, scrollbackMsg) } } } diff --git a/mm-go-irckit/userbridge.go b/mm-go-irckit/userbridge.go index 9e753d54..384ad114 100644 --- a/mm-go-irckit/userbridge.go +++ b/mm-go-irckit/userbridge.go @@ -294,27 +294,30 @@ func (u *User) handleChannelMessageEvent(event *bridge.ChannelMessageEvent) { } func (u *User) handleFileEvent(event *bridge.FileEvent) { - ch := u.getMessageChannel(event.ChannelID, event.Sender) + for _, fname := range event.Files { + fileMsg := "download file - " + fname.Name + if u.v.GetString(u.br.Protocol()+".threadcontext") == "mattermost" { + threadMsgID := u.prefixContext(event.ChannelID, event.MessageID, event.ParentID, "") + fileMsg = u.formatContextMessage("", threadMsgID, fileMsg) + } - switch event.ChannelType { - case "D": - for _, fname := range event.Files { + switch event.ChannelType { + case "D": if event.Sender.Me { if event.Receiver.Me { - u.MsgSpoofUser(u, u.Nick, "download file - "+fname.Name) + u.MsgSpoofUser(u, u.Nick, fileMsg) } else { - u.MsgSpoofUser(u, event.Receiver.Nick, "download file - "+fname.Name) + u.MsgSpoofUser(u, event.Receiver.Nick, fileMsg) } } else { - u.MsgSpoofUser(u.createUserFromInfo(event.Sender), event.Receiver.Nick, "download file - "+fname.Name) + u.MsgSpoofUser(u.createUserFromInfo(event.Sender), event.Receiver.Nick, fileMsg) } - } - default: - for _, fname := range event.Files { + default: + ch := u.getMessageChannel(event.ChannelID, event.Sender) if event.Sender.Me { - ch.SpoofMessage(u.Nick, "download file - "+fname.Name) + ch.SpoofMessage(u.Nick, fileMsg) } else { - ch.SpoofMessage(event.Sender.Nick, "download file - "+fname.Name) + ch.SpoofMessage(event.Sender.Nick, fileMsg) } } } @@ -614,6 +617,10 @@ func (u *User) addUserToChannelWorker(channels <-chan *bridge.ChannelInfo, throt } for _, post := range strings.Split(p.Message, "\n") { + if post == "" { + continue + } + if showReplayHdr { date := ts.Format("2006-01-02 15:04:05") channame := brchannel.Name @@ -634,6 +641,19 @@ func (u *User) addUserToChannelWorker(channels <-chan *bridge.ChannelInfo, throt } spoof(nick, replayMsg) } + + if len(p.FileIds) == 0 { + continue + } + + for _, fname := range u.br.GetFileLinks(p.FileIds) { + fileMsg := "download file - " + fname + if u.v.GetString(u.br.Protocol()+".threadcontext") == "mattermost" { + threadMsgID := u.prefixContext("", p.Id, p.ParentId, "") + fileMsg = u.formatContextMessage(ts.Format("15:04"), threadMsgID, fileMsg) + } + spoof(nick, fileMsg) + } } if len(mmPostList.Order) > 0 { @@ -805,13 +825,16 @@ func (u *User) increaseMsgCounter(channelID string) int { return u.msgCounter[channelID] } -func (u *User) formatContextMessage(ts, context, msg string) string { +func (u *User) formatContextMessage(ts, threadMsgID, msg string) string { var formattedMsg string switch { case u.v.GetBool(u.br.Protocol() + ".prefixcontext"): - formattedMsg = "[" + ts + "] " + context + " " + msg + formattedMsg = threadMsgID + " " + msg case u.v.GetBool(u.br.Protocol() + ".suffixcontext"): - formattedMsg = "[" + ts + "] " + msg + " " + context + formattedMsg = msg + " " + threadMsgID + } + if ts != "" { + formattedMsg = "[" + ts + "] " + formattedMsg } return formattedMsg }