mirror of
https://github.com/matrix-org/sliding-sync.git
synced 2025-03-10 13:37:11 +00:00
Track heroes' avatars
This commit is contained in:
parent
5913fbb0f3
commit
7097c1d279
@ -94,7 +94,13 @@ func (m *RoomMetadata) SameRoomName(other *RoomMetadata) bool {
|
||||
m.CanonicalAlias == other.CanonicalAlias &&
|
||||
m.JoinCount == other.JoinCount &&
|
||||
m.InviteCount == other.InviteCount &&
|
||||
sameHeroes(m.Heroes, other.Heroes))
|
||||
sameHeroNames(m.Heroes, other.Heroes))
|
||||
}
|
||||
|
||||
// SameRoomAvatar checks if the fields relevant for room avatars have changed between the two metadatas.
|
||||
// Returns true if there are no changes.
|
||||
func (m *RoomMetadata) SameRoomAvatar(other *RoomMetadata) bool {
|
||||
return m.AvatarEvent == other.AvatarEvent && sameHeroAvatars(m.Heroes, other.Heroes)
|
||||
}
|
||||
|
||||
func (m *RoomMetadata) SameJoinCount(other *RoomMetadata) bool {
|
||||
@ -105,7 +111,7 @@ func (m *RoomMetadata) SameInviteCount(other *RoomMetadata) bool {
|
||||
return m.InviteCount == other.InviteCount
|
||||
}
|
||||
|
||||
func sameHeroes(a, b []Hero) bool {
|
||||
func sameHeroNames(a, b []Hero) bool {
|
||||
if len(a) != len(b) {
|
||||
return false
|
||||
}
|
||||
@ -120,6 +126,21 @@ func sameHeroes(a, b []Hero) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func sameHeroAvatars(a, b []Hero) bool {
|
||||
if len(a) != len(b) {
|
||||
return false
|
||||
}
|
||||
for i := range a {
|
||||
if a[i].ID != b[i].ID {
|
||||
return false
|
||||
}
|
||||
if a[i].Avatar != b[i].Avatar {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (m *RoomMetadata) RemoveHero(userID string) {
|
||||
for i, h := range m.Heroes {
|
||||
if h.ID == userID {
|
||||
@ -134,8 +155,9 @@ func (m *RoomMetadata) IsSpace() bool {
|
||||
}
|
||||
|
||||
type Hero struct {
|
||||
ID string
|
||||
Name string
|
||||
ID string
|
||||
Name string
|
||||
Avatar string
|
||||
}
|
||||
|
||||
func CalculateRoomName(heroInfo *RoomMetadata, maxNumNamesPerRoom int) string {
|
||||
|
@ -284,8 +284,9 @@ func (s *Storage) MetadataForAllRooms(txn *sqlx.Tx, tempTableName string, result
|
||||
seen[key] = true
|
||||
metadata := result[roomID]
|
||||
metadata.Heroes = append(metadata.Heroes, internal.Hero{
|
||||
ID: targetUser,
|
||||
Name: ev.Get("content.displayname").Str,
|
||||
ID: targetUser,
|
||||
Name: ev.Get("content.displayname").Str,
|
||||
Avatar: ev.Get("content.avatar_url").Str,
|
||||
})
|
||||
result[roomID] = metadata
|
||||
}
|
||||
|
@ -347,14 +347,16 @@ func (c *GlobalCache) OnNewEvent(
|
||||
for i := range metadata.Heroes {
|
||||
if metadata.Heroes[i].ID == *ed.StateKey {
|
||||
metadata.Heroes[i].Name = ed.Content.Get("displayname").Str
|
||||
metadata.Heroes[i].Avatar = ed.Content.Get("avatar_url").Str
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
metadata.Heroes = append(metadata.Heroes, internal.Hero{
|
||||
ID: *ed.StateKey,
|
||||
Name: ed.Content.Get("displayname").Str,
|
||||
ID: *ed.StateKey,
|
||||
Name: ed.Content.Get("displayname").Str,
|
||||
Avatar: ed.Content.Get("avatar_url").Str,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -109,8 +109,9 @@ func NewInviteData(ctx context.Context, userID, roomID string, inviteState []jso
|
||||
id.IsDM = j.Get("is_direct").Bool()
|
||||
} else if target == j.Get("sender").Str {
|
||||
id.Heroes = append(id.Heroes, internal.Hero{
|
||||
ID: target,
|
||||
Name: j.Get("content.displayname").Str,
|
||||
ID: target,
|
||||
Name: j.Get("content.displayname").Str,
|
||||
Avatar: j.Get("content.avatar_url").Str,
|
||||
})
|
||||
}
|
||||
case "m.room.name":
|
||||
|
Loading…
x
Reference in New Issue
Block a user