summaryrefslogtreecommitdiffstats
path: root/matterclient/matterclient.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2017-04-09 23:15:11 +0200
committerWim <wim@42.be>2017-04-09 23:15:11 +0200
commit36024d5439fa746a29152e33f3cab161d4d37d63 (patch)
tree11abf0ccc6b4c29e83b59757ba5ad7eeb5aa391c /matterclient/matterclient.go
parent8d52c983733f7c282164b5ae7f3edfc49c251a4c (diff)
downloadmatterbridge-msglm-36024d5439fa746a29152e33f3cab161d4d37d63.tar.gz
matterbridge-msglm-36024d5439fa746a29152e33f3cab161d4d37d63.tar.bz2
matterbridge-msglm-36024d5439fa746a29152e33f3cab161d4d37d63.zip
Add 3.8.0 support (mattermost)
Diffstat (limited to 'matterclient/matterclient.go')
-rw-r--r--matterclient/matterclient.go73
1 files changed, 58 insertions, 15 deletions
diff --git a/matterclient/matterclient.go b/matterclient/matterclient.go
index bdd8cbc6..a066d654 100644
--- a/matterclient/matterclient.go
+++ b/matterclient/matterclient.go
@@ -4,9 +4,11 @@ import (
"crypto/tls"
"encoding/json"
"errors"
+ "fmt"
"net/http"
"net/http/cookiejar"
"net/url"
+ "strconv"
"strings"
"sync"
"time"
@@ -48,19 +50,20 @@ type Team struct {
type MMClient struct {
sync.RWMutex
*Credentials
- Team *Team
- OtherTeams []*Team
- Client *model.Client
- User *model.User
- Users map[string]*model.User
- MessageChan chan *Message
- log *log.Entry
- WsClient *websocket.Conn
- WsQuit bool
- WsAway bool
- WsConnected bool
- WsSequence int64
- WsPingChan chan *model.WebSocketResponse
+ Team *Team
+ OtherTeams []*Team
+ Client *model.Client
+ User *model.User
+ Users map[string]*model.User
+ MessageChan chan *Message
+ log *log.Entry
+ WsClient *websocket.Conn
+ WsQuit bool
+ WsAway bool
+ WsConnected bool
+ WsSequence int64
+ WsPingChan chan *model.WebSocketResponse
+ ServerVersion string
}
func New(login, pass, team, server string) *MMClient {
@@ -105,6 +108,14 @@ func (m *MMClient) Login() error {
m.Client = model.NewClient(uriScheme + m.Credentials.Server)
m.Client.HttpClient.Transport = &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: m.SkipTLSVerify}}
m.Client.HttpClient.Timeout = time.Second * 10
+ // bogus call to get the serverversion
+ m.Client.GetClientProperties()
+ if firstConnection && !supportedVersion(m.Client.ServerVersion) {
+ return fmt.Errorf("unsupported mattermost version: %s", m.Client.ServerVersion)
+ }
+ m.ServerVersion = m.Client.ServerVersion
+ m.log.Infof("Found version %s", m.ServerVersion)
+
var myinfo *model.Result
var appErr *model.AppError
var logmsg = "trying login"
@@ -295,7 +306,12 @@ func (m *MMClient) UpdateChannels() error {
if err != nil {
return errors.New(err.DetailedError)
}
- mmchannels2, err := m.Client.GetMoreChannels("")
+ var mmchannels2 *model.Result
+ if m.mmVersion() >= 3.8 {
+ mmchannels2, err = m.Client.GetMoreChannelsPage(0, 5000)
+ } else {
+ mmchannels2, err = m.Client.GetMoreChannels("")
+ }
if err != nil {
return errors.New(err.DetailedError)
}
@@ -430,6 +446,14 @@ func (m *MMClient) UpdateChannelHeader(channelId string, header string) {
func (m *MMClient) UpdateLastViewed(channelId string) {
m.log.Debugf("posting lastview %#v", channelId)
+ if m.mmVersion() >= 3.8 {
+ view := model.ChannelView{ChannelId: channelId}
+ res, _ := m.Client.ViewChannel(view)
+ if res == false {
+ m.log.Errorf("ChannelView update for %s failed", channelId)
+ }
+ return
+ }
_, err := m.Client.UpdateLastViewedAt(channelId, true)
if err != nil {
m.log.Error(err)
@@ -663,7 +687,11 @@ func (m *MMClient) initUser() error {
return errors.New(err.DetailedError)
}
t.Channels = mmchannels.Data.(*model.ChannelList)
- mmchannels, err = m.Client.GetMoreChannels("")
+ if m.mmVersion() >= 3.8 {
+ mmchannels, err = m.Client.GetMoreChannelsPage(0, 5000)
+ } else {
+ mmchannels, err = m.Client.GetMoreChannels("")
+ }
if err != nil {
return errors.New(err.DetailedError)
}
@@ -691,3 +719,18 @@ func (m *MMClient) sendWSRequest(action string, data map[string]interface{}) err
m.WsClient.WriteJSON(req)
return nil
}
+
+func (m *MMClient) mmVersion() float64 {
+ v, _ := strconv.ParseFloat(m.ServerVersion[0:3], 64)
+ return v
+}
+
+func supportedVersion(version string) bool {
+ if strings.HasPrefix(version, "3.5.0") ||
+ strings.HasPrefix(version, "3.6.0") ||
+ strings.HasPrefix(version, "3.7.0") ||
+ strings.HasPrefix(version, "3.8.0") {
+ return true
+ }
+ return false
+}