Hide tombstoned rooms from room list

This commit is contained in:
Tulir Asokan 2020-02-20 01:10:26 +02:00
parent 8a0a3a6487
commit db7d2da50c
5 changed files with 41 additions and 7 deletions

2
go.mod
View File

@ -19,7 +19,7 @@ require (
golang.org/x/net v0.0.0-20200202094626-16171245cfb2 golang.org/x/net v0.0.0-20200202094626-16171245cfb2
gopkg.in/toast.v1 v1.0.0-20180812000517-0a84660828b2 gopkg.in/toast.v1 v1.0.0-20180812000517-0a84660828b2
gopkg.in/yaml.v2 v2.2.8 gopkg.in/yaml.v2 v2.2.8
maunium.net/go/mautrix v0.1.0-alpha.3.0.20200219223957-21a588b7e623 maunium.net/go/mautrix v0.1.0-alpha.3.0.20200219230859-de66c34ea5bc
maunium.net/go/mauview v0.0.0-20200219222453-b984e20438e6 maunium.net/go/mauview v0.0.0-20200219222453-b984e20438e6
maunium.net/go/tcell v1.1.2-0.20200218183045-87c4a25c5b09 maunium.net/go/tcell v1.1.2-0.20200218183045-87c4a25c5b09
) )

2
go.sum
View File

@ -78,6 +78,8 @@ maunium.net/go/mautrix v0.1.0-alpha.3.0.20200218232310-9638cb6d80d2 h1:X4ONPO3Ny
maunium.net/go/mautrix v0.1.0-alpha.3.0.20200218232310-9638cb6d80d2/go.mod h1:g10T1fh2Q2HkJWycVs93eBXdWpqD67f1YVQhNxdIDr4= maunium.net/go/mautrix v0.1.0-alpha.3.0.20200218232310-9638cb6d80d2/go.mod h1:g10T1fh2Q2HkJWycVs93eBXdWpqD67f1YVQhNxdIDr4=
maunium.net/go/mautrix v0.1.0-alpha.3.0.20200219223957-21a588b7e623 h1:StXwGEEdQA+aACru6CSPXPafhQqYCc9CnQW4fIwz+KU= maunium.net/go/mautrix v0.1.0-alpha.3.0.20200219223957-21a588b7e623 h1:StXwGEEdQA+aACru6CSPXPafhQqYCc9CnQW4fIwz+KU=
maunium.net/go/mautrix v0.1.0-alpha.3.0.20200219223957-21a588b7e623/go.mod h1:g10T1fh2Q2HkJWycVs93eBXdWpqD67f1YVQhNxdIDr4= maunium.net/go/mautrix v0.1.0-alpha.3.0.20200219223957-21a588b7e623/go.mod h1:g10T1fh2Q2HkJWycVs93eBXdWpqD67f1YVQhNxdIDr4=
maunium.net/go/mautrix v0.1.0-alpha.3.0.20200219230859-de66c34ea5bc h1:1iMzqdMF4z9Rp3CDfDa+gjuRHGfb9cZjZZR9Y68nPuo=
maunium.net/go/mautrix v0.1.0-alpha.3.0.20200219230859-de66c34ea5bc/go.mod h1:g10T1fh2Q2HkJWycVs93eBXdWpqD67f1YVQhNxdIDr4=
maunium.net/go/mauview v0.0.0-20200218183549-88ecb1321176 h1:KoTm7ASEzFIZ1SvPWuWYzpkeA+wiR1fuUu4l7TCHcE0= maunium.net/go/mauview v0.0.0-20200218183549-88ecb1321176 h1:KoTm7ASEzFIZ1SvPWuWYzpkeA+wiR1fuUu4l7TCHcE0=
maunium.net/go/mauview v0.0.0-20200218183549-88ecb1321176/go.mod h1:jwg3Ow7akzsCX3q38pZAfmEC5gGN8gXwMyyjy/yZVMg= maunium.net/go/mauview v0.0.0-20200218183549-88ecb1321176/go.mod h1:jwg3Ow7akzsCX3q38pZAfmEC5gGN8gXwMyyjy/yZVMg=
maunium.net/go/mauview v0.0.0-20200218231215-04d01c601d5b h1:Bfov5IkJQpkqDexiFioHIZpx4XL7AILDA1GwLVdqtBw= maunium.net/go/mauview v0.0.0-20200218231215-04d01c601d5b h1:Bfov5IkJQpkqDexiFioHIZpx4XL7AILDA1GwLVdqtBw=

