remove unused code

pull/21833/head
Bruno Windels 2019-12-20 21:32:11 +01:00
parent 52c7c5b837
commit 3b9c5c0a27
1 changed files with 0 additions and 148 deletions

View File

@ -17,154 +17,6 @@ limitations under the License.
import MatrixClientPeg from '../MatrixClientPeg'; import MatrixClientPeg from '../MatrixClientPeg';
import { _t } from '../languageHandler'; import { _t } from '../languageHandler';
const SUB_EVENT_TYPES_OF_INTEREST = ["start", "cancel", "done"];
export default class KeyVerificationStateObserver {
constructor(requestEvent, client, updateCallback) {
this._requestEvent = requestEvent;
this._client = client;
this._updateCallback = updateCallback;
this.accepted = false;
this.done = false;
this.cancelled = false;
this._updateVerificationState();
}
get concluded() {
return this.accepted || this.done || this.cancelled;
}
get pending() {
return !this.concluded;
}
setCallback(callback) {
this._updateCallback = callback;
}
attach() {
this._requestEvent.on("Event.relationsCreated", this._onRelationsCreated);
for (const phaseName of SUB_EVENT_TYPES_OF_INTEREST) {
this._tryListenOnRelationsForType(`m.key.verification.${phaseName}`);
}
}
detach() {
const roomId = this._requestEvent.getRoomId();
const room = this._client.getRoom(roomId);
for (const phaseName of SUB_EVENT_TYPES_OF_INTEREST) {
const relations = room.getUnfilteredTimelineSet()
.getRelationsForEvent(this._requestEvent.getId(), "m.reference", `m.key.verification.${phaseName}`);
if (relations) {
relations.removeListener("Relations.add", this._onRelationsUpdated);
relations.removeListener("Relations.remove", this._onRelationsUpdated);
relations.removeListener("Relations.redaction", this._onRelationsUpdated);
}
}
this._requestEvent.removeListener("Event.relationsCreated", this._onRelationsCreated);
}
_onRelationsCreated = (relationType, eventType) => {
if (relationType !== "m.reference") {
return;
}
if (
eventType !== "m.key.verification.start" &&
eventType !== "m.key.verification.cancel" &&
eventType !== "m.key.verification.done"
) {
return;
}
this._tryListenOnRelationsForType(eventType);
this._updateVerificationState();
this._updateCallback();
};
_tryListenOnRelationsForType(eventType) {
const roomId = this._requestEvent.getRoomId();
const room = this._client.getRoom(roomId);
const relations = room.getUnfilteredTimelineSet()
.getRelationsForEvent(this._requestEvent.getId(), "m.reference", eventType);
if (relations) {
relations.on("Relations.add", this._onRelationsUpdated);
relations.on("Relations.remove", this._onRelationsUpdated);
relations.on("Relations.redaction", this._onRelationsUpdated);
}
}
_onRelationsUpdated = (event) => {
this._updateVerificationState();
this._updateCallback && this._updateCallback();
};
_updateVerificationState() {
const roomId = this._requestEvent.getRoomId();
const room = this._client.getRoom(roomId);
const timelineSet = room.getUnfilteredTimelineSet();
const fromUserId = this._requestEvent.getSender();
const content = this._requestEvent.getContent();
const toUserId = content.to;
this.cancelled = false;
this.done = false;
this.accepted = false;
this.otherPartyUserId = null;
this.cancelPartyUserId = null;
const startRelations = timelineSet.getRelationsForEvent(
this._requestEvent.getId(), "m.reference", "m.key.verification.start");
if (startRelations) {
for (const startEvent of startRelations.getRelations()) {
if (startEvent.getSender() === toUserId) {
this.accepted = true;
}
}
}
const doneRelations = timelineSet.getRelationsForEvent(
this._requestEvent.getId(), "m.reference", "m.key.verification.done");
if (doneRelations) {
let senderDone = false;
let receiverDone = false;
for (const doneEvent of doneRelations.getRelations()) {
if (doneEvent.getSender() === toUserId) {
receiverDone = true;
} else if (doneEvent.getSender() === fromUserId) {
senderDone = true;
}
}
if (senderDone && receiverDone) {
this.done = true;
}
}
if (!this.done) {
const cancelRelations = timelineSet.getRelationsForEvent(
this._requestEvent.getId(), "m.reference", "m.key.verification.cancel");
if (cancelRelations) {
let earliestCancelEvent;
for (const cancelEvent of cancelRelations.getRelations()) {
// only accept cancellation from the users involved
if (cancelEvent.getSender() === toUserId || cancelEvent.getSender() === fromUserId) {
this.cancelled = true;
if (!earliestCancelEvent || cancelEvent.getTs() < earliestCancelEvent.getTs()) {
earliestCancelEvent = cancelEvent;
}
}
}
if (earliestCancelEvent) {
this.cancelPartyUserId = earliestCancelEvent.getSender();
}
}
}
this.otherPartyUserId = fromUserId === this._client.getUserId() ? toUserId : fromUserId;
console.log("KeyVerificationStateObserver update for txnId", this._requestEvent.getId(), {accepted: this.accepted, cancelled: this.cancelled, done: this.done});
}
}
export function getNameForEventRoom(userId, mxEvent) { export function getNameForEventRoom(userId, mxEvent) {
const roomId = mxEvent.getRoomId(); const roomId = mxEvent.getRoomId();
const client = MatrixClientPeg.get(); const client = MatrixClientPeg.get();