shared

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2023 License: Apache-2.0 Imports: 17 Imported by: 8

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Database

type Database struct {
	DB                  *sql.DB
	Writer              sqlutil.Writer
	Invites             tables.Invites
	Peeks               tables.Peeks
	AccountData         tables.AccountData
	OutputEvents        tables.Events
	Topology            tables.Topology
	CurrentRoomState    tables.CurrentRoomState
	BackwardExtremities tables.BackwardsExtremities
	SendToDevice        tables.SendToDevice
	Filter              tables.Filter
	Receipts            tables.Receipts
	Memberships         tables.Memberships
	NotificationData    tables.NotificationData
	Ignores             tables.Ignores
	Presence            tables.Presence
	Relations           tables.Relations
}

Database is a temporary struct until we have made syncserver.go the same for both pq/sqlite For now this contains the shared functions

func (*Database) AddInviteEvent

func (d *Database) AddInviteEvent(
	ctx context.Context, inviteEvent *rstypes.HeaderedEvent,
) (sp types.StreamPosition, err error)

AddInviteEvent stores a new invite event for a user. If the invite was successfully stored this returns the stream ID it was stored at. Returns an error if there was a problem communicating with the database.

func (*Database) AddPeek

func (d *Database) AddPeek(
	ctx context.Context, roomID, userID, deviceID string,
) (sp types.StreamPosition, err error)

AddPeek tracks the fact that a user has started peeking. If the peek was successfully stored this returns the stream ID it was stored at. Returns an error if there was a problem communicating with the database.

func (*Database) CleanSendToDeviceUpdates

func (d *Database) CleanSendToDeviceUpdates(
	ctx context.Context,
	userID, deviceID string, before types.StreamPosition,
) (err error)

func (*Database) DeletePeek added in v0.3.3

func (d *Database) DeletePeek(
	ctx context.Context, roomID, userID, deviceID string,
) (sp types.StreamPosition, err error)

DeletePeek tracks the fact that a user has stopped peeking from the specified device. If the peeks was successfully deleted this returns the stream ID it was stored at. Returns an error if there was a problem communicating with the database.

func (*Database) DeletePeeks

func (d *Database) DeletePeeks(
	ctx context.Context, roomID, userID string,
) (sp types.StreamPosition, err error)

DeletePeeks tracks the fact that a user has stopped peeking from all devices If the peeks was successfully deleted this returns the stream ID it was stored at. Returns an error if there was a problem communicating with the database.

func (*Database) Events

func (d *Database) Events(ctx context.Context, eventIDs []string) ([]*rstypes.HeaderedEvent, error)

func (*Database) GetFilter

func (d *Database) GetFilter(
	ctx context.Context, target *synctypes.Filter, localpart string, filterID string,
) error

func (*Database) GetPresences added in v0.10.9

func (d *Database) GetPresences(ctx context.Context, userIDs []string) ([]*types.PresenceInternal, error)

func (*Database) IgnoresForUser added in v0.8.0

func (d *Database) IgnoresForUser(ctx context.Context, userID string) (*types.IgnoredUsers, error)

func (*Database) NewDatabaseSnapshot added in v0.10.0

func (d *Database) NewDatabaseSnapshot(ctx context.Context) (*DatabaseTransaction, error)

func (*Database) NewDatabaseTransaction added in v0.10.0

func (d *Database) NewDatabaseTransaction(ctx context.Context) (*DatabaseTransaction, error)

func (*Database) PurgeRoom

func (d *Database) PurgeRoom(ctx context.Context, roomID string) error

func (*Database) PurgeRoomState added in v0.2.1

func (d *Database) PurgeRoomState(
	ctx context.Context, roomID string,
) error

func (*Database) PutFilter

func (d *Database) PutFilter(
	ctx context.Context, localpart string, filter *synctypes.Filter,
) (string, error)

func (*Database) ReIndex added in v0.10.0

func (d *Database) ReIndex(ctx context.Context, limit, afterID int64) (map[int64]rstypes.HeaderedEvent, error)

func (*Database) RedactEvent

func (d *Database) RedactEvent(ctx context.Context, redactedEventID string, redactedBecause *rstypes.HeaderedEvent, querier api.QuerySenderIDAPI) error

func (*Database) RedactRelations added in v0.10.3

func (d *Database) RedactRelations(ctx context.Context, roomID, redactedEventID string) error

func (*Database) RetireInviteEvent

func (d *Database) RetireInviteEvent(
	ctx context.Context, inviteEventID string,
) (sp types.StreamPosition, err error)

RetireInviteEvent removes an old invite event from the database. Returns an error if there was a problem communicating with the database.

func (*Database) SelectContextAfterEvent added in v0.6.4

