diff options
author | Tulir Asokan <tulir@maunium.net> | 2018-03-20 12:16:32 +0200 |
---|---|---|
committer | Tulir Asokan <tulir@maunium.net> | 2018-03-20 12:16:32 +0200 |
commit | 3897f23bc4dd24cf54ba39fad544d10feb273120 (patch) | |
tree | dbf3e8393661ccf1200b5127ace087077ddba413 /matrix | |
parent | de2a8aee060fa870f17cdd08b9ce5e0cd0287718 (diff) |
Add support for loading more history
Diffstat (limited to 'matrix')
-rw-r--r-- | matrix/matrix.go | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/matrix/matrix.go b/matrix/matrix.go index 564dc81..f20825c 100644 --- a/matrix/matrix.go +++ b/matrix/matrix.go @@ -74,7 +74,7 @@ func (c *Container) InitClient() error { c.stop = make(chan bool, 1) - if c.config.Session != nil { + if c.config.Session != nil && len(c.config.Session.AccessToken) > 0 { go c.Start() } return nil @@ -120,6 +120,11 @@ func (c *Container) Client() *gomatrix.Client { func (c *Container) UpdateRoomList() { resp, err := c.client.JoinedRooms() if err != nil { + respErr, _ := err.(gomatrix.HTTPError).WrappedError.(gomatrix.RespError) + if respErr.ErrCode == "M_UNKNOWN_TOKEN" { + c.OnLogout() + return + } debug.Print("Error fetching room list:", err) return } @@ -127,6 +132,11 @@ func (c *Container) UpdateRoomList() { c.ui.MainView().SetRooms(resp.JoinedRooms) } +func (c *Container) OnLogout() { + c.Stop() + c.ui.SetView(ifc.ViewLogin) +} + func (c *Container) OnLogin() { c.client.Store = c.config.Session @@ -145,6 +155,10 @@ func (c *Container) Start() { c.ui.SetView(ifc.ViewMain) c.OnLogin() + if c.client == nil { + return + } + debug.Print("Starting sync...") c.running = true for { @@ -167,6 +181,7 @@ func (c *Container) HandleMessage(evt *gomatrix.Event) { room, message := c.ui.MainView().ProcessMessageEvent(evt) if room != nil { room.AddMessage(message, widget.AppendMessage) + c.ui.Render() } } @@ -184,6 +199,7 @@ func (c *Container) HandleMembership(evt *gomatrix.Event) { room.UpdateUserList() room.AddMessage(message, widget.AppendMessage) + c.ui.Render() } } |