Documentation
¶
Index ¶
- Constants
- type AccountDataUpdate
- type CacheFinder
- type DeviceDataUpdate
- type DeviceEventsUpdate
- type EventData
- type GlobalCache
- func (c *GlobalCache) LoadJoinedRooms(userID string) (pos int64, joinedRooms map[string]*internal.RoomMetadata, err error)
- func (c *GlobalCache) LoadRoomState(ctx context.Context, roomIDs []string, loadPosition int64, ...) map[string][]json.RawMessage
- func (c *GlobalCache) LoadRooms(roomIDs ...string) 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) OnRegistered(_ int64) 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(deviceID string, roomIDToEvents map[string][]json.RawMessage) map[string][]json.RawMessage
- func (c *UserCache) Invites() map[string]UserRoomData
- func (c *UserCache) LazyLoadTimelines(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) OnRegistered(_ int64) 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
)
const PosAlwaysProcess = -2
const PosDoNotProcess = -1
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AccountDataUpdate ¶
type AccountDataUpdate struct {
AccountData []state.AccountData
}
type CacheFinder ¶
type DeviceDataUpdate ¶ added in v0.98.1
type DeviceDataUpdate struct {
}
type DeviceEventsUpdate ¶ added in v0.98.1
type DeviceEventsUpdate struct {
}
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
// the absolute latest position for this event data. The NID for this event is guaranteed to
// be <= this value. See PosAlwaysProcess and PosDoNotProcess for things outside the event timeline
// e.g invites
LatestPos int64
// 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 func(userID string) (pos int64, joinedRooms map[string]*internal.RoomMetadata, 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(userID string) (pos int64, joinedRooms map[string]*internal.RoomMetadata, err error)
Load all current joined room metadata for the user given. Returns the absolute database position along with the results. TODO: remove with LoadRoomState?
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(roomIDs ...string) map[string]*internal.RoomMetadata
Load 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. Keeps the ordering of the room IDs given.
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) OnRegistered ¶
func (c *GlobalCache) OnRegistered(_ int64) 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
// 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(userID, roomID string, inviteState []json.RawMessage) *InviteData
func (*InviteData) RoomMetadata ¶
func (i *InviteData) RoomMetadata() *internal.RoomMetadata
type InviteUpdate ¶
type InviteUpdate struct {
RoomUpdate
InviteData InviteData
}
type LeftRoomUpdate ¶
type LeftRoomUpdate struct {
RoomUpdate
}
type ReceiptUpdate ¶
type ReceiptUpdate struct {
RoomUpdate
EphemeralEvent json.RawMessage
}
type RoomAccountDataUpdate ¶
type RoomAccountDataUpdate struct {
RoomUpdate
AccountData []state.AccountData
}
type RoomEventUpdate ¶
type RoomEventUpdate struct {
RoomUpdate
EventData *EventData
}
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
}
type UnreadCountUpdate ¶
type UnreadCountUpdate struct {
RoomUpdate
HasCountDecreased bool
}
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(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 (*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 ¶
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
// (event_id, last_event_id) -> closest prev_batch
// We mux in last_event_id so we can invalidate prev batch tokens for the same event ID when a new timeline event
// comes in, without having to do a SQL query.
PrevBatches *lru.Cache
Timeline []json.RawMessage
Invite *InviteData
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
// the load state of the timeline
LoadPos int64
}
func NewUserRoomData ¶
func NewUserRoomData() UserRoomData
func (UserRoomData) PrevBatch ¶
func (u UserRoomData) PrevBatch() (string, bool)
fetch the prev batch for this timeline
func (UserRoomData) SetPrevBatch ¶
func (u UserRoomData) SetPrevBatch(eventID string, pb string)
set the prev batch token for the given event ID. This should come from the database. The prev batch cache will be updated to return this prev batch token for this event ID as well as the latest event ID in this timeline.