summaryrefslogtreecommitdiffstats
path: root/bridge
diff options
context:
space:
mode:
authorQais Patankar <qaisjp@gmail.com>2020-12-31 18:01:57 +0000
committerGitHub <noreply@github.com>2020-12-31 18:01:57 +0000
commita9d8ac8bc0c745d43440aa56f1b602edf8e4aef7 (patch)
treee6ce1698337ae6882470028fe659f690f384efe9 /bridge
parent1a4717b366a2371dacc0ce205b0a42c5b31f52dc (diff)
downloadmatterbridge-msglm-a9d8ac8bc0c745d43440aa56f1b602edf8e4aef7.tar.gz
matterbridge-msglm-a9d8ac8bc0c745d43440aa56f1b602edf8e4aef7.tar.bz2
matterbridge-msglm-a9d8ac8bc0c745d43440aa56f1b602edf8e4aef7.zip
Refactor "msg-parent-not-found" to config.ParentIDNotFound (#1347)
Diffstat (limited to 'bridge')
-rw-r--r--bridge/config/config.go10
-rw-r--r--bridge/discord/discord.go4
-rw-r--r--bridge/mattermost/mattermost.go2
-rw-r--r--bridge/msteams/msteams.go7
-rw-r--r--bridge/slack/slack.go2
5 files changed, 19 insertions, 6 deletions
diff --git a/bridge/config/config.go b/bridge/config/config.go
index 7dbbc80b..98935208 100644
--- a/bridge/config/config.go
+++ b/bridge/config/config.go
@@ -29,6 +29,8 @@ const (
EventNoticeIRC = "notice_irc"
)
+const ParentIDNotFound = "msg-parent-not-found"
+
type Message struct {
Text string `json:"text"`
Channel string `json:"channel"`
@@ -45,6 +47,14 @@ type Message struct {
Extra map[string][]interface{}
}
+func (m Message) ParentNotFound() bool {
+ return m.ParentID == ParentIDNotFound
+}
+
+func (m Message) ParentValid() bool {
+ return m.ParentID != "" && !m.ParentNotFound()
+}
+
type FileInfo struct {
Name string
Data *[]byte
diff --git a/bridge/discord/discord.go b/bridge/discord/discord.go
index daeaa403..184dde85 100644
--- a/bridge/discord/discord.go
+++ b/bridge/discord/discord.go
@@ -243,7 +243,7 @@ func (b *Bdiscord) Send(msg config.Message) (string, error) {
}
// Handle prefix hint for unthreaded messages.
- if msg.ParentID == "msg-parent-not-found" {
+ if msg.ParentNotFound() {
msg.ParentID = ""
msg.Text = fmt.Sprintf("[thread]: %s", msg.Text)
}
@@ -297,7 +297,7 @@ func (b *Bdiscord) handleEventBotUser(msg *config.Message, channelID string) (st
Content: msg.Username + msg.Text,
}
- if msg.ParentID != "" && msg.ParentID != "msg-parent-not-found" {
+ if msg.ParentValid() {
m.Reference = &discordgo.MessageReference{
MessageID: msg.ParentID,
ChannelID: channelID,
diff --git a/bridge/mattermost/mattermost.go b/bridge/mattermost/mattermost.go
index 2c11b79e..bb44c48a 100644
--- a/bridge/mattermost/mattermost.go
+++ b/bridge/mattermost/mattermost.go
@@ -122,7 +122,7 @@ func (b *Bmattermost) Send(msg config.Message) (string, error) {
}
// Handle prefix hint for unthreaded messages.
- if msg.ParentID == "msg-parent-not-found" {
+ if msg.ParentNotFound() {
msg.ParentID = ""
msg.Text = fmt.Sprintf("[thread]: %s", msg.Text)
}
diff --git a/bridge/msteams/msteams.go b/bridge/msteams/msteams.go
index 4d4acc2a..87a15a7a 100644
--- a/bridge/msteams/msteams.go
+++ b/bridge/msteams/msteams.go
@@ -86,13 +86,16 @@ func (b *Bmsteams) JoinChannel(channel config.ChannelInfo) error {
func (b *Bmsteams) Send(msg config.Message) (string, error) {
b.Log.Debugf("=> Receiving %#v", msg)
- if msg.ParentID != "" && msg.ParentID != "msg-parent-not-found" {
+ if msg.ParentValid() {
return b.sendReply(msg)
}
- if msg.ParentID == "msg-parent-not-found" {
+
+ // Handle prefix hint for unthreaded messages.
+ if msg.ParentNotFound() {
msg.ParentID = ""
msg.Text = fmt.Sprintf("[thread]: %s", msg.Text)
}
+
ct := b.gc.Teams().ID(b.GetString("TeamID")).Channels().ID(msg.Channel).Messages().Request()
text := msg.Username + msg.Text
content := &msgraph.ItemBody{Content: &text}
diff --git a/bridge/slack/slack.go b/bridge/slack/slack.go
index 384581ef..e016a64f 100644
--- a/bridge/slack/slack.go
+++ b/bridge/slack/slack.go
@@ -299,7 +299,7 @@ func (b *Bslack) sendRTM(msg config.Message) (string, error) {
}
// Handle prefix hint for unthreaded messages.
- if msg.ParentID == "msg-parent-not-found" {
+ if msg.ParentNotFound() {
msg.ParentID = ""
msg.Text = fmt.Sprintf("[thread]: %s", msg.Text)
}