From 439d8371dbe36d3316e739f8c5ff06d29c35d711 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Tue, 18 Jun 2019 17:31:55 +0300 Subject: Cache canonical alias in room list so tab completing wouldn't load state from disk --- matrix/rooms/room.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'matrix/rooms') diff --git a/matrix/rooms/room.go b/matrix/rooms/room.go index 4928871..7581316 100644 --- a/matrix/rooms/room.go +++ b/matrix/rooms/room.go @@ -104,7 +104,7 @@ type Room struct { // The topic of the room. Directly fetched from the m.room.topic state event. topicCache string // The canonical alias of the room. Directly fetched from the m.room.canonical_alias state event. - canonicalAliasCache string + CanonicalAliasCache string // The list of aliases. Directly fetched from the m.room.aliases state event. aliasesCache []string @@ -196,7 +196,7 @@ func (room *Room) Unload() bool { room.state = nil room.aliasesCache = nil room.topicCache = "" - room.canonicalAliasCache = "" + room.CanonicalAliasCache = "" room.firstMemberCache = nil room.secondMemberCache = nil if room.postUnload != nil { @@ -356,7 +356,7 @@ func (room *Room) UpdateState(event *mautrix.Event) { room.NameCache = event.Content.Alias room.nameCacheSource = CanonicalAliasRoomName } - room.canonicalAliasCache = event.Content.Alias + room.CanonicalAliasCache = event.Content.Alias case mautrix.StateAliases: if room.nameCacheSource <= AliasRoomName { room.NameCache = "" @@ -427,18 +427,18 @@ func (room *Room) GetTopic() string { } func (room *Room) GetCanonicalAlias() string { - if len(room.canonicalAliasCache) == 0 { + if len(room.CanonicalAliasCache) == 0 { canonicalAliasEvt := room.GetStateEvent(mautrix.StateCanonicalAlias, "") if canonicalAliasEvt != nil { - room.canonicalAliasCache = canonicalAliasEvt.Content.Alias + room.CanonicalAliasCache = canonicalAliasEvt.Content.Alias } else { - room.canonicalAliasCache = "-" + room.CanonicalAliasCache = "-" } } - if room.canonicalAliasCache == "-" { + if room.CanonicalAliasCache == "-" { return "" } - return room.canonicalAliasCache + return room.CanonicalAliasCache } // GetAliases returns the list of aliases that point to this room. -- cgit v1.2.3