diff --git a/matterircd.toml.example b/matterircd.toml.example index 0336a7b0..ac574701 100644 --- a/matterircd.toml.example +++ b/matterircd.toml.example @@ -138,6 +138,8 @@ SuffixContext = false # If either PrefixContext or SuffixContext specify which thread ID to use. Default is the # matterircd generated @@([0-9][a-f]){3}. Uncomment to use Mattermost's message/parent thread IDs instead. #ThreadContext = "mattermost" +# Similar to the above, but also show the message post IDs in addition to the parent thread ID. +#ThreadContext = "mattermost+post" #This will show (mention yournick) after a message if it contains one of the words configured #in your mattermost "word that trigger mentions" notifications. diff --git a/mm-go-irckit/service.go b/mm-go-irckit/service.go index d0021eff..5cf017d5 100644 --- a/mm-go-irckit/service.go +++ b/mm-go-irckit/service.go @@ -394,14 +394,14 @@ func scrollback(u *User, toUser *User, args []string, service string) { } switch { // nolint:dupl - case u.v.GetString(u.br.Protocol()+".threadcontext") == "mattermost" && strings.HasPrefix(args[0], "#") && nick != "system": + case (u.v.GetString(u.br.Protocol()+".threadcontext") == "mattermost" || u.v.GetString(u.br.Protocol()+".threadcontext") == "mattermost+post") && strings.HasPrefix(args[0], "#") && nick != "system": threadMsgID := u.prefixContext("", p.Id, p.ParentId, "") scrollbackMsg := u.formatContextMessage(ts.Format("2006-01-02 15:04"), threadMsgID, post) spoof(nick, scrollbackMsg) case strings.HasPrefix(args[0], "#"): scrollbackMsg := "[" + ts.Format("2006-01-02 15:04") + "] " + post spoof(nick, scrollbackMsg) - case u.v.GetString(u.br.Protocol()+".threadcontext") == "mattermost": + case u.v.GetString(u.br.Protocol()+".threadcontext") == "mattermost" || u.v.GetString(u.br.Protocol()+".threadcontext") == "mattermost+post": threadMsgID := u.prefixContext("", p.Id, p.ParentId, "") scrollbackMsg := u.formatContextMessage(ts.Format("2006-01-02 15:04"), threadMsgID, post) u.MsgSpoofUser(scrollbackUser, nick, scrollbackMsg) @@ -418,11 +418,11 @@ func scrollback(u *User, toUser *User, args []string, service string) { 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], "#"): + case (u.v.GetString(u.br.Protocol()+".threadcontext") == "mattermost" || u.v.GetString(u.br.Protocol()+".threadcontext") == "mattermost+post") && 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": + case u.v.GetString(u.br.Protocol()+".threadcontext") == "mattermost" || u.v.GetString(u.br.Protocol()+".threadcontext") == "mattermost+post": threadMsgID := u.prefixContext("", p.Id, p.ParentId, "") scrollbackMsg := u.formatContextMessage(ts.Format("2006-01-02 15:04"), threadMsgID, fileMsg) u.MsgSpoofUser(scrollbackUser, nick, scrollbackMsg) @@ -514,14 +514,14 @@ func scrollback6(u *User, toUser *User, args []string, service string) { } switch { // nolint:dupl - case u.v.GetString(u.br.Protocol()+".threadcontext") == "mattermost" && strings.HasPrefix(args[0], "#") && nick != "system": + case (u.v.GetString(u.br.Protocol()+".threadcontext") == "mattermost" || u.v.GetString(u.br.Protocol()+".threadcontext") == "mattermost+post") && strings.HasPrefix(args[0], "#") && nick != "system": threadMsgID := u.prefixContext("", p.Id, p.RootId, "") scrollbackMsg := u.formatContextMessage(ts.Format("2006-01-02 15:04"), threadMsgID, post) spoof(nick, scrollbackMsg) case strings.HasPrefix(args[0], "#"): scrollbackMsg := "[" + ts.Format("2006-01-02 15:04") + "] " + post spoof(nick, scrollbackMsg) - case u.v.GetString(u.br.Protocol()+".threadcontext") == "mattermost": + case u.v.GetString(u.br.Protocol()+".threadcontext") == "mattermost" || u.v.GetString(u.br.Protocol()+".threadcontext") == "mattermost+post": threadMsgID := u.prefixContext("", p.Id, p.RootId, "") scrollbackMsg := u.formatContextMessage(ts.Format("2006-01-02 15:04"), threadMsgID, post) u.MsgSpoofUser(scrollbackUser, nick, scrollbackMsg) @@ -538,11 +538,11 @@ func scrollback6(u *User, toUser *User, args []string, service string) { 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], "#"): + case (u.v.GetString(u.br.Protocol()+".threadcontext") == "mattermost" || u.v.GetString(u.br.Protocol()+".threadcontext") == "mattermost+post") && strings.HasPrefix(args[0], "#"): threadMsgID := u.prefixContext("", p.Id, p.RootId, "") scrollbackMsg := u.formatContextMessage(ts.Format("2006-01-02 15:04"), threadMsgID, fileMsg) spoof(nick, scrollbackMsg) - case u.v.GetString(u.br.Protocol()+".threadcontext") == "mattermost": + case u.v.GetString(u.br.Protocol()+".threadcontext") == "mattermost" || u.v.GetString(u.br.Protocol()+".threadcontext") == "mattermost+post": threadMsgID := u.prefixContext("", p.Id, p.RootId, "") scrollbackMsg := u.formatContextMessage(ts.Format("2006-01-02 15:04"), threadMsgID, fileMsg) u.MsgSpoofUser(scrollbackUser, nick, scrollbackMsg) diff --git a/mm-go-irckit/userbridge.go b/mm-go-irckit/userbridge.go index e8376879..0199af44 100644 --- a/mm-go-irckit/userbridge.go +++ b/mm-go-irckit/userbridge.go @@ -306,7 +306,7 @@ func (u *User) handleChannelMessageEvent(event *bridge.ChannelMessageEvent) { func (u *User) handleFileEvent(event *bridge.FileEvent) { for _, fname := range event.Files { fileMsg := "download file - " + fname.Name - if u.v.GetString(u.br.Protocol()+".threadcontext") == "mattermost" { + if u.v.GetString(u.br.Protocol()+".threadcontext") == "mattermost" || u.v.GetString(u.br.Protocol()+".threadcontext") == "mattermost+post" { threadMsgID := u.prefixContext(event.ChannelID, event.MessageID, event.ParentID, "") fileMsg = u.formatContextMessage("", threadMsgID, fileMsg) } @@ -710,7 +710,7 @@ func (u *User) addUserToChannelWorker(channels <-chan *bridge.ChannelInfo, throt } replayMsg := fmt.Sprintf("[%s] %s", ts.Format("15:04"), post) - if (u.v.GetBool(u.br.Protocol()+".prefixcontext") || u.v.GetBool(u.br.Protocol()+".suffixcontext")) && u.v.GetString(u.br.Protocol()+".threadcontext") == "mattermost" && nick != systemUser { + if (u.v.GetBool(u.br.Protocol()+".prefixcontext") || u.v.GetBool(u.br.Protocol()+".suffixcontext")) && (u.v.GetString(u.br.Protocol()+".threadcontext") == "mattermost" || u.v.GetString(u.br.Protocol()+".threadcontext") == "mattermost+post") && nick != systemUser { threadMsgID := u.prefixContext("", p.Id, p.ParentId, "") replayMsg = u.formatContextMessage(ts.Format("15:04"), threadMsgID, post) } @@ -723,7 +723,7 @@ func (u *User) addUserToChannelWorker(channels <-chan *bridge.ChannelInfo, throt for _, fname := range u.br.GetFileLinks(p.FileIds) { fileMsg := "download file - " + fname - if u.v.GetString(u.br.Protocol()+".threadcontext") == "mattermost" { + if u.v.GetString(u.br.Protocol()+".threadcontext") == "mattermost" || u.v.GetString(u.br.Protocol()+".threadcontext") == "mattermost+post" { threadMsgID := u.prefixContext("", p.Id, p.ParentId, "") fileMsg = u.formatContextMessage(ts.Format("15:04"), threadMsgID, fileMsg) } @@ -837,7 +837,7 @@ func (u *User) addUserToChannelWorker6(channels <-chan *bridge.ChannelInfo, thro } replayMsg := fmt.Sprintf("[%s] %s", ts.Format("15:04"), post) - if (u.v.GetBool(u.br.Protocol()+".prefixcontext") || u.v.GetBool(u.br.Protocol()+".suffixcontext")) && u.v.GetString(u.br.Protocol()+".threadcontext") == "mattermost" && nick != systemUser { + if (u.v.GetBool(u.br.Protocol()+".prefixcontext") || u.v.GetBool(u.br.Protocol()+".suffixcontext")) && (u.v.GetString(u.br.Protocol()+".threadcontext") == "mattermost" || u.v.GetString(u.br.Protocol()+".threadcontext") == "mattermost+post") && nick != systemUser { threadMsgID := u.prefixContext("", p.Id, p.RootId, "") replayMsg = u.formatContextMessage(ts.Format("15:04"), threadMsgID, post) } @@ -850,7 +850,7 @@ func (u *User) addUserToChannelWorker6(channels <-chan *bridge.ChannelInfo, thro for _, fname := range u.br.GetFileLinks(p.FileIds) { fileMsg := "download file - " + fname - if u.v.GetString(u.br.Protocol()+".threadcontext") == "mattermost" { + if u.v.GetString(u.br.Protocol()+".threadcontext") == "mattermost" || u.v.GetString(u.br.Protocol()+".threadcontext") == "mattermost+post" { threadMsgID := u.prefixContext("", p.Id, p.RootId, "") fileMsg = u.formatContextMessage(ts.Format("15:04"), threadMsgID, fileMsg) } @@ -1080,6 +1080,16 @@ func (u *User) prefixContext(channelID, messageID, parentID, event string) strin return fmt.Sprintf("[->@@%s]", parentID) } + if u.v.GetString(u.br.Protocol()+".threadcontext") == "mattermost+post" { + if parentID == "" { + return fmt.Sprintf("[@@%s]", messageID) + } + if u.v.GetBool(u.br.Protocol() + ".unicode") { + return fmt.Sprintf("[↪@@%s,@@%s]", parentID, messageID) + } + return fmt.Sprintf("[->@@%s,@@%s]", parentID, messageID) + } + u.msgMapMutex.Lock() defer u.msgMapMutex.Unlock()