Skip to content

Commit 37a5baa

Browse files
committed
remove decline reason and better m.mentions check
Signed-off-by: Timo K <[email protected]>
1 parent 4c624be commit 37a5baa

File tree

2 files changed

+6
-20
lines changed

2 files changed

+6
-20
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: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ export type RTCNotificationType = "ring" | "notification";
104104
* @returns a parsed IRTCNotificationContent
105105
*/
106106
export function parseCallNotificationContent(content: IContent): IRTCNotificationContent {
107-
if (!content["m.mentions"]) {
108-
throw new Error("Missing m.mentions");
107+
if (content["m.mentions"] && typeof content["m.mentions"] !== "object") {
108+
throw new Error("malformed m.mentions");
109109
}
110110
if (typeof content["notification_type"] !== "string") {
111111
throw new Error("Missing or invalid notification_type");
@@ -117,9 +117,6 @@ export function parseCallNotificationContent(content: IContent): IRTCNotificatio
117117
throw new Error("Missing or invalid lifetime");
118118
}
119119

120-
if (content["decline_reason"] && typeof content["decline_reason"] !== "string") {
121-
throw new Error("Invalid decline_reason");
122-
}
123120
if (content["relation"] && content["relation"]["rel_type"] !== "m.reference") {
124121
throw new Error("Invalid relation");
125122
}
@@ -133,7 +130,6 @@ export function parseCallNotificationContent(content: IContent): IRTCNotificatio
133130
*/
134131
export interface IRTCNotificationContent extends RelationEvent {
135132
"m.mentions": IMentions;
136-
"decline_reason"?: string;
137133
"notification_type": RTCNotificationType;
138134
"sender_ts": number;
139135
"lifetime": number;

0 commit comments

Comments
 (0)