summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWim <wim@42.be>2018-10-27 22:03:41 +0200
committerWim <wim@42.be>2018-10-27 22:03:41 +0200
commit32f478e4a0783762667b4e964802b3d612d1f150 (patch)
tree819c8a1745d26d71c8d8e7c08ae433e4422ff4a8
parente2b50d6194ab825de8c6443d46b642ecd3a0313c (diff)
downloadmatterbridge-msglm-32f478e4a0783762667b4e964802b3d612d1f150.tar.gz
matterbridge-msglm-32f478e4a0783762667b4e964802b3d612d1f150.tar.bz2
matterbridge-msglm-32f478e4a0783762667b4e964802b3d612d1f150.zip
Check for expiring sessions and reconnect (mattermost)
-rw-r--r--matterclient/matterclient.go17
1 files changed, 14 insertions, 3 deletions
diff --git a/matterclient/matterclient.go b/matterclient/matterclient.go
index 8b3c07d1..5a173fe9 100644
--- a/matterclient/matterclient.go
+++ b/matterclient/matterclient.go
@@ -639,13 +639,15 @@ func (m *MMClient) UpdateChannelHeader(channelId string, header string) {
}
}
-func (m *MMClient) UpdateLastViewed(channelId string) {
+func (m *MMClient) UpdateLastViewed(channelId string) error {
m.log.Debugf("posting lastview %#v", channelId)
view := &model.ChannelView{ChannelId: channelId}
_, resp := m.Client.ViewChannel(m.User.Id, view)
if resp.Error != nil {
m.log.Errorf("ChannelView update for %s failed: %s", channelId, resp.Error)
+ return resp.Error
}
+ return nil
}
func (m *MMClient) UpdateUserNick(nick string) error {
@@ -896,8 +898,7 @@ func (m *MMClient) StatusLoop() {
return
}
if m.WsConnected {
- m.log.Debug("WS PING")
- m.sendWSRequest("ping", nil)
+ m.checkAlive()
select {
case <-m.WsPingChan:
m.log.Debug("WS PONG received")
@@ -972,6 +973,16 @@ func (m *MMClient) initUser() error {
return nil
}
+func (m *MMClient) checkAlive() error {
+ // check if session still is valid
+ _, resp := m.Client.GetMe("")
+ if resp.Error != nil {
+ return resp.Error
+ }
+ m.log.Debug("WS PING")
+ return m.sendWSRequest("ping", nil)
+}
+
func (m *MMClient) sendWSRequest(action string, data map[string]interface{}) error {
req := &model.WebSocketRequest{}
req.Seq = m.WsSequence