Skip to content

Commit 6cf3878

Browse files
committed
remove decline reason and better m.mentions check
Signed-off-by: Timo K <[email protected]>
1 parent 604b0f2 commit 6cf3878

File tree

2 files changed

+7
-21
lines changed

2 files changed

+7
-21
lines changed

spec/unit/matrixrtc/types.spec.ts

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,13 @@ describe("IRTCNotificationContent", () => {
5858
expect(res.lifetime).toBe(120000);
5959
});
6060

61-
it("throws on missing m.mentions", () => {
61+
it("throws on malformed m.mentions", () => {
6262
expect(() =>
6363
parseCallNotificationContent({
64-
notification_type: "notification",
65-
sender_ts: 123,
66-
lifetime: 1000,
64+
...validBase,
65+
"m.mentions": "not an object",
6766
} as any),
68-
).toThrow("Missing m.mentions");
67+
).toThrow("malformed m.mentions");
6968
});
7069

7170
it("throws on missing or invalid notification_type", () => {
@@ -116,15 +115,6 @@ describe("IRTCNotificationContent", () => {
116115
).toThrow("Missing or invalid lifetime");
117116
});
118117

119-
it("throws on invalid decline_reason type", () => {
120-
expect(() =>
121-
parseCallNotificationContent({
122-
...validBase,
123-
decline_reason: 42 as any,
124-
} as any),
125-
).toThrow("Invalid decline_reason");
126-
});
127-
128118
it("accepts valid relation (m.reference)", () => {
129119
// Note: parseCallNotificationContent currently checks `relation.rel_type` rather than `m.relates_to`.
130120
const res = parseCallNotificationContent({

src/matrixrtc/types.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ export type RTCCallIntent = "audio" | "video" | string;
111111
* @returns a parsed IRTCNotificationContent
112112
*/
113113
export function parseCallNotificationContent(content: IContent): IRTCNotificationContent {
114-
if (typeof content["m.mentions"] !== "object") {
115-
throw new Error("Missing m.mentions");
114+
if (content["m.mentions"] && typeof content["m.mentions"] !== "object") {
115+
throw new Error("malformed m.mentions");
116116
}
117117
if (typeof content["notification_type"] !== "string") {
118118
throw new Error("Missing or invalid notification_type");
@@ -124,9 +124,6 @@ export function parseCallNotificationContent(content: IContent): IRTCNotificatio
124124
throw new Error("Missing or invalid lifetime");
125125
}
126126

127-
if (content["decline_reason"] && typeof content["decline_reason"] !== "string") {
128-
throw new Error("Invalid decline_reason");
129-
}
130127
if (content["relation"] && content["relation"]["rel_type"] !== "m.reference") {
131128
throw new Error("Invalid relation");
132129
}
@@ -143,8 +140,7 @@ export function parseCallNotificationContent(content: IContent): IRTCNotificatio
143140
* Don't cast event content to this directly. Use `parseCallNotificationContent` instead to validate the content first.
144141
*/
145142
export interface IRTCNotificationContent extends RelationEvent {
146-
"m.mentions": IMentions;
147-
"decline_reason"?: string;
143+
"m.mentions"?: IMentions;
148144
"notification_type": RTCNotificationType;
149145
/**
150146
* The initial intent of the calling user.

0 commit comments

Comments
 (0)