From c6e9f498a4d4c12460c73d8d3358742ed60b7816 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Sun, 1 Apr 2018 09:53:00 +0300 Subject: Stop sending notifications from first sync --- matrix/matrix.go | 27 ++++++++++++++++----------- matrix/sync.go | 12 ++++++++---- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/matrix/matrix.go b/matrix/matrix.go index 5bd9d17..7391ca0 100644 --- a/matrix/matrix.go +++ b/matrix/matrix.go @@ -36,6 +36,7 @@ import ( // It is used for all Matrix calls from the UI and Matrix event handlers. type Container struct { client *gomatrix.Client + syncer *GomuksSyncer gmx ifc.Gomuks ui ifc.GomuksUI config *config.Config @@ -172,13 +173,13 @@ func (c *Container) OnLogout() { func (c *Container) OnLogin() { c.client.Store = c.config.Session - syncer := NewGomuksSyncer(c.config.Session) - syncer.OnEventType("m.room.message", c.HandleMessage) - syncer.OnEventType("m.room.member", c.HandleMembership) - syncer.OnEventType("m.typing", c.HandleTyping) - syncer.OnEventType("m.push_rules", c.HandlePushRules) - syncer.OnEventType("m.tag", c.HandleTag) - c.client.Syncer = syncer + c.syncer = NewGomuksSyncer(c.config.Session) + c.syncer.OnEventType("m.room.message", c.HandleMessage) + c.syncer.OnEventType("m.room.member", c.HandleMembership) + c.syncer.OnEventType("m.typing", c.HandleTyping) + c.syncer.OnEventType("m.push_rules", c.HandlePushRules) + c.syncer.OnEventType("m.tag", c.HandleTag) + c.client.Syncer = c.syncer c.UpdateRoomList() } @@ -222,8 +223,10 @@ func (c *Container) HandleMessage(evt *gomatrix.Event) { message := mainView.ProcessMessageEvent(roomView, evt) if message != nil { - pushRules := c.PushRules().GetActions(roomView.Room, evt).Should() - mainView.NotifyMessage(roomView.Room, message, pushRules) + if c.syncer.FirstSyncDone { + pushRules := c.PushRules().GetActions(roomView.Room, evt).Should() + mainView.NotifyMessage(roomView.Room, message, pushRules) + } roomView.AddMessage(message, widget.AppendMessage) c.ui.Render() } @@ -283,8 +286,10 @@ func (c *Container) HandleMembership(evt *gomatrix.Event) { // TODO This should probably also be in a different place roomView.UpdateUserList() - pushRules := c.PushRules().GetActions(roomView.Room, evt).Should() - mainView.NotifyMessage(roomView.Room, message, pushRules) + if c.syncer.FirstSyncDone { + pushRules := c.PushRules().GetActions(roomView.Room, evt).Should() + mainView.NotifyMessage(roomView.Room, message, pushRules) + } roomView.AddMessage(message, widget.AppendMessage) c.ui.Render() } diff --git a/matrix/sync.go b/matrix/sync.go index 0169e8e..35a694a 100644 --- a/matrix/sync.go +++ b/matrix/sync.go @@ -33,15 +33,17 @@ import ( // replace parts of this default syncer (e.g. the ProcessResponse method). The default syncer uses the observer // pattern to notify callers about incoming events. See GomuksSyncer.OnEventType for more information. type GomuksSyncer struct { - Session *config.Session - listeners map[string][]gomatrix.OnEventListener // event type to listeners array + Session *config.Session + listeners map[string][]gomatrix.OnEventListener // event type to listeners array + FirstSyncDone bool } // NewGomuksSyncer returns an instantiated GomuksSyncer func NewGomuksSyncer(session *config.Session) *GomuksSyncer { return &GomuksSyncer{ - Session: session, - listeners: make(map[string][]gomatrix.OnEventListener), + Session: session, + listeners: make(map[string][]gomatrix.OnEventListener), + FirstSyncDone: false, } } @@ -87,6 +89,8 @@ func (s *GomuksSyncer) ProcessResponse(res *gomatrix.RespSync, since string) (er } } + s.FirstSyncDone = true + return } -- cgit v1.2.3