How to use the m.in_reply_to function in m

To help you get started, we’ve selected a few m examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Half-Shot / matrix-appservice-discord / src / matrixeventprocessor.ts View on Github external
public async GetEmbedForReply(
        event: IMatrixEvent,
        channel: Discord.TextChannel,
    ): Promise {
        if (!event.content) {
            event.content = {};
        }

        const relatesTo = event.content["m.relates_to"];
        let eventId = "";
        if (relatesTo && relatesTo["m.in_reply_to"]) {
            eventId = relatesTo["m.in_reply_to"].event_id;
        } else {
            return;
        }

        const intent = this.bridge.getIntent();
        // Try to get the event.
        try {
            const sourceEvent = await intent.getEvent(event.room_id, eventId);
            sourceEvent.content.body = sourceEvent.content.body  || "Reply with unknown content";
            const replyEmbed = (await this.EventToEmbed(sourceEvent, channel, false)).messageEmbed;

            // if we reply to a discord member, ping them!
            if (this.bridge.getBot().isRemoteUser(sourceEvent.sender)) {
                const uid = new MatrixUser(sourceEvent.sender.replace("@", "")).localpart.substring("_discord".length);
                replyEmbed.addField("ping", `<@${uid}>`);
github FabricLabs / fabric / src / components / views / elements / ReplyThread.js View on Github external
static getParentEventId(ev) {
        if (!ev || ev.isRedacted()) return;

        // XXX: For newer relations (annotations, replacements, etc.), we now
        // have a `getRelation` helper on the event, and you might assume it
        // could be used here for replies as well... However, the helper
        // currently assumes the relation has a `rel_type`, which older replies
        // do not, so this block is left as-is for now.
        const mRelatesTo = ev.getWireContent()['m.relates_to'];
        if (mRelatesTo && mRelatesTo['m.in_reply_to']) {
            const mInReplyTo = mRelatesTo['m.in_reply_to'];
            if (mInReplyTo && mInReplyTo['event_id']) return mInReplyTo['event_id'];
        }
    }
github matrix-org / matrix-appservice-slack / src / BridgedRoom.ts View on Github external
private async findParentReply(message: any, depth: number = 0): Promise {
        const MAX_DEPTH = 10;
        // Extract the referenced event
        if (!message.content) { return message.event_id; }
        if (!message.content["m.relates_to"]) { return message.event_id; }
        if (!message.content["m.relates_to"]["m.in_reply_to"]) { return message.event_id; }
        const parentEventId = message.content["m.relates_to"]["m.in_reply_to"].event_id;
        if (!parentEventId) { return message.event_id; }
        if (depth > MAX_DEPTH) {
            return parentEventId; // We have hit our depth limit, use this one.
        }

        const intent = await this.getIntentForRoom(message.room_id);
        const nextEvent = await intent.getClient().fetchRoomEvent(message.room_id, parentEventId);

        return this.findParentReply(nextEvent, depth++);
    }
github matrix-org / matrix-appservice-slack / lib / BridgedRoom.js View on Github external
BridgedRoom.prototype.findParentReply = async function(message) {
    // Extract the referenced event
    if (!message["content"]) return message.event_id;
    if (!message["content"]["m.relates_to"]) return message.event_id;
    if (!message["content"]["m.relates_to"]["m.in_reply_to"]) return message.event_id;
    const parentEventId = message["content"]["m.relates_to"]["m.in_reply_to"]["event_id"];
    if (!parentEventId) return message.event_id;

    // Get the previous event
    const intent = this._main.getBotIntent();
    const nextEvent = await intent.getClient().fetchRoomEvent(message.room_id, parentEventId);

    return this.findParentReply(nextEvent);
};
github FabricLabs / fabric / src / components / views / elements / ReplyThread.js View on Github external
static getParentEventId(ev) {
        if (!ev || ev.isRedacted()) return;

        // XXX: For newer relations (annotations, replacements, etc.), we now
        // have a `getRelation` helper on the event, and you might assume it
        // could be used here for replies as well... However, the helper
        // currently assumes the relation has a `rel_type`, which older replies
        // do not, so this block is left as-is for now.
        const mRelatesTo = ev.getWireContent()['m.relates_to'];
        if (mRelatesTo && mRelatesTo['m.in_reply_to']) {
            const mInReplyTo = mRelatesTo['m.in_reply_to'];
            if (mInReplyTo && mInReplyTo['event_id']) return mInReplyTo['event_id'];
        }
    }
github Half-Shot / matrix-appservice-discord / src / matrixeventprocessor.ts View on Github external
public async GetEmbedForReply(
        event: IMatrixEvent,
        channel: Discord.TextChannel,
    ): Promise {
        if (!event.content) {
            event.content = {};
        }

        const relatesTo = event.content["m.relates_to"];
        let eventId = "";
        if (relatesTo && relatesTo["m.in_reply_to"]) {
            eventId = relatesTo["m.in_reply_to"].event_id;
        } else {
            return;
        }

        const intent = this.bridge.getIntent();
        // Try to get the event.
        try {
            const sourceEvent = await intent.getEvent(event.room_id, eventId);
            sourceEvent.content.body = sourceEvent.content.body  || "Reply with unknown content";
            const replyEmbed = (await this.EventToEmbed(sourceEvent, channel, false)).messageEmbed;

            // if we reply to a discord member, ping them!
            if (this.bridge.getBot().isRemoteUser(sourceEvent.sender)) {
                const uid = new MatrixUser(sourceEvent.sender.replace("@", "")).localpart.substring("_discord".length);
                replyEmbed.addField("ping", `<@${uid}>`);
            }
github matrix-org / matrix-appservice-slack / src / BridgedRoom.ts View on Github external
private async findParentReply(message: any, depth: number = 0): Promise {
        const MAX_DEPTH = 10;
        // Extract the referenced event
        if (!message.content) { return message.event_id; }
        if (!message.content["m.relates_to"]) { return message.event_id; }
        if (!message.content["m.relates_to"]["m.in_reply_to"]) { return message.event_id; }
        const parentEventId = message.content["m.relates_to"]["m.in_reply_to"].event_id;
        if (!parentEventId) { return message.event_id; }
        if (depth > MAX_DEPTH) {
            return parentEventId; // We have hit our depth limit, use this one.
        }

        const intent = await this.getIntentForRoom(message.room_id);
        const nextEvent = await intent.getClient().fetchRoomEvent(message.room_id, parentEventId);

        return this.findParentReply(nextEvent, depth++);
    }
github matrix-org / matrix-appservice-slack / lib / BridgedRoom.js View on Github external
BridgedRoom.prototype.findParentReply = async function(message) {
    // Extract the referenced event
    if (!message["content"]) return message.event_id;
    if (!message["content"]["m.relates_to"]) return message.event_id;
    if (!message["content"]["m.relates_to"]["m.in_reply_to"]) return message.event_id;
    const parentEventId = message["content"]["m.relates_to"]["m.in_reply_to"]["event_id"];
    if (!parentEventId) return message.event_id;

    // Get the previous event
    const intent = this._main.getBotIntent();
    const nextEvent = await intent.getClient().fetchRoomEvent(message.room_id, parentEventId);

    return this.findParentReply(nextEvent);
};