Documentation ¶
Index ¶
- Constants
- func PackReceiptsIntoEDU(receipts []internal.Receipt) (json.RawMessage, error)
- type AccountData
- type AccountDataChunker
- type AccountDataTable
- func (t *AccountDataTable) Insert(txn *sqlx.Tx, accDatas []AccountData) ([]AccountData, error)
- func (t *AccountDataTable) Select(txn *sqlx.Tx, userID string, eventTypes []string, roomID string) (datas []AccountData, err error)
- func (t *AccountDataTable) SelectMany(txn *sqlx.Tx, userID string, roomIDs ...string) (datas []AccountData, err error)
- func (t *AccountDataTable) SelectWithType(txn *sqlx.Tx, userID, evType string) (datas []AccountData, err error)
- type Accumulator
- func (a *Accumulator) Accumulate(roomID string, prevBatch string, timeline []json.RawMessage) (numNew int, timelineNIDs []int64, err error)
- func (a *Accumulator) Delta(roomID string, lastEventNID int64, limit int) (eventsJSON []json.RawMessage, latest int64, err error)
- func (a *Accumulator) Initialise(roomID string, state []json.RawMessage) (bool, int64, error)
- type DeviceDataRow
- type DeviceDataTable
- type Event
- type EventChunker
- type EventTable
- func (t *EventTable) Insert(txn *sqlx.Tx, events []Event, checkFields bool) (map[string]int, error)
- func (t *EventTable) LatestEventInRooms(txn *sqlx.Tx, roomIDs []string, highestNID int64) (events []Event, err error)
- func (t *EventTable) SelectByIDs(txn *sqlx.Tx, verifyAll bool, ids []string) (events []Event, err error)
- func (t *EventTable) SelectByNIDs(txn *sqlx.Tx, verifyAll bool, nids []int64) (events []Event, err error)
- func (t *EventTable) SelectClosestPrevBatch(roomID string, eventNID int64) (prevBatch string, err error)
- func (t *EventTable) SelectClosestPrevBatchByID(roomID string, eventID string) (prevBatch string, err error)
- func (t *EventTable) SelectEventNIDsWithTypeInRoom(txn *sqlx.Tx, eventType string, limit int, targetRoom string, ...) (eventNIDs []int64, err error)
- func (t *EventTable) SelectEventsBetween(txn *sqlx.Tx, roomID string, lowerExclusive, upperInclusive int64, limit int) ([]Event, error)
- func (t *EventTable) SelectEventsWithTypeStateKey(eventType, stateKey string, lowerExclusive, upperInclusive int64) ([]Event, error)
- func (t *EventTable) SelectEventsWithTypeStateKeyInRooms(roomIDs []string, eventType, stateKey string, ...) ([]Event, error)
- func (t *EventTable) SelectHighestNID() (highest int64, err error)
- func (t *EventTable) SelectLatestEventsBetween(txn *sqlx.Tx, roomID string, lowerExclusive, upperInclusive int64, limit int) ([]Event, error)
- func (t *EventTable) SelectNIDsByIDs(txn *sqlx.Tx, ids []string) (nids map[string]int64, err error)
- func (t *EventTable) SelectStrippedEventsByIDs(txn *sqlx.Tx, verifyAll bool, ids []string) (StrippedEvents, error)
- func (t *EventTable) SelectStrippedEventsByNIDs(txn *sqlx.Tx, verifyAll bool, nids []int64) (StrippedEvents, error)
- func (t *EventTable) UpdateBeforeSnapshotID(txn *sqlx.Tx, eventNID, snapID, replacesNID int64) error
- type InvitesTable
- func (t *InvitesTable) InsertInvite(userID, roomID string, inviteRoomState []json.RawMessage) error
- func (t *InvitesTable) RemoveInvite(userID, roomID string) error
- func (t *InvitesTable) SelectAllInvitesForUser(userID string) (map[string][]json.RawMessage, error)
- func (t *InvitesTable) SelectInviteState(userID, roomID string) (inviteState []json.RawMessage, err error)
- type ReceiptChunker
- type ReceiptTable
- func (t *ReceiptTable) Insert(roomID string, ephEvent json.RawMessage) (receipts []internal.Receipt, err error)
- func (t *ReceiptTable) SelectReceiptsForEvents(roomID string, eventIDs []string) (receipts []internal.Receipt, err error)
- func (t *ReceiptTable) SelectReceiptsForUser(roomID, userID string) (receipts []internal.Receipt, err error)
- type RoomInfo
- type RoomsTable
- func (t *RoomsTable) CurrentAfterSnapshotID(txn *sqlx.Tx, roomID string) (snapshotID int64, err error)
- func (t *RoomsTable) LatestNIDs(txn *sqlx.Tx, roomIDs []string) (nids map[string]int64, err error)
- func (t *RoomsTable) SelectRoomInfos(txn *sqlx.Tx) (infos []RoomInfo, err error)
- func (t *RoomsTable) Upsert(txn *sqlx.Tx, info RoomInfo, snapshotID, latestNID int64) (err error)
- type SnapshotRow
- type SnapshotTable
- func (t *SnapshotTable) CurrentSnapshots(txn *sqlx.Tx) (map[string][]int64, error)
- func (s *SnapshotTable) Delete(txn *sqlx.Tx, snapshotIDs []int64) error
- func (s *SnapshotTable) Insert(txn *sqlx.Tx, row *SnapshotRow) error
- func (s *SnapshotTable) Select(txn *sqlx.Tx, snapshotID int64) (row SnapshotRow, err error)
- type SpaceRelation
- type SpaceRelationChunker
- type SpacesTable
- func (t *SpacesTable) BulkDelete(txn *sqlx.Tx, relations []SpaceRelation) error
- func (t *SpacesTable) BulkInsert(txn *sqlx.Tx, relations []SpaceRelation) error
- func (t *SpacesTable) HandleSpaceUpdates(txn *sqlx.Tx, events []Event) error
- func (t *SpacesTable) SelectChildren(txn *sqlx.Tx, spaces []string) (map[string][]SpaceRelation, error)
- type StartupSnapshot
- type Storage
- func (s *Storage) AccountData(userID, roomID string, eventTypes []string) (data []AccountData, err error)
- func (s *Storage) AccountDatas(userID string, roomIDs ...string) (datas []AccountData, err error)
- func (s *Storage) Accumulate(roomID, prevBatch string, timeline []json.RawMessage) (numNew int, timelineNIDs []int64, err error)
- func (s *Storage) Cleaner(n time.Duration)
- func (s *Storage) EventNIDs(eventNIDs []int64) ([]json.RawMessage, error)
- func (s *Storage) GlobalSnapshot(chanName string) (ss StartupSnapshot, err error)
- func (s *Storage) Initialise(roomID string, state []json.RawMessage) (bool, int64, error)
- func (s *Storage) InsertAccountData(userID, roomID string, events []json.RawMessage) (data []AccountData, err error)
- func (s *Storage) JoinedRoomsAfterPosition(userID string, pos int64) ([]string, error)
- func (s *Storage) LatestEventNID() (int64, error)
- func (s *Storage) LatestEventsInRooms(userID string, roomIDs []string, to int64, limit int) (map[string][]json.RawMessage, map[string]string, error)
- func (s *Storage) MaxPayloadIDForChannel(chanName string) (id int64, err error)
- func (s *Storage) RoomAccountDatasWithType(userID, eventType string) (data []AccountData, err error)
- func (s *Storage) RoomMembershipDelta(roomID string, from, to int64, limit int) (eventJSON []json.RawMessage, upTo int64, err error)
- func (s *Storage) RoomStateAfterEventPosition(ctx context.Context, roomIDs []string, pos int64, ...) (roomToEvents map[string][]Event, err error)
- func (s *Storage) StateSnapshot(snapID int64) (state []json.RawMessage, err error)
- func (s *Storage) Teardown()
- func (s *Storage) VisibleEventNIDsBetween(userID string, from, to int64) (map[string][][2]int64, error)
- type StrippedEvents
- type ToDeviceRow
- type ToDeviceRowChunker
- type ToDeviceTable
- func (t *ToDeviceTable) DeleteMessagesUpToAndIncluding(deviceID string, toIncl int64) error
- func (t *ToDeviceTable) InsertMessages(deviceID string, msgs []json.RawMessage) (pos int64, err error)
- func (t *ToDeviceTable) Messages(deviceID string, from, limit int64) (msgs []json.RawMessage, upTo int64, err error)
- type TransactionsTable
- type UnreadTable
- func (t *UnreadTable) SelectAllNonZeroCountsForUser(userID string, ...) error
- func (t *UnreadTable) SelectUnreadCounters(userID, roomID string) (highlightCount, notificationCount int, err error)
- func (t *UnreadTable) UpdateUnreadCounters(userID, roomID string, highlightCount, notificationCount *int) error
Constants ¶
const ( EventsStart = -1 EventsEnd = math.MaxInt64 - 1 )
const ( RelationMSpaceParent = 1 RelationMSpaceChild = 2 )
const AccountDataGlobalRoom = ""
const MaxPostgresParameters = 65535
Max number of parameters in a single SQL command
Variables ¶
This section is empty.
Functions ¶
func PackReceiptsIntoEDU ¶ added in v0.7.3
func PackReceiptsIntoEDU(receipts []internal.Receipt) (json.RawMessage, error)
PackReceiptsIntoEDU bundles all the receipts into a single m.receipt EDU, suitable for sending down client connections.
Types ¶
type AccountData ¶
type AccountDataChunker ¶
type AccountDataChunker []AccountData
func (AccountDataChunker) Len ¶
func (c AccountDataChunker) Len() int
type AccountDataTable ¶
type AccountDataTable struct{}
AccountDataTable stores the account data for users.
func NewAccountDataTable ¶
func NewAccountDataTable(db *sqlx.DB) *AccountDataTable
func (*AccountDataTable) Insert ¶
func (t *AccountDataTable) Insert(txn *sqlx.Tx, accDatas []AccountData) ([]AccountData, error)
Insert account data.
func (*AccountDataTable) Select ¶
func (t *AccountDataTable) Select(txn *sqlx.Tx, userID string, eventTypes []string, roomID string) (datas []AccountData, err error)
func (*AccountDataTable) SelectMany ¶
func (t *AccountDataTable) SelectMany(txn *sqlx.Tx, userID string, roomIDs ...string) (datas []AccountData, err error)
func (*AccountDataTable) SelectWithType ¶ added in v0.4.0
func (t *AccountDataTable) SelectWithType(txn *sqlx.Tx, userID, evType string) (datas []AccountData, err error)
type Accumulator ¶
type Accumulator struct {
// contains filtered or unexported fields
}
Accumulator tracks room state and timelines.
In order for it to remain simple(ish), the accumulator DOES NOT SUPPORT arbitrary timeline gaps. There is an Initialise function for new rooms (with some pre-determined state) and then a constant Accumulate function for timeline events. v2 sync must be called with a large enough timeline.limit for this to work!
func NewAccumulator ¶
func NewAccumulator(db *sqlx.DB) *Accumulator
func (*Accumulator) Accumulate ¶
func (a *Accumulator) Accumulate(roomID string, prevBatch string, timeline []json.RawMessage) (numNew int, timelineNIDs []int64, err error)
Accumulate internal state from a user's sync response. The timeline order MUST be in the order received from the server. Returns the number of new events in the timeline, the new timeline event NIDs or an error.
This function does several things:
- It ensures all events are persisted in the database. This is shared amongst users.
- If all events have been stored before, then it short circuits and returns. This is because we must have already processed this part of the timeline in order for the event to exist in the database, and the sync stream is already linearised for us.
- Else it creates a new room state snapshot if the timeline contains state events (as this now represents the current state)
- It adds entries to the membership log for membership events.
func (*Accumulator) Delta ¶
func (a *Accumulator) Delta(roomID string, lastEventNID int64, limit int) (eventsJSON []json.RawMessage, latest int64, err error)
Delta returns a list of events of at most `limit` for the room not including `lastEventNID`. Returns the latest NID of the last event (most recent)
func (*Accumulator) Initialise ¶
func (a *Accumulator) Initialise(roomID string, state []json.RawMessage) (bool, int64, error)
Initialise starts a new sync accumulator for the given room using the given state as a baseline. This will only take effect if this is the first time the v3 server has seen this room, and it wasn't possible to get all events up to the create event (e.g Matrix HQ). Returns true if this call actually added new events, along with the snapshot NID.
This function: - Stores these events - Sets up the current snapshot based on the state list given.
type DeviceDataRow ¶ added in v0.5.0
type DeviceDataTable ¶ added in v0.5.0
type DeviceDataTable struct {
// contains filtered or unexported fields
}
func NewDeviceDataTable ¶ added in v0.5.0
func NewDeviceDataTable(db *sqlx.DB) *DeviceDataTable
func (*DeviceDataTable) Select ¶ added in v0.5.0
func (t *DeviceDataTable) Select(userID, deviceID string, swap bool) (dd *internal.DeviceData, err error)
Atomically select the device data for this user|device and then swap DeviceLists around if set. This should only be called by the v3 HTTP APIs when servicing an E2EE extension request.
func (*DeviceDataTable) SelectFrom ¶ added in v0.5.0
func (t *DeviceDataTable) SelectFrom(pos int64) (results []internal.DeviceData, nextPos int64, err error)
func (*DeviceDataTable) Upsert ¶ added in v0.5.0
func (t *DeviceDataTable) Upsert(dd *internal.DeviceData) (pos int64, err error)
Upsert combines what is in the database for this user|device with the partial entry `dd`
type Event ¶
type Event struct { NID int64 `db:"event_nid"` Type string `db:"event_type"` StateKey string `db:"state_key"` Membership string `db:"membership"` // whether this was part of a v2 state response and hence not part of the timeline IsState bool `db:"is_state"` // This is a snapshot ID which corresponds to some room state BEFORE this event has been applied. BeforeStateSnapshotID int64 `db:"before_state_snapshot_id"` ReplacesNID int64 `db:"event_replaces_nid"` ID string `db:"event_id"` RoomID string `db:"room_id"` // not all events include a prev batch (e.g if it was part of state not timeline, and only the first // event in a timeline has a prev_batch attached), but we'll look for the 'closest' prev batch // when returning these tokens to the caller (closest = next newest, assume clients de-dupe) PrevBatch sql.NullString `db:"prev_batch"` // stripped events will be missing this field JSON []byte `db:"event"` }
type EventChunker ¶
type EventChunker []Event
func (EventChunker) Len ¶
func (c EventChunker) Len() int
type EventTable ¶
type EventTable struct {
// contains filtered or unexported fields
}
EventTable stores events. A unique numeric ID is associated with each event.
func NewEventTable ¶
func NewEventTable(db *sqlx.DB) *EventTable
NewEventTable makes a new EventTable
func (*EventTable) Insert ¶
Insert events into the event table. Returns a map of event ID to NID for new events only.
func (*EventTable) LatestEventInRooms ¶ added in v0.1.3
func (t *EventTable) LatestEventInRooms(txn *sqlx.Tx, roomIDs []string, highestNID int64) (events []Event, err error)
query the latest events in each of the room IDs given, using highestNID as the highest event.
func (*EventTable) SelectByIDs ¶
func (*EventTable) SelectByNIDs ¶
func (*EventTable) SelectClosestPrevBatch ¶
func (t *EventTable) SelectClosestPrevBatch(roomID string, eventNID int64) (prevBatch string, err error)
Select the closest prev batch token for the provided event NID. Returns the empty string if there is no closest.
func (*EventTable) SelectClosestPrevBatchByID ¶
func (t *EventTable) SelectClosestPrevBatchByID(roomID string, eventID string) (prevBatch string, err error)
SelectClosestPrevBatchByID is the same as SelectClosestPrevBatch but works on event IDs not NIDs
func (*EventTable) SelectEventNIDsWithTypeInRoom ¶
func (t *EventTable) SelectEventNIDsWithTypeInRoom(txn *sqlx.Tx, eventType string, limit int, targetRoom string, lowerExclusive, upperInclusive int64) (eventNIDs []int64, err error)
Select all events matching the given event type in a room. Used to implement the room member stream (paginated room lists)
func (*EventTable) SelectEventsBetween ¶
func (*EventTable) SelectEventsWithTypeStateKey ¶
func (t *EventTable) SelectEventsWithTypeStateKey(eventType, stateKey string, lowerExclusive, upperInclusive int64) ([]Event, error)
Select all events between the bounds matching the type, state_key given. Used to work out which rooms the user was joined to at a given point in time.
func (*EventTable) SelectEventsWithTypeStateKeyInRooms ¶
func (t *EventTable) SelectEventsWithTypeStateKeyInRooms(roomIDs []string, eventType, stateKey string, lowerExclusive, upperInclusive int64) ([]Event, error)
Select all events between the bounds matching the type, state_key given, in the rooms specified only. Used to work out which rooms the user was joined to at a given point in time.
func (*EventTable) SelectHighestNID ¶
func (t *EventTable) SelectHighestNID() (highest int64, err error)
func (*EventTable) SelectLatestEventsBetween ¶
func (*EventTable) SelectNIDsByIDs ¶
func (*EventTable) SelectStrippedEventsByIDs ¶
func (t *EventTable) SelectStrippedEventsByIDs(txn *sqlx.Tx, verifyAll bool, ids []string) (StrippedEvents, error)
func (*EventTable) SelectStrippedEventsByNIDs ¶
func (t *EventTable) SelectStrippedEventsByNIDs(txn *sqlx.Tx, verifyAll bool, nids []int64) (StrippedEvents, error)
func (*EventTable) UpdateBeforeSnapshotID ¶
func (t *EventTable) UpdateBeforeSnapshotID(txn *sqlx.Tx, eventNID, snapID, replacesNID int64) error
UpdateBeforeSnapshotID sets the before_state_snapshot_id field to `snapID` for the given NIDs.
type InvitesTable ¶
type InvitesTable struct {
// contains filtered or unexported fields
}
InvitesTable stores invites for each user. Originally, invites were stored with the main events in a room. We ignored stripped state and just kept the m.room.member invite event. This had many problems though:
- The room would be initialised by the invite event, causing the room to not populate with state correctly when the user joined the room.
- The user could read room data in the room without being joined to the room e.g could pull `required_state` and `timeline` as they would be authorised by the invite to see this data.
Instead, we now completely split out invites from the normal event flow. This fixes the issues outlined above but introduce more problems:
- How do you sort the invite with rooms?
- How do you calculate the room name when you lack heroes?
For now, we say that invites:
- are treated as a highlightable event for the purposes of sorting by highlight count.
- are given the timestamp of when the invite arrived.
- calculate the room name on a best-effort basis given the lack of heroes (same as element-web).
When an invite is rejected, it appears in the `leave` section which then causes the invite to be removed from this table.
func NewInvitesTable ¶
func NewInvitesTable(db *sqlx.DB) *InvitesTable
func (*InvitesTable) InsertInvite ¶
func (t *InvitesTable) InsertInvite(userID, roomID string, inviteRoomState []json.RawMessage) error
func (*InvitesTable) RemoveInvite ¶
func (t *InvitesTable) RemoveInvite(userID, roomID string) error
func (*InvitesTable) SelectAllInvitesForUser ¶
func (t *InvitesTable) SelectAllInvitesForUser(userID string) (map[string][]json.RawMessage, error)
Select all invites for this user. Returns a map of room ID to invite_state (json array).
func (*InvitesTable) SelectInviteState ¶ added in v0.5.0
func (t *InvitesTable) SelectInviteState(userID, roomID string) (inviteState []json.RawMessage, err error)
type ReceiptChunker ¶ added in v0.7.3
func (ReceiptChunker) Len ¶ added in v0.7.3
func (c ReceiptChunker) Len() int
type ReceiptTable ¶ added in v0.7.3
type ReceiptTable struct {
// contains filtered or unexported fields
}
func NewReceiptTable ¶ added in v0.7.3
func NewReceiptTable(db *sqlx.DB) *ReceiptTable
func (*ReceiptTable) Insert ¶ added in v0.7.3
func (t *ReceiptTable) Insert(roomID string, ephEvent json.RawMessage) (receipts []internal.Receipt, err error)
Insert new receipts based on a receipt EDU Returns newly inserted receipts, or nil if there are no new receipts. These newly inserted receipts can then be sent to the API processes for live updates.
func (*ReceiptTable) SelectReceiptsForEvents ¶ added in v0.7.3
func (t *ReceiptTable) SelectReceiptsForEvents(roomID string, eventIDs []string) (receipts []internal.Receipt, err error)
Select all non-private receipts for the event IDs given. Events must be in the room ID given. The parsed receipts are returned so callers can use information in the receipts in further queries e.g to pull out profile information for users read receipts. Call PackReceiptsIntoEDU when sending to clients.
func (*ReceiptTable) SelectReceiptsForUser ¶ added in v0.7.3
func (t *ReceiptTable) SelectReceiptsForUser(roomID, userID string) (receipts []internal.Receipt, err error)
Select all (including private) receipts for this user in this room.
type RoomsTable ¶
type RoomsTable struct{}
RoomsTable stores the current snapshot for a room.
func NewRoomsTable ¶
func NewRoomsTable(db *sqlx.DB) *RoomsTable
func (*RoomsTable) CurrentAfterSnapshotID ¶
func (t *RoomsTable) CurrentAfterSnapshotID(txn *sqlx.Tx, roomID string) (snapshotID int64, err error)
Return the snapshot for this room AFTER the latest event has been applied.
func (*RoomsTable) LatestNIDs ¶ added in v0.1.3
func (*RoomsTable) SelectRoomInfos ¶ added in v0.2.1
func (t *RoomsTable) SelectRoomInfos(txn *sqlx.Tx) (infos []RoomInfo, err error)
type SnapshotRow ¶
type SnapshotRow struct { SnapshotID int64 `db:"snapshot_id"` RoomID string `db:"room_id"` Events pq.Int64Array `db:"events"` }
type SnapshotTable ¶
type SnapshotTable struct {
// contains filtered or unexported fields
}
SnapshotTable stores room state snapshots. Each snapshot has a unique numeric ID. Not every event will be associated with a snapshot.
func NewSnapshotsTable ¶
func NewSnapshotsTable(db *sqlx.DB) *SnapshotTable
func (*SnapshotTable) CurrentSnapshots ¶
func (*SnapshotTable) Delete ¶
func (s *SnapshotTable) Delete(txn *sqlx.Tx, snapshotIDs []int64) error
Delete the snapshot IDs given
func (*SnapshotTable) Insert ¶
func (s *SnapshotTable) Insert(txn *sqlx.Tx, row *SnapshotRow) error
Insert the row. Modifies SnapshotID to be the inserted primary key.
func (*SnapshotTable) Select ¶
func (s *SnapshotTable) Select(txn *sqlx.Tx, snapshotID int64) (row SnapshotRow, err error)
Select a row based on its snapshot ID.
type SpaceRelation ¶ added in v0.2.1
type SpaceRelation struct { Parent string `db:"parent"` Child string `db:"child"` Relation int `db:"relation"` Ordering string `db:"ordering"` IsSuggested bool `db:"suggested"` }
func NewSpaceRelationFromEvent ¶ added in v0.2.1
func NewSpaceRelationFromEvent(ev Event) (sr *SpaceRelation, isDeleted bool)
Returns a space relation from a compatible event, else nil.
func (*SpaceRelation) Key ¶ added in v0.2.1
func (sr *SpaceRelation) Key() string
type SpaceRelationChunker ¶ added in v0.2.1
type SpaceRelationChunker []SpaceRelation
func (SpaceRelationChunker) Len ¶ added in v0.2.1
func (c SpaceRelationChunker) Len() int
type SpacesTable ¶ added in v0.2.1
type SpacesTable struct{}
SpacesTable stores the space graph for all users.
func NewSpacesTable ¶ added in v0.2.1
func NewSpacesTable(db *sqlx.DB) *SpacesTable
func (*SpacesTable) BulkDelete ¶ added in v0.2.1
func (t *SpacesTable) BulkDelete(txn *sqlx.Tx, relations []SpaceRelation) error
Delete space relations by (parent, child, relation)
func (*SpacesTable) BulkInsert ¶ added in v0.2.1
func (t *SpacesTable) BulkInsert(txn *sqlx.Tx, relations []SpaceRelation) error
Insert space relations by (parent, child, relation)
func (*SpacesTable) HandleSpaceUpdates ¶ added in v0.2.1
func (t *SpacesTable) HandleSpaceUpdates(txn *sqlx.Tx, events []Event) error
func (*SpacesTable) SelectChildren ¶ added in v0.2.1
func (t *SpacesTable) SelectChildren(txn *sqlx.Tx, spaces []string) (map[string][]SpaceRelation, error)
Select all children for these spaces
type StartupSnapshot ¶ added in v0.5.0
type StartupSnapshot struct { GlobalMetadata map[string]internal.RoomMetadata // room_id -> metadata AllJoinedMembers map[string][]string // room_id -> [user_id] PayloadStartID int64 }
StartupSnapshot represents a snapshot of startup data for the sliding sync HTTP API instances
type Storage ¶
type Storage struct { EventsTable *EventTable ToDeviceTable *ToDeviceTable UnreadTable *UnreadTable AccountDataTable *AccountDataTable InvitesTable *InvitesTable PayloadTable *notify.PayloadTable TransactionsTable *TransactionsTable DeviceDataTable *DeviceDataTable ReceiptTable *ReceiptTable DB *sqlx.DB // contains filtered or unexported fields }
func NewStorage ¶
func (*Storage) AccountData ¶
func (s *Storage) AccountData(userID, roomID string, eventTypes []string) (data []AccountData, err error)
func (*Storage) AccountDatas ¶
func (s *Storage) AccountDatas(userID string, roomIDs ...string) (datas []AccountData, err error)
Pull out all account data for this user. If roomIDs is empty, global account data is returned. If roomIDs is non-empty, all account data for these rooms are extracted.
func (*Storage) Accumulate ¶
func (*Storage) Cleaner ¶ added in v0.5.0
Cleaner blocks forever cleaning every N. Stops cleaning when torn down.
func (*Storage) EventNIDs ¶ added in v0.5.0
func (s *Storage) EventNIDs(eventNIDs []int64) ([]json.RawMessage, error)
func (*Storage) GlobalSnapshot ¶ added in v0.5.0
func (s *Storage) GlobalSnapshot(chanName string) (ss StartupSnapshot, err error)
GlobalSnapshot snapshots the entire database for the purposes of initialising a sliding sync HTTP API instance. It will atomically grab metadata for all rooms, all joined members and the latest pubsub position in a single transaction.
func (*Storage) Initialise ¶
func (*Storage) InsertAccountData ¶
func (s *Storage) InsertAccountData(userID, roomID string, events []json.RawMessage) (data []AccountData, err error)
func (*Storage) JoinedRoomsAfterPosition ¶
func (*Storage) LatestEventNID ¶
func (*Storage) LatestEventsInRooms ¶
func (*Storage) MaxPayloadIDForChannel ¶ added in v0.5.0
func (*Storage) RoomAccountDatasWithType ¶ added in v0.4.0
func (s *Storage) RoomAccountDatasWithType(userID, eventType string) (data []AccountData, err error)
func (*Storage) RoomMembershipDelta ¶
func (*Storage) RoomStateAfterEventPosition ¶
func (s *Storage) RoomStateAfterEventPosition(ctx context.Context, roomIDs []string, pos int64, eventTypesToStateKeys map[string][]string) (roomToEvents map[string][]Event, err error)
Look up room state after the given event position and no further. eventTypesToStateKeys is a map of event type to a list of state keys for that event type. If the list of state keys is empty then all events matching that event type will be returned. If the map is empty entirely, then all room state will be returned.
func (*Storage) StateSnapshot ¶ added in v0.5.0
func (s *Storage) StateSnapshot(snapID int64) (state []json.RawMessage, err error)
func (*Storage) VisibleEventNIDsBetween ¶
func (s *Storage) VisibleEventNIDsBetween(userID string, from, to int64) (map[string][][2]int64, error)
Work out the NID ranges to pull events from for this user. Given a from and to event nid stream position, this function returns a map of room ID to a slice of 2-element from|to positions. These positions are all INCLUSIVE, and the client should be informed of these events at some point. For example:
Stream Positions 1 2 3 4 5 6 7 8 9 10 Room A Maj E E E Room B E Maj E Room C E Mal E (a already joined to this room at position 0) E=message event, M=membership event, followed by user letter, followed by 'i' or 'j' or 'l' for invite|join|leave - For Room A: from=1, to=10, returns { RoomA: [ [1,10] ]} (tests events in joined room) - For Room B: from=1, to=10, returns { RoomB: [ [5,10] ]} (tests joining a room starts events) - For Room C: from=1, to=10, returns { RoomC: [ [0,9] ]} (tests leaving a room stops events)
Multiple slices can occur when a user leaves and re-joins the same room, and invites are same-element positions:
Stream Positions 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Room D Maj E Mal E Maj E Mal E Room E E Mai E E Maj E E - For Room D: from=1, to=15 returns { RoomD: [ [1,6], [8,10] ] } (tests multi-join/leave) - For Room E: from=1, to=15 returns { RoomE: [ [3,3], [13,15] ] } (tests invites)
type StrippedEvents ¶
type StrippedEvents []Event
func (StrippedEvents) NIDs ¶
func (se StrippedEvents) NIDs() (result []int64)
type ToDeviceRow ¶
type ToDeviceRowChunker ¶
type ToDeviceRowChunker []ToDeviceRow
func (ToDeviceRowChunker) Len ¶
func (c ToDeviceRowChunker) Len() int
type ToDeviceTable ¶
type ToDeviceTable struct {
// contains filtered or unexported fields
}
ToDeviceTable stores to_device messages for devices.
func NewToDeviceTable ¶
func NewToDeviceTable(db *sqlx.DB) *ToDeviceTable
func (*ToDeviceTable) DeleteMessagesUpToAndIncluding ¶
func (t *ToDeviceTable) DeleteMessagesUpToAndIncluding(deviceID string, toIncl int64) error
func (*ToDeviceTable) InsertMessages ¶
func (t *ToDeviceTable) InsertMessages(deviceID string, msgs []json.RawMessage) (pos int64, err error)
func (*ToDeviceTable) Messages ¶
func (t *ToDeviceTable) Messages(deviceID string, from, limit int64) (msgs []json.RawMessage, upTo int64, err error)
Query to-device messages for this device, exclusive of from and inclusive of to. If a to value is unknown, use -1.
type TransactionsTable ¶ added in v0.5.0
type TransactionsTable struct {
// contains filtered or unexported fields
}
func NewTransactionsTable ¶ added in v0.5.0
func NewTransactionsTable(db *sqlx.DB) *TransactionsTable
func (*TransactionsTable) Clean ¶ added in v0.5.0
func (t *TransactionsTable) Clean(boundaryTime time.Time) error
type UnreadTable ¶
type UnreadTable struct {
// contains filtered or unexported fields
}
UnreadTable stores unread counts per-user
func NewUnreadTable ¶
func NewUnreadTable(db *sqlx.DB) *UnreadTable
func (*UnreadTable) SelectAllNonZeroCountsForUser ¶
func (t *UnreadTable) SelectAllNonZeroCountsForUser(userID string, callback func(roomID string, highlightCount, notificationCount int)) error
func (*UnreadTable) SelectUnreadCounters ¶
func (t *UnreadTable) SelectUnreadCounters(userID, roomID string) (highlightCount, notificationCount int, err error)
func (*UnreadTable) UpdateUnreadCounters ¶
func (t *UnreadTable) UpdateUnreadCounters(userID, roomID string, highlightCount, notificationCount *int) error