diff options
author | Wim <wim@42.be> | 2018-12-12 23:57:17 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-12 23:57:17 +0100 |
commit | ccd55d2a2889349b8526dd55e29e827c12521f08 (patch) | |
tree | 448a595e577265de9e6d4f74e414ad0f4f2e5778 /gateway/router.go | |
parent | bfa9a83d316041769704c8b5da96d6f6fb68d732 (diff) | |
download | matterbridge-msglm-ccd55d2a2889349b8526dd55e29e827c12521f08.tar.gz matterbridge-msglm-ccd55d2a2889349b8526dd55e29e827c12521f08.tar.bz2 matterbridge-msglm-ccd55d2a2889349b8526dd55e29e827c12521f08.zip |
Refactor gateway (#648)
* Decrease complexity of handleMessage, handleReceive, handleFiles
* Move handlers to handlers.go
* Split ignoreMessage up in ignoreTextEmpty, ignoreNicks and IgnoreTexts
* Add ignoreEvent
* Add testcase for ignoreTextEmpty, ignoreNicks, ignoreTexts and ignoreEvent
Diffstat (limited to 'gateway/router.go')
-rw-r--r-- | gateway/router.go | 46 |
1 files changed, 14 insertions, 32 deletions
diff --git a/gateway/router.go b/gateway/router.go index e4478d84..a7181b96 100644 --- a/gateway/router.go +++ b/gateway/router.go @@ -108,41 +108,23 @@ func (r *Router) getBridge(account string) *bridge.Bridge { func (r *Router) handleReceive() { for msg := range r.Message { msg := msg // scopelint - if msg.Event == config.EventFailure { - Loop: - for _, gw := range r.Gateways { - for _, br := range gw.Bridges { - if msg.Account == br.Account { - go gw.reconnectBridge(br) - break Loop - } - } - } - } - if msg.Event == config.EventRejoinChannels { - for _, gw := range r.Gateways { - for _, br := range gw.Bridges { - if msg.Account == br.Account { - br.Joined = make(map[string]bool) - br.JoinChannels() - } - } - } - } + r.handleEventFailure(&msg) + r.handleEventRejoinChannels(&msg) for _, gw := range r.Gateways { // record all the message ID's of the different bridges var msgIDs []*BrMsgID - if !gw.ignoreMessage(&msg) { - msg.Timestamp = time.Now() - gw.modifyMessage(&msg) - gw.handleFiles(&msg) - for _, br := range gw.Bridges { - msgIDs = append(msgIDs, gw.handleMessage(msg, br)...) - } - // only add the message ID if it doesn't already exists - if _, ok := gw.Messages.Get(msg.Protocol + " " + msg.ID); !ok && msg.ID != "" { - gw.Messages.Add(msg.Protocol+" "+msg.ID, msgIDs) - } + if gw.ignoreMessage(&msg) { + continue + } + msg.Timestamp = time.Now() + gw.modifyMessage(&msg) + gw.handleFiles(&msg) + for _, br := range gw.Bridges { + msgIDs = append(msgIDs, gw.handleMessage(msg, br)...) + } + // only add the message ID if it doesn't already exists + if _, ok := gw.Messages.Get(msg.Protocol + " " + msg.ID); !ok && msg.ID != "" { + gw.Messages.Add(msg.Protocol+" "+msg.ID, msgIDs) } } } |