Stop sending notifications from first sync

This commit is contained in:
Tulir Asokan 2018-04-01 09:53:00 +03:00
parent 70343b4536
commit c6e9f498a4
2 changed files with 24 additions and 15 deletions

View File

@ -36,6 +36,7 @@ import (
// It is used for all Matrix calls from the UI and Matrix event handlers. // It is used for all Matrix calls from the UI and Matrix event handlers.
type Container struct { type Container struct {
client *gomatrix.Client client *gomatrix.Client
syncer *GomuksSyncer
gmx ifc.Gomuks gmx ifc.Gomuks
ui ifc.GomuksUI ui ifc.GomuksUI
config *config.Config config *config.Config
@ -172,13 +173,13 @@ func (c *Container) OnLogout() {
func (c *Container) OnLogin() { func (c *Container) OnLogin() {
c.client.Store = c.config.Session c.client.Store = c.config.Session
syncer := NewGomuksSyncer(c.config.Session) c.syncer = NewGomuksSyncer(c.config.Session)
syncer.OnEventType("m.room.message", c.HandleMessage) c.syncer.OnEventType("m.room.message", c.HandleMessage)
syncer.OnEventType("m.room.member", c.HandleMembership) c.syncer.OnEventType("m.room.member", c.HandleMembership)
syncer.OnEventType("m.typing", c.HandleTyping) c.syncer.OnEventType("m.typing", c.HandleTyping)
syncer.OnEventType("m.push_rules", c.HandlePushRules) c.syncer.OnEventType("m.push_rules", c.HandlePushRules)
syncer.OnEventType("m.tag", c.HandleTag) c.syncer.OnEventType("m.tag", c.HandleTag)
c.client.Syncer = syncer c.client.Syncer = c.syncer
c.UpdateRoomList() c.UpdateRoomList()
} }
@ -222,8 +223,10 @@ func (c *Container) HandleMessage(evt *gomatrix.Event) {
message := mainView.ProcessMessageEvent(roomView, evt) message := mainView.ProcessMessageEvent(roomView, evt)
if message != nil { if message != nil {
pushRules := c.PushRules().GetActions(roomView.Room, evt).Should() if c.syncer.FirstSyncDone {
mainView.NotifyMessage(roomView.Room, message, pushRules) pushRules := c.PushRules().GetActions(roomView.Room, evt).Should()
mainView.NotifyMessage(roomView.Room, message, pushRules)
}
roomView.AddMessage(message, widget.AppendMessage) roomView.AddMessage(message, widget.AppendMessage)
c.ui.Render() c.ui.Render()
} }
@ -283,8 +286,10 @@ func (c *Container) HandleMembership(evt *gomatrix.Event) {
// TODO This should probably also be in a different place // TODO This should probably also be in a different place
roomView.UpdateUserList() roomView.UpdateUserList()
pushRules := c.PushRules().GetActions(roomView.Room, evt).Should() if c.syncer.FirstSyncDone {
mainView.NotifyMessage(roomView.Room, message, pushRules) pushRules := c.PushRules().GetActions(roomView.Room, evt).Should()
mainView.NotifyMessage(roomView.Room, message, pushRules)
}
roomView.AddMessage(message, widget.AppendMessage) roomView.AddMessage(message, widget.AppendMessage)
c.ui.Render() c.ui.Render()
} }

View File

@ -33,15 +33,17 @@ import (
// replace parts of this default syncer (e.g. the ProcessResponse method). The default syncer uses the observer // 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. // pattern to notify callers about incoming events. See GomuksSyncer.OnEventType for more information.
type GomuksSyncer struct { type GomuksSyncer struct {
Session *config.Session Session *config.Session
listeners map[string][]gomatrix.OnEventListener // event type to listeners array listeners map[string][]gomatrix.OnEventListener // event type to listeners array
FirstSyncDone bool
} }
// NewGomuksSyncer returns an instantiated GomuksSyncer // NewGomuksSyncer returns an instantiated GomuksSyncer
func NewGomuksSyncer(session *config.Session) *GomuksSyncer { func NewGomuksSyncer(session *config.Session) *GomuksSyncer {
return &GomuksSyncer{ return &GomuksSyncer{
Session: session, Session: session,
listeners: make(map[string][]gomatrix.OnEventListener), 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 return
} }