better reply stuffs

This commit is contained in:
Sorunome 2020-04-30 14:52:23 +02:00
parent 34f46e8c51
commit 7e9b6f1e3d
No known key found for this signature in database
GPG Key ID: B19471D07FC9BE9C
4 changed files with 28 additions and 32 deletions

19
package-lock.json generated
View File

@ -1068,9 +1068,9 @@
} }
}, },
"graceful-fs": { "graceful-fs": {
"version": "4.2.3", "version": "4.2.4",
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.3.tgz", "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.4.tgz",
"integrity": "sha512-a30VEBm4PEdx1dRB7MFK7BejejvCvBronbLjht+sHuGYj8PHs7M/5Z+rt5lw551vZ7yfTCj4Vuyy3mSJytDWRQ==" "integrity": "sha512-WjKPNJF79dtJAVniUlGGWHYGz2jWxT6VhN/4m1NdkbZ2nOsEF+cI1Edgql5zCRhs/VsQYRvrXctxktVXZUkixw=="
}, },
"has-flag": { "has-flag": {
"version": "3.0.0", "version": "3.0.0",
@ -1223,9 +1223,9 @@
} }
}, },
"is-promise": { "is-promise": {
"version": "2.1.0", "version": "2.2.2",
"resolved": "https://registry.npmjs.org/is-promise/-/is-promise-2.1.0.tgz", "resolved": "https://registry.npmjs.org/is-promise/-/is-promise-2.2.2.tgz",
"integrity": "sha1-eaKp7OfwlugPNtKy87wWwf9L8/o=" "integrity": "sha512-+lP4/6lKUBfQjZ2pdxThZvLUAafmZb8OAxFb8XXtiQmS35INgr85hdOGoEs124ez1FCnZJt6jau/T+alh58QFQ=="
}, },
"is-stream": { "is-stream": {
"version": "2.0.0", "version": "2.0.0",
@ -1519,12 +1519,13 @@
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
}, },
"mx-puppet-bridge": { "mx-puppet-bridge": {
"version": "0.0.39", "version": "0.0.41",
"resolved": "https://registry.npmjs.org/mx-puppet-bridge/-/mx-puppet-bridge-0.0.39.tgz", "resolved": "https://registry.npmjs.org/mx-puppet-bridge/-/mx-puppet-bridge-0.0.41.tgz",
"integrity": "sha512-0Lw7E06tbxci1V4Gkiijd8kdCU3o0PrTjxOBuoGI3zieOu7osAZ1TMzQ3rZKZddtboN8oy9h4/GkTqsIf9T67Q==", "integrity": "sha512-3L+L8ecT0C8nm//jVTojwXax9Z0V/fQOPB0ohcQ7eoHsMfn+e7W6q7lSJOQg3zfMedANc+Bagw8J6rFcNK/B9A==",
"requires": { "requires": {
"@sorunome/matrix-bot-sdk": "^0.5.3-2", "@sorunome/matrix-bot-sdk": "^0.5.3-2",
"better-sqlite3": "^6.0.1", "better-sqlite3": "^6.0.1",
"escape-html": "^1.0.3",
"events": "^3.1.0", "events": "^3.1.0",
"expire-set": "^1.0.0", "expire-set": "^1.0.0",
"file-type": "^12.4.2", "file-type": "^12.4.2",

View File

@ -20,7 +20,7 @@
"events": "^3.0.0", "events": "^3.0.0",
"expire-set": "^1.0.0", "expire-set": "^1.0.0",
"js-yaml": "^3.13.1", "js-yaml": "^3.13.1",
"mx-puppet-bridge": "0.0.39", "mx-puppet-bridge": "0.0.41",
"node-emoji": "^1.10.0", "node-emoji": "^1.10.0",
"node-html-parser": "^1.2.13", "node-html-parser": "^1.2.13",
"tslint": "^5.17.0", "tslint": "^5.17.0",

View File

@ -13,7 +13,7 @@ limitations under the License.
import { import {
PuppetBridge, IRemoteUser, IRemoteRoom, IReceiveParams, IMessageEvent, IFileEvent, Log, MessageDeduplicator, Util, PuppetBridge, IRemoteUser, IRemoteRoom, IReceiveParams, IMessageEvent, IFileEvent, Log, MessageDeduplicator, Util,
IRetList, IRetList, IReplyEvent,
} from "mx-puppet-bridge"; } from "mx-puppet-bridge";
import { Client } from "./client"; import { Client } from "./client";
import * as skypeHttp from "@sorunome/skype-http"; import * as skypeHttp from "@sorunome/skype-http";
@ -409,11 +409,13 @@ export class Skype {
} }
} }
public async handleMatrixReply(room: IRemoteRoom, eventId: string, data: IMessageEvent) { public async handleMatrixReply(room: IRemoteRoom, eventId: string, data: IReplyEvent) {
const p = this.puppets[room.puppetId]; const p = this.puppets[room.puppetId];
if (!p) { if (!p) {
return; return;
} }
console.log("===================");
console.log(data);
log.info("Received reply from matrix"); log.info("Received reply from matrix");
const conversation = await p.client.getConversation(room); const conversation = await p.client.getConversation(room);
if (!conversation) { if (!conversation) {
@ -427,30 +429,23 @@ export class Skype {
msg = escapeHtml(data.body); msg = escapeHtml(data.body);
} }
// now prepend the reply // now prepend the reply
const author = escapeHtml(p.client.username.substr(p.client.username.indexOf(":") + 1)); const reply = data.reply;
const authorRawId = reply.user.user ? reply.user.user.userId : p.client.username;
const author = escapeHtml(authorRawId.substr(authorRawId.indexOf(":") + 1));
const ownContact = await p.client.getContact(p.client.username); const ownContact = await p.client.getContact(p.client.username);
const authorname = escapeHtml(ownContact ? ownContact.displayName : p.client.username); const authorname = escapeHtml(reply.user.displayname);
const conversationId = escapeHtml(conversation.id); const conversationId = escapeHtml(conversation.id);
const timestamp = Math.round(Number(eventId) / 1000).toString(); const timestamp = Math.round(Number(eventId) / 1000).toString();
const origEventId = (await this.puppet.eventSync.getMatrix(room, eventId))[0]; const origEventId = (await this.puppet.eventSync.getMatrix(room, eventId))[0];
let contents = "blah"; let contents = "";
if (origEventId) { if (reply.message) {
const roomId = await this.puppet.roomSync.maybeGetMxid(room); if (reply.message.formattedBody) {
if (roomId) { contents = this.matrixMessageParser.parse(reply.message.formattedBody);
try { } else {
const client = (await this.puppet.roomSync.getRoomOp(roomId)) || this.puppet.botIntent.underlyingClient; contents = escapeHtml(reply.message.body);
const evt = await client.getEvent(roomId, origEventId);
if (evt && evt.content && typeof evt.content.body === "string") {
if (evt.content.formatted_body) {
contents = this.matrixMessageParser.parse(evt.content.formatted_body);
} else {
contents = escapeHtml(evt.content.body);
}
}
} catch (err) {
log.verbose("Event not found", err.body || err);
}
} }
} else if (reply.file) {
contents = `${reply.file.filename}: ${reply.file.url}`;
} }
const quote = `<quote author="${author}" authorname="${authorname}" timestamp="${timestamp}" ` + const quote = `<quote author="${author}" authorname="${authorname}" timestamp="${timestamp}" ` +
`conversation="${conversationId}" messageid="${escapeHtml(eventId)}">` + `conversation="${conversationId}" messageid="${escapeHtml(eventId)}">` +

View File

@ -51,7 +51,7 @@ export class SkypeMessageParser {
private escape(s: string): IMessageEvent { private escape(s: string): IMessageEvent {
return { return {
body: decodeHtml(s), body: decodeHtml(s),
formattedBody: s.replace("\n", "<br>"), formattedBody: s.replace(/\n/g, "<br>"),
}; };
} }