func (d *Database) SelectContextAfterEvent(ctx context.Context, id int, roomID string, filter *synctypes.RoomEventFilter) (int, []*rstypes.HeaderedEvent, error)

func (*Database) SelectContextBeforeEvent added in v0.6.4

func (d *Database) SelectContextBeforeEvent(ctx context.Context, id int, roomID string, filter *synctypes.RoomEventFilter) ([]*rstypes.HeaderedEvent, error)

func (*Database) SelectContextEvent added in v0.6.4

func (d *Database) SelectContextEvent(ctx context.Context, roomID, eventID string) (int, rstypes.HeaderedEvent, error)

func (*Database) SelectMembershipForUser added in v0.9.2

func (d *Database) SelectMembershipForUser(ctx context.Context, roomID, userID string, pos int64) (membership string, topologicalPos int, err error)

func (*Database) SelectMemberships added in v0.10.5

func (d *Database) SelectMemberships(
	ctx context.Context,
	roomID string, pos types.TopologyToken,
	membership, notMembership *string,
) (eventIDs []string, err error)

func (*Database) StoreNewSendForDeviceMessage

func (d *Database) StoreNewSendForDeviceMessage(
	ctx context.Context, userID, deviceID string, event gomatrixserverlib.SendToDeviceEvent,
) (newPos types.StreamPosition, err error)

func (*Database) StoreReceipt added in v0.3.0

func (d *Database) StoreReceipt(ctx context.Context, roomId, receiptType, userId, eventId string, timestamp spec.Timestamp) (pos types.StreamPosition, err error)

StoreReceipt stores user receipts

func (*Database) StreamEventsToEvents

func (d *Database) StreamEventsToEvents(ctx context.Context, device *userapi.Device, in []types.StreamEvent, rsAPI api.SyncRoomserverAPI) []*rstypes.HeaderedEvent

func (*Database) UpdateIgnoresForUser added in v0.8.0

func (d *Database) UpdateIgnoresForUser(ctx context.Context, userID string, ignores *types.IgnoredUsers) error

func (*Database) UpdatePresence added in v0.8.0

func (d *Database) UpdatePresence(ctx context.Context, userID string, presence types.Presence, statusMsg *string, lastActiveTS spec.Timestamp, fromSync bool) (types.StreamPosition, error)

func (*Database) UpdateRelations added in v0.10.3

func (d *Database) UpdateRelations(ctx context.Context, event *rstypes.HeaderedEvent) error

func (*Database) UpsertAccountData

func (d *Database) UpsertAccountData(
	ctx context.Context, userID, roomID, dataType string,
) (sp types.StreamPosition, err error)

UpsertAccountData keeps track of new or updated account data, by saving the type of the new/updated data, and the user ID and room ID the data is related to (empty) room ID means the data isn't specific to any room) If no data with the given type, user ID and room ID exists in the database, creates a new row, else update the existing one Returns an error if there was an issue with the upsert

func (*Database) UpsertRoomUnreadNotificationCounts added in v0.6.5

func (d *Database) UpsertRoomUnreadNotificationCounts(ctx context.Context, userID, roomID string, notificationCount, highlightCount int) (pos types.StreamPosition, err error)

func (*Database) WriteEvent

func (d *Database) WriteEvent(
	ctx context.Context,
	ev *rstypes.HeaderedEvent,
	addStateEvents []*rstypes.HeaderedEvent,
	addStateEventIDs, removeStateEventIDs []string,
	transactionID *api.TransactionID, excludeFromSync bool,
	historyVisibility gomatrixserverlib.HistoryVisibility,
) (pduPosition types.StreamPosition, returnErr error)

type DatabaseTransaction added in v0.10.0

type DatabaseTransaction struct {
	*Database
	// contains filtered or unexported fields
}

func (*DatabaseTransaction) AllJoinedUsersInRoom added in v0.10.0

func (d *DatabaseTransaction) AllJoinedUsersInRoom(ctx context.Context, roomIDs []string) (map[string][]string, error)

func (*DatabaseTransaction) AllJoinedUsersInRooms added in v0.10.0

func (d *DatabaseTransaction) AllJoinedUsersInRooms(ctx context.Context) (map[string][]string, error)

func (*DatabaseTransaction) AllPeekingDevicesInRooms added in v0.10.0

func (d *DatabaseTransaction) AllPeekingDevicesInRooms(ctx context.Context) (map[string][]types.PeekingDevice, error)

func (*DatabaseTransaction) BackwardExtremitiesForRoom added in v0.10.0

func (d *DatabaseTransaction) BackwardExtremitiesForRoom(
	ctx context.Context, roomID string,
) (backwardExtremities map[string][]string, err error)

func (*DatabaseTransaction) Commit added in v0.10.0

func (d *DatabaseTransaction) Commit() error

