shared

package
v0.10.8 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2022 License: Apache-2.0 Imports: 13 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 *gomatrixserverlib.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) ([]*gomatrixserverlib.HeaderedEvent, error)

func (*Database) GetFilter

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

func (*Database) GetPresence added in v0.8.0

func (d *Database) GetPresence(ctx context.Context, userID 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) 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 *gomatrixserverlib.Filter,
) (string, error)

func (*Database) ReIndex added in v0.10.0

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

func (*Database) RedactEvent

func (d *Database) RedactEvent(ctx context.Context, redactedEventID string, redactedBecause *gomatrixserverlib.HeaderedEvent) 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 *gomatrixserverlib.RoomEventFilter) (int, []*gomatrixserverlib.HeaderedEvent, error)

func (*Database) SelectContextBeforeEvent added in v0.6.4

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

func (*Database) SelectContextEvent added in v0.6.4

func (d *Database) SelectContextEvent(ctx context.Context, roomID, eventID string) (int, gomatrixserverlib.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 gomatrixserverlib.Timestamp) (pos types.StreamPosition, err error)

StoreReceipt stores user receipts

func (*Database) StreamEventsToEvents

func (d *Database) StreamEventsToEvents(device *userapi.Device, in []types.StreamEvent) []*gomatrixserverlib.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 gomatrixserverlib.Timestamp, fromSync bool) (types.StreamPosition, error)

func (*Database) UpdateRelations added in v0.10.3

func (d *Database) UpdateRelations(ctx context.Context, event *gomatrixserverlib.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 *gomatrixserverlib.HeaderedEvent,
	addStateEvents []*gomatrixserverlib.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 *gomatrixserverlib.StateFilter, excludeEventIDs []string) ([]*gomatrixserverlib.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

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 *gomatrixserverlib.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 []*gomatrixserverlib.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 *gomatrixserverlib.RoomEventFilter,
	backwardOrdering bool,
) (events []types.StreamEvent, err error)

func (*DatabaseTransaction) GetPresence added in v0.10.0

func (d *DatabaseTransaction) GetPresence(ctx context.Context, userID string) (*types.PresenceInternal, error)

func (*DatabaseTransaction) GetRoomHeroes added in v0.10.0

func (d *DatabaseTransaction) GetRoomHeroes(ctx context.Context, roomID, userID string, memberships []string) ([]string, 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) GetStateDeltas added in v0.10.0

func (d *DatabaseTransaction) GetStateDeltas(
	ctx context.Context, device *userapi.Device,
	r types.Range, userID string,
	stateFilter *gomatrixserverlib.StateFilter,
) (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 *gomatrixserverlib.StateFilter,
) ([]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,
) (*gomatrixserverlib.HeaderedEvent, error)

func (*DatabaseTransaction) GetStateEventsForRoom added in v0.10.0

func (d *DatabaseTransaction) GetStateEventsForRoom(
	ctx context.Context, roomID string, stateFilter *gomatrixserverlib.StateFilter,
) (stateEvents []*gomatrixserverlib.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) MaxTopologicalPosition added in v0.10.0

func (d *DatabaseTransaction) MaxTopologicalPosition(
	ctx context.Context, roomID string,
) (types.TopologyToken, 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, roomID string, r types.Range, eventFilter *gomatrixserverlib.RoomEventFilter, chronologicalOrder bool, onlySyncEvents bool) ([]types.StreamEvent, bool, 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