shared

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2020 License: Apache-2.0 Imports: 14 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
	EDUCache            *cache.EDUCache
}

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) AddSendToDevice

func (d *Database) AddSendToDevice() types.StreamPosition

func (*Database) AddTypingUser

func (d *Database) AddTypingUser(
	userID, roomID string, expireTime *time.Time,
) types.StreamPosition

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,
	toUpdate, toDelete []types.SendToDeviceNID,
	token types.StreamingToken,
) (err error)

func (*Database) CompleteSync

func (d *Database) CompleteSync(
	ctx context.Context, res *types.Response,
	device userapi.Device, numRecentEventsPerRoom int,
) (*types.Response, error)

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, 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) GetEventsInStreamingRange

func (d *Database) GetEventsInStreamingRange(
	ctx context.Context,
	from, to *types.StreamingToken,
	roomID string, limit int,
	backwardOrdering bool,
) (events []types.StreamEvent, err error)

GetEventsInStreamingRange retrieves all of the events on a given ordering using the given extremities and limit.

func (*Database) GetEventsInTopologicalRange

func (d *Database) GetEventsInTopologicalRange(
	ctx context.Context,
	from, to *types.TopologyToken,
	roomID string, limit int,
	backwardOrdering bool,
) (events []types.StreamEvent, err error)

func (*Database) GetFilter

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

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) IncrementalSync

func (d *Database) IncrementalSync(
	ctx context.Context, res *types.Response,
	device userapi.Device,
	fromPos, toPos types.StreamingToken,
	numRecentEventsPerRoom int,
	wantFullState bool,
) (*types.Response, error)

func (*Database) MaxTopologicalPosition

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

func (*Database) PurgeRoom

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

func (d *Database) RedactEvent(ctx context.Context, redactedEventID string, redactedBecause *gomatrixserverlib.HeaderedEvent) error

func (*Database) RemoveTypingUser

func (d *Database) RemoveTypingUser(
	userID, roomID string,
) types.StreamPosition

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) SendToDeviceUpdatesForSync

func (d *Database) SendToDeviceUpdatesForSync(
	ctx context.Context,
	userID, deviceID string,
	token types.StreamingToken,
) ([]types.SendToDeviceEvent, []types.SendToDeviceNID, []types.SendToDeviceNID, error)

func (*Database) SendToDeviceUpdatesWaiting

func (d *Database) SendToDeviceUpdatesWaiting(
	ctx context.Context, userID, deviceID string,
) (bool, error)

func (*Database) SetTypingTimeoutCallback

func (d *Database) SetTypingTimeoutCallback(fn cache.TimeoutCallbackFn)

func (*Database) StoreNewSendForDeviceMessage

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

func (*Database) StreamEventsToEvents

func (d *Database) StreamEventsToEvents(device *userapi.Device, in []types.StreamEvent) []gomatrixserverlib.HeaderedEvent

func (*Database) SyncPosition

func (d *Database) SyncPosition(ctx context.Context) (tok types.StreamingToken, err 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) WriteEvent

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

Jump to

Keyboard shortcuts

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