Socket
Socket
Sign inDemoInstall

mx-puppet-bridge

Package Overview
Dependencies
251
Maintainers
1
Versions
112
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.9 to 0.0.10-1

3

lib/puppetbridge.d.ts

@@ -28,2 +28,3 @@ /// <reference types="node" />

edit?: boolean;
reply?: boolean;
}

@@ -139,2 +140,4 @@ export interface IReceiveParams {

sendRedact(params: IReceiveParams, eventId: string): Promise<void>;
sendReply(params: IReceiveParams, eventId: string, opts: IMessageEvent): Promise<void>;
sendReaction(params: IReceiveParams, eventId: string, reaction: string): Promise<void>;
private sendFileByType;

@@ -141,0 +144,0 @@ private maybePrepareSend;

@@ -425,2 +425,62 @@ "use strict";

}
sendReply(params, eventId, opts) {
return __awaiter(this, void 0, void 0, function* () {
log.verbose(`Received reply to send`);
const { client, mxid } = yield this.prepareSend(params);
let msgtype = "m.text";
if (opts.emote) {
msgtype = "m.emote";
}
else if (opts.notice) {
msgtype = "m.notice";
}
const origEvents = yield this.eventStore.getMatrix(params.chan.puppetId, eventId);
const origEvent = origEvents[0];
const send = {
msgtype,
body: opts.body,
source: "remote",
};
if (origEvent) {
send["m.relates_to"] = {
"m.in_reply_to": {
event_id: origEvent,
},
};
}
else {
log.warn("Couldn't find event, sending as normal message...");
}
if (opts.formattedBody) {
send.format = "org.matrix.custom.html";
send.formatted_body = opts.formattedBody;
}
const matrixEventId = yield client.sendMessage(mxid, send);
if (matrixEventId && params.eventId) {
yield this.eventStore.insert(params.chan.puppetId, matrixEventId, params.eventId);
}
});
}
sendReaction(params, eventId, reaction) {
return __awaiter(this, void 0, void 0, function* () {
log.verbose(`Received reaction to send`);
const { client, mxid } = yield this.prepareSend(params);
const origEvents = yield this.eventStore.getMatrix(params.chan.puppetId, eventId);
const origEvent = origEvents[0];
if (!origEvent) {
return; // nothing to do
}
const send = {
"m.relates_to": {
rel_type: "m.annotation",
event_id: origEvent,
key: reaction,
},
};
const matrixEventId = yield client.sendEvent(mxid, "m.reaction", send);
if (matrixEventId && params.eventId) {
yield this.eventStore.insert(params.chan.puppetId, matrixEventId, params.eventId);
}
});
}
sendFileByType(msgtype, params, thing, name) {

@@ -573,5 +633,12 @@ return __awaiter(this, void 0, void 0, function* () {

const relate = event.content["m.relates_to"];
const msgData = {
body: event.content.body,
emote: msgtype === "m.emote",
notice: msgtype === "m.notice",
eventId: event.event_id,
};
if (relate) {
// relation events
const relEvent = (yield this.eventStore.getRemote(room.puppetId, relate.event_id))[0];
const relEvent = (yield this.eventStore.getRemote(room.puppetId, relate.event_id || relate["m.in_reply_to"].event_id))[0];
log.silly(relEvent);
if (relEvent) {

@@ -592,10 +659,13 @@ if (this.features.edit && relate.rel_type === "m.replace") {

}
if (this.features.reply && (relate.rel_type === "m.in_reply_to" || relate["m.in_reply_to"])) {
this.emit("reply", room, relEvent, msgData, event);
return;
}
if (relate.rel_type === "m.annotation") {
// no feature setting as reactions are hidden if they aren't supported
this.emit("reaction", room, relEvent, relate.key, event);
return;
}
}
}
const msgData = {
body: event.content.body,
emote: msgtype === "m.emote",
notice: msgtype === "m.notice",
eventId: event.event_id,
};
if (event.content.format) {

@@ -624,3 +694,3 @@ msgData.formattedBody = event.content.formatted_body;

}
const validTypes = ["m.room.message", "m.sticker"];
const validTypes = ["m.room.message", "m.sticker", "m.reaction"];
if (!validTypes.includes(event.type)) {

@@ -649,6 +719,6 @@ return; // we don't handle this here, silently drop the event

let msgtype = event.content.msgtype;
if (event.type === "m.sticker") {
msgtype = "m.sticker";
if (event.type !== "m.room.message") {
msgtype = event.type;
}
if (msgtype === "m.emote" || msgtype === "m.notice" || msgtype === "m.text") {
if (!["m.file", "m.image", "m.audio", "m.sticker", "m.video"].includes(msgtype)) {
// short-circuit text stuff

@@ -655,0 +725,0 @@ yield this.handleTextEvent(room, event);

4

package.json
{
"name": "mx-puppet-bridge",
"version": "0.0.9",
"version": "0.0.10-1",
"description": "Matrix Puppeting Bridge library",

@@ -27,3 +27,3 @@ "repository": {

"js-yaml": "^3.13.1",
"matrix-bot-sdk": "git+https://github.com/Sorunome/matrix-js-bot-sdk.git#957f94828c17a043b797e152417d128cc48641b7",
"matrix-bot-sdk": "0.4.0-beta.3",
"pg-promise": "^8.7.2",

@@ -30,0 +30,0 @@ "tslint": "^5.17.0",

@@ -63,4 +63,5 @@ import * as fs from "fs";

// edits
// event types
edit?: boolean;
reply?: boolean;
}

@@ -528,2 +529,58 @@

public async sendReply(params: IReceiveParams, eventId: string, opts: IMessageEvent) {
log.verbose(`Received reply to send`);
const { client, mxid } = await this.prepareSend(params);
let msgtype = "m.text";
if (opts.emote) {
msgtype = "m.emote";
} else if (opts.notice) {
msgtype = "m.notice";
}
const origEvents = await this.eventStore.getMatrix(params.chan.puppetId, eventId);
const origEvent = origEvents[0];
const send = {
msgtype,
body: opts.body,
source: "remote",
} as any;
if (origEvent) {
send["m.relates_to"] = {
"m.in_reply_to": {
event_id: origEvent,
},
};
} else {
log.warn("Couldn't find event, sending as normal message...");
}
if (opts.formattedBody) {
send.format = "org.matrix.custom.html";
send.formatted_body = opts.formattedBody;
}
const matrixEventId = await client.sendMessage(mxid, send);
if (matrixEventId && params.eventId) {
await this.eventStore.insert(params.chan.puppetId, matrixEventId, params.eventId);
}
}
public async sendReaction(params: IReceiveParams, eventId: string, reaction: string) {
log.verbose(`Received reaction to send`);
const { client, mxid } = await this.prepareSend(params);
const origEvents = await this.eventStore.getMatrix(params.chan.puppetId, eventId);
const origEvent = origEvents[0];
if (!origEvent) {
return; // nothing to do
}
const send = {
"m.relates_to": {
rel_type: "m.annotation",
event_id: origEvent,
key: reaction,
},
};
const matrixEventId = await client.sendEvent(mxid, "m.reaction", send);
if (matrixEventId && params.eventId) {
await this.eventStore.insert(params.chan.puppetId, matrixEventId, params.eventId);
}
}
private async sendFileByType(msgtype: string, params: IReceiveParams, thing: string | Buffer, name?: string) {

@@ -673,5 +730,13 @@ log.verbose(`Received file to send. thing=${typeof thing === "string" ? thing : "<Buffer>"} name=${name}`);

const relate = event.content["m.relates_to"];
const msgData = {
body: event.content.body,
emote: msgtype === "m.emote",
notice: msgtype === "m.notice",
eventId: event.event_id,
} as IMessageEvent;
if (relate) {
// relation events
const relEvent = (await this.eventStore.getRemote(room.puppetId, relate.event_id))[0];
const relEvent = (await this.eventStore.getRemote(room.puppetId,
relate.event_id || relate["m.in_reply_to"].event_id))[0];
log.silly(relEvent);
if (relEvent) {

@@ -692,10 +757,13 @@ if (this.features.edit && relate.rel_type === "m.replace") {

}
if (this.features.reply && (relate.rel_type === "m.in_reply_to" || relate["m.in_reply_to"])) {
this.emit("reply", room, relEvent, msgData, event);
return;
}
if (relate.rel_type === "m.annotation") {
// no feature setting as reactions are hidden if they aren't supported
this.emit("reaction", room, relEvent, relate.key, event);
return;
}
}
}
const msgData = {
body: event.content.body,
emote: msgtype === "m.emote",
notice: msgtype === "m.notice",
eventId: event.event_id,
} as IMessageEvent;
if (event.content.format) {

@@ -723,3 +791,3 @@ msgData.formattedBody = event.content.formatted_body;

}
const validTypes = ["m.room.message", "m.sticker"];
const validTypes = ["m.room.message", "m.sticker", "m.reaction"];
if (!validTypes.includes(event.type)) {

@@ -748,6 +816,6 @@ return; // we don't handle this here, silently drop the event

let msgtype = event.content.msgtype;
if (event.type === "m.sticker") {
msgtype = "m.sticker";
if (event.type !== "m.room.message") {
msgtype = event.type;
}
if (msgtype === "m.emote" || msgtype === "m.notice" || msgtype === "m.text") {
if (!["m.file", "m.image", "m.audio", "m.sticker", "m.video"].includes(msgtype)) {
// short-circuit text stuff

@@ -754,0 +822,0 @@ await this.handleTextEvent(room, event);

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc