1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-25 05:23:13 +03:00

Improve typing (#2055)

This commit is contained in:
Michael Telatynski
2021-12-09 14:22:58 +00:00
committed by GitHub
parent 95e7a76ba9
commit f8097221e6
28 changed files with 189 additions and 284 deletions

View File

@@ -29,7 +29,7 @@ import {
MsgType,
RelationType,
} from "../@types/event";
import { Crypto } from "../crypto";
import { Crypto, IEventDecryptionResult } from "../crypto";
import { deepSortedObjectEntries } from "../utils";
import { RoomMember } from "./room-member";
import { Thread, ThreadEvent } from "./thread";
@@ -85,7 +85,7 @@ export interface IUnsigned {
age?: number;
prev_sender?: string;
prev_content?: IContent;
redacted_because?: IEvent;
redacted_because?: IClearEvent;
transaction_id?: string;
invite_room_state?: StrippedState[];
}
@@ -124,25 +124,13 @@ export interface IEventRelation {
key?: string;
}
interface IDecryptionResult {
clearEvent: {
room_id?: string;
type: string;
content: IContent;
unsigned?: IUnsigned;
};
forwardingCurve25519KeyChain?: string[];
senderCurve25519Key?: string;
claimedEd25519Key?: string;
untrusted?: boolean;
}
/* eslint-enable camelcase */
export interface IClearEvent {
room_id?: string;
type: string;
content: Omit<IContent, "membership" | "avatar_url" | "displayname" | "m.relates_to">;
unsigned?: IUnsigned;
}
/* eslint-enable camelcase */
interface IKeyRequestRecipient {
userId: string;
@@ -215,14 +203,14 @@ export class MatrixEvent extends EventEmitter {
public sender: RoomMember = null;
public target: RoomMember = null;
public status: EventStatus = null;
public error = null;
public error: Error = null;
public forwardLooking = true;
/* If the event is a `m.key.verification.request` (or to_device `m.key.verification.start`) event,
* `Crypto` will set this the `VerificationRequest` for the event
* so it can be easily accessed from the timeline.
*/
public verificationRequest = null;
public verificationRequest: VerificationRequest = null;
private readonly reEmitter: ReEmitter;
@@ -690,8 +678,8 @@ export class MatrixEvent extends EventEmitter {
while (true) {
this.retryDecryption = false;
let res;
let err;
let res: IEventDecryptionResult;
let err: Error;
try {
if (!crypto) {
res = this.badEncryptedMessage("Encryption not enabled");
@@ -779,7 +767,7 @@ export class MatrixEvent extends EventEmitter {
}
}
private badEncryptedMessage(reason: string): IDecryptionResult {
private badEncryptedMessage(reason: string): IEventDecryptionResult {
return {
clearEvent: {
type: "m.room.message",
@@ -803,7 +791,7 @@ export class MatrixEvent extends EventEmitter {
* @param {module:crypto~EventDecryptionResult} decryptionResult
* the decryption result, including the plaintext and some key info
*/
private setClearData(decryptionResult: IDecryptionResult): void {
private setClearData(decryptionResult: IEventDecryptionResult): void {
this.clearEvent = decryptionResult.clearEvent;
this.senderCurve25519Key =
decryptionResult.senderCurve25519Key || null;