diff options
author | Wim <wim@42.be> | 2019-01-18 18:35:31 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-01-18 18:35:31 +0100 |
commit | fb713ed91bfb48c0037e489f80be85c54e69953a (patch) | |
tree | e82901d1a604b02bbb5e3a2c4712f20e61d0513b /bridge/bridge.go | |
parent | d99eacc2e1b0deadc7368b35adf0818493fd2fb9 (diff) | |
download | matterbridge-msglm-fb713ed91bfb48c0037e489f80be85c54e69953a.tar.gz matterbridge-msglm-fb713ed91bfb48c0037e489f80be85c54e69953a.tar.bz2 matterbridge-msglm-fb713ed91bfb48c0037e489f80be85c54e69953a.zip |
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
Diffstat (limited to 'bridge/bridge.go')
-rw-r--r-- | bridge/bridge.go | 34 |
1 files changed, 23 insertions, 11 deletions
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] { |