Send-to-device support (#1072)
* Groundwork for send-to-device messaging
* Update sample config
* Add unstable routing for now
* Send to device consumer in sync API
* Start the send-to-device consumer
* fix indentation in dendrite-config.yaml
* Create send-to-device database tables, other tweaks
* Add some logic for send-to-device messages, add them into sync stream
* Handle incoming send-to-device messages, count them with EDU stream pos
* Undo changes to test
* pq.Array
* Fix sync
* Logging
* Fix a couple of transaction things, fix client API
* Add send-to-device test, hopefully fix bugs
* Comments
* Refactor a bit
* Fix schema
* Fix queries
* Debug logging
* Fix storing and retrieving of send-to-device messages
* Try to avoid database locks
* Update sync position
* Use latest sync position
* Jiggle about sync a bit
* Fix tests
* Break out the retrieval from the update/delete behaviour
* Comments
* nolint on getResponseWithPDUsForCompleteSync
* Try to line up sync tokens again
* Implement wildcard
* Add all send-to-device tests to whitelist, what could possibly go wrong?
* Only care about wildcard when targeted locally
* Deduplicate transactions
* Handle tokens properly, return immediately if waiting send-to-device messages
* Fix sync
* Update sytest-whitelist
* Fix copyright notice (need to do more of this)
* Comments, copyrights
* Return errors from Do, fix dendritejs
* Review comments
* Comments
* Constructor for TransactionWriter
* defletions
* Update gomatrixserverlib, sytest-blacklist
2020-06-01 18:50:19 +02:00
// Copyright 2020 The Matrix.org Foundation C.I.C.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
2020-05-13 18:28:42 +02:00
package tables
import (
"context"
"database/sql"
2022-08-05 11:12:41 +02:00
"github.com/matrix-org/gomatrixserverlib"
2023-04-19 16:50:33 +02:00
"github.com/matrix-org/gomatrixserverlib/spec"
2022-08-05 11:12:41 +02:00
2022-03-03 12:40:53 +01:00
"github.com/matrix-org/dendrite/internal/eventutil"
2020-05-14 10:53:55 +02:00
"github.com/matrix-org/dendrite/roomserver/api"
2023-04-27 13:54:20 +02:00
rstypes "github.com/matrix-org/dendrite/roomserver/types"
2023-04-04 19:16:53 +02:00
"github.com/matrix-org/dendrite/syncapi/synctypes"
2020-05-13 18:28:42 +02:00
"github.com/matrix-org/dendrite/syncapi/types"
)
2020-05-14 10:53:55 +02:00
type AccountData interface {
InsertAccountData ( ctx context . Context , txn * sql . Tx , userID , roomID , dataType string ) ( pos types . StreamPosition , err error )
2020-05-15 10:41:12 +02:00
// SelectAccountDataInRange returns a map of room ID to a list of `dataType`.
2023-04-04 19:16:53 +02:00
SelectAccountDataInRange ( ctx context . Context , txn * sql . Tx , userID string , r types . Range , accountDataEventFilter * synctypes . EventFilter ) ( data map [ string ] [ ] string , pos types . StreamPosition , err error )
2020-05-14 10:53:55 +02:00
SelectMaxAccountDataID ( ctx context . Context , txn * sql . Tx ) ( id int64 , err error )
}
2020-05-13 18:28:42 +02:00
type Invites interface {
2023-04-27 13:54:20 +02:00
InsertInviteEvent ( ctx context . Context , txn * sql . Tx , inviteEvent * rstypes . HeaderedEvent ) ( streamPos types . StreamPosition , err error )
2020-09-01 12:28:35 +02:00
DeleteInviteEvent ( ctx context . Context , txn * sql . Tx , inviteEventID string ) ( types . StreamPosition , error )
2020-08-25 19:59:00 +02:00
// SelectInviteEventsInRange returns a map of room ID to invite events. If multiple invite/retired invites exist in the given range, return the latest value
// for the room.
2023-04-27 13:54:20 +02:00
SelectInviteEventsInRange ( ctx context . Context , txn * sql . Tx , targetUserID string , r types . Range ) ( invites map [ string ] * rstypes . HeaderedEvent , retired map [ string ] * rstypes . HeaderedEvent , maxID types . StreamPosition , err error )
2020-05-13 18:28:42 +02:00
SelectMaxInviteID ( ctx context . Context , txn * sql . Tx ) ( id int64 , err error )
2023-01-19 21:02:32 +01:00
PurgeInvites ( ctx context . Context , txn * sql . Tx , roomID string ) error
2020-05-13 18:28:42 +02:00
}
2020-05-14 10:53:55 +02:00
2020-09-10 15:39:18 +02:00
type Peeks interface {
InsertPeek ( ctx context . Context , txn * sql . Tx , roomID , userID , deviceID string ) ( streamPos types . StreamPosition , err error )
DeletePeek ( ctx context . Context , txn * sql . Tx , roomID , userID , deviceID string ) ( streamPos types . StreamPosition , err error )
DeletePeeks ( ctx context . Context , txn * sql . Tx , roomID , userID string ) ( streamPos types . StreamPosition , err error )
SelectPeeksInRange ( ctxt context . Context , txn * sql . Tx , userID , deviceID string , r types . Range ) ( peeks [ ] types . Peek , err error )
2022-09-28 11:18:03 +02:00
SelectPeekingDevices ( ctxt context . Context , txn * sql . Tx ) ( peekingDevices map [ string ] [ ] types . PeekingDevice , err error )
2020-09-10 15:39:18 +02:00
SelectMaxPeekID ( ctx context . Context , txn * sql . Tx ) ( id int64 , err error )
2023-01-19 21:02:32 +01:00
PurgePeeks ( ctx context . Context , txn * sql . Tx , roomID string ) error
2020-09-10 15:39:18 +02:00
}
2020-05-14 10:53:55 +02:00
type Events interface {
2023-04-04 19:16:53 +02:00
SelectStateInRange ( ctx context . Context , txn * sql . Tx , r types . Range , stateFilter * synctypes . StateFilter , roomIDs [ ] string ) ( map [ string ] map [ string ] bool , map [ string ] types . StreamEvent , error )
2020-05-14 10:53:55 +02:00
SelectMaxEventID ( ctx context . Context , txn * sql . Tx ) ( id int64 , err error )
2022-07-18 14:46:15 +02:00
InsertEvent (
ctx context . Context , txn * sql . Tx ,
2023-04-27 13:54:20 +02:00
event * rstypes . HeaderedEvent ,
2022-07-18 14:46:15 +02:00
addState , removeState [ ] string ,
transactionID * api . TransactionID ,
excludeFromSync bool ,
historyVisibility gomatrixserverlib . HistoryVisibility ,
) ( streamPos types . StreamPosition , err error )
2020-05-15 10:41:12 +02:00
// SelectRecentEvents returns events between the two stream positions: exclusive of low and inclusive of high.
2020-05-14 18:30:16 +02:00
// If onlySyncEvents has a value of true, only returns the events that aren't marked as to exclude from sync.
2020-06-26 16:34:41 +02:00
// Returns up to `limit` events. Returns `limited=true` if there are more events in this range but we hit the `limit`.
2023-04-04 19:16:53 +02:00
SelectRecentEvents ( ctx context . Context , txn * sql . Tx , roomIDs [ ] string , r types . Range , eventFilter * synctypes . RoomEventFilter , chronologicalOrder bool , onlySyncEvents bool ) ( map [ string ] types . RecentEvents , error )
SelectEvents ( ctx context . Context , txn * sql . Tx , eventIDs [ ] string , filter * synctypes . RoomEventFilter , preserveOrder bool ) ( [ ] types . StreamEvent , error )
2023-04-27 13:54:20 +02:00
UpdateEventJSON ( ctx context . Context , txn * sql . Tx , event * rstypes . HeaderedEvent ) error
2020-09-15 12:17:46 +02:00
// DeleteEventsForRoom removes all event information for a room. This should only be done when removing the room entirely.
DeleteEventsForRoom ( ctx context . Context , txn * sql . Tx , roomID string ) ( err error )
2022-02-21 17:12:22 +01:00
2023-04-27 13:54:20 +02:00
SelectContextEvent ( ctx context . Context , txn * sql . Tx , roomID , eventID string ) ( int , rstypes . HeaderedEvent , error )
SelectContextBeforeEvent ( ctx context . Context , txn * sql . Tx , id int , roomID string , filter * synctypes . RoomEventFilter ) ( [ ] * rstypes . HeaderedEvent , error )
SelectContextAfterEvent ( ctx context . Context , txn * sql . Tx , id int , roomID string , filter * synctypes . RoomEventFilter ) ( int , [ ] * rstypes . HeaderedEvent , error )
2023-01-19 21:02:32 +01:00
PurgeEvents ( ctx context . Context , txn * sql . Tx , roomID string ) error
2023-04-27 13:54:20 +02:00
ReIndex ( ctx context . Context , txn * sql . Tx , limit , offset int64 , types [ ] string ) ( map [ int64 ] rstypes . HeaderedEvent , error )
2020-05-14 10:53:55 +02:00
}
2020-05-14 17:11:37 +02:00
2020-05-14 18:30:16 +02:00
// Topology keeps track of the depths and stream positions for all events.
// These positions are used as types.TopologyToken when backfilling events locally.
2020-05-14 17:11:37 +02:00
type Topology interface {
2020-05-14 18:30:16 +02:00
// InsertEventInTopology inserts the given event in the room's topology, based on the event's depth.
// `pos` is the stream position of this event in the events table, and is used to order events which have the same depth.
2023-04-27 13:54:20 +02:00
InsertEventInTopology ( ctx context . Context , txn * sql . Tx , event * rstypes . HeaderedEvent , pos types . StreamPosition ) ( topoPos types . StreamPosition , err error )
2023-07-13 14:18:37 +02:00
// SelectEventIDsInRange selects the IDs and the topological position of events whose depths are within a given range in a given room's topological order.
// Events with `minDepth` are *exclusive*, as is the event which has exactly `minDepth`,`maxStreamPos`. Returns the eventIDs and start/end topological tokens.
2020-05-14 18:30:16 +02:00
// `maxStreamPos` is only used when events have the same depth as `maxDepth`, which results in events less than `maxStreamPos` being returned.
2020-05-14 17:11:37 +02:00
// Returns an empty slice if no events match the given range.
2023-07-13 14:18:37 +02:00
SelectEventIDsInRange ( ctx context . Context , txn * sql . Tx , roomID string , minDepth , maxDepth , maxStreamPos types . StreamPosition , limit int , chronologicalOrder bool ) ( eventIDs [ ] string , start , end types . TopologyToken , err error )
2020-05-14 18:30:16 +02:00
// SelectPositionInTopology returns the depth and stream position of a given event in the topology of the room it belongs to.
SelectPositionInTopology ( ctx context . Context , txn * sql . Tx , eventID string ) ( depth , spos types . StreamPosition , err error )
2022-03-18 11:40:01 +01:00
// SelectStreamToTopologicalPosition converts a stream position to a topological position by finding the nearest topological position in the room.
SelectStreamToTopologicalPosition ( ctx context . Context , txn * sql . Tx , roomID string , streamPos types . StreamPosition , forward bool ) ( topoPos types . StreamPosition , err error )
2023-01-19 21:02:32 +01:00
PurgeEventsTopology ( ctx context . Context , txn * sql . Tx , roomID string ) error
2020-05-14 17:11:37 +02:00
}
type CurrentRoomState interface {
2023-04-27 13:54:20 +02:00
SelectStateEvent ( ctx context . Context , txn * sql . Tx , roomID , evType , stateKey string ) ( * rstypes . HeaderedEvent , error )
2020-05-14 17:11:37 +02:00
SelectEventsWithEventIDs ( ctx context . Context , txn * sql . Tx , eventIDs [ ] string ) ( [ ] types . StreamEvent , error )
2023-04-27 13:54:20 +02:00
UpsertRoomState ( ctx context . Context , txn * sql . Tx , event * rstypes . HeaderedEvent , membership * string , addedAt types . StreamPosition ) error
2020-05-14 17:11:37 +02:00
DeleteRoomStateByEventID ( ctx context . Context , txn * sql . Tx , eventID string ) error
2020-09-15 12:17:46 +02:00
DeleteRoomStateForRoom ( ctx context . Context , txn * sql . Tx , roomID string ) error
2020-05-14 17:11:37 +02:00
// SelectCurrentState returns all the current state events for the given room.
2023-04-27 13:54:20 +02:00
SelectCurrentState ( ctx context . Context , txn * sql . Tx , roomID string , stateFilter * synctypes . StateFilter , excludeEventIDs [ ] string ) ( [ ] * rstypes . HeaderedEvent , error )
2020-05-14 17:11:37 +02:00
// SelectRoomIDsWithMembership returns the list of room IDs which have the given user in the given membership state.
SelectRoomIDsWithMembership ( ctx context . Context , txn * sql . Tx , userID string , membership string ) ( [ ] string , error )
2022-03-11 13:48:45 +01:00
// SelectRoomIDsWithAnyMembership returns a map of all memberships for the given user.
SelectRoomIDsWithAnyMembership ( ctx context . Context , txn * sql . Tx , userID string ) ( map [ string ] string , error )
2020-05-14 17:11:37 +02:00
// SelectJoinedUsers returns a map of room ID to a list of joined user IDs.
2022-09-28 11:18:03 +02:00
SelectJoinedUsers ( ctx context . Context , txn * sql . Tx ) ( map [ string ] [ ] string , error )
2022-04-28 18:53:28 +02:00
// SelectJoinedUsersInRoom returns a map of room ID to a list of joined user IDs for a given room.
2022-09-28 11:18:03 +02:00
SelectJoinedUsersInRoom ( ctx context . Context , txn * sql . Tx , roomIDs [ ] string ) ( map [ string ] [ ] string , error )
2022-07-15 17:25:26 +02:00
// SelectSharedUsers returns a subset of otherUserIDs that share a room with userID.
SelectSharedUsers ( ctx context . Context , txn * sql . Tx , userID string , otherUserIDs [ ] string ) ( [ ] string , error )
2023-01-12 10:06:03 +01:00
SelectRoomHeroes ( ctx context . Context , txn * sql . Tx , roomID , excludeUserID string , memberships [ ] string ) ( [ ] string , error )
SelectMembershipCount ( ctx context . Context , txn * sql . Tx , roomID , membership string ) ( int , error )
2020-05-14 17:11:37 +02:00
}
// BackwardsExtremities keeps track of backwards extremities for a room.
// Backwards extremities are the earliest (DAG-wise) known events which we have
// the entire event JSON. These event IDs are used in federation requests to fetch
// even earlier events.
//
// We persist the previous event IDs as well, one per row, so when we do fetch even
// earlier events we can simply delete rows which referenced it. Consider the graph:
2022-08-05 11:12:41 +02:00
//
// A
// | Event C has 1 prev_event ID: A.
// B C
// |___| Event D has 2 prev_event IDs: B and C.
// |
// D
//
2020-05-14 17:11:37 +02:00
// The earliest known event we have is D, so this table has 2 rows.
// A backfill request gives us C but not B. We delete rows where prev_event=C. This
// still means that D is a backwards extremity as we do not have event B. However, event
// C is *also* a backwards extremity at this point as we do not have event A. Later,
// when we fetch event B, we delete rows where prev_event=B. This then removes D as
// a backwards extremity because there are no more rows with event_id=B.
type BackwardsExtremities interface {
// InsertsBackwardExtremity inserts a new backwards extremity.
InsertsBackwardExtremity ( ctx context . Context , txn * sql . Tx , roomID , eventID string , prevEventID string ) ( err error )
2020-05-20 17:04:31 +02:00
// SelectBackwardExtremitiesForRoom retrieves all backwards extremities for the room, as a map of event_id to list of prev_event_ids.
2022-09-28 11:18:03 +02:00
SelectBackwardExtremitiesForRoom ( ctx context . Context , txn * sql . Tx , roomID string ) ( bwExtrems map [ string ] [ ] string , err error )
2020-05-14 17:11:37 +02:00
// DeleteBackwardExtremity removes a backwards extremity for a room, if one existed.
DeleteBackwardExtremity ( ctx context . Context , txn * sql . Tx , roomID , knownEventID string ) ( err error )
2023-01-19 21:02:32 +01:00
PurgeBackwardExtremities ( ctx context . Context , txn * sql . Tx , roomID string ) error
2020-05-14 17:11:37 +02:00
}
Send-to-device support (#1072)
* Groundwork for send-to-device messaging
* Update sample config
* Add unstable routing for now
* Send to device consumer in sync API
* Start the send-to-device consumer
* fix indentation in dendrite-config.yaml
* Create send-to-device database tables, other tweaks
* Add some logic for send-to-device messages, add them into sync stream
* Handle incoming send-to-device messages, count them with EDU stream pos
* Undo changes to test
* pq.Array
* Fix sync
* Logging
* Fix a couple of transaction things, fix client API
* Add send-to-device test, hopefully fix bugs
* Comments
* Refactor a bit
* Fix schema
* Fix queries
* Debug logging
* Fix storing and retrieving of send-to-device messages
* Try to avoid database locks
* Update sync position
* Use latest sync position
* Jiggle about sync a bit
* Fix tests
* Break out the retrieval from the update/delete behaviour
* Comments
* nolint on getResponseWithPDUsForCompleteSync
* Try to line up sync tokens again
* Implement wildcard
* Add all send-to-device tests to whitelist, what could possibly go wrong?
* Only care about wildcard when targeted locally
* Deduplicate transactions
* Handle tokens properly, return immediately if waiting send-to-device messages
* Fix sync
* Update sytest-whitelist
* Fix copyright notice (need to do more of this)
* Comments, copyrights
* Return errors from Do, fix dendritejs
* Review comments
* Comments
* Constructor for TransactionWriter
* defletions
* Update gomatrixserverlib, sytest-blacklist
2020-06-01 18:50:19 +02:00
// SendToDevice tracks send-to-device messages which are sent to individual
// clients. Each message gets inserted into this table at the point that we
// receive it from the EDU server.
//
// We're supposed to try and do our best to deliver send-to-device messages
// once, but the only way that we can really guarantee that they have been
// delivered is if the client successfully requests the next sync as given
// in the next_batch. Each time the device syncs, we will request all of the
// updates that either haven't been sent yet, along with all updates that we
// *have* sent but we haven't confirmed to have been received yet. If it's the
// first time we're sending a given update then we update the table to say
// what the "since" parameter was when we tried to send it.
//
// When the client syncs again, if their "since" parameter is *later* than
// the recorded one, we drop the entry from the DB as it's "sent". If the
// sync parameter isn't later then we will keep including the updates in the
// sync response, as the client is seemingly trying to repeat the same /sync.
type SendToDevice interface {
2020-12-18 12:11:21 +01:00
InsertSendToDeviceMessage ( ctx context . Context , txn * sql . Tx , userID , deviceID , content string ) ( pos types . StreamPosition , err error )
2021-01-13 18:29:46 +01:00
SelectSendToDeviceMessages ( ctx context . Context , txn * sql . Tx , userID , deviceID string , from , to types . StreamPosition ) ( lastPos types . StreamPosition , events [ ] types . SendToDeviceEvent , err error )
DeleteSendToDeviceMessages ( ctx context . Context , txn * sql . Tx , userID , deviceID string , from types . StreamPosition ) ( err error )
SelectMaxSendToDeviceMessageID ( ctx context . Context , txn * sql . Tx ) ( id int64 , err error )
Send-to-device support (#1072)
* Groundwork for send-to-device messaging
* Update sample config
* Add unstable routing for now
* Send to device consumer in sync API
* Start the send-to-device consumer
* fix indentation in dendrite-config.yaml
* Create send-to-device database tables, other tweaks
* Add some logic for send-to-device messages, add them into sync stream
* Handle incoming send-to-device messages, count them with EDU stream pos
* Undo changes to test
* pq.Array
* Fix sync
* Logging
* Fix a couple of transaction things, fix client API
* Add send-to-device test, hopefully fix bugs
* Comments
* Refactor a bit
* Fix schema
* Fix queries
* Debug logging
* Fix storing and retrieving of send-to-device messages
* Try to avoid database locks
* Update sync position
* Use latest sync position
* Jiggle about sync a bit
* Fix tests
* Break out the retrieval from the update/delete behaviour
* Comments
* nolint on getResponseWithPDUsForCompleteSync
* Try to line up sync tokens again
* Implement wildcard
* Add all send-to-device tests to whitelist, what could possibly go wrong?
* Only care about wildcard when targeted locally
* Deduplicate transactions
* Handle tokens properly, return immediately if waiting send-to-device messages
* Fix sync
* Update sytest-whitelist
* Fix copyright notice (need to do more of this)
* Comments, copyrights
* Return errors from Do, fix dendritejs
* Review comments
* Comments
* Constructor for TransactionWriter
* defletions
* Update gomatrixserverlib, sytest-blacklist
2020-06-01 18:50:19 +02:00
}
2020-06-26 16:34:41 +02:00
type Filter interface {
2023-04-04 19:16:53 +02:00
SelectFilter ( ctx context . Context , txn * sql . Tx , target * synctypes . Filter , localpart string , filterID string ) error
InsertFilter ( ctx context . Context , txn * sql . Tx , filter * synctypes . Filter , localpart string ) ( filterID string , err error )
2020-06-26 16:34:41 +02:00
}
2020-11-09 19:46:11 +01:00
type Receipts interface {
2023-04-19 16:50:33 +02:00
UpsertReceipt ( ctx context . Context , txn * sql . Tx , roomId , receiptType , userId , eventId string , timestamp spec . Timestamp ) ( pos types . StreamPosition , err error )
2022-09-28 11:18:03 +02:00
SelectRoomReceiptsAfter ( ctx context . Context , txn * sql . Tx , roomIDs [ ] string , streamPos types . StreamPosition ) ( types . StreamPosition , [ ] types . OutputReceiptEvent , error )
2020-12-11 15:02:17 +01:00
SelectMaxReceiptID ( ctx context . Context , txn * sql . Tx ) ( id int64 , err error )
2023-01-19 21:02:32 +01:00
PurgeReceipts ( ctx context . Context , txn * sql . Tx , roomID string ) error
2020-11-09 19:46:11 +01:00
}
2021-01-20 21:43:20 +01:00
type Memberships interface {
2023-04-27 13:54:20 +02:00
UpsertMembership ( ctx context . Context , txn * sql . Tx , event * rstypes . HeaderedEvent , streamPos , topologicalPos types . StreamPosition ) error
2022-04-01 17:14:38 +02:00
SelectMembershipCount ( ctx context . Context , txn * sql . Tx , roomID , membership string , pos types . StreamPosition ) ( count int , err error )
2023-09-28 14:50:31 +02:00
SelectMembershipForUser ( ctx context . Context , txn * sql . Tx , roomID , userID string , pos int64 ) ( membership string , topologicalPos int64 , err error )
2023-01-19 21:02:32 +01:00
PurgeMemberships ( ctx context . Context , txn * sql . Tx , roomID string ) error
2022-10-25 12:39:10 +02:00
SelectMemberships (
ctx context . Context , txn * sql . Tx ,
roomID string , pos types . TopologyToken ,
membership , notMembership * string ,
) ( eventIDs [ ] string , err error )
2021-01-20 21:43:20 +01:00
}
2022-03-03 12:40:53 +01:00
type NotificationData interface {
2022-09-09 14:06:42 +02:00
UpsertRoomUnreadCounts ( ctx context . Context , txn * sql . Tx , userID , roomID string , notificationCount , highlightCount int ) ( types . StreamPosition , error )
2022-09-27 15:01:34 +02:00
SelectUserUnreadCountsForRooms ( ctx context . Context , txn * sql . Tx , userID string , roomIDs [ ] string ) ( map [ string ] * eventutil . NotificationData , error )
2022-09-09 14:06:42 +02:00
SelectMaxID ( ctx context . Context , txn * sql . Tx ) ( int64 , error )
2023-01-19 21:02:32 +01:00
PurgeNotificationData ( ctx context . Context , txn * sql . Tx , roomID string ) error
2022-03-03 12:40:53 +01:00
}
2022-04-06 13:11:19 +02:00
2022-04-07 16:08:19 +02:00
type Ignores interface {
2022-09-09 14:06:42 +02:00
SelectIgnores ( ctx context . Context , txn * sql . Tx , userID string ) ( * types . IgnoredUsers , error )
UpsertIgnores ( ctx context . Context , txn * sql . Tx , userID string , ignores * types . IgnoredUsers ) error
2022-04-07 16:08:19 +02:00
}
2022-04-06 13:11:19 +02:00
type Presence interface {
2023-04-19 16:50:33 +02:00
UpsertPresence ( ctx context . Context , txn * sql . Tx , userID string , statusMsg * string , presence types . Presence , lastActiveTS spec . Timestamp , fromSync bool ) ( pos types . StreamPosition , err error )
2022-12-08 08:25:03 +01:00
GetPresenceForUsers ( ctx context . Context , txn * sql . Tx , userIDs [ ] string ) ( presence [ ] * types . PresenceInternal , err error )
2022-04-06 13:11:19 +02:00
GetMaxPresenceID ( ctx context . Context , txn * sql . Tx ) ( pos types . StreamPosition , err error )
2023-04-04 19:16:53 +02:00
GetPresenceAfter ( ctx context . Context , txn * sql . Tx , after types . StreamPosition , filter synctypes . EventFilter ) ( presences map [ string ] * types . PresenceInternal , err error )
2022-04-06 13:11:19 +02:00
}
2022-10-13 15:50:52 +02:00
type Relations interface {
// Inserts a relation which refers from the child event ID to the event ID in the given room.
// If the relation already exists then this function will do nothing and return no error.
InsertRelation ( ctx context . Context , txn * sql . Tx , roomID , eventID , childEventID , childEventType , relType string ) ( err error )
// Deletes a relation which already exists as the result of an event redaction. If the relation
// does not exist then this function will do nothing and return no error.
DeleteRelation ( ctx context . Context , txn * sql . Tx , roomID , childEventID string ) error
// SelectRelationsInRange will return relations grouped by relation type within the given range.
// The map is relType -> []entry. If a relType parameter is specified then the results will only
// contain relations of that type, otherwise if "" is specified then all relations in the range
// will be returned, inclusive of the "to" position but excluding the "from" position. The stream
// position returned is the maximum position of the returned results.
SelectRelationsInRange ( ctx context . Context , txn * sql . Tx , roomID , eventID , relType , eventType string , r types . Range , limit int ) ( map [ string ] [ ] types . RelationEntry , types . StreamPosition , error )
// SelectMaxRelationID returns the maximum ID of all relations, used to determine what the boundaries
// should be if there are no boundaries supplied (i.e. we want to work backwards but don't have a
// "from" or want to work forwards and don't have a "to").
SelectMaxRelationID ( ctx context . Context , txn * sql . Tx ) ( id int64 , err error )
}