-
-
Notifications
You must be signed in to change notification settings - Fork 607
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 9 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,38 @@ 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: [ | ||||||
{ | ||||||
room_id: "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,32 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa | |||||||||
* @event module:client~MatrixClient#"WellKnown.client" | ||||||||||
* @param {object} data The JSON object returned by the server | ||||||||||
*/ | ||||||||||
|
||||||||||
/** | ||||||||||
* Ignore all invites to this room. | ||||||||||
*/ | ||||||||||
export type IgnoredRoomInvites = { | ||||||||||
/** | ||||||||||
* The room ID for the room to ignore. | ||||||||||
*/ | ||||||||||
room_id: string; | ||||||||||
|
||||||||||
/** | ||||||||||
* When this instruction to ignore was decided by the user, | ||||||||||
* as a Matrix timestamp. | ||||||||||
*/ | ||||||||||
ts: number; | ||||||||||
}; | ||||||||||
|
||||||||||
/** | ||||||||||
* 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 data structure is expected to gain additional fields, all of | ||||||||||
* them optional. | ||||||||||
*/ | ||||||||||
export type IgnoredInvites = { | ||||||||||
/** | ||||||||||
* A list of rooms the user does not wish to be invited to. | ||||||||||
*/ | ||||||||||
ignored_rooms?: IgnoredRoomInvites[]; | ||||||||||
}; |
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: