add logging to accepting or rejecting an invite

This commit is contained in:
Bruno Windels 2021-04-21 15:31:55 +02:00
parent 5ce138539b
commit 465e0c191f
2 changed files with 20 additions and 16 deletions

View file

@ -405,7 +405,7 @@ export class Session {
emitCollectionRemove: this._inviteRemoveCallback, emitCollectionRemove: this._inviteRemoveCallback,
emitCollectionUpdate: this._inviteUpdateCallback, emitCollectionUpdate: this._inviteUpdateCallback,
user: this._user, user: this._user,
clock: this._platform.clock, platform: this._platform,
}); });
} }

View file

@ -20,14 +20,14 @@ import {Heroes} from "./members/Heroes.js";
import {MemberChange, RoomMember, EVENT_TYPE as MEMBER_EVENT_TYPE} from "./members/RoomMember.js"; import {MemberChange, RoomMember, EVENT_TYPE as MEMBER_EVENT_TYPE} from "./members/RoomMember.js";
export class Invite extends EventEmitter { export class Invite extends EventEmitter {
constructor({roomId, user, hsApi, emitCollectionRemove, emitCollectionUpdate, clock}) { constructor({roomId, user, hsApi, emitCollectionRemove, emitCollectionUpdate, platform}) {
super(); super();
this._roomId = roomId; this._roomId = roomId;
this._user = user; this._user = user;
this._hsApi = hsApi; this._hsApi = hsApi;
this._emitCollectionRemove = emitCollectionRemove; this._emitCollectionRemove = emitCollectionRemove;
this._emitCollectionUpdate = emitCollectionUpdate; this._emitCollectionUpdate = emitCollectionUpdate;
this._clock = clock; this._platform = platform;
this._inviteData = null; this._inviteData = null;
this._accepting = false; this._accepting = false;
this._rejecting = false; this._rejecting = false;
@ -67,16 +67,20 @@ export class Invite extends EventEmitter {
return this._inviteData.joinRule; return this._inviteData.joinRule;
} }
async accept() { async accept(log = null) {
this._accepting = true; await this._platform.logger.wrapOrRun(log, "acceptInvite", async log => {
this._emitChange("accepting"); this._accepting = true;
await this._hsApi.join(this._roomId).response(); this._emitChange("accepting");
await this._hsApi.join(this._roomId, {log}).response();
});
} }
async reject() { async reject(log = null) {
this._rejecting = true; await this._platform.logger.wrapOrRun(log, "rejectInvite", async log => {
this._emitChange("rejecting"); this._rejecting = true;
await this._hsApi.leave(this._roomId).response(); this._emitChange("rejecting");
await this._hsApi.leave(this._roomId, {log}).response();
});
} }
get accepting() { get accepting() {
@ -167,7 +171,7 @@ export class Invite extends EventEmitter {
name, name,
avatarUrl, avatarUrl,
canonicalAlias: summaryData.canonicalAlias, canonicalAlias: summaryData.canonicalAlias,
timestamp: this._clock.now(), timestamp: this._platform.clock.now(),
joinRule: this._getJoinRule(inviteState), joinRule: this._getJoinRule(inviteState),
inviter: inviter?.serialize(), inviter: inviter?.serialize(),
}; };
@ -251,7 +255,7 @@ export function tests() {
"invite for room has correct fields": async assert => { "invite for room has correct fields": async assert => {
const invite = new Invite({ const invite = new Invite({
roomId, roomId,
clock: new MockClock(1001), platform: {clock: new MockClock(1001)},
user: {id: "@bob:hs.tld"} user: {id: "@bob:hs.tld"}
}); });
const txn = createStorage(); const txn = createStorage();
@ -272,7 +276,7 @@ export function tests() {
"invite for encrypted DM has correct fields": async assert => { "invite for encrypted DM has correct fields": async assert => {
const invite = new Invite({ const invite = new Invite({
roomId, roomId,
clock: new MockClock(1003), platform: {clock: new MockClock(1003)},
user: {id: "@bob:hs.tld"} user: {id: "@bob:hs.tld"}
}); });
const txn = createStorage(); const txn = createStorage();
@ -292,7 +296,7 @@ export function tests() {
"load persisted invite has correct fields": async assert => { "load persisted invite has correct fields": async assert => {
const writeInvite = new Invite({ const writeInvite = new Invite({
roomId, roomId,
clock: new MockClock(1003), platform: {clock: new MockClock(1003)},
user: {id: "@bob:hs.tld"} user: {id: "@bob:hs.tld"}
}); });
const txn = createStorage(); const txn = createStorage();
@ -313,7 +317,7 @@ export function tests() {
let removedEmitted = false; let removedEmitted = false;
const invite = new Invite({ const invite = new Invite({
roomId, roomId,
clock: new MockClock(1003), platform: {clock: new MockClock(1003)},
user: {id: "@bob:hs.tld"}, user: {id: "@bob:hs.tld"},
emitCollectionRemove: emittingInvite => { emitCollectionRemove: emittingInvite => {
assert.equal(emittingInvite, invite); assert.equal(emittingInvite, invite);