Skip to content

Commit

Permalink
Revert custom user/room mention conditions.
Browse files Browse the repository at this point in the history
  • Loading branch information
clokep committed Mar 13, 2023
1 parent 4fac636 commit fe89122
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 64 deletions.
12 changes: 0 additions & 12 deletions src/@types/PushRules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ export enum ConditionKind {
EventMatch = "event_match",
EventPropertyIs = "event_property_is",
EventPropertyContains = "event_property_contains",
IsUserMention = "org.matrix.msc3952.is_user_mention",
IsRoomMention = "org.matrix.msc3952.is_room_mention",
ContainsDisplayName = "contains_display_name",
RoomMemberCount = "room_member_count",
SenderNotificationPermission = "sender_notification_permission",
Expand Down Expand Up @@ -96,14 +94,6 @@ export interface IEventPropertyContainsCondition extends IPushRuleCondition<Cond
value: string | boolean | null | number;
}

export interface IIsUserMentionCondition extends IPushRuleCondition<ConditionKind.IsUserMention> {
// no additional fields
}

export interface IIsRoomMentionCondition extends IPushRuleCondition<ConditionKind.IsRoomMention> {
// no additional fields
}

export interface IContainsDisplayNameCondition extends IPushRuleCondition<ConditionKind.ContainsDisplayName> {
// no additional fields
}
Expand Down Expand Up @@ -131,8 +121,6 @@ export type PushRuleCondition =
| IEventMatchCondition
| IEventPropertyIsCondition
| IEventPropertyContainsCondition
| IIsUserMentionCondition
| IIsRoomMentionCondition
| IContainsDisplayNameCondition
| IRoomMemberCountCondition
| ISenderNotificationPermissionCondition
Expand Down
52 changes: 0 additions & 52 deletions src/pushprocessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ import {
IEventMatchCondition,
IEventPropertyIsCondition,
IEventPropertyContainsCondition,
IIsRoomMentionCondition,
IIsUserMentionCondition,
IPushRule,
IPushRules,
IRoomMemberCountCondition,
Expand All @@ -51,8 +49,6 @@ const RULEKINDS_IN_ORDER = [
PushRuleKind.Underride,
];

const MENTIONS_FIELD = "org.matrix.msc3952.mentions";

// The default override rules to apply to the push rules that arrive from the server.
// We do this for two reasons:
// 1. Synapse is unlikely to send us the push rule in an incremental sync - see
Expand Down Expand Up @@ -391,10 +387,6 @@ export class PushProcessor {
return this.eventFulfillsEventPropertyIsCondition(cond, ev);
case ConditionKind.EventPropertyContains:
return this.eventFulfillsEventPropertyContains(cond, ev);
case ConditionKind.IsUserMention:
return this.eventFulfillsUserMentionCondition(cond, ev);
case ConditionKind.IsRoomMention:
return this.eventFulfillsRoomMentionCondition(cond, ev);
case ConditionKind.ContainsDisplayName:
return this.eventFulfillsDisplayNameCondition(cond, ev);
case ConditionKind.RoomMemberCount:
Expand Down Expand Up @@ -470,50 +462,6 @@ export class PushProcessor {
}
}

private eventFulfillsUserMentionCondition(cond: IIsUserMentionCondition, ev: MatrixEvent): boolean {
const content = ev.getContent();
// Ensure the mentions field exists as an object and contains a user_ids
// field which is an array.
if (
!content ||
!content[MENTIONS_FIELD] ||
typeof content[MENTIONS_FIELD] != "object" ||
!content[MENTIONS_FIELD].user_ids ||
!Array.isArray(content[MENTIONS_FIELD].user_ids)
) {
return false;
}

// Ensure the user is still in the room.
// XXX Why do we do this?
const room = this.client.getRoom(ev.getRoomId());
const userId = this.client.credentials.userId!;
const member = room?.currentState?.getMember(userId);
if (!member) {
return false;
}

return content[MENTIONS_FIELD].user_ids.includes(userId);
}

private eventFulfillsRoomMentionCondition(cond: IIsRoomMentionCondition, ev: MatrixEvent): boolean {
const content = ev.getContent();
// Ensure the mentions field exists as an object and contains a room
// field which is a boolean.
if (
!content ||
!content[MENTIONS_FIELD] ||
typeof content[MENTIONS_FIELD] != "object" ||
!content[MENTIONS_FIELD].room ||
typeof content[MENTIONS_FIELD].user_ids != "boolean"
) {
return false;
}

// This must be a boolean, so can just return it directly.
return content[MENTIONS_FIELD].room;
}

private eventFulfillsDisplayNameCondition(cond: IContainsDisplayNameCondition, ev: MatrixEvent): boolean {
let content = ev.getContent();
if (ev.isEncrypted() && ev.getClearContent()) {
Expand Down

0 comments on commit fe89122

Please sign in to comment.