Include m.room.encryption state events in timeline in sync filter

This commit is contained in:
Tulir Asokan 2020-11-29 02:05:11 +02:00
parent f3854524bc
commit 45f71dbaa3
2 changed files with 25 additions and 23 deletions

View File

@ -36,6 +36,7 @@ import (
type AuthCache struct { type AuthCache struct {
NextBatch string `yaml:"next_batch"` NextBatch string `yaml:"next_batch"`
FilterID string `yaml:"filter_id"` FilterID string `yaml:"filter_id"`
FilterVersion int `yaml:"filter_version"`
InitialSyncDone bool `yaml:"initial_sync_done"` InitialSyncDone bool `yaml:"initial_sync_done"`
} }
@ -262,12 +263,18 @@ func (config *Config) GetUserID() id.UserID {
return config.UserID return config.UserID
} }
const FilterVersion = 1
func (config *Config) SaveFilterID(_ id.UserID, filterID string) { func (config *Config) SaveFilterID(_ id.UserID, filterID string) {
config.AuthCache.FilterID = filterID config.AuthCache.FilterID = filterID
config.AuthCache.FilterVersion = FilterVersion
config.SaveAuthCache() config.SaveAuthCache()
} }
func (config *Config) LoadFilterID(_ id.UserID) string { func (config *Config) LoadFilterID(_ id.UserID) string {
if config.AuthCache.FilterVersion != FilterVersion {
return ""
}
return config.AuthCache.FilterID return config.AuthCache.FilterID
} }

View File

@ -226,12 +226,7 @@ func (s *GomuksSyncer) OnFailedSync(res *mautrix.RespSync, err error) (time.Dura
// GetFilterJSON returns a filter with a timeline limit of 50. // GetFilterJSON returns a filter with a timeline limit of 50.
func (s *GomuksSyncer) GetFilterJSON(_ id.UserID) *mautrix.Filter { func (s *GomuksSyncer) GetFilterJSON(_ id.UserID) *mautrix.Filter {
return &mautrix.Filter{ stateEvents := []event.Type{
Room: mautrix.RoomFilter{
IncludeLeave: false,
State: mautrix.FilterPart{
LazyLoadMembers: true,
Types: []event.Type{
event.StateMember, event.StateMember,
event.StateRoomName, event.StateRoomName,
event.StateTopic, event.StateTopic,
@ -239,24 +234,24 @@ func (s *GomuksSyncer) GetFilterJSON(_ id.UserID) *mautrix.Filter {
event.StatePowerLevels, event.StatePowerLevels,
event.StateTombstone, event.StateTombstone,
event.StateEncryption, event.StateEncryption,
}, }
}, messageEvents := []event.Type{
Timeline: mautrix.FilterPart{
LazyLoadMembers: true,
Types: []event.Type{
event.EventMessage, event.EventMessage,
event.EventRedaction, event.EventRedaction,
event.EventEncrypted, event.EventEncrypted,
event.EventSticker, event.EventSticker,
event.EventReaction, event.EventReaction,
}
event.StateMember, return &mautrix.Filter{
event.StateRoomName, Room: mautrix.RoomFilter{
event.StateTopic, IncludeLeave: false,
event.StateCanonicalAlias, State: mautrix.FilterPart{
event.StatePowerLevels, LazyLoadMembers: true,
event.StateTombstone, Types: stateEvents,
}, },
Timeline: mautrix.FilterPart{
LazyLoadMembers: true,
Types: append(messageEvents, stateEvents...),
Limit: 50, Limit: 50,
}, },
Ephemeral: mautrix.FilterPart{ Ephemeral: mautrix.FilterPart{