View File

@ -108,6 +108,10 @@ type Room struct {
CanonicalAliasCache string CanonicalAliasCache string
// The list of aliases. Directly fetched from the m.room.aliases state event. // The list of aliases. Directly fetched from the m.room.aliases state event.
aliasesCache []string 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 for state store file.
path string 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 // UpdateState updates the room's current state with the given Event. This will clobber events based
// on the type/state_key combination. // on the type/state_key combination.
func (room *Room) UpdateState(event *mautrix.Event) { func (room *Room) UpdateState(event *mautrix.Event) {
if event.StateKey == nil {
panic("Tried to UpdateState() event with no state key.")
}
room.Load() room.Load()
room.lock.Lock() room.lock.Lock()
defer room.lock.Unlock() defer room.lock.Unlock()
@ -378,12 +385,8 @@ func (room *Room) UpdateState(event *mautrix.Event) {
debug.Printf("Updating state %s#%s for %s", event.Type.String(), event.GetStateKey(), room.ID) 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) { func (room *Room) updateMemberState(event *mautrix.Event) {
userID := event.GetStateKey() userID := event.GetStateKey()
@ -549,6 +552,26 @@ func (room *Room) GetTitle() string {
return room.NameCache 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 { func (room *Room) eventToMember(userID string, content *mautrix.Content) *mautrix.Member {
member := &content.Member member := &content.Member
member.Membership = content.Membership member.Membership = content.Membership

View File

@ -89,6 +89,10 @@ func (fs *FuzzySearchModal) Blur() {
func (fs *FuzzySearchModal) InitList(rooms map[string]*RoomView) { func (fs *FuzzySearchModal) InitList(rooms map[string]*RoomView) {
for _, room := range rooms { for _, room := range rooms {
if room.Room.IsReplaced() {
//if _, ok := rooms[room.Room.ReplacedBy()]; ok
continue
}
fs.roomList = append(fs.roomList, room.Room) fs.roomList = append(fs.roomList, room.Room)
fs.roomTitles = append(fs.roomTitles, room.Room.GetTitle()) fs.roomTitles = append(fs.roomTitles, room.Room.GetTitle())
} }
@ -134,6 +138,7 @@ func (fs *FuzzySearchModal) OnKeyEvent(event mauview.KeyEvent) bool {
fs.results.Highlight(strconv.Itoa(fs.matches[fs.selected].OriginalIndex)) fs.results.Highlight(strconv.Itoa(fs.matches[fs.selected].OriginalIndex))
fs.results.ScrollToHighlight() fs.results.ScrollToHighlight()
} }
return true
case tcell.KeyEnter: case tcell.KeyEnter:
// Switch room to currently selected room // Switch room to currently selected room
if len(highlights) > 0 { if len(highlights) > 0 {

View File

@ -88,7 +88,11 @@ func (list *RoomList) Contains(roomID string) bool {
} }
func (list *RoomList) Add(room *rooms.Room) { func (list *RoomList) Add(room *rooms.Room) {
debug.Print("Adding room to list", room.ID, room.GetTitle(), room.IsDirect, room.Tags()) if room.IsReplaced() {
debug.Print(room.ID, "is replaced by", room.ReplacedBy(), "-> not adding to room list")
return
}
debug.Print("Adding room to list", room.ID, room.GetTitle(), room.IsDirect, room.ReplacedBy(), room.Tags())
for _, tag := range room.Tags() { for _, tag := range room.Tags() {
list.AddToTag(tag, room) list.AddToTag(tag, room)
} }