~geb/sup

9f6afa7c260d05b17f35f9893136fdd5e1991a25 — John Gebbie 1 year, 11 months ago a5f9132
store state events more simply
1 files changed, 7 insertions(+), 11 deletions(-)

M main.go
M main.go => main.go +7 -11
@@ 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)
	})