Make view messages applicable to users

This commit is contained in:
RMidhunSuresh 2023-06-16 14:28:09 +05:30
parent f64cfd67f6
commit 93f4158645
4 changed files with 89 additions and 36 deletions

View File

@ -16,7 +16,7 @@ limitations under the License.
import {Options as BaseOptions} from "../../../ViewModel";
import {DismissibleVerificationViewModel} from "./DismissibleVerificationViewModel";
import type {CancelReason} from "../../../../matrix/verification/SAS/channel/types";
import {CancelReason} from "../../../../matrix/verification/SAS/channel/types";
import type {Session} from "../../../../matrix/Session.js";
import type {IChannel} from "../../../../matrix/verification/SAS/channel/IChannel";
import type {SASVerification} from "../../../../matrix/verification/SAS/SASVerification";
@ -39,4 +39,74 @@ export class VerificationCancelledViewModel extends DismissibleVerificationViewM
get kind(): string {
return "verification-cancelled";
}
get title(): string {
if (this.isCancelledByUs) {
return this.i18n`You cancelled the verification!`;
}
if (this.getOption("sas").isCrossSigningAnotherUser) {
return this.i18n`The other user cancelled the verification!`;
}
else {
return this.i18n`The other device cancelled the verification!`;
}
}
get description(): string {
const descriptionsWhenWeCancelledForDeviceVerification = {
[CancelReason.InvalidMessage]: "Your other device sent an invalid message.",
[CancelReason.KeyMismatch]: "The key could not be verified.",
[CancelReason.TimedOut]: "The verification process timed out.",
[CancelReason.UnexpectedMessage]: "Your other device sent an unexpected message.",
[CancelReason.UnknownMethod]: "Your other device is using an unknown method for verification.",
[CancelReason.UnknownTransaction]: "Your other device sent a message with an unknown transaction id.",
[CancelReason.UserMismatch]: "The expected user did not match the user verified.",
[CancelReason.MismatchedCommitment]: "The hash commitment does not match.",
[CancelReason.MismatchedSAS]: "The emoji/decimal did not match.",
}
const descriptionsWhenTheyCancelledForDeviceVerification = {
[CancelReason.UserCancelled]: "Your other device cancelled the verification!",
[CancelReason.InvalidMessage]: "Invalid message sent to the other device.",
[CancelReason.KeyMismatch]: "The other device could not verify our keys",
[CancelReason.TimedOut]: "The verification process timed out.",
[CancelReason.UnexpectedMessage]: "Unexpected message sent to the other device.",
[CancelReason.UnknownMethod]: "Your other device does not understand the method you chose",
[CancelReason.UnknownTransaction]: "Your other device rejected our message.",
[CancelReason.UserMismatch]: "The expected user did not match the user verified.",
[CancelReason.MismatchedCommitment]: "Your other device was not able to verify the hash commitment",
[CancelReason.MismatchedSAS]: "The emoji/decimal did not match.",
}
const descriptionsWhenWeCancelledForCrossSigning = {
[CancelReason.InvalidMessage]: "The other user sent an invalid message.",
[CancelReason.KeyMismatch]: "The key could not be verified.",
[CancelReason.TimedOut]: "The verification process timed out.",
[CancelReason.UnexpectedMessage]: "The other user sent an unexpected message.",
[CancelReason.UnknownMethod]: "The other user is using an unknown method for verification.",
[CancelReason.UnknownTransaction]: "The other user sent a message with an unknown transaction id.",
[CancelReason.UserMismatch]: "The expected user did not match the user verified.",
[CancelReason.MismatchedCommitment]: "The hash commitment does not match.",
[CancelReason.MismatchedSAS]: "The emoji/decimal did not match.",
}
const descriptionsWhenTheyCancelledForCrossSigning = {
[CancelReason.UserCancelled]: "The other user cancelled the verification!",
[CancelReason.InvalidMessage]: "Invalid message sent to the other user.",
[CancelReason.KeyMismatch]: "The other user could not verify our keys",
[CancelReason.TimedOut]: "The verification process timed out.",
[CancelReason.UnexpectedMessage]: "Unexpected message sent to the other user.",
[CancelReason.UnknownMethod]: "The other user does not understand the method you chose",
[CancelReason.UnknownTransaction]: "The other user rejected our message.",
[CancelReason.UserMismatch]: "The expected user did not match the user verified.",
[CancelReason.MismatchedCommitment]: "The other user was not able to verify the hash commitment",
[CancelReason.MismatchedSAS]: "The emoji/decimal did not match.",
}
let map;
if (this.getOption("sas").isCrossSigningAnotherUser) {
map = this.isCancelledByUs ? descriptionsWhenWeCancelledForCrossSigning : descriptionsWhenTheyCancelledForCrossSigning;
} else {
map = this.isCancelledByUs ? descriptionsWhenWeCancelledForDeviceVerification : descriptionsWhenTheyCancelledForDeviceVerification;
}
const description = map[this.cancelCode] ?? ""
return this.i18n`${description}`;
}
}

