shared

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2022 License: Apache-2.0 Imports: 12 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
}

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) AllJoinedUsersInRoom added in v0.8.3

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

func (*Database) AllJoinedUsersInRooms

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

func (*Database) AllPeekingDevicesInRooms

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

func (*Database) BackwardExtremitiesForRoom

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

func (*Database) CleanSendToDeviceUpdates

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

func (*Database) CurrentState added in v0.3.5

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

DeletePeeks 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) EventPositionInTopology

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

func (*Database) Events

func (d *Database) Events(ctx context.Context, eventIDs []string) ([]*gomatrixserverlib.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 (*Database) GetAccountDataInRange

func (d *Database) 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 (*Database) GetBackwardTopologyPos added in v0.3.5

func (d *Database) GetBackwardTopologyPos(
	ctx context.Context,
	events []types.StreamEvent,
) (types.TopologyToken, error)

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

func (*Database) GetEventsInTopologicalRange

func (d *Database) GetEventsInTopologicalRange(
	ctx context.Context,
	from, to *types.TopologyToken,
	roomID string,
	filter *gomatrixserverlib.RoomEventFilter,
	backwardOrdering bool,
) (events []types.StreamEvent, err 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 (s *Database) GetPresence(ctx context.Context, userID string) (*types.PresenceInternal, error)

func (*Database) GetRoomHeroes added in v0.8.2

func (d *Database) GetRoomHeroes(ctx context.Context, roomID, userID string, memberships []string) ([]string, error)

func (*Database) GetRoomReceipts added in v0.3.0

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

func (*Database) GetStateDeltas added in v0.3.5

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

func (*Database) GetStateDeltasForFullStateSync added in v0.3.5

func (d *Database) 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 (*Database) GetStateEvent

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

func (*Database) GetStateEventsForRoom

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

func (*Database) GetUserUnreadNotificationCounts added in v0.6.5

func (d *Database) GetUserUnreadNotificationCounts(ctx context.Context, userID string, from, to types.StreamPosition) (map[string]*eventutil.NotificationData, error)

func (*Database) IgnoresForUser added in v0.8.0

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

func (*Database) InviteEventsInRange added in v0.3.5

func (d *Database) InviteEventsInRange(ctx context.Context, targetUserID string, r types.Range) (map[string]*gomatrixserverlib.HeaderedEvent, map[string]*gomatrixserverlib.HeaderedEvent, error)

func (*Database) MaxStreamPositionForAccountData added in v0.3.5

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

func (*Database) MaxStreamPositionForInvites added in v0.3.5

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

func (*Database) MaxStreamPositionForNotificationData added in v0.6.5

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

func (*Database) MaxStreamPositionForPDUs added in v0.3.5

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

func (*Database) MaxStreamPositionForPresence added in v0.8.0

func (s *Database) MaxStreamPositionForPresence(ctx context.Context) (types.StreamPosition, error)

func (*Database) MaxStreamPositionForReceipts added in v0.3.5

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

func (*Database) MaxStreamPositionForSendToDeviceMessages added in v0.3.6

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

func (*Database) MaxTopologicalPosition

func (d *Database) MaxTopologicalPosition(
	ctx context.Context, roomID string,
) (types.TopologyToken, error)

func (*Database) MembershipCount added in v0.8.0

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

func (*Database) PeeksInRange added in v0.3.5

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

func (*Database) PositionInTopology added in v0.3.5

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

func (*Database) PresenceAfter added in v0.8.0

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) RecentEvents added in v0.3.5

func (d *Database) RecentEvents(ctx context.Context, roomID string, r types.Range, eventFilter *gomatrixserverlib.RoomEventFilter, chronologicalOrder bool, onlySyncEvents bool) ([]types.StreamEvent, bool, error)

func (*Database) RedactEvent

func (d *Database) RedactEvent(ctx context.Context, redactedEventID string, redactedBecause *gomatrixserverlib.HeaderedEvent) 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) RoomIDsWithMembership added in v0.3.5

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

func (*Database) RoomReceiptsAfter added in v0.3.5

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

func (*Database) SelectContextAfterEvent added in v0.6.4

func (s *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 (s *Database) SelectContextBeforeEvent(ctx context.Context, id int, roomID string, filter *gomatrixserverlib.RoomEventFilter) ([]*gomatrixserverlib.HeaderedEvent, error)

func (*Database) SelectContextEvent added in v0.6.4

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

func (*Database) SendToDeviceUpdatesForSync

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

func (*Database) SharedUsers added in v0.9.0

func (d *Database) SharedUsers(ctx context.Context, userID string, otherUserIDs []string) ([]string, 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) StreamToTopologicalPosition added in v0.7.0

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

func (*Database) UpdateIgnoresForUser added in v0.8.0

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

func (*Database) UpdatePresence added in v0.8.0

func (s *Database) UpdatePresence(ctx context.Context, userID string, presence types.Presence, statusMsg *string, lastActiveTS gomatrixserverlib.Timestamp, fromSync bool) (types.StreamPosition, 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)

Jump to

Keyboard shortcuts

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