shared

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

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

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

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

func (*Database) IgnoresForUser

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

func (*Database) NewDatabaseSnapshot

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

func (*Database) NewDatabaseTransaction

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

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

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

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

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

func (*Database) SelectContextBeforeEvent

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

func (*Database) SelectContextEvent

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

func (*Database) SelectMembershipForUser

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

func (*Database) SelectMemberships

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

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

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

func (*Database) UpdatePresence

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

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

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

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

func (*DatabaseTransaction) AllJoinedUsersInRoom

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

func (*DatabaseTransaction) AllJoinedUsersInRooms

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

func (*DatabaseTransaction) AllPeekingDevicesInRooms

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

func (*DatabaseTransaction) BackwardExtremitiesForRoom

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

func (*DatabaseTransaction) Commit

func (d *DatabaseTransaction) Commit() error

func (*DatabaseTransaction) CurrentState

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

func (*DatabaseTransaction) EventPositionInTopology

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

func (*DatabaseTransaction) Events

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

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

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

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

func (*DatabaseTransaction) GetPresences

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

func (*DatabaseTransaction) GetRoomReceipts

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

func (*DatabaseTransaction) GetRoomSummary

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

func (*DatabaseTransaction) GetStateDeltas

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

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

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

func (*DatabaseTransaction) GetStateEventsForRoom

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

func (*DatabaseTransaction) GetUserUnreadNotificationCountsForRooms

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

func (*DatabaseTransaction) InviteEventsInRange

func (*DatabaseTransaction) MaxStreamPositionForAccountData

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

func (*DatabaseTransaction) MaxStreamPositionForInvites

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

func (*DatabaseTransaction) MaxStreamPositionForNotificationData

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

func (*DatabaseTransaction) MaxStreamPositionForPDUs

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

func (*DatabaseTransaction) MaxStreamPositionForPresence

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

func (*DatabaseTransaction) MaxStreamPositionForReceipts

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

func (*DatabaseTransaction) MaxStreamPositionForRelations

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

func (*DatabaseTransaction) MaxStreamPositionForSendToDeviceMessages

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

func (*DatabaseTransaction) MembershipCount

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

func (*DatabaseTransaction) PeeksInRange

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

func (*DatabaseTransaction) PositionInTopology

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

func (*DatabaseTransaction) PresenceAfter

func (*DatabaseTransaction) RecentEvents

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

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

func (d *DatabaseTransaction) Rollback() error

func (*DatabaseTransaction) RoomIDsWithMembership

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

func (*DatabaseTransaction) RoomReceiptsAfter

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

func (*DatabaseTransaction) SendToDeviceUpdatesForSync

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

func (*DatabaseTransaction) SharedUsers

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

func (*DatabaseTransaction) StreamToTopologicalPosition

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