summaryrefslogtreecommitdiffstats
path: root/bridge/slack/slack.go
diff options
context:
space:
mode:
authorPatrick Connolly <patrick.c.connolly@gmail.com>2018-11-26 17:47:04 +0800
committerDuco van Amstel <duco.vanamstel@gmail.com>2018-11-26 09:47:04 +0000
commitf5659d455d2c28a6f2fe4c40f4dc344419ff523a (patch)
tree76447e104bfafeea83f3df6cf7f540d7c0bf048c /bridge/slack/slack.go
parent5ed7abdbeb8a81599b3516583e15df75651fb9bc (diff)
downloadmatterbridge-msglm-f5659d455d2c28a6f2fe4c40f4dc344419ff523a.tar.gz
matterbridge-msglm-f5659d455d2c28a6f2fe4c40f4dc344419ff523a.tar.bz2
matterbridge-msglm-f5659d455d2c28a6f2fe4c40f4dc344419ff523a.zip
Sync channel topics between Slack bridges (#585)
Added logic to allow for configurable synchronisation of topics and purposes of channels between Slack bridges.
Diffstat (limited to 'bridge/slack/slack.go')
-rw-r--r--bridge/slack/slack.go51
1 files changed, 50 insertions, 1 deletions
diff --git a/bridge/slack/slack.go b/bridge/slack/slack.go
index d054ae81..a38bbb53 100644
--- a/bridge/slack/slack.go
+++ b/bridge/slack/slack.go
@@ -281,8 +281,14 @@ func (b *Bslack) sendRTM(msg config.Message) (string, error) {
return "", nil
}
- // Handle message deletions.
var handled bool
+
+ // Handle topic/purpose updates.
+ if handled, err = b.handleTopicOrPurpose(&msg, channelInfo); handled {
+ return "", err
+ }
+
+ // Handle message deletions.
if handled, err = b.deleteMessage(&msg, channelInfo); handled {
return msg.ID, err
}
@@ -315,6 +321,49 @@ func (b *Bslack) sendRTM(msg config.Message) (string, error) {
return b.postMessage(&msg, messageParameters, channelInfo)
}
+func (b *Bslack) updateTopicOrPurpose(msg *config.Message, channelInfo *slack.Channel) (bool, error) {
+ var updateFunc func(channelID string, value string) (*slack.Channel, error)
+
+ incomingChangeType, text := b.extractTopicOrPurpose(msg.Text)
+ switch incomingChangeType {
+ case "topic":
+ updateFunc = b.rtm.SetTopicOfConversation
+ case "purpose":
+ updateFunc = b.rtm.SetPurposeOfConversation
+ default:
+ b.Log.Errorf("Unhandled type received from extractTopicOrPurpose: %s", incomingChangeType)
+ return true, nil
+ }
+ for {
+ _, err := updateFunc(channelInfo.ID, text)
+ if err == nil {
+ return true, nil
+ }
+ if err = b.handleRateLimit(err); err != nil {
+ return true, err
+ }
+ }
+}
+
+// handles updating topic/purpose and determining whether to further propagate update messages.
+func (b *Bslack) handleTopicOrPurpose(msg *config.Message, channelInfo *slack.Channel) (bool, error) {
+ if msg.Event != config.EventTopicChange {
+ return false, nil
+ }
+
+ if b.GetBool("SyncTopic") {
+ return b.updateTopicOrPurpose(msg, channelInfo)
+ }
+
+ // Pass along to normal message handlers.
+ if b.GetBool("ShowTopicChange") {
+ return false, nil
+ }
+
+ // Swallow message as handled no-op.
+ return true, nil
+}
+
func (b *Bslack) deleteMessage(msg *config.Message, channelInfo *slack.Channel) (bool, error) {
if msg.Event != config.EventMsgDelete {
return false, nil