Skip to content

Commit

Permalink
Implement canAcceptVerificationRequest
Browse files Browse the repository at this point in the history
  • Loading branch information
richvdh committed Jun 7, 2023
1 parent 4e45fb5 commit 850b03a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/crypto-api/verification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,3 +350,11 @@ export interface GeneratedSas {
* English name.
*/
export type EmojiMapping = [emoji: string, name: string];

/**
* True if the request is in a state where it can be accepted (ie, that we're in phases {@link VerificationPhase.Unsent}
* or {@link VerificationPhase.Requested}, and that we're not in the process of sending a `ready` or `cancel`).
*/
export function canAcceptVerificationRequest(req: VerificationRequest): boolean {
return req.phase < VerificationPhase.Ready && !req.accepting && !req.declining;
}
3 changes: 2 additions & 1 deletion src/crypto/verification/request/VerificationRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { VerificationBase } from "../Base";
import { VerificationMethod } from "../../index";
import { TypedEventEmitter } from "../../../models/typed-event-emitter";
import {
canAcceptVerificationRequest,
VerificationPhase as Phase,
VerificationRequest as IVerificationRequest,
VerificationRequestEvent,
Expand Down Expand Up @@ -248,7 +249,7 @@ export class VerificationRequest<C extends IVerificationChannel = IVerificationC
}

public get canAccept(): boolean {
return this.phase < PHASE_READY && !this._accepting && !this._declining;
return canAcceptVerificationRequest(this);
}

public get accepting(): boolean {
Expand Down

0 comments on commit 850b03a

Please sign in to comment.