Class PushRuleService
A user's push rules, kept as the m.push_rules account data that clients sync, and the unread counts they give.
Inherited Members
Namespace: Uniform.Matrix.Server.Accounts
Assembly: Uniform.Matrix.Server.dll
Syntax
public sealed class PushRuleService
Remarks
The stored rules are merged with the current Defaults(string) on every read, so changes to the defaults reach users who customised their rules: a stored default rule keeps only its enabled and actions. User rules come before the defaults of their kind, except that .m.rule.master stays first.
Constructors
| Edit this page View SourcePushRuleService(AccountDataService)
Create the service.
Declaration
public PushRuleService(AccountDataService accountData)
Parameters
| Type | Name | Description |
|---|---|---|
| AccountDataService | accountData |
Fields
| Edit this page View SourceAccountDataType
Global account data type of the push rules.
Declaration
public const string AccountDataType = "m.push_rules"
Field Value
| Type | Description |
|---|---|
| string |
MaxCounted
Most unread events looked at per room, so a long unread history costs a bounded amount per sync.
Declaration
public const int MaxCounted = 200
Field Value
| Type | Description |
|---|---|
| int |
Methods
| Edit this page View SourceCountAllUnreadAsync(ServerDbContext, JsonObject, string, CancellationToken)
Return the user's unread notifications across all their joined rooms, e.g. for a push gateway's badge.
Declaration
public static Task<int> CountAllUnreadAsync(ServerDbContext dbContext, JsonObject ruleset, string userId, CancellationToken cancellationToken)
Parameters
| Type | Name | Description |
|---|---|---|
| ServerDbContext | dbContext | |
| JsonObject | ruleset | |
| string | userId | |
| CancellationToken | cancellationToken |
Returns
| Type | Description |
|---|---|
| Task<int> |
CountUnreadAsync(ServerDbContext, JsonObject, string, string, long, CancellationToken)
Return the user's unread notifications and highlights in a room: events by others after their read receipt, their own latest message or their join, as the rules decide.
Declaration
public static Task<(int Notifications, int Highlights)> CountUnreadAsync(ServerDbContext dbContext, JsonObject ruleset, string userId, string roomId, long until, CancellationToken cancellationToken)
Parameters
| Type | Name | Description |
|---|---|---|
| ServerDbContext | dbContext | Open database. |
| JsonObject | ruleset | The user's rules, from GetRulesetAsync(string, CancellationToken). |
| string | userId | The user. |
| string | roomId | A room the user is joined to. |
| long | until | Last stream position counted, e.g. a sync's, so the counts match the events it sends; MaxValue for all. |
| CancellationToken | cancellationToken | Cancellation token. |
Returns
| Type | Description |
|---|---|
| Task<(int Notifications, int Highlights)> |
DecideAsync(ServerDbContext, JsonObject, string, string, JsonObject, CancellationToken)
Return what the user's rules decide for one event of a room, with the room's current members and power levels.
Declaration
public static Task<PushDecision> DecideAsync(ServerDbContext dbContext, JsonObject ruleset, string userId, string roomId, JsonObject clientEvent, CancellationToken cancellationToken)
Parameters
| Type | Name | Description |
|---|---|---|
| ServerDbContext | dbContext | Open database. |
| JsonObject | ruleset | The user's rules, from GetRulesetAsync(string, CancellationToken). |
| string | userId | The user. |
| string | roomId | The event's room. |
| JsonObject | clientEvent | The event, with |
| CancellationToken | cancellationToken | Cancellation token. |
Returns
| Type | Description |
|---|---|
| Task<PushDecision> |
DeleteRuleAsync(string, string, string, CancellationToken)
Delete a user rule; the default rules can only be disabled.
Declaration
public Task DeleteRuleAsync(string userId, string kind, string ruleId, CancellationToken cancellationToken)
Parameters
| Type | Name | Description |
|---|---|---|
| string | userId | |
| string | kind | |
| string | ruleId | |
| CancellationToken | cancellationToken |
Returns
| Type | Description |
|---|---|
| Task |
GetAccountDataContentAsync(string, CancellationToken)
Return the m.push_rules content to sync: {"global": rules}.
Declaration
public Task<JsonObject> GetAccountDataContentAsync(string userId, CancellationToken cancellationToken)
Parameters
| Type | Name | Description |
|---|---|---|
| string | userId | |
| CancellationToken | cancellationToken |
Returns
| Type | Description |
|---|---|
| Task<JsonObject> |
GetRuleAsync(string, string, string, CancellationToken)
Return one rule; throw M_NOT_FOUND when there is none.
Declaration
public Task<JsonObject> GetRuleAsync(string userId, string kind, string ruleId, CancellationToken cancellationToken)
Parameters
| Type | Name | Description |
|---|---|---|
| string | userId | |
| string | kind | |
| string | ruleId | |
| CancellationToken | cancellationToken |
Returns
| Type | Description |
|---|---|
| Task<JsonObject> |
GetRulesetAsync(string, CancellationToken)
Return the user's rule set by kind: the defaults merged with what the user changed.
Declaration
public Task<JsonObject> GetRulesetAsync(string userId, CancellationToken cancellationToken)
Parameters
| Type | Name | Description |
|---|---|---|
| string | userId | |
| CancellationToken | cancellationToken |
Returns
| Type | Description |
|---|---|
| Task<JsonObject> |
PutRuleAsync(string, string, string, JsonObject, string?, string?, CancellationToken)
Add or replace a user rule, placed before or after another user rule of its kind when given.
Declaration
public Task PutRuleAsync(string userId, string kind, string ruleId, JsonObject body, string? before, string? after, CancellationToken cancellationToken)
Parameters
| Type | Name | Description |
|---|---|---|
| string | userId | Owner of the rules. |
| string | kind | Rule kind, e.g. |
| string | ruleId | Rule ID; for |
| JsonObject | body |
|
| string | before | Rule ID to place the rule before, or null. |
| string | after | Rule ID to place the rule after, or null. |
| CancellationToken | cancellationToken | Cancellation token. |
Returns
| Type | Description |
|---|---|
| Task |
SetRuleFieldAsync(string, string, string, string, JsonNode, CancellationToken)
Change one field, enabled or actions, of any rule.
Declaration
public Task SetRuleFieldAsync(string userId, string kind, string ruleId, string field, JsonNode value, CancellationToken cancellationToken)
Parameters
| Type | Name | Description |
|---|---|---|
| string | userId | |
| string | kind | |
| string | ruleId | |
| string | field | |
| JsonNode | value | |
| CancellationToken | cancellationToken |
Returns
| Type | Description |
|---|---|
| Task |