Hopefully better microformat handling outgoing
This commit is contained in:
parent
a24ec5fd67
commit
c3335ce062
|
@ -3,7 +3,7 @@ const ActivityPubObject = require('./object');
|
||||||
const { Errors } = require('../enig_error');
|
const { Errors } = require('../enig_error');
|
||||||
const { getISOTimestampString } = require('../database');
|
const { getISOTimestampString } = require('../database');
|
||||||
const User = require('../user');
|
const User = require('../user');
|
||||||
const { messageBodyToHtml, htmlToMessageBody } = require('./util');
|
const { messageToHtml, htmlToMessageBody } = require('./util');
|
||||||
const { isAnsi } = require('../string_util');
|
const { isAnsi } = require('../string_util');
|
||||||
const Log = require('../logger').log;
|
const Log = require('../logger').log;
|
||||||
|
|
||||||
|
@ -117,7 +117,7 @@ module.exports = class Note extends ActivityPubObject {
|
||||||
published: getISOTimestampString(message.modTimestamp),
|
published: getISOTimestampString(message.modTimestamp),
|
||||||
to,
|
to,
|
||||||
attributedTo: fromActor.id,
|
attributedTo: fromActor.id,
|
||||||
content: messageBodyToHtml(message.message.trim()),
|
content: messageToHtml(message, remoteActor),
|
||||||
source: {
|
source: {
|
||||||
content: message.message,
|
content: message.message,
|
||||||
mediaType: sourceMediaType,
|
mediaType: sourceMediaType,
|
||||||
|
@ -237,7 +237,6 @@ module.exports = class Note extends ActivityPubObject {
|
||||||
message.modTimestamp = moment();
|
message.modTimestamp = moment();
|
||||||
}
|
}
|
||||||
|
|
||||||
// :TODO: replyToMsgId from 'inReplyTo'
|
|
||||||
message.setRemoteFromUser(this.attributedTo);
|
message.setRemoteFromUser(this.attributedTo);
|
||||||
message.setExternalFlavor(Message.AddressFlavor.ActivityPub);
|
message.setExternalFlavor(Message.AddressFlavor.ActivityPub);
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@ exports.localActorId = localActorId;
|
||||||
exports.userFromActorId = userFromActorId;
|
exports.userFromActorId = userFromActorId;
|
||||||
exports.getUserProfileTemplatedBody = getUserProfileTemplatedBody;
|
exports.getUserProfileTemplatedBody = getUserProfileTemplatedBody;
|
||||||
exports.messageBodyToHtml = messageBodyToHtml;
|
exports.messageBodyToHtml = messageBodyToHtml;
|
||||||
|
exports.messageToHtml = messageToHtml;
|
||||||
exports.htmlToMessageBody = htmlToMessageBody;
|
exports.htmlToMessageBody = htmlToMessageBody;
|
||||||
exports.userNameFromSubject = userNameFromSubject;
|
exports.userNameFromSubject = userNameFromSubject;
|
||||||
|
|
||||||
|
@ -194,13 +195,6 @@ function getUserProfileTemplatedBody(
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
// Apply very basic HTML to a message following
|
|
||||||
// Mastodon's supported tags of 'p', 'br', 'a', and 'span':
|
|
||||||
// - https://docs.joinmastodon.org/spec/activitypub/#sanitization
|
|
||||||
// - https://blog.joinmastodon.org/2018/06/how-to-implement-a-basic-activitypub-server/
|
|
||||||
//
|
|
||||||
// :TODO: https://docs.joinmastodon.org/spec/microformats/
|
|
||||||
function messageBodyToHtml(body) {
|
function messageBodyToHtml(body) {
|
||||||
body = encode(stripAnsiControlCodes(body), { mode: 'nonAsciiPrintable' }).replace(
|
body = encode(stripAnsiControlCodes(body), { mode: 'nonAsciiPrintable' }).replace(
|
||||||
/\r?\n/g,
|
/\r?\n/g,
|
||||||
|
@ -210,6 +204,35 @@ function messageBodyToHtml(body) {
|
||||||
return `<p>${body}</p>`;
|
return `<p>${body}</p>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Apply very basic HTML to a message following
|
||||||
|
// Mastodon's supported tags of 'p', 'br', 'a', and 'span':
|
||||||
|
// - https://docs.joinmastodon.org/spec/activitypub/#sanitization
|
||||||
|
// - https://blog.joinmastodon.org/2018/06/how-to-implement-a-basic-activitypub-server/
|
||||||
|
//
|
||||||
|
// Microformats:
|
||||||
|
// - https://microformats.org/wiki/
|
||||||
|
// - https://indieweb.org/note
|
||||||
|
// - https://docs.joinmastodon.org/spec/microformats/
|
||||||
|
//
|
||||||
|
function messageToHtml(message, remoteActor) {
|
||||||
|
const msg = encode(stripAnsiControlCodes(message.message.trim()), {
|
||||||
|
mode: 'nonAsciiPrintable',
|
||||||
|
}).replace(/\r?\n/g, '<br>');
|
||||||
|
|
||||||
|
if (message.isPrivate()) {
|
||||||
|
const toId = remoteActor.id;
|
||||||
|
return `<p>
|
||||||
|
<span class="h-card">
|
||||||
|
<a href="${toId}" class="u-url mention">@ <span>${remoteActor.preferredUsername}</span></a>
|
||||||
|
</span>
|
||||||
|
${msg}
|
||||||
|
</p>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return `<p>${msg}</p>`;
|
||||||
|
}
|
||||||
|
|
||||||
function htmlToMessageBody(html) {
|
function htmlToMessageBody(html) {
|
||||||
// <br>, </br>, and <br />, <br/> -> \r\n
|
// <br>, </br>, and <br />, <br/> -> \r\n
|
||||||
// </p> -> \r\n
|
// </p> -> \r\n
|
||||||
|
|
Loading…
Reference in New Issue