mirror of
https://github.com/plantroon/mx-puppet-xmpp.git
synced 2024-12-27 00:51:41 +00:00
better reply stuffs
This commit is contained in:
parent
34f46e8c51
commit
7e9b6f1e3d
19
package-lock.json
generated
19
package-lock.json
generated
@ -1068,9 +1068,9 @@
|
||||
}
|
||||
},
|
||||
"graceful-fs": {
|
||||
"version": "4.2.3",
|
||||
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.3.tgz",
|
||||
"integrity": "sha512-a30VEBm4PEdx1dRB7MFK7BejejvCvBronbLjht+sHuGYj8PHs7M/5Z+rt5lw551vZ7yfTCj4Vuyy3mSJytDWRQ=="
|
||||
"version": "4.2.4",
|
||||
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.4.tgz",
|
||||
"integrity": "sha512-WjKPNJF79dtJAVniUlGGWHYGz2jWxT6VhN/4m1NdkbZ2nOsEF+cI1Edgql5zCRhs/VsQYRvrXctxktVXZUkixw=="
|
||||
},
|
||||
"has-flag": {
|
||||
"version": "3.0.0",
|
||||
@ -1223,9 +1223,9 @@
|
||||
}
|
||||
},
|
||||
"is-promise": {
|
||||
"version": "2.1.0",
|
||||
"resolved": "https://registry.npmjs.org/is-promise/-/is-promise-2.1.0.tgz",
|
||||
"integrity": "sha1-eaKp7OfwlugPNtKy87wWwf9L8/o="
|
||||
"version": "2.2.2",
|
||||
"resolved": "https://registry.npmjs.org/is-promise/-/is-promise-2.2.2.tgz",
|
||||
"integrity": "sha512-+lP4/6lKUBfQjZ2pdxThZvLUAafmZb8OAxFb8XXtiQmS35INgr85hdOGoEs124ez1FCnZJt6jau/T+alh58QFQ=="
|
||||
},
|
||||
"is-stream": {
|
||||
"version": "2.0.0",
|
||||
@ -1519,12 +1519,13 @@
|
||||
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
|
||||
},
|
||||
"mx-puppet-bridge": {
|
||||
"version": "0.0.39",
|
||||
"resolved": "https://registry.npmjs.org/mx-puppet-bridge/-/mx-puppet-bridge-0.0.39.tgz",
|
||||
"integrity": "sha512-0Lw7E06tbxci1V4Gkiijd8kdCU3o0PrTjxOBuoGI3zieOu7osAZ1TMzQ3rZKZddtboN8oy9h4/GkTqsIf9T67Q==",
|
||||
"version": "0.0.41",
|
||||
"resolved": "https://registry.npmjs.org/mx-puppet-bridge/-/mx-puppet-bridge-0.0.41.tgz",
|
||||
"integrity": "sha512-3L+L8ecT0C8nm//jVTojwXax9Z0V/fQOPB0ohcQ7eoHsMfn+e7W6q7lSJOQg3zfMedANc+Bagw8J6rFcNK/B9A==",
|
||||
"requires": {
|
||||
"@sorunome/matrix-bot-sdk": "^0.5.3-2",
|
||||
"better-sqlite3": "^6.0.1",
|
||||
"escape-html": "^1.0.3",
|
||||
"events": "^3.1.0",
|
||||
"expire-set": "^1.0.0",
|
||||
"file-type": "^12.4.2",
|
||||
|
@ -20,7 +20,7 @@
|
||||
"events": "^3.0.0",
|
||||
"expire-set": "^1.0.0",
|
||||
"js-yaml": "^3.13.1",
|
||||
"mx-puppet-bridge": "0.0.39",
|
||||
"mx-puppet-bridge": "0.0.41",
|
||||
"node-emoji": "^1.10.0",
|
||||
"node-html-parser": "^1.2.13",
|
||||
"tslint": "^5.17.0",
|
||||
|
37
src/skype.ts
37
src/skype.ts
@ -13,7 +13,7 @@ limitations under the License.
|
||||
|
||||
import {
|
||||
PuppetBridge, IRemoteUser, IRemoteRoom, IReceiveParams, IMessageEvent, IFileEvent, Log, MessageDeduplicator, Util,
|
||||
IRetList,
|
||||
IRetList, IReplyEvent,
|
||||
} from "mx-puppet-bridge";
|
||||
import { Client } from "./client";
|
||||
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];
|
||||
if (!p) {
|
||||
return;
|
||||
}
|
||||
console.log("===================");
|
||||
console.log(data);
|
||||
log.info("Received reply from matrix");
|
||||
const conversation = await p.client.getConversation(room);
|
||||
if (!conversation) {
|
||||
@ -427,30 +429,23 @@ export class Skype {
|
||||
msg = escapeHtml(data.body);
|
||||
}
|
||||
// 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 authorname = escapeHtml(ownContact ? ownContact.displayName : p.client.username);
|
||||
const authorname = escapeHtml(reply.user.displayname);
|
||||
const conversationId = escapeHtml(conversation.id);
|
||||
const timestamp = Math.round(Number(eventId) / 1000).toString();
|
||||
const origEventId = (await this.puppet.eventSync.getMatrix(room, eventId))[0];
|
||||
let contents = "blah";
|
||||
if (origEventId) {
|
||||
const roomId = await this.puppet.roomSync.maybeGetMxid(room);
|
||||
if (roomId) {
|
||||
try {
|
||||
const client = (await this.puppet.roomSync.getRoomOp(roomId)) || this.puppet.botIntent.underlyingClient;
|
||||
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);
|
||||
}
|
||||
let contents = "";
|
||||
if (reply.message) {
|
||||
if (reply.message.formattedBody) {
|
||||
contents = this.matrixMessageParser.parse(reply.message.formattedBody);
|
||||
} else {
|
||||
contents = escapeHtml(reply.message.body);
|
||||
}
|
||||
} else if (reply.file) {
|
||||
contents = `${reply.file.filename}: ${reply.file.url}`;
|
||||
}
|
||||
const quote = `<quote author="${author}" authorname="${authorname}" timestamp="${timestamp}" ` +
|
||||
`conversation="${conversationId}" messageid="${escapeHtml(eventId)}">` +
|
||||
|
@ -51,7 +51,7 @@ export class SkypeMessageParser {
|
||||
private escape(s: string): IMessageEvent {
|
||||
return {
|
||||
body: decodeHtml(s),
|
||||
formattedBody: s.replace("\n", "<br>"),
|
||||
formattedBody: s.replace(/\n/g, "<br>"),
|
||||
};
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user