View File

@ -27,6 +27,20 @@ export class WaitingForOtherUserViewModel extends ViewModel<SegmentType, Options
await this.options.sas.abort();
}
get title() {
const message = this.getOption("sas").isCrossSigningAnotherUser
? "Waiting for the other user to accept the verification request"
: "Waiting for any of your device to accept the verification request";
return this.i18n`${message}`;
}
get description() {
const message = this.getOption("sas").isCrossSigningAnotherUser
? "Ask the other user to accept the request from their client!"
: "Accept the request from the device you wish to verify!";
return this.i18n`${message}`;
}
get kind(): string {
return "waiting-for-user";
}

View File

@ -16,12 +16,9 @@ limitations under the License.
import {Builder, TemplateView} from "../../../general/TemplateView";
import {VerificationCancelledViewModel} from "../../../../../../domain/session/verification/stages/VerificationCancelledViewModel";
import {CancelReason} from "../../../../../../matrix/verification/SAS/channel/types";
export class VerificationCancelledView extends TemplateView<VerificationCancelledViewModel> {
render(t: Builder<VerificationCancelledViewModel>, vm: VerificationCancelledViewModel) {
const headerTextStart = vm.isCancelledByUs ? "You" : "The other device";
return t.div(
{
className: "VerificationCancelledView",
@ -29,11 +26,11 @@ export class VerificationCancelledView extends TemplateView<VerificationCancelle
[
t.h2(
{ className: "VerificationCancelledView__title" },
vm.i18n`${headerTextStart} cancelled the verification!`
vm.title,
),
t.p(
{ className: "VerificationCancelledView__description" },
vm.i18n`${this.getDescriptionFromCancellationCode(vm.cancelCode, vm.isCancelledByUs)}`
vm.description,
),
t.div({ className: "VerificationCancelledView__actions" }, [
t.button({
@ -47,32 +44,4 @@ export class VerificationCancelledView extends TemplateView<VerificationCancelle
]
);
}
getDescriptionFromCancellationCode(code: CancelReason, isCancelledByUs: boolean): string {
const descriptionsWhenWeCancelled = {
[CancelReason.InvalidMessage]: "You other device sent an invalid message.",
[CancelReason.KeyMismatch]: "The key could not be verified.",
[CancelReason.TimedOut]: "The verification process timed out.",
[CancelReason.UnexpectedMessage]: "Your other device sent an unexpected message.",
[CancelReason.UnknownMethod]: "Your other device is using an unknown method for verification.",
[CancelReason.UnknownTransaction]: "Your other device sent a message with an unknown transaction id.",
[CancelReason.UserMismatch]: "The expected user did not match the user verified.",
[CancelReason.MismatchedCommitment]: "The hash commitment does not match.",
[CancelReason.MismatchedSAS]: "The emoji/decimal did not match.",
}
const descriptionsWhenTheyCancelled = {
[CancelReason.UserCancelled]: "Your other device cancelled the verification!",
[CancelReason.InvalidMessage]: "Invalid message sent to the other device.",
[CancelReason.KeyMismatch]: "The other device could not verify our keys",
[CancelReason.TimedOut]: "The verification process timed out.",
[CancelReason.UnexpectedMessage]: "Unexpected message sent to the other device.",
[CancelReason.UnknownMethod]: "Your other device does not understand the method you chose",
[CancelReason.UnknownTransaction]: "Your other device rejected our message.",
[CancelReason.UserMismatch]: "The expected user did not match the user verified.",
[CancelReason.MismatchedCommitment]: "Your other device was not able to verify the hash commitment",
[CancelReason.MismatchedSAS]: "The emoji/decimal did not match.",
}
const map = isCancelledByUs ? descriptionsWhenWeCancelled : descriptionsWhenTheyCancelled;
return map[code] ?? "";
}
}

View File

@ -25,11 +25,11 @@ export class WaitingForOtherUserView extends TemplateView<WaitingForOtherUserVie
spinner(t),
t.h2(
{ className: "WaitingForOtherUserView__title" },
vm.i18n`Waiting for any of your device to accept the verification request`
vm.title,
),
]),
t.p({ className: "WaitingForOtherUserView__description" },
vm.i18n`Accept the request from the device you wish to verify!`
vm.description,
),
t.div({ className: "WaitingForOtherUserView__actions" },
t.button({