Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show Mattermost message/thread IDs for file attachments #396

Merged
merged 2 commits into from
Feb 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions bridge/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ type FileEvent struct {
ChannelID string
ChannelType string
Files []*File
MessageID string
ParentID string
}

type ReactionAddEvent struct {
Expand Down
2 changes: 2 additions & 0 deletions bridge/mattermost/mattermost.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 22 additions & 8 deletions mm-go-irckit/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}
}
}
Expand Down
53 changes: 38 additions & 15 deletions mm-go-irckit/userbridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down