-
-
Notifications
You must be signed in to change notification settings - Fork 592
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Base support for MSC3840: Ignore invites #2483
Changes from all commits
a35d962
73fdb36
78a7317
0c1b39c
608e87b
eee42b2
1564ad7
200f3a1
96516bc
7143515
7546df8
8955612
de90f89
188d123
6b84eb0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -1297,4 +1297,37 @@ describe("MatrixClient", function() { | |||||
expect(result!.aliases).toEqual(response.aliases); | ||||||
}); | ||||||
}); | ||||||
|
||||||
describe("ignoring invites", () => { | ||||||
it('stores ignored invites', async function() { | ||||||
// Mockup account data storage. | ||||||
const dataStore = new Map(); | ||||||
client.setAccountData = function(eventType, content) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
dataStore.set(eventType, content); | ||||||
return Promise.resolve(); | ||||||
}; | ||||||
client.getAccountData = function(eventType) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
const data = dataStore.get(eventType); | ||||||
return new MatrixEvent({ | ||||||
content: data, | ||||||
}); | ||||||
}; | ||||||
|
||||||
// Initially, the invite list should be empty but not `null`. | ||||||
expect(await client.getIgnoredInvites()).toEqual({}); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
// Insert something, we should be able to recover it. | ||||||
const SAMPLE = { | ||||||
ignored_rooms: { | ||||||
"12345": { | ||||||
ts: Date.now(), | ||||||
}, | ||||||
}, | ||||||
}; | ||||||
await client.setIgnoredInvites(SAMPLE); | ||||||
|
||||||
// Check that it was (mock)stored on the client. | ||||||
expect(await client.getIgnoredInvites()).toEqual(SAMPLE); | ||||||
}); | ||||||
}); | ||||||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,6 +81,7 @@ export enum EventType { | |
PushRules = "m.push_rules", | ||
Direct = "m.direct", | ||
IgnoredUserList = "m.ignored_user_list", | ||
IgnoredInvites = "org.matrix.msc3840.ignored_invites", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we're not supposed to define unstable event types here - we should be using |
||
|
||
// to_device events | ||
RoomKey = "m.room_key", | ||
|
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -3424,6 +3424,23 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa | |||||||||
return this.getIgnoredUsers().includes(userId); | ||||||||||
} | ||||||||||
|
||||||||||
/** | ||||||||||
* Gets the list of currently ignored invites. | ||||||||||
*/ | ||||||||||
public getIgnoredInvites(): IgnoredInvites { | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. apologies, should have caught this in the first round of review: this function and the setter will need to be named Additionally, the return value for both will need to be documented in the jsdoc - see other functions for examples
turt2live marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
const event = this.getAccountData(EventType.IgnoredInvites); | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what's the computational complexity of this function call? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I haven't been able to find exactly where this is implemented. However, as far as I understand, Also note that you can subscribe to |
||||||||||
if (!event || !event.getContent()) return {}; | ||||||||||
return event.getContent(); | ||||||||||
} | ||||||||||
|
||||||||||
/** | ||||||||||
* Update the list of ignored invites. | ||||||||||
* @param invites The new list of ignored invites. | ||||||||||
*/ | ||||||||||
public setIgnoredInvites(invites: IgnoredInvites): Promise<{}> { | ||||||||||
return this.setAccountData(EventType.IgnoredInvites, invites); | ||||||||||
} | ||||||||||
|
||||||||||
/** | ||||||||||
* Join a room. If you have already joined the room, this will no-op. | ||||||||||
* @param {string} roomIdOrAlias The room ID or room alias to join. | ||||||||||
|
@@ -9320,3 +9337,35 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa | |||||||||
* @event module:client~MatrixClient#"WellKnown.client" | ||||||||||
* @param {object} data The JSON object returned by the server | ||||||||||
*/ | ||||||||||
|
||||||||||
/** | ||||||||||
* Metadata on ignored invites. | ||||||||||
* | ||||||||||
* This interface is expected to gain additional fields, all | ||||||||||
* of them optional. | ||||||||||
*/ | ||||||||||
export interface IgnoreInviteMetadata { | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All of these interfaces will need a jsdoc line that says they can be removed at any point without notice due to being unstable. |
||||||||||
/** | ||||||||||
* The instant the user decided to ignore this invite, | ||||||||||
* as a Matrix timestamp. | ||||||||||
Comment on lines
+9349
to
+9350
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
*/ | ||||||||||
readonly ts: number; | ||||||||||
|
||||||||||
/** | ||||||||||
* A human-readable reason for ignoring this invite. | ||||||||||
*/ | ||||||||||
readonly reason?: string; | ||||||||||
} | ||||||||||
|
||||||||||
/** | ||||||||||
* Invites to ignore across all devices/sessions, as per MSC 3840. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
* | ||||||||||
* This interface is expected to gain additional fields, all of | ||||||||||
* them optional. | ||||||||||
*/ | ||||||||||
export interface IgnoredInvites { | ||||||||||
/** | ||||||||||
* A map of room ids => metadata for rooms the user does not wish to be invited to. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
*/ | ||||||||||
readonly ignored_rooms?: Record<string, IgnoreInviteMetadata>; | ||||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should be using
should
, and arrow functions: