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/bridge.go | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) (limited to 'bridge/bridge.go') diff --git a/bridge/bridge.go b/bridge/bridge.go index 336e2e2c..6b955a9e 100644 --- a/bridge/bridge.go +++ b/bridge/bridge.go @@ -5,6 +5,7 @@ import ( "github.com/42wim/matterbridge/bridge/config" "github.com/sirupsen/logrus" + "sync" ) type Bridger interface { @@ -16,14 +17,16 @@ type Bridger interface { type Bridge struct { Bridger - Name string - Account string - Protocol string - Channels map[string]config.ChannelInfo - Joined map[string]bool - Log *logrus.Entry - Config config.Config - General *config.Protocol + Name string + Account string + Protocol string + Channels map[string]config.ChannelInfo + Joined map[string]bool + ChannelMembers *config.ChannelMembers + Log *logrus.Entry + Config config.Config + General *config.Protocol + *sync.RWMutex } type Config struct { @@ -37,15 +40,17 @@ type Config struct { type Factory func(*Config) Bridger func New(bridge *config.Bridge) *Bridge { - b := new(Bridge) - b.Channels = make(map[string]config.ChannelInfo) + b := &Bridge{ + Channels: make(map[string]config.ChannelInfo), + RWMutex: new(sync.RWMutex), + Joined: make(map[string]bool), + } accInfo := strings.Split(bridge.Account, ".") protocol := accInfo[0] name := accInfo[1] b.Name = name b.Protocol = protocol b.Account = bridge.Account - b.Joined = make(map[string]bool) return b } @@ -54,6 +59,13 @@ func (b *Bridge) JoinChannels() error { return err } +// SetChannelMembers sets the newMembers to the bridge ChannelMembers +func (b *Bridge) SetChannelMembers(newMembers *config.ChannelMembers) { + b.Lock() + b.ChannelMembers = newMembers + b.Unlock() +} + func (b *Bridge) joinChannels(channels map[string]config.ChannelInfo, exists map[string]bool) error { for ID, channel := range channels { if !exists[ID] { -- cgit v1.2.3