forked from lug/matterbridge
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
This commit is contained in:
@@ -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] {
|
||||
|
||||
Reference in New Issue
Block a user