Skip to content

Commit

Permalink
Fix channel mentions and add option to disable channel mentions as IR…
Browse files Browse the repository at this point in the history
…C NOTICEs (mattermost) (#418)

* Allow overriding default channel wide mentions as IRC NOTICEs (#416)

* Fixed so only original message with channel wide mentions are IRC NOTICEs (#416)
  • Loading branch information
hloeung committed Mar 19, 2021
1 parent c764837 commit 1251960
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
12 changes: 9 additions & 3 deletions bridge/mattermost/mattermost.go
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,7 @@ func (m *Mattermost) handleWsActionPost(rmsg *model.WebSocketEvent) {
return
}

replyMessage := ""
if data.ParentId != "" {
parentPost, resp := m.mc.Client.GetPost(data.ParentId, "")
if resp.Error != nil {
Expand All @@ -744,7 +745,7 @@ func (m *Mattermost) handleWsActionPost(rmsg *model.WebSocketEvent) {

if !m.v.GetBool("mattermost.hidereplies") {
parentMessage := maybeShorten(parentPost.Message, m.v.GetInt("mattermost.ShortenRepliesTo"), "@", m.v.GetBool("mattermost.unicode"))
data.Message = fmt.Sprintf("%s (re @%s: %s)", data.Message, parentGhost.Nick, parentMessage)
replyMessage = fmt.Sprintf(" (re @%s: %s)", parentGhost.Nick, parentMessage)
}
}
}
Expand Down Expand Up @@ -809,7 +810,7 @@ func (m *Mattermost) handleWsActionPost(rmsg *model.WebSocketEvent) {
return
}

msgs := strings.Split(data.Message, "\n")
msgs := strings.Split(data.Message+replyMessage, "\n")

channelType := ""
if t, ok := props["channel_type"].(string); ok {
Expand Down Expand Up @@ -886,13 +887,18 @@ func (m *Mattermost) handleWsActionPost(rmsg *model.WebSocketEvent) {
}
case strings.Contains(data.Message, "@channel") || strings.Contains(data.Message, "@here") ||
strings.Contains(data.Message, "@all"):

messageType := "notice"
if m.v.GetBool("mattermost.disabledefaultmentions") {
messageType = ""
}
event := &bridge.Event{
Type: "channel_message",
Data: &bridge.ChannelMessageEvent{
Text: msg,
ChannelID: data.ChannelId,
Sender: ghost,
MessageType: "notice",
MessageType: messageType,
ChannelType: channelType,
Files: m.getFilesFromData(data),
MessageID: data.Id,
Expand Down
3 changes: 3 additions & 0 deletions matterircd.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ SuffixContext = false
#This will show (mention yournick) after a message if it contains one of the words configured
#in your mattermost "word that trigger mentions" notifications.
ShowMentions = false
# Channel wide default mentions @channel, @all, and @here are shown as IRC NOTICEs.
# This disables that making them appear as normal PRIVMSGs.
#DisableDefaultMentions = true

# Path to file to store last viewed information. This is useful for replying only
# the messages missed.
Expand Down

0 comments on commit 1251960

Please sign in to comment.