matrix-spam-ml

git clone git://archive.git.mtrnord.blog/MTRNord/matrix-spam-ml.git
Log | Files | Refs | Submodules | README | LICENSE

ReactionEvent.ts (1423B)


      1 import { RoomEvent } from "matrix-bot-sdk";
      2 
      3 /**
      4  * The defintion for the relation
      5  * @category Matrix event contents
      6  * @see ReactionEventContent
      7  */
      8 export interface RelatesTo {
      9     rel_type: "m.annotation";
     10     event_id: string;
     11     key: string;
     12 }
     13 
     14 /**
     15  * The content definition for m.reaction events
     16  * @category Matrix event contents
     17  * @see ReactionEvent
     18  */
     19 export interface ReactionEventContent {
     20     "m.relates_to": RelatesTo | undefined;
     21 }
     22 
     23 /**
     24  * Represents an m.reaction room event
     25  * @category Matrix events
     26  */
     27 export class ReactionEvent<T extends ReactionEventContent> extends RoomEvent<T> {
     28     // eslint-disable-next-line @typescript-eslint/no-explicit-any
     29     constructor(event: any) {
     30         super(event);
     31     }
     32 
     33     /**
     34      * Whether or not the event is redacted (or looked redacted).
     35      */
     36     public get isRedacted(): boolean {
     37         // Presume the event redacted if we're missing content
     38         return this.content["m.relates_to"] === undefined;
     39     }
     40 
     41     public get relatesTo(): RelatesTo {
     42         // eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-extra-non-null-assertion
     43         return this.content["m.relates_to"]!!;
     44     }
     45 
     46     public get reaction(): string | undefined {
     47         return this.content["m.relates_to"]?.key;
     48     }
     49 
     50     public get targetEventId(): string | undefined {
     51         return this.content["m.relates_to"]?.event_id;
     52     }
     53 }