Documentation ¶
Index ¶
- Constants
- Variables
- type AvatarChange
- type Conn
- type ConnHandler
- type ConnID
- type ConnMap
- func (m *ConnMap) ClearUpdateQueues(userID, roomID string, nid int64)
- func (m *ConnMap) CloseConnsForDevice(userID, deviceID string)
- func (m *ConnMap) CloseConnsForUsers(userIDs []string) (closed int)
- func (m *ConnMap) Conn(cid ConnID) *Conn
- func (m *ConnMap) Conns(userID, deviceID string) []*Conn
- func (m *ConnMap) CreateConn(cid ConnID, cancel context.CancelFunc, newConnHandler func() ConnHandler) *Conn
- func (m *ConnMap) Teardown()
- func (m *ConnMap) UpdateMetrics()
- type Dispatcher
- func (d *Dispatcher) IsUserJoined(userID, roomID string) bool
- func (d *Dispatcher) OnEphemeralEvent(ctx context.Context, roomID string, ephEvent json.RawMessage)
- func (d *Dispatcher) OnInvalidateRoom(roomID string, joins, invites []string)
- func (d *Dispatcher) OnNewEvent(ctx context.Context, roomID string, event json.RawMessage, nid int64)
- func (d *Dispatcher) OnNewInitialRoomState(ctx context.Context, roomID string, state []json.RawMessage)
- func (d *Dispatcher) OnReceipt(ctx context.Context, receipt internal.Receipt)
- func (d *Dispatcher) ReceiverForUser(userID string) Receiver
- func (d *Dispatcher) Register(ctx context.Context, userID string, r Receiver) error
- func (d *Dispatcher) Startup(roomToJoinedUsers map[string][]string) error
- func (d *Dispatcher) Unregister(userID string)
- func (d *Dispatcher) UnregisterBulk(userIDs []string) []string
- type FilteredSortableRooms
- type InternalRequestLists
- func (s *InternalRequestLists) AssignList(ctx context.Context, listKey string, filters *RequestFilters, sort []string, ...) (*FilteredSortableRooms, bool)
- func (s *InternalRequestLists) Count(listKey string) int
- func (s *InternalRequestLists) DeleteList(listKey string)
- func (s *InternalRequestLists) Get(listKey string) *FilteredSortableRooms
- func (s *InternalRequestLists) Len() int
- func (s *InternalRequestLists) ListKeys() []string
- func (s *InternalRequestLists) ListsByVisibleRoomIDs(muxedReqLists map[string]RequestList) map[string][]string
- func (s *InternalRequestLists) ReadOnlyRoom(roomID string) *RoomConnMetadata
- func (s *InternalRequestLists) RemoveRoom(roomID string)
- func (s *InternalRequestLists) SetRoom(r RoomConnMetadata) (delta RoomDelta)
- type JoinedRoomsTracker
- func (t *JoinedRoomsTracker) IsUserJoined(userID, roomID string) bool
- func (t *JoinedRoomsTracker) JoinedRoomsForUser(userID string) []string
- func (t *JoinedRoomsTracker) JoinedUsersForRoom(roomID string, filter func(userID string) bool) (matchedUserIDs []string, joinCount int)
- func (t *JoinedRoomsTracker) NumInvitedUsersForRoom(roomID string) int
- func (t *JoinedRoomsTracker) ReloadMembershipsForRoom(roomID string, joined, invited []string)
- func (t *JoinedRoomsTracker) Startup(roomToJoinedUsers map[string][]string)
- func (t *JoinedRoomsTracker) UserJoinedRoom(userID, roomID string) bool
- func (t *JoinedRoomsTracker) UserLeftRoom(userID, roomID string) bool
- func (t *JoinedRoomsTracker) UsersInvitedToRoom(userIDs []string, roomID string)
- func (t *JoinedRoomsTracker) UsersJoinedRoom(userIDs []string, roomID string) bool
- type List
- type ListOp
- type OverwriteVal
- type Receiver
- type Request
- func (r *Request) ApplyDelta(nextReq *Request) (result *Request, delta *RequestDelta)
- func (r *Request) ListKeys() []string
- func (r *Request) Same(other *Request) bool
- func (r *Request) SetPos(pos int64)
- func (r *Request) SetTimeoutMSecs(timeout int)
- func (r *Request) TimeoutMSecs() int
- func (r *Request) Validate() error
- type RequestDelta
- type RequestFilters
- type RequestList
- func (rl *RequestList) CalculateMoveIndexes(fromIndex, toIndex int) (fromTos [][2]int)
- func (rl *RequestList) FiltersChanged(next *RequestList) bool
- func (rl *RequestList) ShouldGetAllRooms() bool
- func (rl *RequestList) SortOrderChanged(next *RequestList) bool
- func (rl *RequestList) TimelineLimitChanged(next *RequestList) bool
- func (rl *RequestList) WriteDeleteOp(deletedIndex int) *ResponseOpSingle
- func (rl *RequestList) WriteInsertOp(insertedIndex int, roomID string) *ResponseOpSingle
- func (rl *RequestList) WriteSwapOp(roomID string, fromIndex, toIndex int) []ResponseOp
- type RequestListDelta
- type Response
- type ResponseList
- type ResponseOp
- type ResponseOpRange
- type ResponseOpSingle
- type Room
- type RoomConnMetadata
- type RoomDelta
- type RoomFinder
- type RoomListDelta
- type RoomSubscription
- func (rs RoomSubscription) Combine(other RoomSubscription) RoomSubscription
- func (rs RoomSubscription) IncludeHeroes() bool
- func (rs RoomSubscription) LazyLoadMembers() bool
- func (rs RoomSubscription) RequiredStateChanged(other RoomSubscription) bool
- func (rs RoomSubscription) RequiredStateMap(userID string) *internal.RequiredStateMap
- type SliceRanges
- func (r SliceRanges) ClosestInDirection(i int64, towardsZero bool) (closestIndex int64)
- func (r SliceRanges) Delta(next SliceRanges) (added SliceRanges, removed SliceRanges, same SliceRanges)
- func (r SliceRanges) Inside(i int64) ([2]int64, bool)
- func (r SliceRanges) SliceInto(slice Subslicer) []Subslicer
- func (r SliceRanges) Valid() bool
- type SortableRooms
- func (s *SortableRooms) Add(roomID string) bool
- func (s *SortableRooms) Get(index int) string
- func (s *SortableRooms) IndexOf(roomID string) (int, bool)
- func (s *SortableRooms) Len() int64
- func (s *SortableRooms) Remove(roomID string) int
- func (s *SortableRooms) RoomIDs() []string
- func (s *SortableRooms) Sort(sortBy []string) error
- func (s *SortableRooms) Subslice(i, j int64) Subslicer
- type Subslicer
Constants ¶
const ( OpSync = "SYNC" OpInvalidate = "INVALIDATE" OpInsert = "INSERT" OpDelete = "DELETE" )
const DeletedAvatar = AvatarChange("<no-avatar>")
const DispatcherAllUsers = "-"
Variables ¶
var ( SortByName = "by_name" SortByRecency = "by_recency" SortByNotificationLevel = "by_notification_level" SortByNotificationCount = "by_notification_count" // deprecated SortByHighlightCount = "by_highlight_count" // deprecated SortBy = []string{SortByHighlightCount, SortByName, SortByNotificationCount, SortByRecency, SortByNotificationLevel} Wildcard = "*" StateKeyLazy = "$LAZY" StateKeyMe = "$ME" DefaultTimelineLimit = int64(20) DefaultTimeoutMSecs = 10 * 1000 // 10s )
var SpamProtectionInterval = 10 * time.Millisecond
The amount of time to artificially wait if the server detects spamming clients. This time will be added to responses when the server detects the same request being sent over and over e.g /sync?pos=5 then /sync?pos=5 over and over. Likewise /sync without a ?pos=.
Functions ¶
This section is empty.
Types ¶
type AvatarChange ¶ added in v0.99.5
type AvatarChange string
An AvatarChange represents a change to a room's avatar. There are three cases:
- an empty string represents no change, and should be omitted when JSON-serialised;
- the sentinel `<no-avatar>` represents a room that has never had an avatar, or a room whose avatar has been removed. It is JSON-serialised as null.
- All other strings represent the current avatar of the room and JSON-serialise as normal.
const UnchangedAvatar AvatarChange = ""
func NewAvatarChange ¶ added in v0.99.5
func NewAvatarChange(avatar string) AvatarChange
NewAvatarChange interprets an optional avatar string as an AvatarChange.
func (AvatarChange) MarshalJSON ¶ added in v0.99.5
func (a AvatarChange) MarshalJSON() ([]byte, error)
func (*AvatarChange) UnmarshalJSON ¶ added in v0.99.5
func (a *AvatarChange) UnmarshalJSON(data []byte) error
Note: the unmarshalling is only used in tests.
type Conn ¶
type Conn struct { ConnID // contains filtered or unexported fields }
Conn is an abstraction of a long-poll connection. It automatically handles the position values of the /sync request, including sending cached data in the event of retries. It does not handle the contents of the data at all.
func NewConn ¶
func NewConn(connID ConnID, h ConnHandler) *Conn
func (*Conn) OnIncomingRequest ¶
func (c *Conn) OnIncomingRequest(ctx context.Context, req *Request, start time.Time) (resp *Response, herr *internal.HandlerError)
OnIncomingRequest advances the client's position in the stream, returning the response position and data. If an error is returned, it will be logged by the caller and transmitted to the client. It will NOT be reported to Sentry---this should happen as close as possible to the creation of the error (or else Sentry cannot provide a meaningful traceback.)
func (*Conn) SetCancelCallback ¶ added in v0.99.12
func (c *Conn) SetCancelCallback(cancel context.CancelFunc)
type ConnHandler ¶
type ConnHandler interface { // Callback which is allowed to block as long as the context is active. Return the response // to send back or an error. Errors of type *internal.HandlerError are inspected for the correct // status code to send back. OnIncomingRequest(ctx context.Context, cid ConnID, req *Request, isInitial bool, start time.Time) (*Response, error) OnUpdate(ctx context.Context, update caches.Update) PublishEventsUpTo(roomID string, nid int64) Destroy() Alive() bool SetCancelCallback(cancel context.CancelFunc) }
type ConnMap ¶
type ConnMap struct {
// contains filtered or unexported fields
}
ConnMap stores a collection of Conns.
func (*ConnMap) ClearUpdateQueues ¶ added in v0.99.5
func (*ConnMap) CloseConnsForDevice ¶ added in v0.99.3
func (*ConnMap) CloseConnsForUsers ¶ added in v0.99.13
CloseConnsForUsers closes all conns for a given slice of users. Returns the number of conns closed.
func (*ConnMap) Conn ¶
Conn returns a connection with this ConnID. Returns nil if no connection exists.
func (*ConnMap) CreateConn ¶
func (m *ConnMap) CreateConn(cid ConnID, cancel context.CancelFunc, newConnHandler func() ConnHandler) *Conn
Atomically gets or creates a connection with this connection ID. Calls newConn if a new connection is required.
func (*ConnMap) UpdateMetrics ¶ added in v0.99.5
func (m *ConnMap) UpdateMetrics()
UpdateMetrics recalculates the number of active connections. Do this when you think there is a change.
type Dispatcher ¶
type Dispatcher struct {
// contains filtered or unexported fields
}
Dispatches live events to caches
func NewDispatcher ¶
func NewDispatcher() *Dispatcher
func (*Dispatcher) IsUserJoined ¶
func (d *Dispatcher) IsUserJoined(userID, roomID string) bool
func (*Dispatcher) OnEphemeralEvent ¶
func (d *Dispatcher) OnEphemeralEvent(ctx context.Context, roomID string, ephEvent json.RawMessage)
func (*Dispatcher) OnInvalidateRoom ¶ added in v0.99.11
func (d *Dispatcher) OnInvalidateRoom(roomID string, joins, invites []string)
func (*Dispatcher) OnNewEvent ¶ added in v0.99.2
func (d *Dispatcher) OnNewEvent( ctx context.Context, roomID string, event json.RawMessage, nid int64, )
func (*Dispatcher) OnNewInitialRoomState ¶
func (d *Dispatcher) OnNewInitialRoomState(ctx context.Context, roomID string, state []json.RawMessage)
Called by v2 pollers when we receive an initial state block. Very similar to OnNewEvents but done in bulk for speed.
func (*Dispatcher) OnReceipt ¶ added in v0.99.1
func (d *Dispatcher) OnReceipt(ctx context.Context, receipt internal.Receipt)
func (*Dispatcher) ReceiverForUser ¶ added in v0.99.3
func (d *Dispatcher) ReceiverForUser(userID string) Receiver
func (*Dispatcher) Startup ¶
func (d *Dispatcher) Startup(roomToJoinedUsers map[string][]string) error
Load joined members into the dispatcher. MUST BE CALLED BEFORE V2 POLL LOOPS START.
func (*Dispatcher) Unregister ¶
func (d *Dispatcher) Unregister(userID string)
func (*Dispatcher) UnregisterBulk ¶ added in v0.99.13
func (d *Dispatcher) UnregisterBulk(userIDs []string) []string
UnregisterBulk accepts a slice of user IDs to unregister. The given users need not already be registered (in which case unregistering them is a no-op). Returns the list of users that were unregistered.
type FilteredSortableRooms ¶
type FilteredSortableRooms struct { *SortableRooms // contains filtered or unexported fields }
FilteredSortableRooms is SortableRooms but where rooms are filtered before being added to the list. Updates to room metadata may result in rooms being added/removed.
func NewFilteredSortableRooms ¶
func NewFilteredSortableRooms(finder RoomFinder, listKey string, roomIDs []string, filter *RequestFilters) *FilteredSortableRooms
func (*FilteredSortableRooms) Add ¶
func (f *FilteredSortableRooms) Add(roomID string) bool
type InternalRequestLists ¶
type InternalRequestLists struct {
// contains filtered or unexported fields
}
InternalRequestLists is a list of lists which matches each index position in the request JSON 'lists'. It contains all the internal metadata for rooms and controls access and updatings of said lists.
func NewInternalRequestLists ¶
func NewInternalRequestLists() *InternalRequestLists
func (*InternalRequestLists) AssignList ¶
func (s *InternalRequestLists) AssignList(ctx context.Context, listKey string, filters *RequestFilters, sort []string, shouldOverwrite OverwriteVal) (*FilteredSortableRooms, bool)
Assign a new list at the given key. If Overwrite, any existing list is replaced. If DoNotOverwrite, the existing list is returned if one exists, else a new list is created. Returns the list and true if the list was overwritten.
func (*InternalRequestLists) Count ¶
func (s *InternalRequestLists) Count(listKey string) int
Count returns the count of total rooms in this list
func (*InternalRequestLists) DeleteList ¶
func (s *InternalRequestLists) DeleteList(listKey string)
func (*InternalRequestLists) Get ¶
func (s *InternalRequestLists) Get(listKey string) *FilteredSortableRooms
Get returns the sorted list of rooms. Returns a shared pointer, not a copy. It is only safe to read this data, never to write.
func (*InternalRequestLists) Len ¶
func (s *InternalRequestLists) Len() int
func (*InternalRequestLists) ListKeys ¶ added in v0.99.3
func (s *InternalRequestLists) ListKeys() []string
ListKeys returns a copy of the list keys currently tracked by this InternalRequestLists struct, in no particular order. Outside of test code, you probably don't want to call this---you probably have the set of list keys tracked elsewhere in the application.
func (*InternalRequestLists) ListsByVisibleRoomIDs ¶ added in v0.99.2
func (s *InternalRequestLists) ListsByVisibleRoomIDs(muxedReqLists map[string]RequestList) map[string][]string
ListsByVisibleRoomIDs builds a map from room IDs to a slice of list names. Keys are all room IDs that are currently visible in at least one sliding window. Values are the names of all lists (in no particular order) in which the given room ID is currently visible. The value slices are nonnil and contain at least one list name (possibly more).
The returned map is a copy, i.e. is safe to modify by the caller.
func (*InternalRequestLists) ReadOnlyRoom ¶ added in v0.99.1
func (s *InternalRequestLists) ReadOnlyRoom(roomID string) *RoomConnMetadata
Returns the underlying RoomConnMetadata object. Returns a shared pointer, not a copy. It is only safe to read this data, never to write.
func (*InternalRequestLists) RemoveRoom ¶
func (s *InternalRequestLists) RemoveRoom(roomID string)
Remove a room from all lists e.g retired an invite, left a room
func (*InternalRequestLists) SetRoom ¶
func (s *InternalRequestLists) SetRoom(r RoomConnMetadata) (delta RoomDelta)
type JoinedRoomsTracker ¶
type JoinedRoomsTracker struct {
// contains filtered or unexported fields
}
Tracks who is joined to which rooms. This is critical from a security perspective in order to ensure that only the users joined to the room receive events in that room. Consider the situation where Alice and Bob are joined to room X. If Alice gets kicked from X, the proxy server will still receive messages for room X due to Bob being joined to the room. We therefore need to decide which active connections should be pushed events, which is what this tracker does.
func NewJoinedRoomsTracker ¶
func NewJoinedRoomsTracker() *JoinedRoomsTracker
func (*JoinedRoomsTracker) IsUserJoined ¶
func (t *JoinedRoomsTracker) IsUserJoined(userID, roomID string) bool
func (*JoinedRoomsTracker) JoinedRoomsForUser ¶
func (t *JoinedRoomsTracker) JoinedRoomsForUser(userID string) []string
func (*JoinedRoomsTracker) JoinedUsersForRoom ¶
func (t *JoinedRoomsTracker) JoinedUsersForRoom(roomID string, filter func(userID string) bool) (matchedUserIDs []string, joinCount int)
JoinedUsersForRoom returns the joined users in the given room, filtered by the filter function if provided. If one is not provided, all joined users are returned. Returns the join count at the time this function was called.
func (*JoinedRoomsTracker) NumInvitedUsersForRoom ¶
func (t *JoinedRoomsTracker) NumInvitedUsersForRoom(roomID string) int
func (*JoinedRoomsTracker) ReloadMembershipsForRoom ¶ added in v0.99.12
func (t *JoinedRoomsTracker) ReloadMembershipsForRoom(roomID string, joined, invited []string)
ReloadMembershipsForRoom overwrites the JoinedRoomsTracker state for one room to the given list of joined and invited users.
func (*JoinedRoomsTracker) Startup ¶
func (t *JoinedRoomsTracker) Startup(roomToJoinedUsers map[string][]string)
Startup efficiently sets up the joined rooms tracker, but isn't safe to call with live traffic, as it replaces all known in-memory state. Panics if called on a non-empty tracker.
func (*JoinedRoomsTracker) UserJoinedRoom ¶
func (t *JoinedRoomsTracker) UserJoinedRoom(userID, roomID string) bool
UserJoinedRoom marks the given user as having joined the given room. Returns true if the user was not joined to the room prior to this call, and false otherwise.
func (*JoinedRoomsTracker) UserLeftRoom ¶
func (t *JoinedRoomsTracker) UserLeftRoom(userID, roomID string) bool
UserLeftRoom marks the given user as having left the given room. Returns true if this user _was_ joined or invited to the room before this call, and false otherwise.
func (*JoinedRoomsTracker) UsersInvitedToRoom ¶
func (t *JoinedRoomsTracker) UsersInvitedToRoom(userIDs []string, roomID string)
func (*JoinedRoomsTracker) UsersJoinedRoom ¶
func (t *JoinedRoomsTracker) UsersJoinedRoom(userIDs []string, roomID string) bool
UsersJoinedRoom marks the given slice of users as having joined the given room. Returns true if at least one of the users was not joined to the room prior to the call, and false otherwise.
type OverwriteVal ¶
type OverwriteVal bool
var ( DoNotOverwrite OverwriteVal = false Overwrite OverwriteVal = true )
type Receiver ¶
type Receiver interface { OnNewEvent(ctx context.Context, event *caches.EventData) OnReceipt(ctx context.Context, receipt internal.Receipt) OnEphemeralEvent(ctx context.Context, roomID string, ephEvent json.RawMessage) // OnRegistered is called after a successful call to Dispatcher.Register OnRegistered(ctx context.Context) error }
Receiver represents the callbacks that a Dispatcher may fire.
type Request ¶
type Request struct { TxnID string `json:"txn_id"` ConnID string `json:"conn_id"` Lists map[string]RequestList `json:"lists"` RoomSubscriptions map[string]RoomSubscription `json:"room_subscriptions"` UnsubscribeRooms []string `json:"unsubscribe_rooms"` Extensions extensions.Request `json:"extensions"` // contains filtered or unexported fields }
func (*Request) ApplyDelta ¶
func (r *Request) ApplyDelta(nextReq *Request) (result *Request, delta *RequestDelta)
Apply this delta on top of the request. Returns a new Request with the combined output, along with the delta operations `nextReq` cannot be nil, but `r` can be nil in the case of an initial request.
func (*Request) ListKeys ¶ added in v0.99.6
ListKeys builds a slice containing the names of the lists this request has defined.
func (*Request) Same ¶
Same determines if the given request would produce the same output as the other if given the same input data.
func (*Request) SetTimeoutMSecs ¶
func (*Request) TimeoutMSecs ¶
type RequestDelta ¶
type RequestDelta struct { // new room IDs to subscribe to Subs []string // room IDs to unsubscribe from Unsubs []string // The complete union of both lists (contains max(a,b) lists) Lists map[string]RequestListDelta }
Internal struct used to represent the diffs between 2 requests
type RequestFilters ¶
type RequestFilters struct { Spaces []string `json:"spaces"` IsDM *bool `json:"is_dm"` IsEncrypted *bool `json:"is_encrypted"` IsInvite *bool `json:"is_invite"` IsTombstoned *bool `json:"is_tombstoned"` // deprecated RoomTypes []*string `json:"room_types"` NotRoomTypes []*string `json:"not_room_types"` RoomNameFilter string `json:"room_name_like"` Tags []string `json:"tags"` NotTags []string `json:"not_tags"` }
func (*RequestFilters) Include ¶
func (rf *RequestFilters) Include(r *RoomConnMetadata, finder RoomFinder) bool
type RequestList ¶
type RequestList struct { RoomSubscription Ranges SliceRanges `json:"ranges"` Sort []string `json:"sort"` Filters *RequestFilters `json:"filters"` SlowGetAllRooms *bool `json:"slow_get_all_rooms,omitempty"` Deleted bool `json:"deleted,omitempty"` BumpEventTypes []string `json:"bump_event_types"` }
func (*RequestList) CalculateMoveIndexes ¶
func (rl *RequestList) CalculateMoveIndexes(fromIndex, toIndex int) (fromTos [][2]int)
Calculate the real from -> to index positions for the two input index positions. This takes into account the ranges on the list.
func (*RequestList) FiltersChanged ¶
func (rl *RequestList) FiltersChanged(next *RequestList) bool
func (*RequestList) ShouldGetAllRooms ¶
func (rl *RequestList) ShouldGetAllRooms() bool
func (*RequestList) SortOrderChanged ¶
func (rl *RequestList) SortOrderChanged(next *RequestList) bool
func (*RequestList) TimelineLimitChanged ¶ added in v0.99.0
func (rl *RequestList) TimelineLimitChanged(next *RequestList) bool
func (*RequestList) WriteDeleteOp ¶
func (rl *RequestList) WriteDeleteOp(deletedIndex int) *ResponseOpSingle
Write a delete operation for this list. Can return nil for invalid indexes or if this index isn't being tracked. Useful when rooms are removed from the list e.g left rooms.
func (*RequestList) WriteInsertOp ¶
func (rl *RequestList) WriteInsertOp(insertedIndex int, roomID string) *ResponseOpSingle
Write an insert operation for this list. Can return nil for indexes not being tracked. Useful when rooms are added to the list e.g newly joined rooms.
func (*RequestList) WriteSwapOp ¶
func (rl *RequestList) WriteSwapOp( roomID string, fromIndex, toIndex int, ) []ResponseOp
Move a room from an absolute index position to another absolute position. These positions do not need to be inside a valid range. Returns 0-2 operations. For example:
1,2,3,4,5 tracking range [0,4] 3 bumps to top -> 3,1,2,4,5 -> DELETE index=2, INSERT val=3 index=0 7 bumps to top -> 7,1,2,3,4 -> DELETE index=4, INSERT val=7 index=0 7 bumps to op again -> 7,1,2,3,4 -> no-op as from == to index new room 8 in i=5 -> 7,1,2,3,4,8 -> no-op as 8 is outside the range.
Returns the list of ops as well as the new toIndex if it wasn't inside a range.
type RequestListDelta ¶
type RequestListDelta struct { // What was there before, nullable Prev *RequestList // What is there now, nullable. Combined result. Curr *RequestList }
Internal struct used to represent a single list delta.
type Response ¶
type Response struct { Lists map[string]ResponseList `json:"lists"` Rooms map[string]Room `json:"rooms"` Extensions extensions.Response `json:"extensions"` Pos string `json:"pos"` TxnID string `json:"txn_id,omitempty"` }
func (*Response) RoomIDsToTimelineEventIDs ¶ added in v0.99.1
func (*Response) UnmarshalJSON ¶
Custom unmarshal so we can dynamically create the right ResponseOp for Ops
type ResponseList ¶
type ResponseList struct { Ops []ResponseOp `json:"ops,omitempty"` Count int `json:"count"` }
type ResponseOp ¶
type ResponseOp interface { Op() string // which rooms are we giving data about IncludedRoomIDs() []string }
func CalculateListOps ¶
func CalculateListOps(ctx context.Context, reqList *RequestList, list List, roomID string, listOp ListOp) (ops []ResponseOp, subs []string)
CalculateListOps contains the core list moving algorithm. It accepts the client's list of ranges, the underlying list on which to perform operations on, and the room which was modified and in what way. It returns a list of INSERT/DELETE operations, which may be zero length, as well as which rooms are newly added into the window.
A,B,C,D,E,F,G,H,I <-- List `----` `----` <-- RequestList.Ranges DEL E | ADD J | CHANGE C <-- ListOp RoomID
returns:
[ {op:DELETE, index:2}, {op:INSERT, index:0, room_id:A} ] <--- []ResponseOp [ "A" ] <--- []string, new room subscriptions, if it wasn't in the window before
This function will modify List to Add/Delete/Sort appropriately.
type ResponseOpRange ¶
type ResponseOpRange struct { Operation string `json:"op"` Range [2]int64 `json:"range,omitempty"` RoomIDs []string `json:"room_ids,omitempty"` }
func (*ResponseOpRange) IncludedRoomIDs ¶
func (r *ResponseOpRange) IncludedRoomIDs() []string
func (*ResponseOpRange) Op ¶
func (r *ResponseOpRange) Op() string
type ResponseOpSingle ¶
type ResponseOpSingle struct { Operation string `json:"op"` Index *int `json:"index,omitempty"` // 0 is a valid value, hence *int RoomID string `json:"room_id,omitempty"` }
func (*ResponseOpSingle) IncludedRoomIDs ¶
func (r *ResponseOpSingle) IncludedRoomIDs() []string
func (*ResponseOpSingle) Op ¶
func (r *ResponseOpSingle) Op() string
type Room ¶
type Room struct { Name string `json:"name,omitempty"` AvatarChange AvatarChange `json:"avatar,omitempty"` Heroes []internal.Hero `json:"heroes,omitempty"` RequiredState []json.RawMessage `json:"required_state,omitempty"` Timeline []json.RawMessage `json:"timeline,omitempty"` InviteState []json.RawMessage `json:"invite_state,omitempty"` NotificationCount int64 `json:"notification_count"` HighlightCount int64 `json:"highlight_count"` Initial bool `json:"initial,omitempty"` IsDM bool `json:"is_dm,omitempty"` JoinedCount int `json:"joined_count,omitempty"` InvitedCount *int `json:"invited_count,omitempty"` PrevBatch string `json:"prev_batch,omitempty"` NumLive int `json:"num_live,omitempty"` Timestamp uint64 `json:"timestamp,omitempty"` }
type RoomConnMetadata ¶
type RoomConnMetadata struct { // We enclose copies of the data kept in the global and user caches. These snapshots // represent the state we reported to the connection the last time they requested // a sync. Note that we are free to tweak fields within these copies if we want, to // report more appropriate data to clients that kept in the caches. internal.RoomMetadata caches.UserRoomData // LastInterestedEventTimestamps is a map from list name to the origin_server_ts of // the most recent event seen in the room since the user's join that the list is // interested in. // // Connections can specify that a list is only interested in certain event types by // providing "bump_event_types" in their sliding sync request. This happens on a // list-by-list basis. Because the same room can appear in different lists with // different bump criteria, we need to track a LastInterestedEventTimestamp for each // list. // // While this conceptually tracks the internal.RoomMetadata.LastMessageTimestamp // field, said field can decrease rapidly at any moment---so // LastInterestedEventTimestamp can also decrease at any moment. When sorting by // recency, this means rooms can suddenly fall down and jump back up the room // list. See also the description of this in the React SDK docs: // https://github.com/matrix-org/matrix-react-sdk/blob/526645c79160ab1ad4b4c3845de27d51263a405e/docs/room-list-store.md#tag-sorting-algorithm-recent LastInterestedEventTimestamps map[string]uint64 }
RoomConnMetadata represents a room as seen by one specific connection (hence one specific device).
func (*RoomConnMetadata) GetLastInterestedEventTimestamp ¶ added in v0.99.3
func (r *RoomConnMetadata) GetLastInterestedEventTimestamp(listKey string) uint64
type RoomFinder ¶
type RoomFinder interface {
ReadOnlyRoom(roomID string) *RoomConnMetadata
}
type RoomListDelta ¶
type RoomSubscription ¶
type RoomSubscription struct { RequiredState [][2]string `json:"required_state"` TimelineLimit int64 `json:"timeline_limit"` IncludeOldRooms *RoomSubscription `json:"include_old_rooms"` Heroes *bool `json:"include_heroes"` }
func (RoomSubscription) Combine ¶
func (rs RoomSubscription) Combine(other RoomSubscription) RoomSubscription
Combine this subcription with another, returning a union of both as a copy.
func (RoomSubscription) IncludeHeroes ¶ added in v0.99.11
func (rs RoomSubscription) IncludeHeroes() bool
func (RoomSubscription) LazyLoadMembers ¶
func (rs RoomSubscription) LazyLoadMembers() bool
func (RoomSubscription) RequiredStateChanged ¶ added in v0.99.0
func (rs RoomSubscription) RequiredStateChanged(other RoomSubscription) bool
func (RoomSubscription) RequiredStateMap ¶
func (rs RoomSubscription) RequiredStateMap(userID string) *internal.RequiredStateMap
Calculate the required state map for this room subscription. Given event types A,B,C and state keys 1,2,3, the following Venn diagrams are possible:
.---------[*,*]----------. | .---------. | | | A,2 | A,3 | | .----+--[B,*]--+-----. | | | | .-----. | | | | |B,1 | | B,2 | | B,3 | | | | | `[B,2]` | | | | `----+---------+-----` | | | C,2 | C,3 | | `--[*,2]--` | `------------------------`
The largest set will be used when returning the required state map. For example, [B,2] + [B,*] = [B,*] because [B,*] encompasses [B,2]. This means [*,*] encompasses everything. 'userID' is the ID of the user performing this request, so $ME can be replaced.
type SliceRanges ¶
type SliceRanges [][2]int64
SliceRanges is a slice of integer pairs [a, b]. Each pair represents the integers x in the range a <= x <= b (note: closed at both ends). The slice as a whole represents the set of integers x in any of the slice's closed intervals.
Within the slice, pairs are arranged in no particular order. Two pairs may represent overlapping ranges of integers; use Valid to test for this.
func (SliceRanges) ClosestInDirection ¶
func (r SliceRanges) ClosestInDirection(i int64, towardsZero bool) (closestIndex int64)
ClosestInDirection returns the index position of a range bound that is closest to `i`, heading either towards 0 or towards infinity. If there is no range boundary in that direction, -1 is returned. For example:
[0,20] i=25,towardsZero=true => 20 [0,20] i=15,towardsZero=true => 0 [0,20] i=15,towardsZero=false => 20 [0,20] i=25,towardsZero=false => -1 [0,20],[40,60] i=25,towardsZero=true => 20 [0,20],[40,60] i=25,towardsZero=false => 40 [0,20],[40,60] i=40,towardsZero=true => 40 [20,40] i=40,towardsZero=true => 20
func (SliceRanges) Delta ¶
func (r SliceRanges) Delta(next SliceRanges) (added SliceRanges, removed SliceRanges, same SliceRanges)
Delta returns the ranges which are unchanged, added and removed. Intelligently handles overlaps.
func (SliceRanges) Inside ¶
func (r SliceRanges) Inside(i int64) ([2]int64, bool)
Inside returns true if i is inside the range
func (SliceRanges) SliceInto ¶
func (r SliceRanges) SliceInto(slice Subslicer) []Subslicer
Slice into this range, returning subslices of slice
func (SliceRanges) Valid ¶
func (r SliceRanges) Valid() bool
type SortableRooms ¶
type SortableRooms struct {
// contains filtered or unexported fields
}
SortableRooms represents a list of rooms which can be sorted and updated. Maintains mappings of room IDs to current index positions after sorting.
func NewSortableRooms ¶
func NewSortableRooms(finder RoomFinder, listKey string, rooms []string) *SortableRooms
func (*SortableRooms) Add ¶
func (s *SortableRooms) Add(roomID string) bool
Add a room to the list. Returns true if the room was added.
func (*SortableRooms) Get ¶
func (s *SortableRooms) Get(index int) string
func (*SortableRooms) Len ¶
func (s *SortableRooms) Len() int64
func (*SortableRooms) Remove ¶
func (s *SortableRooms) Remove(roomID string) int
func (*SortableRooms) RoomIDs ¶
func (s *SortableRooms) RoomIDs() []string
func (*SortableRooms) Sort ¶
func (s *SortableRooms) Sort(sortBy []string) error
func (*SortableRooms) Subslice ¶
func (s *SortableRooms) Subslice(i, j int64) Subslicer
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
package extensions contains the interface and concrete implementations for all sliding sync extensions
|
package extensions contains the interface and concrete implementations for all sliding sync extensions |