Apply prettier formatting
This commit is contained in:
parent
1cac306093
commit
526645c791
1576 changed files with 65385 additions and 62478 deletions
|
@ -22,7 +22,7 @@ import { EventType } from "matrix-js-sdk/src/@types/event";
|
|||
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
|
||||
import { Optional } from "matrix-events-sdk";
|
||||
|
||||
import { MatrixClientPeg } from '../MatrixClientPeg';
|
||||
import { MatrixClientPeg } from "../MatrixClientPeg";
|
||||
|
||||
/**
|
||||
* Class that takes a Matrix Client and flips the m.direct map
|
||||
|
@ -35,10 +35,10 @@ export default class DMRoomMap {
|
|||
private static sharedInstance: DMRoomMap;
|
||||
|
||||
// TODO: convert these to maps
|
||||
private roomToUser: {[key: string]: string} = null;
|
||||
private userToRooms: {[key: string]: string[]} = null;
|
||||
private roomToUser: { [key: string]: string } = null;
|
||||
private userToRooms: { [key: string]: string[] } = null;
|
||||
private hasSentOutPatchDirectAccountDataPatch: boolean;
|
||||
private mDirectEvent: {[key: string]: string[]};
|
||||
private mDirectEvent: { [key: string]: string[] };
|
||||
|
||||
constructor(private readonly matrixClient: MatrixClient) {
|
||||
// see onAccountData
|
||||
|
@ -102,23 +102,24 @@ export default class DMRoomMap {
|
|||
const selfRoomIds = userToRooms[myUserId];
|
||||
if (selfRoomIds) {
|
||||
// any self-chats that should not be self-chats?
|
||||
const guessedUserIdsThatChanged = selfRoomIds.map((roomId) => {
|
||||
const room = this.matrixClient.getRoom(roomId);
|
||||
if (room) {
|
||||
const userId = room.guessDMUserId();
|
||||
if (userId && userId !== myUserId) {
|
||||
return { userId, roomId };
|
||||
const guessedUserIdsThatChanged = selfRoomIds
|
||||
.map((roomId) => {
|
||||
const room = this.matrixClient.getRoom(roomId);
|
||||
if (room) {
|
||||
const userId = room.guessDMUserId();
|
||||
if (userId && userId !== myUserId) {
|
||||
return { userId, roomId };
|
||||
}
|
||||
}
|
||||
}
|
||||
}).filter((ids) => !!ids); //filter out
|
||||
})
|
||||
.filter((ids) => !!ids); //filter out
|
||||
// these are actually all legit self-chats
|
||||
// bail out
|
||||
if (!guessedUserIdsThatChanged.length) {
|
||||
return false;
|
||||
}
|
||||
userToRooms[myUserId] = selfRoomIds.filter((roomId) => {
|
||||
return !guessedUserIdsThatChanged
|
||||
.some((ids) => ids.roomId === roomId);
|
||||
return !guessedUserIdsThatChanged.some((ids) => ids.roomId === roomId);
|
||||
});
|
||||
guessedUserIdsThatChanged.forEach(({ userId, roomId }) => {
|
||||
const roomIds = userToRooms[userId];
|
||||
|
@ -151,11 +152,12 @@ export default class DMRoomMap {
|
|||
let commonRooms = this.getDMRoomsForUserId(ids[0]);
|
||||
for (let i = 1; i < ids.length; i++) {
|
||||
const userRooms = this.getDMRoomsForUserId(ids[i]);
|
||||
commonRooms = commonRooms.filter(r => userRooms.includes(r));
|
||||
commonRooms = commonRooms.filter((r) => userRooms.includes(r));
|
||||
}
|
||||
|
||||
const joinedRooms = commonRooms.map(r => MatrixClientPeg.get().getRoom(r))
|
||||
.filter(r => r && r.getMyMembership() === 'join');
|
||||
const joinedRooms = commonRooms
|
||||
.map((r) => MatrixClientPeg.get().getRoom(r))
|
||||
.filter((r) => r && r.getMyMembership() === "join");
|
||||
|
||||
return joinedRooms[0];
|
||||
}
|
||||
|
@ -182,15 +184,15 @@ export default class DMRoomMap {
|
|||
return this.roomToUser[roomId];
|
||||
}
|
||||
|
||||
public getUniqueRoomsWithIndividuals(): {[userId: string]: Room} {
|
||||
public getUniqueRoomsWithIndividuals(): { [userId: string]: Room } {
|
||||
if (!this.roomToUser) return {}; // No rooms means no map.
|
||||
return Object.keys(this.roomToUser)
|
||||
.map(r => ({ userId: this.getUserIdForRoomId(r), room: this.matrixClient.getRoom(r) }))
|
||||
.filter(r => r.userId && r.room && r.room.getInvitedAndJoinedMemberCount() === 2)
|
||||
.map((r) => ({ userId: this.getUserIdForRoomId(r), room: this.matrixClient.getRoom(r) }))
|
||||
.filter((r) => r.userId && r.room && r.room.getInvitedAndJoinedMemberCount() === 2)
|
||||
.reduce((obj, r) => (obj[r.userId] = r.room) && obj, {});
|
||||
}
|
||||
|
||||
private getUserToRooms(): {[key: string]: string[]} {
|
||||
private getUserToRooms(): { [key: string]: string[] } {
|
||||
if (!this.userToRooms) {
|
||||
const userToRooms = this.mDirectEvent;
|
||||
const myUserId = this.matrixClient.getUserId();
|
||||
|
@ -200,8 +202,9 @@ export default class DMRoomMap {
|
|||
// to avoid multiple devices fighting to correct
|
||||
// the account data, only try to send the corrected
|
||||
// version once.
|
||||
logger.warn(`Invalid m.direct account data detected ` +
|
||||
`(self-chats that shouldn't be), patching it up.`);
|
||||
logger.warn(
|
||||
`Invalid m.direct account data detected ` + `(self-chats that shouldn't be), patching it up.`,
|
||||
);
|
||||
if (neededPatching && !this.hasSentOutPatchDirectAccountDataPatch) {
|
||||
this.hasSentOutPatchDirectAccountDataPatch = true;
|
||||
this.matrixClient.setAccountData(EventType.Direct, userToRooms);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue