Documentation
¶
Index ¶
- Constants
- type AccountDataUpdate
- type CacheFinder
- type DeviceDataUpdate
- type DeviceEventsUpdate
- type EventData
- type GlobalCache
- func (c *GlobalCache) LoadJoinedRooms(ctx context.Context, userID string) (pos int64, joinedRooms map[string]*internal.RoomMetadata, ...)
- func (c *GlobalCache) LoadRoomState(ctx context.Context, roomIDs []string, loadPosition int64, ...) map[string][]json.RawMessage
- func (c *GlobalCache) LoadRooms(ctx context.Context, roomIDs ...string) map[string]*internal.RoomMetadata
- func (c *GlobalCache) LoadRoomsFromMap(ctx context.Context, joinTimingsByRoomID map[string]internal.EventMetadata) map[string]*internal.RoomMetadata
- func (c *GlobalCache) LoadStateEvent(ctx context.Context, roomID string, loadPosition int64, ...) json.RawMessage
- func (c *GlobalCache) OnEphemeralEvent(ctx context.Context, roomID string, ephEvent json.RawMessage)
- func (c *GlobalCache) OnNewEvent(ctx context.Context, ed *EventData)
- func (c *GlobalCache) OnReceipt(ctx context.Context, receipt internal.Receipt)
- func (c *GlobalCache) OnRegistered(_ context.Context) error
- func (c *GlobalCache) Startup(roomIDToMetadata map[string]internal.RoomMetadata) error
- type InviteData
- type InviteUpdate
- type LeftRoomUpdate
- type ReceiptUpdate
- type RoomAccountDataUpdate
- type RoomEventUpdate
- type RoomUpdate
- type TransactionIDFetcher
- type TypingUpdate
- type UnreadCountUpdate
- type Update
- type UserCache
- func (c *UserCache) AnnotateWithTransactionIDs(ctx context.Context, userID string, deviceID string, ...) map[string][]json.RawMessage
- func (c *UserCache) Invites() map[string]UserRoomData
- func (c *UserCache) LazyLoadTimelines(ctx context.Context, loadPos int64, roomIDs []string, maxTimelineEvents int) map[string]UserRoomData
- func (c *UserCache) LoadRoomData(roomID string) UserRoomData
- func (c *UserCache) OnAccountData(ctx context.Context, datas []state.AccountData)
- func (c *UserCache) OnEphemeralEvent(ctx context.Context, roomID string, ephEvent json.RawMessage)
- func (c *UserCache) OnInvite(ctx context.Context, roomID string, inviteStateEvents []json.RawMessage)
- func (c *UserCache) OnLeftRoom(ctx context.Context, roomID string)
- func (c *UserCache) OnNewEvent(ctx context.Context, eventData *EventData)
- func (c *UserCache) OnReceipt(ctx context.Context, receipt internal.Receipt)
- func (c *UserCache) OnRegistered(ctx context.Context) error
- func (c *UserCache) OnSpaceUpdate(ctx context.Context, parentRoomID, childRoomID string, isDeleted bool, ...)
- func (c *UserCache) OnUnreadCounts(ctx context.Context, roomID string, highlightCount, notifCount *int)
- func (c *UserCache) Subsribe(ucl UserCacheListener) (id int)
- func (c *UserCache) Unsubscribe(id int)
- type UserCacheListener
- type UserRoomData
Constants ¶
const (
InvitesAreHighlightsValue = 1 // invite -> highlight count = 1
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AccountDataUpdate ¶
type AccountDataUpdate struct {
AccountData []state.AccountData
}
AccountDataUpdate represents the (global) `account_data` section of a v2 sync response.
func (*AccountDataUpdate) Type ¶ added in v0.99.1
func (u *AccountDataUpdate) Type() string
type CacheFinder ¶
type DeviceDataUpdate ¶ added in v0.98.1
type DeviceDataUpdate struct { }
func (DeviceDataUpdate) Type ¶ added in v0.99.1
func (u DeviceDataUpdate) Type() string
type DeviceEventsUpdate ¶ added in v0.98.1
type DeviceEventsUpdate struct { }
func (DeviceEventsUpdate) Type ¶ added in v0.99.1
func (u DeviceEventsUpdate) Type() string
type EventData ¶
type EventData struct { Event json.RawMessage RoomID string EventType string StateKey *string Content gjson.Result Timestamp uint64 Sender string // the number of joined users in this room. Use this value and don't try to work it out as you // may get it wrong due to Synapse sending duplicate join events(!) This value has them de-duped // correctly. JoinCount int InviteCount int // NID is the nid for this event; or a non-nid sentinel value. Current sentinels are // - PosAlwaysProcess and PosDoNotProcess, for things outside the event timeline // e.g invites; and // - `0` used by UserCache.OnRegistered to inject space children events at startup. // It's referenced in ConnState.OnRoomUpdateand UserCache.OnSpaceUpdate NID int64 // Update consumers will usually ignore updates with a NID < what they have seen before for this room. // However, in some cases, we want to force the consumer to process this event even though the NID // may be < what they have seen before. Currently, we use this to force consumers to process invites // for a connected client, as the invite itself has no event NID due to the proxy not being in the room yet. AlwaysProcess bool // Flag set when this event should force the room contents to be resent e.g // state res, initial join, etc ForceInitial bool }
type GlobalCache ¶
type GlobalCache struct { // LoadJoinedRoomsOverride allows tests to mock out the behaviour of LoadJoinedRooms. LoadJoinedRoomsOverride func(userID string) (pos int64, joinedRooms map[string]*internal.RoomMetadata, joinTimings map[string]internal.EventMetadata, latestNIDs map[string]int64, err error) // contains filtered or unexported fields }
The purpose of global cache is to store global-level information about all rooms the server is aware of. Global-level information is represented as internal.RoomMetadata and includes things like Heroes, join/invite counts, if the room is encrypted, etc. Basically anything that is the same for all users of the system. This information is populated at startup from the database and then kept up-to-date by hooking into the Dispatcher for new events.
func NewGlobalCache ¶
func NewGlobalCache(store *state.Storage) *GlobalCache
func (*GlobalCache) LoadJoinedRooms ¶
func (c *GlobalCache) LoadJoinedRooms(ctx context.Context, userID string) ( pos int64, joinedRooms map[string]*internal.RoomMetadata, joinTimingByRoomID map[string]internal.EventMetadata, latestNIDs map[string]int64, err error, )
LoadJoinedRooms loads all current joined room metadata for the user given, together with timing info for the user's latest join (excluding profile changes) to the room. Returns the absolute database position (the latest event NID across the whole DB), along with the results.
The two maps returned by this function have exactly the same set of keys. Each is nil iff a non-nil error is returned. TODO: remove with LoadRoomState? FIXME: return args are a mess
func (*GlobalCache) LoadRoomState ¶
func (c *GlobalCache) LoadRoomState(ctx context.Context, roomIDs []string, loadPosition int64, requiredStateMap *internal.RequiredStateMap, roomToUsersInTimeline map[string][]string) map[string][]json.RawMessage
TODO: remove? Doesn't touch global cache fields
func (*GlobalCache) LoadRooms ¶
func (c *GlobalCache) LoadRooms(ctx context.Context, roomIDs ...string) map[string]*internal.RoomMetadata
LoadRooms loads the current room metadata for the given room IDs. Races unless you call this in a dispatcher loop. Always returns copies of the room metadata so ownership can be passed to other threads.
func (*GlobalCache) LoadRoomsFromMap ¶ added in v0.99.3
func (c *GlobalCache) LoadRoomsFromMap(ctx context.Context, joinTimingsByRoomID map[string]internal.EventMetadata) map[string]*internal.RoomMetadata
LoadRoomsFromMap is like LoadRooms, except it is given a map with room IDs as keys and returns rooms in a map. The output map is non-nil and contains exactly the same set of keys as the input map. The values in the input map are completely ignored.
func (*GlobalCache) LoadStateEvent ¶
func (c *GlobalCache) LoadStateEvent(ctx context.Context, roomID string, loadPosition int64, evType, stateKey string) json.RawMessage
func (*GlobalCache) OnEphemeralEvent ¶
func (c *GlobalCache) OnEphemeralEvent(ctx context.Context, roomID string, ephEvent json.RawMessage)
func (*GlobalCache) OnNewEvent ¶
func (c *GlobalCache) OnNewEvent( ctx context.Context, ed *EventData, )
func (*GlobalCache) OnReceipt ¶ added in v0.99.1
func (c *GlobalCache) OnReceipt(ctx context.Context, receipt internal.Receipt)
func (*GlobalCache) OnRegistered ¶
func (c *GlobalCache) OnRegistered(_ context.Context) error
func (*GlobalCache) Startup ¶
func (c *GlobalCache) Startup(roomIDToMetadata map[string]internal.RoomMetadata) error
Startup will populate the cache with the provided metadata. Must be called prior to starting any v2 pollers else this operation can race. Consider:
- V2 poll loop started early
- Join event arrives, NID=50
- PopulateGlobalCache loads the latest NID=50, processes this join event in the process
- OnNewEvents is called with the join event
- join event is processed twice.
type InviteData ¶
type InviteData struct { InviteState []json.RawMessage Heroes []internal.Hero InviteEvent *EventData NameEvent string // the content of m.room.name, NOT the calculated name CanonicalAlias string LastMessageTimestamp uint64 Encrypted bool IsDM bool RoomType string // contains filtered or unexported fields }
Subset of data from internal.RoomMetadata which we can glean from invite_state. Processed in the same way as joined rooms!
func NewInviteData ¶
func NewInviteData(ctx context.Context, userID, roomID string, inviteState []json.RawMessage) *InviteData
func (*InviteData) RoomMetadata ¶
func (i *InviteData) RoomMetadata() *internal.RoomMetadata
type InviteUpdate ¶
type InviteUpdate struct { RoomUpdate InviteData InviteData }
InviteUpdate corresponds to a key-value pair from a v2 sync's `invite` section.
func (*InviteUpdate) Type ¶ added in v0.99.1
func (u *InviteUpdate) Type() string
type LeftRoomUpdate ¶
type LeftRoomUpdate struct {
RoomUpdate
}
LeftRoomUpdate corresponds to a key-value pair from a v2 sync's `leave` section.
func (*LeftRoomUpdate) Type ¶ added in v0.99.1
func (u *LeftRoomUpdate) Type() string
type ReceiptUpdate ¶
type ReceiptUpdate struct { RoomUpdate Receipt internal.Receipt }
RecieptUpdate corresponds to a receipt EDU in the `ephemeral` section of a joined room's v2 sync resposne.
func (*ReceiptUpdate) Type ¶ added in v0.99.1
func (u *ReceiptUpdate) Type() string
type RoomAccountDataUpdate ¶
type RoomAccountDataUpdate struct { RoomUpdate AccountData []state.AccountData }
RoomAccountDataUpdate represents the `account_data` section of joined room's v2 sync response.
func (*RoomAccountDataUpdate) Type ¶ added in v0.99.1
func (u *RoomAccountDataUpdate) Type() string
type RoomEventUpdate ¶
type RoomEventUpdate struct { RoomUpdate EventData *EventData }
RoomEventUpdate corresponds to a single event seen in a joined room's timeline under sync v2.
func (*RoomEventUpdate) Type ¶ added in v0.99.1
func (u *RoomEventUpdate) Type() string
type RoomUpdate ¶
type RoomUpdate interface { Update RoomID() string GlobalRoomMetadata() *internal.RoomMetadata UserRoomMetadata() *UserRoomData }
type TransactionIDFetcher ¶ added in v0.99.0
type TypingUpdate ¶
type TypingUpdate struct {
RoomUpdate
}
TypingEdu corresponds to a typing EDU in the `ephemeral` section of a joined room's v2 sync resposne.
func (*TypingUpdate) Type ¶ added in v0.99.1
func (u *TypingUpdate) Type() string
type UnreadCountUpdate ¶
type UnreadCountUpdate struct { RoomUpdate HasCountDecreased bool }
UnreadCountUpdate represents a change in highlight or notification count change. The current counts are determinted from sync v2 responses; the pollers track changes to those counts to determine if they have decreased, remained unchanged, or increased.
func (*UnreadCountUpdate) Type ¶ added in v0.99.1
func (u *UnreadCountUpdate) Type() string
type UserCache ¶
type UserCache struct { LazyRoomDataOverride func(loadPos int64, roomIDs []string, maxTimelineEvents int) map[string]UserRoomData UserID string // contains filtered or unexported fields }
Tracks data specific to a given user. Specifically, this is the map of room ID to UserRoomData. This data is user-scoped, not global or connection scoped.
func NewUserCache ¶
func NewUserCache(userID string, globalCache *GlobalCache, store *state.Storage, txnIDs TransactionIDFetcher) *UserCache
func (*UserCache) AnnotateWithTransactionIDs ¶
func (c *UserCache) AnnotateWithTransactionIDs(ctx context.Context, userID string, deviceID string, roomIDToEvents map[string][]json.RawMessage) map[string][]json.RawMessage
AnnotateWithTransactionIDs should be called just prior to returning events to the client. This will modify the events to insert the correct transaction IDs if needed. This is required because events are globally scoped, so if Alice sends a message, Bob might receive it first on his v2 loop which would cause the transaction ID to be missing from the event. Instead, we always look for txn IDs in the v2 poller, and then set them appropriately at request time.
func (*UserCache) Invites ¶
func (c *UserCache) Invites() map[string]UserRoomData
func (*UserCache) LazyLoadTimelines ¶
func (c *UserCache) LazyLoadTimelines(ctx context.Context, loadPos int64, roomIDs []string, maxTimelineEvents int) map[string]UserRoomData
Load timelines from the database. Uses cached UserRoomData for metadata purposes only.
func (*UserCache) LoadRoomData ¶
func (c *UserCache) LoadRoomData(roomID string) UserRoomData
func (*UserCache) OnAccountData ¶
func (c *UserCache) OnAccountData(ctx context.Context, datas []state.AccountData)
func (*UserCache) OnEphemeralEvent ¶
func (*UserCache) OnNewEvent ¶
func (*UserCache) OnRegistered ¶
OnRegistered is called after the sync3.Dispatcher has successfully registered this cache to receive updates. We use this to run some final initialisation logic that is sensitive to race conditions; confusingly, most of the initialisation is driven externally by sync3.SyncLiveHandler.userCache. It's importatn that we don't spend too long inside this function, because it is called within a global lock on the sync3.Dispatcher (see sync3.Dispatcher.Register).
func (*UserCache) OnSpaceUpdate ¶
func (*UserCache) OnUnreadCounts ¶
func (*UserCache) Subsribe ¶
func (c *UserCache) Subsribe(ucl UserCacheListener) (id int)
func (*UserCache) Unsubscribe ¶
type UserCacheListener ¶
type UserCacheListener interface { // Called when there is an update affecting a room e.g new event, unread count update, room account data. // Type-cast to find out what the update is about. OnRoomUpdate(ctx context.Context, up RoomUpdate) // Called when there is an update affecting this user but not in the room e.g global account data, presence. // Type-cast to find out what the update is about. OnUpdate(ctx context.Context, up Update) }
type UserRoomData ¶
type UserRoomData struct { IsDM bool IsInvite bool HasLeft bool NotificationCount int HighlightCount int Invite *InviteData // this field is set by LazyLoadTimelines and is per-function call, and is not persisted in-memory. // The zero value of this safe to use (0 latest nid, no prev batch, no timeline). RequestedLatestEvents state.LatestEvents // TODO: should Canonicalised really be in RoomConMetadata? It's only set in SetRoom AFAICS CanonicalisedName string // stripped leading symbols like #, all in lower case // Set of spaces this room is a part of, from the perspective of this user. This is NOT global room data // as the set of spaces may be different for different users. Spaces map[string]struct{} // Map of tag to order float. // See https://spec.matrix.org/latest/client-server-api/#room-tagging Tags map[string]float64 // JoinTiming tracks our latest join to the room, excluding profile changes. JoinTiming internal.EventMetadata }
UserRoomData describes a single room from the perspective of particular user. It is primarily used in two places:
- in the caches.UserCache, to hold the latest version of user-specific data; and
- in the sync3.RoomConnMetadata struct, to hold the version of data last seen by a given sync connection.
Roughly speaking, the sync3.RoomConnMetadata is constantly catching up with changes in the caches.UserCache.
func NewUserRoomData ¶
func NewUserRoomData() UserRoomData