func (*DatabaseTransaction) CurrentState added in v0.10.0

func (d *DatabaseTransaction) CurrentState(ctx context.Context, roomID string, stateFilterPart *synctypes.StateFilter, excludeEventIDs []string) ([]*rstypes.HeaderedEvent, error)

func (*DatabaseTransaction) EventPositionInTopology added in v0.10.0

func (d *DatabaseTransaction) EventPositionInTopology(
	ctx context.Context, eventID string,
) (types.TopologyToken, error)

func (*DatabaseTransaction) Events added in v0.10.0

func (d *DatabaseTransaction) Events(ctx context.Context, eventIDs []string) ([]*rstypes.HeaderedEvent, error)

Events lookups a list of event by their event ID. Returns a list of events matching the requested IDs found in the database. If an event is not found in the database then it will be omitted from the list. Returns an error if there was a problem talking with the database. Does not include any transaction IDs in the returned events.

func (*DatabaseTransaction) GetAccountDataInRange added in v0.10.0

func (d *DatabaseTransaction) GetAccountDataInRange(
	ctx context.Context, userID string, r types.Range,
	accountDataFilterPart *synctypes.EventFilter,
) (map[string][]string, types.StreamPosition, error)

GetAccountDataInRange returns all account data for a given user inserted or updated between two given positions Returns a map following the format data[roomID] = []dataTypes If no data is retrieved, returns an empty map If there was an issue with the retrieval, returns an error

func (*DatabaseTransaction) GetBackwardTopologyPos added in v0.10.0

func (d *DatabaseTransaction) GetBackwardTopologyPos(
	ctx context.Context,
	events []*rstypes.HeaderedEvent,
) (types.TopologyToken, error)

GetBackwardTopologyPos retrieves the backward topology position, i.e. the position of the oldest event in the room's topology.

func (*DatabaseTransaction) GetEventsInTopologicalRange added in v0.10.0

func (d *DatabaseTransaction) GetEventsInTopologicalRange(
	ctx context.Context,
	from, to *types.TopologyToken,
	roomID string,
	filter *synctypes.RoomEventFilter,
	backwardOrdering bool,
) (events []types.StreamEvent, err error)

func (*DatabaseTransaction) GetPresences added in v0.10.9

func (d *DatabaseTransaction) GetPresences(ctx context.Context, userIDs []string) ([]*types.PresenceInternal, error)

func (*DatabaseTransaction) GetRoomReceipts added in v0.10.0

func (d *DatabaseTransaction) GetRoomReceipts(ctx context.Context, roomIDs []string, streamPos types.StreamPosition) ([]types.OutputReceiptEvent, error)

func (*DatabaseTransaction) GetRoomSummary added in v0.10.9

func (d *DatabaseTransaction) GetRoomSummary(ctx context.Context, roomID, userID string) (*types.Summary, error)

func (*DatabaseTransaction) GetStateDeltas added in v0.10.0

func (d *DatabaseTransaction) GetStateDeltas(
	ctx context.Context, device *userapi.Device,
	r types.Range, userID string,
	stateFilter *synctypes.StateFilter, rsAPI api.SyncRoomserverAPI,
) (deltas []types.StateDelta, joinedRoomsIDs []string, err error)

GetStateDeltas returns the state deltas between fromPos and toPos, exclusive of oldPos, inclusive of newPos, for the rooms in which the user has new membership events. A list of joined room IDs is also returned in case the caller needs it. nolint:gocyclo

func (*DatabaseTransaction) GetStateDeltasForFullStateSync added in v0.10.0

func (d *DatabaseTransaction) GetStateDeltasForFullStateSync(
	ctx context.Context, device *userapi.Device,
	r types.Range, userID string,
	stateFilter *synctypes.StateFilter, rsAPI api.SyncRoomserverAPI,
) ([]types.StateDelta, []string, error)

GetStateDeltasForFullStateSync is a variant of getStateDeltas used for /sync requests with full_state=true. Fetches full state for all joined rooms and uses selectStateInRange to get updates for other rooms.

func (*DatabaseTransaction) GetStateEvent added in v0.10.0

func (d *DatabaseTransaction) GetStateEvent(
	ctx context.Context, roomID, evType, stateKey string,
) (*rstypes.HeaderedEvent, error)

func (*DatabaseTransaction) GetStateEventsForRoom added in v0.10.0

func (d *DatabaseTransaction) GetStateEventsForRoom(
	ctx context.Context, roomID string, stateFilter *synctypes.StateFilter,
) (stateEvents []*rstypes.HeaderedEvent, err error)

func (*DatabaseTransaction) GetUserUnreadNotificationCountsForRooms added in v0.10.0

func (d *DatabaseTransaction) GetUserUnreadNotificationCountsForRooms(ctx context.Context, userID string, rooms map[string]string) (map[string]*eventutil.NotificationData, error)

