add public/privates & de-underscore
parent
ea31d5821b
commit
28fe6291d9
|
@ -50,7 +50,7 @@ export default class DMRoomMap {
|
|||
* Makes and returns a new shared instance that can then be accessed
|
||||
* with shared(). This returned instance is not automatically started.
|
||||
*/
|
||||
static makeShared(): DMRoomMap {
|
||||
public static makeShared(): DMRoomMap {
|
||||
DMRoomMap.sharedInstance = new DMRoomMap(MatrixClientPeg.get());
|
||||
return DMRoomMap.sharedInstance;
|
||||
}
|
||||
|
@ -60,16 +60,16 @@ export default class DMRoomMap {
|
|||
* that uses the singleton matrix client
|
||||
* The shared instance must be started before use.
|
||||
*/
|
||||
static shared(): DMRoomMap {
|
||||
public static shared(): DMRoomMap {
|
||||
return DMRoomMap.sharedInstance;
|
||||
}
|
||||
|
||||
start() {
|
||||
this._populateRoomToUser();
|
||||
public start() {
|
||||
this.populateRoomToUser();
|
||||
this.matrixClient.on("accountData", this.onAccountData);
|
||||
}
|
||||
|
||||
stop() {
|
||||
public stop() {
|
||||
this.matrixClient.removeListener("accountData", this.onAccountData);
|
||||
}
|
||||
|
||||
|
@ -86,7 +86,7 @@ export default class DMRoomMap {
|
|||
* with ourself, not the other user. Fix it by guessing the other user and
|
||||
* modifying userToRooms
|
||||
*/
|
||||
_patchUpSelfDMs(userToRooms) {
|
||||
private patchUpSelfDMs(userToRooms) {
|
||||
const myUserId = this.matrixClient.getUserId();
|
||||
const selfRoomIds = userToRooms[myUserId];
|
||||
if (selfRoomIds) {
|
||||
|
@ -122,10 +122,10 @@ export default class DMRoomMap {
|
|||
}
|
||||
}
|
||||
|
||||
getDMRoomsForUserId(userId): string[] {
|
||||
public getDMRoomsForUserId(userId): string[] {
|
||||
// Here, we return the empty list if there are no rooms,
|
||||
// since the number of conversations you have with this user is zero.
|
||||
return this._getUserToRooms()[userId] || [];
|
||||
return this.getUserToRooms()[userId] || [];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -133,7 +133,7 @@ export default class DMRoomMap {
|
|||
* @param {string[]} ids The identifiers (user IDs and email addresses) to look for.
|
||||
* @returns {Room} The DM room which all IDs given share, or falsey if no common room.
|
||||
*/
|
||||
getDMRoomForIdentifiers(ids: string[]): Room {
|
||||
public getDMRoomForIdentifiers(ids: string[]): Room {
|
||||
// TODO: [Canonical DMs] Handle lookups for email addresses.
|
||||
// For now we'll pretend we only get user IDs and end up returning nothing for email addresses
|
||||
|
||||
|
@ -149,7 +149,7 @@ export default class DMRoomMap {
|
|||
return joinedRooms[0];
|
||||
}
|
||||
|
||||
getUserIdForRoomId(roomId: string) {
|
||||
public getUserIdForRoomId(roomId: string) {
|
||||
if (this.roomToUser == null) {
|
||||
// we lazily populate roomToUser so you can use
|
||||
// this class just to call getDMRoomsForUserId
|
||||
|
@ -157,7 +157,7 @@ export default class DMRoomMap {
|
|||
// convenient wrapper and there's no point
|
||||
// iterating through the map if getUserIdForRoomId()
|
||||
// is never called.
|
||||
this._populateRoomToUser();
|
||||
this.populateRoomToUser();
|
||||
}
|
||||
// Here, we return undefined if the room is not in the map:
|
||||
// the room ID you gave is not a DM room for any user.
|
||||
|
@ -171,7 +171,7 @@ export default class DMRoomMap {
|
|||
return this.roomToUser[roomId];
|
||||
}
|
||||
|
||||
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)}))
|
||||
|
@ -179,7 +179,7 @@ export default class DMRoomMap {
|
|||
.reduce((obj, r) => (obj[r.userId] = r.room) && obj, {});
|
||||
}
|
||||
|
||||
_getUserToRooms(): {[key: string]: string[]} {
|
||||
private getUserToRooms(): {[key: string]: string[]} {
|
||||
if (!this.userToRooms) {
|
||||
const userToRooms = this.mDirectEvent as {[key: string]: string[]};
|
||||
const myUserId = this.matrixClient.getUserId();
|
||||
|
@ -201,7 +201,7 @@ export default class DMRoomMap {
|
|||
return this.userToRooms;
|
||||
}
|
||||
|
||||
_populateRoomToUser() {
|
||||
private populateRoomToUser() {
|
||||
this.roomToUser = {};
|
||||
for (const user of Object.keys(this._getUserToRooms())) {
|
||||
for (const roomId of this.userToRooms[user]) {
|
||||
|
|
Loading…
Reference in New Issue