aboutsummaryrefslogtreecommitdiff
path: root/matrix
diff options
context:
space:
mode:
authorTulir Asokan <tulir@maunium.net>2020-02-20 01:10:26 +0200
committerTulir Asokan <tulir@maunium.net>2020-02-20 01:10:26 +0200
commitdb7d2da50cd0f4c20bc0966bff7c388c017e182f (patch)
tree0b7c450f0df7d912a9c30354ed84197a9931582d /matrix
parent8a0a3a6487bafbbcd3e0ae630b7ba95bf8ce76ce (diff)
Hide tombstoned rooms from room list
Diffstat (limited to 'matrix')
-rw-r--r--matrix/rooms/room.go33
1 files changed, 28 insertions, 5 deletions
diff --git a/matrix/rooms/room.go b/matrix/rooms/room.go
index 80c42bd..4632730 100644
--- a/matrix/rooms/room.go
+++ b/matrix/rooms/room.go
@@ -108,6 +108,10 @@ type Room struct {
CanonicalAliasCache string
// The list of aliases. Directly fetched from the m.room.aliases state event.
aliasesCache []string
+ // Whether or not the room has been tombstoned.
+ replacedCache bool
+ // The room ID that replaced this room.
+ replacedByCache *string
// Path for state store file.
path string
@@ -342,6 +346,9 @@ func (room *Room) Tags() []RoomTag {
// UpdateState updates the room's current state with the given Event. This will clobber events based
// on the type/state_key combination.
func (room *Room) UpdateState(event *mautrix.Event) {
+ if event.StateKey == nil {
+ panic("Tried to UpdateState() event with no state key.")
+ }
room.Load()
room.lock.Lock()
defer room.lock.Unlock()
@@ -378,11 +385,7 @@ func (room *Room) UpdateState(event *mautrix.Event) {
debug.Printf("Updating state %s#%s for %s", event.Type.String(), event.GetStateKey(), room.ID)
}
- if event.StateKey == nil {
- room.state[event.Type][""] = event
- } else {
- room.state[event.Type][*event.StateKey] = event
- }
+ room.state[event.Type][*event.StateKey] = event
}
func (room *Room) updateMemberState(event *mautrix.Event) {
@@ -549,6 +552,26 @@ func (room *Room) GetTitle() string {
return room.NameCache
}
+func (room *Room) IsReplaced() bool {
+ if room.replacedByCache == nil {
+ evt := room.GetStateEvent(mautrix.StateTombstone, "")
+ var replacement string
+ if evt != nil {
+ replacement = evt.Content.ReplacementRoom
+ }
+ room.replacedCache = evt != nil
+ room.replacedByCache = &replacement
+ }
+ return room.replacedCache
+}
+
+func (room *Room) ReplacedBy() string {
+ if room.replacedByCache == nil {
+ room.IsReplaced()
+ }
+ return *room.replacedByCache
+}
+
func (room *Room) eventToMember(userID string, content *mautrix.Content) *mautrix.Member {
member := &content.Member
member.Membership = content.Membership