func (*DatabaseTransaction) InviteEventsInRange added in v0.10.0

func (*DatabaseTransaction) MaxStreamPositionForAccountData added in v0.10.0

func (d *DatabaseTransaction) MaxStreamPositionForAccountData(ctx context.Context) (types.StreamPosition, error)

func (*DatabaseTransaction) MaxStreamPositionForInvites added in v0.10.0

func (d *DatabaseTransaction) MaxStreamPositionForInvites(ctx context.Context) (types.StreamPosition, error)

func (*DatabaseTransaction) MaxStreamPositionForNotificationData added in v0.10.0

func (d *DatabaseTransaction) MaxStreamPositionForNotificationData(ctx context.Context) (types.StreamPosition, error)

func (*DatabaseTransaction) MaxStreamPositionForPDUs added in v0.10.0

func (d *DatabaseTransaction) MaxStreamPositionForPDUs(ctx context.Context) (types.StreamPosition, error)

func (*DatabaseTransaction) MaxStreamPositionForPresence added in v0.10.0

func (d *DatabaseTransaction) MaxStreamPositionForPresence(ctx context.Context) (types.StreamPosition, error)

func (*DatabaseTransaction) MaxStreamPositionForReceipts added in v0.10.0

func (d *DatabaseTransaction) MaxStreamPositionForReceipts(ctx context.Context) (types.StreamPosition, error)

func (*DatabaseTransaction) MaxStreamPositionForRelations added in v0.10.3

func (d *DatabaseTransaction) MaxStreamPositionForRelations(ctx context.Context) (types.StreamPosition, error)

func (*DatabaseTransaction) MaxStreamPositionForSendToDeviceMessages added in v0.10.0

func (d *DatabaseTransaction) MaxStreamPositionForSendToDeviceMessages(ctx context.Context) (types.StreamPosition, error)

func (*DatabaseTransaction) MembershipCount added in v0.10.0

func (d *DatabaseTransaction) MembershipCount(ctx context.Context, roomID, membership string, pos types.StreamPosition) (int, error)

func (*DatabaseTransaction) PeeksInRange added in v0.10.0

func (d *DatabaseTransaction) PeeksInRange(ctx context.Context, userID, deviceID string, r types.Range) (peeks []types.Peek, err error)

func (*DatabaseTransaction) PositionInTopology added in v0.10.0

func (d *DatabaseTransaction) PositionInTopology(ctx context.Context, eventID string) (pos types.StreamPosition, spos types.StreamPosition, err error)

func (*DatabaseTransaction) PresenceAfter added in v0.10.0

func (*DatabaseTransaction) RecentEvents added in v0.10.0

func (d *DatabaseTransaction) RecentEvents(ctx context.Context, roomIDs []string, r types.Range, eventFilter *synctypes.RoomEventFilter, chronologicalOrder bool, onlySyncEvents bool) (map[string]types.RecentEvents, error)

func (*DatabaseTransaction) RelationsFor added in v0.10.3

func (d *DatabaseTransaction) RelationsFor(ctx context.Context, roomID, eventID, relType, eventType string, from, to types.StreamPosition, backwards bool, limit int) (
	events []types.StreamEvent, prevBatch, nextBatch string, err error,
)

func (*DatabaseTransaction) Rollback added in v0.10.0

func (d *DatabaseTransaction) Rollback() error

func (*DatabaseTransaction) RoomIDsWithMembership added in v0.10.0

func (d *DatabaseTransaction) RoomIDsWithMembership(ctx context.Context, userID string, membership string) ([]string, error)

func (*DatabaseTransaction) RoomReceiptsAfter added in v0.10.0

func (d *DatabaseTransaction) RoomReceiptsAfter(ctx context.Context, roomIDs []string, streamPos types.StreamPosition) (types.StreamPosition, []types.OutputReceiptEvent, error)

func (*DatabaseTransaction) SendToDeviceUpdatesForSync added in v0.10.0

func (d *DatabaseTransaction) SendToDeviceUpdatesForSync(
	ctx context.Context,
	userID, deviceID string,
	from, to types.StreamPosition,
) (types.StreamPosition, []types.SendToDeviceEvent, error)

func (*DatabaseTransaction) SharedUsers added in v0.10.0

func (d *DatabaseTransaction) SharedUsers(ctx context.Context, userID string, otherUserIDs []string) ([]string, error)

func (*DatabaseTransaction) StreamToTopologicalPosition added in v0.10.0

func (d *DatabaseTransaction) StreamToTopologicalPosition(
	ctx context.Context, roomID string, streamPos types.StreamPosition, backwardOrdering bool,
) (types.TopologyToken, error)

Jump to

Keyboard shortcuts

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