Use uuid instead of userid. Fixes #429

This commit is contained in:
Wim 2018-05-27 21:50:00 +02:00
parent fc6074ea9f
commit 411ef2691c
2 changed files with 11 additions and 6 deletions

View File

@ -8,12 +8,14 @@ import (
"github.com/42wim/matterbridge/bridge/helper" "github.com/42wim/matterbridge/bridge/helper"
"github.com/42wim/matterbridge/matterclient" "github.com/42wim/matterbridge/matterclient"
"github.com/42wim/matterbridge/matterhook" "github.com/42wim/matterbridge/matterhook"
"github.com/rs/xid"
"strings" "strings"
) )
type Bmattermost struct { type Bmattermost struct {
mh *matterhook.Client mh *matterhook.Client
mc *matterclient.MMClient mc *matterclient.MMClient
uuid string
TeamID string TeamID string
*bridge.Config *bridge.Config
avatarMap map[string]string avatarMap map[string]string
@ -21,6 +23,7 @@ type Bmattermost struct {
func New(cfg *bridge.Config) bridge.Bridger { func New(cfg *bridge.Config) bridge.Bridger {
b := &Bmattermost{Config: cfg, avatarMap: make(map[string]string)} b := &Bmattermost{Config: cfg, avatarMap: make(map[string]string)}
b.uuid = xid.New().String()
return b return b
} }
@ -366,7 +369,7 @@ func (b *Bmattermost) sendWebhook(msg config.Message) (string, error) {
// this sends a message only if we received a config.EVENT_FILE_FAILURE_SIZE // this sends a message only if we received a config.EVENT_FILE_FAILURE_SIZE
for _, rmsg := range helper.HandleExtra(&msg, b.General) { for _, rmsg := range helper.HandleExtra(&msg, b.General) {
matterMessage := matterhook.OMessage{IconURL: b.GetString("IconURL"), Channel: rmsg.Channel, UserName: rmsg.Username, Text: rmsg.Text, Props: make(map[string]interface{})} matterMessage := matterhook.OMessage{IconURL: b.GetString("IconURL"), Channel: rmsg.Channel, UserName: rmsg.Username, Text: rmsg.Text, Props: make(map[string]interface{})}
matterMessage.Props["matterbridge_"+b.mc.User.Id] = true matterMessage.Props["matterbridge_"+b.uuid] = true
b.mh.Send(matterMessage) b.mh.Send(matterMessage)
} }
@ -385,7 +388,7 @@ func (b *Bmattermost) sendWebhook(msg config.Message) (string, error) {
if msg.Avatar != "" { if msg.Avatar != "" {
matterMessage.IconURL = msg.Avatar matterMessage.IconURL = msg.Avatar
} }
matterMessage.Props["matterbridge_"+b.mc.User.Id] = true matterMessage.Props["matterbridge_"+b.uuid] = true
err := b.mh.Send(matterMessage) err := b.mh.Send(matterMessage)
if err != nil { if err != nil {
b.Log.Info(err) b.Log.Info(err)
@ -415,7 +418,7 @@ func (b *Bmattermost) skipMessage(message *matterclient.Message) bool {
// Ignore messages sent from matterbridge // Ignore messages sent from matterbridge
if message.Post.Props != nil { if message.Post.Props != nil {
if _, ok := message.Post.Props["matterbridge_"+b.mc.User.Id].(bool); ok { if _, ok := message.Post.Props["matterbridge_"+b.uuid].(bool); ok {
b.Log.Debugf("sent by matterbridge, ignoring") b.Log.Debugf("sent by matterbridge, ignoring")
return true return true
} }

View File

@ -15,6 +15,7 @@ import (
"github.com/42wim/matterbridge/bridge/helper" "github.com/42wim/matterbridge/bridge/helper"
"github.com/42wim/matterbridge/matterhook" "github.com/42wim/matterbridge/matterhook"
"github.com/nlopes/slack" "github.com/nlopes/slack"
"github.com/rs/xid"
) )
type Bslack struct { type Bslack struct {
@ -25,6 +26,7 @@ type Bslack struct {
Usergroups []slack.UserGroup Usergroups []slack.UserGroup
si *slack.Info si *slack.Info
channels []slack.Channel channels []slack.Channel
uuid string
*bridge.Config *bridge.Config
sync.RWMutex sync.RWMutex
} }
@ -32,7 +34,7 @@ type Bslack struct {
const messageDeleted = "message_deleted" const messageDeleted = "message_deleted"
func New(cfg *bridge.Config) bridge.Bridger { func New(cfg *bridge.Config) bridge.Bridger {
return &Bslack{Config: cfg} return &Bslack{Config: cfg, uuid: xid.New().String()}
} }
func (b *Bslack) Command(cmd string) string { func (b *Bslack) Command(cmd string) string {
@ -177,7 +179,7 @@ func (b *Bslack) Send(msg config.Message) (string, error) {
np.IconURL = msg.Avatar np.IconURL = msg.Avatar
} }
// add a callback ID so we can see we created it // add a callback ID so we can see we created it
np.Attachments = append(np.Attachments, slack.Attachment{CallbackID: "matterbridge_" + b.si.User.ID}) np.Attachments = append(np.Attachments, slack.Attachment{CallbackID: "matterbridge_" + b.uuid})
// add file attachments // add file attachments
np.Attachments = append(np.Attachments, b.createAttach(msg.Extra)...) np.Attachments = append(np.Attachments, b.createAttach(msg.Extra)...)
// add slack attachments (from another slack bridge) // add slack attachments (from another slack bridge)
@ -657,7 +659,7 @@ func (b *Bslack) skipMessageEvent(ev *slack.MessageEvent) bool {
// skip messages we made ourselves // skip messages we made ourselves
if len(ev.Attachments) > 0 { if len(ev.Attachments) > 0 {
if ev.Attachments[0].CallbackID == "matterbridge_"+b.si.User.ID { if ev.Attachments[0].CallbackID == "matterbridge_"+b.uuid {
return true return true
} }
} }