From fb713ed91bfb48c0037e489f80be85c54e69953a Mon Sep 17 00:00:00 2001 From: Wim Date: Fri, 18 Jan 2019 18:35:31 +0100 Subject: Add initial support for getting ChannelMember info of all bridges (#678) * Add initial support for getting ChannelMember info of all bridges. Adds an EventGetChannelMembers event, which gets send every x time to all bridges. Bridges should respond on this event with a Message containing ChannelMembers in the EventGetChannelMembers key in the Extra field. handleEventGetChannelMembers will handle this Message and sets the contained ChannelMembers to the Bridge struct. * Add ChannelMembers support to the slack bridge --- bridge/slack/handlers.go | 52 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) (limited to 'bridge/slack/handlers.go') diff --git a/bridge/slack/handlers.go b/bridge/slack/handlers.go index f46eb595..5e601eaa 100644 --- a/bridge/slack/handlers.go +++ b/bridge/slack/handlers.go @@ -309,6 +309,58 @@ func (b *Bslack) handleDownloadFile(rmsg *config.Message, file *slack.File, retr return nil } +// handleGetChannelMembers handles messages containing the GetChannelMembers event +// Sends a message to the router containing *config.ChannelMembers +func (b *Bslack) handleGetChannelMembers(rmsg *config.Message) bool { + if rmsg.Event != config.EventGetChannelMembers { + return false + } + + cMembers := config.ChannelMembers{} + + b.channelMembersMutex.RLock() + + for channelID, members := range b.channelMembers { + for _, member := range members { + channelName := "" + userName := "" + userNick := "" + user := b.getUser(member) + if user != nil { + userName = user.Name + userNick = user.Profile.DisplayName + } + channel, _ := b.getChannelByID(channelID) + if channel != nil { + channelName = channel.Name + } + cMember := config.ChannelMember{ + Username: userName, + Nick: userNick, + UserID: member, + ChannelID: channelID, + ChannelName: channelName, + } + cMembers = append(cMembers, cMember) + } + } + + b.channelMembersMutex.RUnlock() + + extra := make(map[string][]interface{}) + extra[config.EventGetChannelMembers] = append(extra[config.EventGetChannelMembers], cMembers) + msg := config.Message{ + Extra: extra, + Event: config.EventGetChannelMembers, + Account: b.Account, + } + + b.Log.Debugf("sending msg to remote %#v", msg) + b.Remote <- msg + + return true +} + // fileCached implements Matterbridge's caching logic for files // shared via Slack. // -- cgit v1.2.3