@@ 356,8 356,15 @@ func (app *App) updateUnread(rid id.RoomID) {
func (app *App) sync() chan func() {
syncer := app.Client.Syncer.(*mautrix.DefaultSyncer)
+ storer := app.Client.Store.(*mautrix.InMemoryStore)
updates := make(chan func())
+ syncer.OnEvent(func(src mautrix.EventSource, ev *event.Event) {
+ updates <- func() {
+ storer.UpdateState(src, ev)
+ }
+ })
+
onEvent := func(t event.Type, h mautrix.EventHandler) {
syncer.OnEventType(t, func(src mautrix.EventSource, ev *event.Event) {
updates <- func() {
@@ 365,42 372,31 @@ func (app *App) sync() chan func() {
}
})
}
- store := func(src mautrix.EventSource, ev *event.Event) {
- app.Client.Store.(*mautrix.InMemoryStore).UpdateState(src, ev)
- }
onEvent(event.StateEncryption, func(src mautrix.EventSource, ev *event.Event) {
- store(src, ev)
app.refreshRoomDetails(ev.RoomID)
})
onEvent(event.StateCanonicalAlias, func(src mautrix.EventSource, ev *event.Event) {
- store(src, ev)
app.refreshRoomDetails(ev.RoomID)
})
onEvent(event.StateCreate, func(src mautrix.EventSource, ev *event.Event) {
- store(src, ev)
app.refreshRoomSoul(ev.RoomID)
})
onEvent(event.StateHistoryVisibility, func(src mautrix.EventSource, ev *event.Event) {
- store(src, ev)
app.refreshRoomDetails(ev.RoomID)
})
onEvent(event.StateJoinRules, func(src mautrix.EventSource, ev *event.Event) {
- store(src, ev)
})
onEvent(event.StateMember, func(src mautrix.EventSource, ev *event.Event) {
- store(src, ev)
if ev.Sender == app.Client.UserID {
app.refreshRoomSoul(ev.RoomID)
}
app.AddMessage(eventMessage(ev))
})
onEvent(event.StateRoomName, func(src mautrix.EventSource, ev *event.Event) {
- store(src, ev)
app.refreshRoomName(ev.RoomID)
})
onEvent(event.StateTopic, func(src mautrix.EventSource, ev *event.Event) {
- store(src, ev)
app.refreshRoomDetails(ev.RoomID)
})