add public/privates & de-underscore
This commit is contained in:
parent
ea31d5821b
commit
28fe6291d9
1 changed files with 14 additions and 14 deletions
|
@ -50,7 +50,7 @@ export default class DMRoomMap {
|
||||||
* Makes and returns a new shared instance that can then be accessed
|
* Makes and returns a new shared instance that can then be accessed
|
||||||
* with shared(). This returned instance is not automatically started.
|
* with shared(). This returned instance is not automatically started.
|
||||||
*/
|
*/
|
||||||
static makeShared(): DMRoomMap {
|
public static makeShared(): DMRoomMap {
|
||||||
DMRoomMap.sharedInstance = new DMRoomMap(MatrixClientPeg.get());
|
DMRoomMap.sharedInstance = new DMRoomMap(MatrixClientPeg.get());
|
||||||
return DMRoomMap.sharedInstance;
|
return DMRoomMap.sharedInstance;
|
||||||
}
|
}
|
||||||
|
@ -60,16 +60,16 @@ export default class DMRoomMap {
|
||||||
* that uses the singleton matrix client
|
* that uses the singleton matrix client
|
||||||
* The shared instance must be started before use.
|
* The shared instance must be started before use.
|
||||||
*/
|
*/
|
||||||
static shared(): DMRoomMap {
|
public static shared(): DMRoomMap {
|
||||||
return DMRoomMap.sharedInstance;
|
return DMRoomMap.sharedInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
start() {
|
public start() {
|
||||||
this._populateRoomToUser();
|
this.populateRoomToUser();
|
||||||
this.matrixClient.on("accountData", this.onAccountData);
|
this.matrixClient.on("accountData", this.onAccountData);
|
||||||
}
|
}
|
||||||
|
|
||||||
stop() {
|
public stop() {
|
||||||
this.matrixClient.removeListener("accountData", this.onAccountData);
|
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
|
* with ourself, not the other user. Fix it by guessing the other user and
|
||||||
* modifying userToRooms
|
* modifying userToRooms
|
||||||
*/
|
*/
|
||||||
_patchUpSelfDMs(userToRooms) {
|
private patchUpSelfDMs(userToRooms) {
|
||||||
const myUserId = this.matrixClient.getUserId();
|
const myUserId = this.matrixClient.getUserId();
|
||||||
const selfRoomIds = userToRooms[myUserId];
|
const selfRoomIds = userToRooms[myUserId];
|
||||||
if (selfRoomIds) {
|
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,
|
// Here, we return the empty list if there are no rooms,
|
||||||
// since the number of conversations you have with this user is zero.
|
// 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.
|
* @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.
|
* @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.
|
// 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
|
// 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];
|
return joinedRooms[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
getUserIdForRoomId(roomId: string) {
|
public getUserIdForRoomId(roomId: string) {
|
||||||
if (this.roomToUser == null) {
|
if (this.roomToUser == null) {
|
||||||
// we lazily populate roomToUser so you can use
|
// we lazily populate roomToUser so you can use
|
||||||
// this class just to call getDMRoomsForUserId
|
// this class just to call getDMRoomsForUserId
|
||||||
|
@ -157,7 +157,7 @@ export default class DMRoomMap {
|
||||||
// convenient wrapper and there's no point
|
// convenient wrapper and there's no point
|
||||||
// iterating through the map if getUserIdForRoomId()
|
// iterating through the map if getUserIdForRoomId()
|
||||||
// is never called.
|
// is never called.
|
||||||
this._populateRoomToUser();
|
this.populateRoomToUser();
|
||||||
}
|
}
|
||||||
// Here, we return undefined if the room is not in the map:
|
// 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.
|
// 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];
|
return this.roomToUser[roomId];
|
||||||
}
|
}
|
||||||
|
|
||||||
getUniqueRoomsWithIndividuals(): {[userId: string]: Room} {
|
public getUniqueRoomsWithIndividuals(): {[userId: string]: Room} {
|
||||||
if (!this.roomToUser) return {}; // No rooms means no map.
|
if (!this.roomToUser) return {}; // No rooms means no map.
|
||||||
return Object.keys(this.roomToUser)
|
return Object.keys(this.roomToUser)
|
||||||
.map(r => ({userId: this.getUserIdForRoomId(r), room: this.matrixClient.getRoom(r)}))
|
.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, {});
|
.reduce((obj, r) => (obj[r.userId] = r.room) && obj, {});
|
||||||
}
|
}
|
||||||
|
|
||||||
_getUserToRooms(): {[key: string]: string[]} {
|
private getUserToRooms(): {[key: string]: string[]} {
|
||||||
if (!this.userToRooms) {
|
if (!this.userToRooms) {
|
||||||
const userToRooms = this.mDirectEvent as {[key: string]: string[]};
|
const userToRooms = this.mDirectEvent as {[key: string]: string[]};
|
||||||
const myUserId = this.matrixClient.getUserId();
|
const myUserId = this.matrixClient.getUserId();
|
||||||
|
@ -201,7 +201,7 @@ export default class DMRoomMap {
|
||||||
return this.userToRooms;
|
return this.userToRooms;
|
||||||
}
|
}
|
||||||
|
|
||||||
_populateRoomToUser() {
|
private populateRoomToUser() {
|
||||||
this.roomToUser = {};
|
this.roomToUser = {};
|
||||||
for (const user of Object.keys(this._getUserToRooms())) {
|
for (const user of Object.keys(this._getUserToRooms())) {
|
||||||
for (const roomId of this.userToRooms[user]) {
|
for (const roomId of this.userToRooms[user]) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue