state

package
v0.7.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 6, 2022 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EventsStart = -1
	EventsEnd   = math.MaxInt64 - 1
)
View Source
const (
	RelationMSpaceParent = 1
	RelationMSpaceChild  = 2
)
View Source
const AccountDataGlobalRoom = ""
View Source
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 AccountData struct {
	UserID string `db:"user_id"`
	RoomID string `db:"room_id"`
	Type   string `db:"type"`
	Data   []byte `db:"data"`
}

type AccountDataChunker

type AccountDataChunker []AccountData

func (AccountDataChunker) Len

func (c AccountDataChunker) Len() int

func (AccountDataChunker) Subslice

func (c AccountDataChunker) Subslice(i, j int) sqlutil.Chunker

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 DeviceDataRow struct {
	ID       int64  `db:"id"`
	UserID   string `db:"user_id"`
	DeviceID string `db:"device_id"`
	// This will contain internal.DeviceData serialised as JSON. It's stored in a single column as we don't
	// need to perform searches on this data.
	Data []byte `db:"data"`
}

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

func (EventChunker) Subslice

func (c EventChunker) Subslice(i, j int) sqlutil.Chunker

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

func (t *EventTable) Insert(txn *sqlx.Tx, events []Event, checkFields bool) (map[string]int, error)

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 (t *EventTable) SelectByIDs(txn *sqlx.Tx, verifyAll bool, ids []string) (events []Event, err error)

func (*EventTable) SelectByNIDs

func (t *EventTable) SelectByNIDs(txn *sqlx.Tx, verifyAll bool, nids []int64) (events []Event, err error)

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 (t *EventTable) SelectEventsBetween(txn *sqlx.Tx, roomID string, lowerExclusive, upperInclusive int64, limit int) ([]Event, error)

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 (t *EventTable) SelectLatestEventsBetween(txn *sqlx.Tx, roomID string, lowerExclusive, upperInclusive int64, limit int) ([]Event, error)

func (*EventTable) SelectNIDsByIDs

func (t *EventTable) SelectNIDsByIDs(txn *sqlx.Tx, ids []string) (nids map[string]int64, err error)

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

type ReceiptChunker []internal.Receipt

func (ReceiptChunker) Len added in v0.7.3

func (c ReceiptChunker) Len() int

func (ReceiptChunker) Subslice added in v0.7.3

func (c ReceiptChunker) Subslice(i, j int) sqlutil.Chunker

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 RoomInfo added in v0.2.1

type RoomInfo struct {
	ID                string  `db:"room_id"`
	IsEncrypted       bool    `db:"is_encrypted"`
	UpgradedRoomID    *string `db:"upgraded_room_id"`    // from the most recent valid tombstone event, or NULL
	PredecessorRoomID *string `db:"predecessor_room_id"` // from the create event
	Type              *string `db:"type"`
}

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 (t *RoomsTable) LatestNIDs(txn *sqlx.Tx, roomIDs []string) (nids map[string]int64, err error)

func (*RoomsTable) SelectRoomInfos added in v0.2.1

func (t *RoomsTable) SelectRoomInfos(txn *sqlx.Tx) (infos []RoomInfo, err error)

func (*RoomsTable) Upsert added in v0.2.1

func (t *RoomsTable) Upsert(txn *sqlx.Tx, info RoomInfo, snapshotID, latestNID int64) (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 (t *SnapshotTable) CurrentSnapshots(txn *sqlx.Tx) (map[string][]int64, error)

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

func (SpaceRelationChunker) Subslice added in v0.2.1

func (c SpaceRelationChunker) Subslice(i, j int) sqlutil.Chunker

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 NewStorage(postgresURI string) *Storage

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 (s *Storage) Accumulate(roomID, prevBatch string, timeline []json.RawMessage) (numNew int, timelineNIDs []int64, err error)

func (*Storage) Cleaner added in v0.5.0

func (s *Storage) Cleaner(n time.Duration)

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 (s *Storage) Initialise(roomID string, state []json.RawMessage) (bool, int64, error)

func (*Storage) InsertAccountData

func (s *Storage) InsertAccountData(userID, roomID string, events []json.RawMessage) (data []AccountData, err error)

func (*Storage) JoinedRoomsAfterPosition

func (s *Storage) JoinedRoomsAfterPosition(userID string, pos int64) ([]string, error)

func (*Storage) LatestEventNID

func (s *Storage) LatestEventNID() (int64, error)

func (*Storage) LatestEventsInRooms

func (s *Storage) LatestEventsInRooms(userID string, roomIDs []string, to int64, limit int) (map[string][]json.RawMessage, map[string]string, error)

func (*Storage) MaxPayloadIDForChannel added in v0.5.0

func (s *Storage) MaxPayloadIDForChannel(chanName string) (id int64, err error)

func (*Storage) RoomAccountDatasWithType added in v0.4.0

func (s *Storage) RoomAccountDatasWithType(userID, eventType string) (data []AccountData, err error)

func (*Storage) RoomMembershipDelta

func (s *Storage) RoomMembershipDelta(roomID string, from, to int64, limit int) (eventJSON []json.RawMessage, upTo int64, err error)

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) Teardown added in v0.1.1

func (s *Storage) Teardown()

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 ToDeviceRow struct {
	Position int64  `db:"position"`
	DeviceID string `db:"device_id"`
	Message  string `db:"message"`
	Type     string `db:"event_type"`
	Sender   string `db:"sender"`
}

type ToDeviceRowChunker

type ToDeviceRowChunker []ToDeviceRow

func (ToDeviceRowChunker) Len

func (c ToDeviceRowChunker) Len() int

func (ToDeviceRowChunker) Subslice

func (c ToDeviceRowChunker) Subslice(i, j int) sqlutil.Chunker

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

func (*TransactionsTable) Insert added in v0.5.0

func (t *TransactionsTable) Insert(userID string, eventIDToTxnID map[string]string) error

func (*TransactionsTable) Select added in v0.5.0

func (t *TransactionsTable) Select(userID string, eventIDs []string) (map[string]string, 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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL