Skip to content

Commit 9b8eba4

Browse files
committed
Implement canAcceptVerificationRequest
1 parent 527495a commit 9b8eba4

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/crypto-api/verification.ts

+8
Original file line numberDiff line numberDiff line change
@@ -350,3 +350,11 @@ export interface GeneratedSas {
350350
* English name.
351351
*/
352352
export type EmojiMapping = [emoji: string, name: string];
353+
354+
/**
355+
* True if the request is in a state where it can be accepted (ie, that we're in phases {@link VerificationPhase.Unsent}
356+
* or {@link VerificationPhase.Requested}, and that we're not in the process of sending a `ready` or `cancel`).
357+
*/
358+
export function canAcceptVerificationRequest(req: VerificationRequest): boolean {
359+
return req.phase < VerificationPhase.Ready && !req.accepting && !req.declining;
360+
}

src/crypto/verification/request/VerificationRequest.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { VerificationBase } from "../Base";
2525
import { VerificationMethod } from "../../index";
2626
import { TypedEventEmitter } from "../../../models/typed-event-emitter";
2727
import {
28+
canAcceptVerificationRequest,
2829
VerificationPhase as Phase,
2930
VerificationRequest as IVerificationRequest,
3031
VerificationRequestEvent,
@@ -248,7 +249,7 @@ export class VerificationRequest<C extends IVerificationChannel = IVerificationC
248249
}
249250

250251
public get canAccept(): boolean {
251-
return this.phase < PHASE_READY && !this._accepting && !this._declining;
252+
return canAcceptVerificationRequest(this);
252253
}
253254

254255
public get accepting(): boolean {

0 commit comments

Comments
 (0)