From 3897f23bc4dd24cf54ba39fad544d10feb273120 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Tue, 20 Mar 2018 12:16:32 +0200 Subject: Add support for loading more history --- matrix/matrix.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'matrix') 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() } } -- cgit v1.2.3