get other user id from channel

next up is inspecting the .request event to
determine it reliably in InRoomChannel
This commit is contained in:
Bruno Windels
2019-12-20 13:43:49 +00:00
parent 29c04b6f9c
commit efe2488155
2 changed files with 8 additions and 10 deletions
@@ -37,7 +37,7 @@ export class InRoomChannel {
constructor(client, roomId, userId) {
this._client = client;
this._roomId = roomId;
this._userId = userId;
this.userId = userId;
this._requestEventId = null;
}
@@ -202,7 +202,7 @@ export class InRoomChannel {
"verification. You will need to use legacy key " +
"verification to verify keys.",
msgtype: REQUEST_TYPE,
to: this._userId,
to: this.userId,
from_device: content.from_device,
methods: content.methods,
};
@@ -58,7 +58,7 @@ export const PHASE_DONE = 6;
* @event "change" whenever the state of the request object has changed.
*/
export default class VerificationRequest extends EventEmitter {
constructor(channel, verificationMethods, userId, client) {
constructor(channel, verificationMethods, client) {
super();
this.channel = channel;
this._verificationMethods = verificationMethods;
@@ -66,8 +66,6 @@ export default class VerificationRequest extends EventEmitter {
this._commonMethods = [];
this._setPhase(PHASE_UNSENT, false);
this._requestEvent = null;
// TODO: this can also be ourselves, we need to fish .to out of content on a .request
this._otherUserId = userId;
this._initiatedByMe = null;
this._startTimestamp = null;
this._cancellingUserId = null;
@@ -200,14 +198,14 @@ export default class VerificationRequest extends EventEmitter {
if (this.initiatedByMe) {
return this._client.getUserId();
} else {
return this._otherUserId;
return this.otherUserId;
}
}
/** the id of the user that (will) receive(d) the request */
get receivingUserId() {
if (this.initiatedByMe) {
return this._otherUserId;
return this.otherUserId;
} else {
return this._client.getUserId();
}
@@ -215,7 +213,7 @@ export default class VerificationRequest extends EventEmitter {
/** the user id of the other party in this request */
get otherUserId() {
return this._otherUserId;
return this.channel.userId;
}
/**
@@ -364,7 +362,7 @@ export default class VerificationRequest extends EventEmitter {
// only pass events from the other side to the verifier,
// no remote echos of our own events
if (this._verifier && sender === this._otherUserId) {
if (this._verifier && sender === this.otherUserId) {
if (type === CANCEL_TYPE || (this._verifier.events
&& this._verifier.events.includes(type))) {
this._verifier.handleEvent(event);
@@ -463,7 +461,7 @@ export default class VerificationRequest extends EventEmitter {
if (sender === this._client.getUserId()) {
this._doneByUs = true;
console.log("VerificationRequest: received own .done event");
} else if (sender === this._otherUserId) {
} else if (sender === this.otherUserId) {
this._doneByThem = true;
console.log("VerificationRequest: received their .done event");
}