From c600ce68a2684fdeebfbe9580c6ff833257450ed Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Mon, 30 Apr 2018 23:09:14 +0300 Subject: Fix room list updating when joining/leaving --- matrix/matrix.go | 41 ++++++++++++----------------------------- matrix/sync.go | 2 +- 2 files changed, 13 insertions(+), 30 deletions(-) (limited to 'matrix') diff --git a/matrix/matrix.go b/matrix/matrix.go index 655e272..2b0832b 100644 --- a/matrix/matrix.go +++ b/matrix/matrix.go @@ -294,7 +294,7 @@ func (c *Container) processOwnMembershipChange(evt *gomatrix.Event) { } } -// HandleMembership is the event handler for the m.room.membership state event. +// HandleMembership is the event handler for the m.room.member state event. func (c *Container) HandleMembership(source EventSource, evt *gomatrix.Event) { if !c.config.Session.InitialSyncDone && source == EventSourceLeave { return @@ -418,9 +418,9 @@ func (c *Container) SendTyping(roomID string, typing bool) { } // JoinRoom makes the current user try to join the given room. -func (c *Container) JoinRoom(roomID string) error { +func (c *Container) JoinRoom(roomID string) (*rooms.Room, error) { if len(roomID) == 0 { - return fmt.Errorf("invalid room ID") + return nil, fmt.Errorf("invalid room ID") } server := "" @@ -428,12 +428,15 @@ func (c *Container) JoinRoom(roomID string) error { server = roomID[strings.Index(roomID, ":")+1:] } - _, err := c.client.JoinRoom(roomID, server, nil) + resp, err := c.client.JoinRoom(roomID, server, nil) if err != nil { - return err + return nil, err } - return nil + room := c.GetRoom(resp.RoomID) + room.HasLeft = false + + return room, nil } // LeaveRoom makes the current user leave the given room. @@ -447,20 +450,11 @@ func (c *Container) LeaveRoom(roomID string) error { return err } + room := c.GetRoom(roomID) + room.HasLeft = true return nil } -// getState requests the state of the given room. -func (c *Container) getState(roomID string) []*gomatrix.Event { - content := make([]*gomatrix.Event, 0) - err := c.client.StateEvent(roomID, "", "", &content) - if err != nil { - debug.Print("Error getting state of", roomID, err) - return nil - } - return content -} - // GetHistory fetches room history. func (c *Container) GetHistory(roomID, prevBatch string, limit int) ([]gomatrix.Event, string, error) { resp, err := c.client.Messages(roomID, prevBatch, "", 'b', limit) @@ -471,19 +465,8 @@ func (c *Container) GetHistory(roomID, prevBatch string, limit int) ([]gomatrix. } // GetRoom gets the room instance stored in the session. -// -// If the room doesn't have any state events stored, its state will be updated. func (c *Container) GetRoom(roomID string) *rooms.Room { - room := c.config.Session.GetRoom(roomID) - if room != nil && len(room.State) == 0 { - /*events := c.getState(room.ID) - if events != nil { - for _, event := range events { - room.UpdateState(event) - } - }*/ - } - return room + return c.config.Session.GetRoom(roomID) } var mxcRegex = regexp.MustCompile("mxc://(.+)/(.+)") diff --git a/matrix/sync.go b/matrix/sync.go index e2d38df..9488705 100644 --- a/matrix/sync.go +++ b/matrix/sync.go @@ -150,7 +150,7 @@ func (s *GomuksSyncer) OnFailedSync(res *gomatrix.RespSync, err error) (time.Dur func (s *GomuksSyncer) GetFilterJSON(userID string) json.RawMessage { return json.RawMessage(`{ "room": { - "include_leave": true, + "include_leave": false, "state": { "types": [ "m.room.member", -- cgit v1.2.3