Class PresenceService
Presence, kept in memory: what users set, and online while they sync.
Implements
Inherited Members
Namespace: Uniform.Matrix.Server.Accounts
Assembly: Uniform.Matrix.Server.dll
Syntax
public sealed class PresenceService : IDisposable
Remarks
Each change takes a ServerStream position, so waiting syncs wake and incremental syncs send m.presence to everyone who shares a room. Syncing marks a user online unless set_presence says otherwise; a user who has not synced for OfflineAfter goes offline. Users of other servers get their presence from their server, see SetRemoteAsync(string, string, string?, long, CancellationToken). Presence is lost on restart, and users start offline.
Constructors
| Edit this page View SourcePresenceService(IDbContextFactory<ServerDbContext>, ServerStream, TimeProvider, ILogger<PresenceService>)
Create the service and its timer, which takes idle users offline.
Declaration
public PresenceService(IDbContextFactory<ServerDbContext> contexts, ServerStream stream, TimeProvider time, ILogger<PresenceService> logger)
Parameters
| Type | Name | Description |
|---|---|---|
| IDbContextFactory<ServerDbContext> | contexts | |
| ServerStream | stream | |
| TimeProvider | time | |
| ILogger<PresenceService> | logger |
Fields
| Edit this page View SourceActiveFor
How long after their last activity a user still counts as currently active.
Declaration
public static readonly TimeSpan ActiveFor
Field Value
| Type | Description |
|---|---|
| TimeSpan |
OfflineAfter
How long after their last sync or presence update a user counts as offline.
Declaration
public static readonly TimeSpan OfflineAfter
Field Value
| Type | Description |
|---|---|
| TimeSpan |
RemoteOfflineAfter
How long a user of another server keeps their presence here without an update from their server, which normally tells when they go offline.
Declaration
public static readonly TimeSpan RemoteOfflineAfter
Field Value
| Type | Description |
|---|---|
| TimeSpan |
Methods
| Edit this page View SourceDispose()
Stop the timer.
Declaration
public void Dispose()
Get(string)
Return a user's presence for the presence API; offline when unknown.
Declaration
public JsonObject Get(string userId)
Parameters
| Type | Name | Description |
|---|---|---|
| string | userId |
Returns
| Type | Description |
|---|---|
| JsonObject |
GetEventsAsync(ServerDbContext, string, long?, long, CancellationToken)
Return m.presence events of the user and of everyone sharing a joined room with them that changed after since; for initial syncs (null), of everyone known.
Declaration
public Task<IReadOnlyList<JsonObject>> GetEventsAsync(ServerDbContext dbContext, string userId, long? since, long until, CancellationToken cancellationToken)
Parameters
| Type | Name | Description |
|---|---|---|
| ServerDbContext | dbContext | |
| string | userId | |
| long? | since | |
| long | until | |
| CancellationToken | cancellationToken |
Returns
| Type | Description |
|---|---|
| Task<IReadOnlyList<JsonObject>> |
GetLocalChanges(long, long)
Return the presence of users of this server that changed after since up to until, for other servers.
Declaration
public IReadOnlyList<(string UserId, JsonObject Content)> GetLocalChanges(long since, long until)
Parameters
| Type | Name | Description |
|---|---|---|
| long | since | |
| long | until |
Returns
| Type | Description |
|---|---|
| IReadOnlyList<(string UserId, JsonObject Content)> |
SetAsync(string, string, string?, CancellationToken)
Set a user's presence and status message with the presence API.
Declaration
public Task SetAsync(string userId, string presence, string? status, CancellationToken cancellationToken)
Parameters
| Type | Name | Description |
|---|---|---|
| string | userId | |
| string | presence | |
| string | status | |
| CancellationToken | cancellationToken |
Returns
| Type | Description |
|---|---|
| Task |
SetRemoteAsync(string, string, string?, long, CancellationToken)
Set the presence of another server's user from an m.presence EDU of their server.
Declaration
public Task SetRemoteAsync(string userId, string presence, string? status, long lastActiveAgo, CancellationToken cancellationToken)
Parameters
| Type | Name | Description |
|---|---|---|
| string | userId | User of the sending server. |
| string | presence |
|
| string | status | Status message, or null. |
| long | lastActiveAgo | Milliseconds since the user was last active. |
| CancellationToken | cancellationToken | Cancellation token. |
Returns
| Type | Description |
|---|---|
| Task |
TouchAsync(string, string?, CancellationToken)
Record that a user syncs: online, or idle when setPresence is unavailable; offline leaves the presence as it is.
Declaration
public Task TouchAsync(string userId, string? setPresence, CancellationToken cancellationToken)
Parameters
| Type | Name | Description |
|---|---|---|
| string | userId | The syncing user. |
| string | setPresence | The sync's |
| CancellationToken | cancellationToken | Cancellation token. |
Returns
| Type | Description |
|---|---|
| Task |