aboutsummaryrefslogtreecommitdiff
path: root/matrix
diff options
context:
space:
mode:
authorTulir Asokan <tulir@maunium.net>2018-05-10 15:47:24 +0300
committerTulir Asokan <tulir@maunium.net>2018-05-10 15:47:24 +0300
commit151141f288e51e427168cee1340a7163bf58309a (patch)
treeca025dcc96d595fdd77b9934836b96da2773df41 /matrix
parente42ce27e0a3f9d04160f892f67c73b81fc076dd3 (diff)
Add command to log out
Diffstat (limited to 'matrix')
-rw-r--r--matrix/matrix.go22
1 files changed, 15 insertions, 7 deletions
diff --git a/matrix/matrix.go b/matrix/matrix.go
index b43a858..4609876 100644
--- a/matrix/matrix.go
+++ b/matrix/matrix.go
@@ -131,6 +131,15 @@ func (c *Container) Login(user, password string) error {
return nil
}
+// Logout revokes the access token, stops the syncer and calls the OnLogout() method of the UI.
+func (c *Container) Logout() {
+ c.client.Logout()
+ c.config.DeleteSession()
+ c.Stop()
+ c.client = nil
+ c.ui.OnLogout()
+}
+
// Stop stops the Matrix syncer.
func (c *Container) Stop() {
if c.running {
@@ -158,12 +167,6 @@ func (c *Container) PushRules() *pushrules.PushRuleset {
return c.config.Session.PushRules
}
-// OnLogout stops the syncer and moves the UI back to the login view.
-func (c *Container) OnLogout() {
- c.ui.OnLogout()
- c.Stop()
-}
-
// OnLogin initializes the syncer and updates the room list.
func (c *Container) OnLogin() {
c.ui.OnLogin()
@@ -209,7 +212,12 @@ func (c *Container) Start() {
return
default:
if err := c.client.Sync(); err != nil {
- debug.Print("Sync() errored", err)
+ if httpErr, ok := err.(gomatrix.HTTPError); ok && httpErr.Code == http.StatusUnauthorized {
+ debug.Print("Sync() errored with ", err, " -> logging out")
+ c.Logout()
+ } else {
+ debug.Print("Sync() errored", err)
+ }
} else {
debug.Print("Sync() returned without error")
}