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

Fix channel mentions and add option to disable channel mentions as IRC NOTICEs #418

Merged
merged 2 commits into from
Mar 19, 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
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