Bug 1732717 - Show pending direct message invites when connecting to Matrix account. r=clokep

Differential Revision: https://phabricator.services.mozilla.com/D126678
This commit is contained in:
Martin Giger 2021-09-27 14:16:46 +00:00
Родитель c6c0e5018f
Коммит e3cd7eba3c
1 изменённых файлов: 30 добавлений и 4 удалений

Просмотреть файл

@ -468,7 +468,7 @@ MatrixRoom.prototype = {
this._roomId = room.roomId; this._roomId = room.roomId;
// Update the title to the human readable version. // Update the title to the human readable version.
if (room.name && this._name != room.name) { if (room.name && this._name != room.name && room.name !== room.roomId) {
this._name = room.name; this._name = room.name;
this.notifyObservers(null, "update-conv-title"); this.notifyObservers(null, "update-conv-title");
} }
@ -1246,6 +1246,7 @@ function MatrixAccount(aProtocol, aImAccount) {
this.buddies = new Map(); this.buddies = new Map();
this._pendingDirectChats = new Map(); this._pendingDirectChats = new Map();
this._pendingRoomAliases = new Map(); this._pendingRoomAliases = new Map();
this._pendingRoomInvites = new Set();
} }
MatrixAccount.prototype = { MatrixAccount.prototype = {
__proto__: GenericAccountPrototype, __proto__: GenericAccountPrototype,
@ -1922,9 +1923,11 @@ MatrixAccount.prototype = {
* This includes adding and removing rooms and catching up their contents. * This includes adding and removing rooms and catching up their contents.
*/ */
handleCaughtUp() { handleCaughtUp() {
const joinedRooms = this._client const allRooms = this._client
.getRooms() .getVisibleRooms()
.filter(room => room.getMyMembership() === "join" && !room.isSpaceRoom()) .filter(room => !room.isSpaceRoom());
const joinedRooms = allRooms
.filter(room => room.getMyMembership() === "join")
.map(room => room.roomId); .map(room => room.roomId);
// Ensure existing conversations are up to date // Ensure existing conversations are up to date
for (const [roomId, conv] of this.roomList.entries()) { for (const [roomId, conv] of this.roomList.entries()) {
@ -1961,6 +1964,16 @@ MatrixAccount.prototype = {
conv.catchup().catch(error => this.ERROR(error)); conv.catchup().catch(error => this.ERROR(error));
} }
} }
// Add pending invites
const invites = allRooms.filter(
room => room.getMyMembership() === "invite"
);
for (const room of invites) {
const me = room.getMember(this.userId);
if (me.events.member.getContent().is_direct) {
this.invitedToDM(room);
}
}
// Remove orphaned buddies. // Remove orphaned buddies.
for (const [userId, buddy] of this.buddies) { for (const [userId, buddy] of this.buddies) {
// getDMRoomIdsForUserId uses the room list from the client, so we don't // getDMRoomIdsForUserId uses the room list from the client, so we don't
@ -2074,16 +2087,27 @@ MatrixAccount.prototype = {
} }
}, },
/**
* Set of room IDs that have pending invites that are being displayed to the
* user this session.
*
* @type {Set<string>}
*/
_pendingRoomInvites: null,
/** /**
* A user invited this user to a DM room. * A user invited this user to a DM room.
* *
* @param {Room} room - Room we're invited to. * @param {Room} room - Room we're invited to.
*/ */
invitedToDM(room) { invitedToDM(room) {
if (this._pendingRoomInvites.has(room.roomId)) {
return;
}
let userId = room.getDMInviter(); let userId = room.getDMInviter();
this.addBuddyRequest( this.addBuddyRequest(
userId, userId,
() => { () => {
this._pendingRoomInvites.delete(room.roomId);
this.setDirectRoom(userId, room.roomId); this.setDirectRoom(userId, room.roomId);
// For the invited rooms, we will not get the summary info from // For the invited rooms, we will not get the summary info from
// the room object created after the joining. So we need to use // the room object created after the joining. So we need to use
@ -2098,9 +2122,11 @@ MatrixAccount.prototype = {
} }
}, },
() => { () => {
this._pendingRoomInvites.delete(room.roomId);
this._client.leave(room.roomId); this._client.leave(room.roomId);
} }
); );
this._pendingRoomInvites.add(room.roomId);
}, },
/** /**