1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-29 16:43:09 +03:00
This commit is contained in:
Bruno Windels
2020-01-17 16:58:19 +01:00
parent 1205178e26
commit 07cc93cca2
4 changed files with 23 additions and 12 deletions

View File

@@ -1600,7 +1600,8 @@ Crypto.prototype._requestVerificationWithChannel = async function(
// but if the other party is really fast they could potentially respond to the
// request before the server tells us the event got sent, and we would probably
// create a new request object
console.log(`Crypto: adding new request to requestsByTxnId with id ${channel.transactionId}`);
logger.log(`Crypto: adding new request to ` +
`requestsByTxnId with id ${channel.transactionId}`);
requestsMap.setRequestByChannel(channel, request);
return request;
@@ -2579,7 +2580,8 @@ Crypto.prototype._handleVerificationEvent = async function(
request = createRequest(event);
// a request could not be made from this event, so ignore event
if (!request) {
console.log(`Crypto: could not find VerificationRequest for ${event.getType()}, and could not create one, so ignoring.`);
logger.log(`Crypto: could not find VerificationRequest for ` +
`${event.getType()}, and could not create one, so ignoring.`);
return;
}
isNewRequest = true;
@@ -2594,7 +2596,7 @@ Crypto.prototype._handleVerificationEvent = async function(
this._baseApis.emit("crypto.verification.start", request.verifier);
}
} catch (err) {
console.error("error while handling verification event", event, err);
logger.error("error while handling verification event: " + err.message);
}
const shouldEmit = isNewRequest &&
!request.initiatedByMe &&

View File

@@ -21,6 +21,7 @@ import {
READY_TYPE,
START_TYPE,
} from "./VerificationRequest";
import {logger} from '../../../logger';
const MESSAGE_TYPE = "m.room.message";
const M_REFERENCE = "m.reference";
@@ -127,20 +128,23 @@ export class InRoomChannel {
static validateEvent(event, client) {
const txnId = InRoomChannel.getTransactionId(event);
if (typeof txnId !== "string" || txnId.length === 0) {
console.log("InRoomChannel: validateEvent: no valid txnId", type, txnId);
logger.log("InRoomChannel: validateEvent: no valid txnId " + txnId);
return false;
}
const type = InRoomChannel.getEventType(event);
const content = event.getContent();
if (type === REQUEST_TYPE) {
if (!content || typeof content.to !== "string" || !content.to.length) {
console.log("InRoomChannel: validateEvent: no valid to", type, content.to);
logger.log("InRoomChannel: validateEvent: " +
"no valid to " + (content && content.to));
return false;
}
// ignore requests that are not direct to or sent by the syncing user
if (!InRoomChannel.getOtherPartyUserId(event, client)) {
console.log("InRoomChannel: validateEvent: not directed to or sent by me", type, event.getSender(), content.to);
logger.log("InRoomChannel: validateEvent: " +
`not directed to or sent by me: ${event.getSender()}` +
`, ${content && content.to}`);
return false;
}
}
@@ -196,7 +200,8 @@ export class InRoomChannel {
const sender = event.getSender();
if (this.userId !== null) {
if (sender !== ownUserId && sender !== this.userId) {
console.log(`InRoomChannel: ignoring verification event from non-participating sender ${sender}`);
logger.log(`InRoomChannel: ignoring verification event from ` +
`non-participating sender ${sender}`);
return;
}
}

View File

@@ -83,17 +83,19 @@ export class VerificationRequest extends EventEmitter {
const content = event.getContent();
if (!content) {
console.log("VerificationRequest: validateEvent: no content", type);
logger.log("VerificationRequest: validateEvent: no content");
}
if (!type.startsWith(EVENT_PREFIX)) {
console.log("VerificationRequest: validateEvent: fail because type doesnt start with " + EVENT_PREFIX, type);
logger.log("VerificationRequest: validateEvent: " +
"fail because type doesnt start with " + EVENT_PREFIX);
return false;
}
if (type === REQUEST_TYPE || type === READY_TYPE) {
if (!Array.isArray(content.methods)) {
console.log("VerificationRequest: validateEvent: fail because methods", type);
logger.log("VerificationRequest: validateEvent: " +
"fail because methods");
return false;
}
}
@@ -102,7 +104,8 @@ export class VerificationRequest extends EventEmitter {
if (typeof content.from_device !== "string" ||
content.from_device.length === 0
) {
console.log("VerificationRequest: validateEvent: fail because from_device", type);
logger.log("VerificationRequest: validateEvent: "+
"fail because from_device");
return false;
}
}

View File

@@ -1238,7 +1238,8 @@ SyncApi.prototype._processSyncResponse = async function(
}
}
self._processRoomEvents(room, stateEvents, timelineEvents, syncEventData.fromCache);
self._processRoomEvents(room, stateEvents,
timelineEvents, syncEventData.fromCache);
// set summary after processing events,
// because it will trigger a name calculation