From 2ddc4f7ae91a51bc8fa279fdab3c7d64600e1a25 Mon Sep 17 00:00:00 2001 From: Wim Date: Sun, 18 Jun 2017 15:44:54 +0200 Subject: Add UserID to each message. Closes #200 --- bridge/api/api.go | 2 ++ bridge/config/config.go | 1 + bridge/discord/discord.go | 3 ++- bridge/gitter/gitter.go | 2 +- bridge/irc/irc.go | 2 +- bridge/matrix/matrix.go | 2 +- bridge/mattermost/mattermost.go | 5 ++++- bridge/rocketchat/rocketchat.go | 2 +- bridge/slack/slack.go | 4 +++- bridge/telegram/telegram.go | 2 +- bridge/xmpp/xmpp.go | 2 +- gateway/gateway.go | 3 --- matterclient/matterclient.go | 2 ++ 13 files changed, 20 insertions(+), 12 deletions(-) diff --git a/bridge/api/api.go b/bridge/api/api.go index eb27b2c1..26ff3327 100644 --- a/bridge/api/api.go +++ b/bridge/api/api.go @@ -21,6 +21,7 @@ type Api struct { type ApiMessage struct { Text string `json:"text"` Username string `json:"username"` + UserID string `json:"userid"` Avatar string `json:"avatar"` Gateway string `json:"gateway"` } @@ -81,6 +82,7 @@ func (b *Api) handlePostMessage(c echo.Context) error { b.Remote <- config.Message{ Text: message.Text, Username: message.Username, + UserID: message.UserID, Channel: "api", Avatar: message.Avatar, Account: b.Account, diff --git a/bridge/config/config.go b/bridge/config/config.go index f79c40d0..79715b53 100644 --- a/bridge/config/config.go +++ b/bridge/config/config.go @@ -19,6 +19,7 @@ type Message struct { Text string `json:"text"` Channel string `json:"channel"` Username string `json:"username"` + UserID string `json:"userid"` // userid on the bridge Avatar string `json:"avatar"` Account string `json:"account"` Event string `json:"event"` diff --git a/bridge/discord/discord.go b/bridge/discord/discord.go index 66e27256..3d244962 100644 --- a/bridge/discord/discord.go +++ b/bridge/discord/discord.go @@ -142,7 +142,8 @@ func (b *bdiscord) messageCreate(s *discordgo.Session, m *discordgo.MessageCreat m.Message.Content = b.stripCustomoji(m.Message.Content) m.Message.Content = b.replaceChannelMentions(m.Message.Content) b.Remote <- config.Message{Username: username, Text: m.ContentWithMentionsReplaced(), Channel: channelName, - Account: b.Account, Avatar: "https://cdn.discordapp.com/avatars/" + m.Author.ID + "/" + m.Author.Avatar + ".jpg"} + Account: b.Account, Avatar: "https://cdn.discordapp.com/avatars/" + m.Author.ID + "/" + m.Author.Avatar + ".jpg", + UserID: m.Author.ID} } func (b *bdiscord) memberUpdate(s *discordgo.Session, m *discordgo.GuildMemberUpdate) { diff --git a/bridge/gitter/gitter.go b/bridge/gitter/gitter.go index af71d892..973a7300 100644 --- a/bridge/gitter/gitter.go +++ b/bridge/gitter/gitter.go @@ -82,7 +82,7 @@ func (b *Bgitter) JoinChannel(channel string) error { if !strings.HasSuffix(ev.Message.Text, "​") { flog.Debugf("Sending message from %s on %s to gateway", ev.Message.From.Username, b.Account) b.Remote <- config.Message{Username: ev.Message.From.Username, Text: ev.Message.Text, Channel: room, - Account: b.Account, Avatar: b.getAvatar(ev.Message.From.Username)} + Account: b.Account, Avatar: b.getAvatar(ev.Message.From.Username), UserID: ev.Message.From.ID} } case *gitter.GitterConnectionClosed: flog.Errorf("connection with gitter closed for room %s", room) diff --git a/bridge/irc/irc.go b/bridge/irc/irc.go index feb88a55..6d85e7ba 100644 --- a/bridge/irc/irc.go +++ b/bridge/irc/irc.go @@ -252,7 +252,7 @@ func (b *Birc) handlePrivMsg(event *irc.Event) { re := regexp.MustCompile(`[[:cntrl:]](\d+,|)\d+`) msg = re.ReplaceAllString(msg, "") flog.Debugf("Sending message from %s on %s to gateway", event.Arguments[0], b.Account) - b.Remote <- config.Message{Username: event.Nick, Text: msg, Channel: event.Arguments[0], Account: b.Account} + b.Remote <- config.Message{Username: event.Nick, Text: msg, Channel: event.Arguments[0], Account: b.Account, UserID: event.User + "@" + event.Host} } func (b *Birc) handleTopicWhoTime(event *irc.Event) { diff --git a/bridge/matrix/matrix.go b/bridge/matrix/matrix.go index 628e8d91..2fd91b32 100644 --- a/bridge/matrix/matrix.go +++ b/bridge/matrix/matrix.go @@ -109,7 +109,7 @@ func (b *Bmatrix) handlematrix() error { username = re.ReplaceAllString(username, `$1`) } flog.Debugf("Sending message from %s on %s to gateway", ev.Sender, b.Account) - b.Remote <- config.Message{Username: username, Text: ev.Content["body"].(string), Channel: channel, Account: b.Account} + b.Remote <- config.Message{Username: username, Text: ev.Content["body"].(string), Channel: channel, Account: b.Account, UserID: ev.Sender} } flog.Debugf("Received: %#v", ev) }) diff --git a/bridge/mattermost/mattermost.go b/bridge/mattermost/mattermost.go index 3db880ba..e88bf838 100644 --- a/bridge/mattermost/mattermost.go +++ b/bridge/mattermost/mattermost.go @@ -21,6 +21,7 @@ type MMMessage struct { Text string Channel string Username string + UserID string } type Bmattermost struct { @@ -127,7 +128,7 @@ func (b *Bmattermost) handleMatter() { } for message := range mchan { flog.Debugf("Sending message from %s on %s to gateway", message.Username, b.Account) - b.Remote <- config.Message{Text: message.Text, Username: message.Username, Channel: message.Channel, Account: b.Account} + b.Remote <- config.Message{Text: message.Text, Username: message.Username, Channel: message.Channel, Account: b.Account, UserID: message.UserID} } } @@ -150,6 +151,7 @@ func (b *Bmattermost) handleMatterClient(mchan chan *MMMessage) { b.mc.User.Username != message.Username && message.Raw.Data["team_id"].(string) == b.TeamId { flog.Debugf("Receiving from matterclient %#v", message) m := &MMMessage{} + m.UserID = message.UserID m.Username = message.Username m.Channel = message.Channel m.Text = message.Text @@ -171,6 +173,7 @@ func (b *Bmattermost) handleMatterHook(mchan chan *MMMessage) { message := b.mh.Receive() flog.Debugf("Receiving from matterhook %#v", message) m := &MMMessage{} + m.UserID = message.UserID m.Username = message.UserName m.Text = message.Text m.Channel = message.ChannelName diff --git a/bridge/rocketchat/rocketchat.go b/bridge/rocketchat/rocketchat.go index 4590a895..15cac553 100644 --- a/bridge/rocketchat/rocketchat.go +++ b/bridge/rocketchat/rocketchat.go @@ -82,6 +82,6 @@ func (b *Brocketchat) handleRocketHook() { continue } flog.Debugf("Sending message from %s on %s to gateway", message.UserName, b.Account) - b.Remote <- config.Message{Text: message.Text, Username: message.UserName, Channel: message.ChannelName, Account: b.Account} + b.Remote <- config.Message{Text: message.Text, Username: message.UserName, Channel: message.ChannelName, Account: b.Account, UserID: message.UserID} } } diff --git a/bridge/slack/slack.go b/bridge/slack/slack.go index eb08500c..fd4b9e1a 100644 --- a/bridge/slack/slack.go +++ b/bridge/slack/slack.go @@ -15,6 +15,7 @@ type MMMessage struct { Text string Channel string Username string + UserID string Raw *slack.MessageEvent } @@ -185,7 +186,7 @@ func (b *Bslack) handleSlack() { texts := strings.Split(message.Text, "\n") for _, text := range texts { flog.Debugf("Sending message from %s on %s to gateway", message.Username, b.Account) - b.Remote <- config.Message{Text: text, Username: message.Username, Channel: message.Channel, Account: b.Account, Avatar: b.getAvatar(message.Username)} + b.Remote <- config.Message{Text: text, Username: message.Username, Channel: message.Channel, Account: b.Account, Avatar: b.getAvatar(message.Username), UserID: message.UserID} } } } @@ -213,6 +214,7 @@ func (b *Bslack) handleSlackClient(mchan chan *MMMessage) { continue } m := &MMMessage{} + m.UserID = user.ID m.Username = user.Name m.Channel = channel.Name m.Text = ev.Text diff --git a/bridge/telegram/telegram.go b/bridge/telegram/telegram.go index d6b7597a..9f7af284 100644 --- a/bridge/telegram/telegram.go +++ b/bridge/telegram/telegram.go @@ -132,7 +132,7 @@ func (b *Btelegram) handleRecv(updates <-chan tgbotapi.Update) { } if text != "" { flog.Debugf("Sending message from %s on %s to gateway", username, b.Account) - b.Remote <- config.Message{Username: username, Text: text, Channel: channel, Account: b.Account} + b.Remote <- config.Message{Username: username, Text: text, Channel: channel, Account: b.Account, UserID: strconv.Itoa(message.From.ID)} } } } diff --git a/bridge/xmpp/xmpp.go b/bridge/xmpp/xmpp.go index 3756f5b9..0bd664d9 100644 --- a/bridge/xmpp/xmpp.go +++ b/bridge/xmpp/xmpp.go @@ -128,7 +128,7 @@ func (b *Bxmpp) handleXmpp() error { } if nick != b.Config.Nick && v.Stamp == nodelay && v.Text != "" { flog.Debugf("Sending message from %s on %s to gateway", nick, b.Account) - b.Remote <- config.Message{Username: nick, Text: v.Text, Channel: channel, Account: b.Account} + b.Remote <- config.Message{Username: nick, Text: v.Text, Channel: channel, Account: b.Account, UserID: v.Remote} } } case xmpp.Presence: diff --git a/gateway/gateway.go b/gateway/gateway.go index d2c6c220..7d53069c 100644 --- a/gateway/gateway.go +++ b/gateway/gateway.go @@ -198,9 +198,6 @@ func (gw *Gateway) handleMessage(msg config.Message, dest *bridge.Bridge) { log.Debug("empty channel") return } - // hide message from bridge - //if msg.Text HideMessagesPrefix - originchannel := msg.Channel origmsg := msg for _, channel := range gw.DestChannelFunc(&msg, *dest) { diff --git a/matterclient/matterclient.go b/matterclient/matterclient.go index 927518e9..de2aa947 100644 --- a/matterclient/matterclient.go +++ b/matterclient/matterclient.go @@ -37,6 +37,7 @@ type Message struct { Username string Text string Type string + UserID string } type Team struct { @@ -290,6 +291,7 @@ func (m *MMClient) parseActionPost(rmsg *Message) { } rmsg.Username = m.GetUserName(data.UserId) rmsg.Channel = m.GetChannelName(data.ChannelId) + rmsg.UserID = data.UserId rmsg.Type = data.Type teamid, _ := rmsg.Raw.Data["team_id"].(string) // edit messsages have no team_id for some reason -- cgit v1.2.3