From 5c5c5091b4b1095af000657ea462d5c652b8d110 Mon Sep 17 00:00:00 2001
From: Niko
Date: Thu, 17 Feb 2022 21:56:23 +0100
Subject: [PATCH] Make pages.meet post expand post "tags" into the HTML
---
api/src/api/feed.js | 11 ++++++++++
web/src/app/js/app.js | 42 +++++++++++++++++++++++++++++++++++-
web/src/app/js/pages/meet.js | 2 +-
3 files changed, 53 insertions(+), 2 deletions(-)
diff --git a/api/src/api/feed.js b/api/src/api/feed.js
index a39eee3..02f69ec 100644
--- a/api/src/api/feed.js
+++ b/api/src/api/feed.js
@@ -18,6 +18,16 @@ module.exports = {
.toArray()
for (var i = 0; i < notes.length; i++) {
const note = notes[i]
+ var tags = []
+ if (note.tag !== undefined) {
+ for (var j = 0; j < note.tag.length; j++) {
+ tags.push({
+ type: note.tag[j].type,
+ href: utils.firstIfArray(note.tag[j].href),
+ name: utils.firstIfArray(note.tag[j].name),
+ })
+ }
+ }
results.push({
_id: note._id,
text: utils.firstIfArray(note.content),
@@ -25,6 +35,7 @@ module.exports = {
account: await api.accounts.getAccount(
utils.firstIfArray(note.attributedTo)
),
+ tags,
})
}
return res.json(results)
diff --git a/web/src/app/js/app.js b/web/src/app/js/app.js
index e904723..ef94f5f 100644
--- a/web/src/app/js/app.js
+++ b/web/src/app/js/app.js
@@ -108,7 +108,47 @@ app.storage = {
localStorage['fedilove'] = JSON.stringify(js);
return true;
},
-};
+}
+
+app.post = {
+ prepare4html: function(value, tags) {
+ tags = tags || [];
+ console.log(value);
+ value = value.replaceAll('', ' ')
+ .replaceAll(/\s+/g, ' ');
+ value = value.replaceAll('
', '{:br:}{:br:}');
+ value = html2text(value).replaceAll(/\s+/g, ' ')+' ';
+ var replaceAfter = [];
+ for (var i = 0; i < tags.length; i++) {
+ if (tags[i].type.toLowerCase().trim() === 'mention') {
+ var acct = tags[i].name;
+ var href = tags[i].href;
+ if (acct === undefined || href === undefined)
+ continue;
+ if (!acct.match(/^@[^@]+@[^@]+$/))
+ continue;
+ acct = acct.trim().substr(1);
+ href = href.trim();
+ const ps = acct.split('@');
+ const link = '@'+
+ htmlescape(acct) + '';
+ replaceAfter.push(['@'+ps[0], link]);
+ replaceAfter.push(['@'+acct, link]);
+ }
+ }
+ value = html2text(value);
+ for (var i = 0; i < replaceAfter.length; i++) {
+ const it = replaceAfter[i];
+ value = value.replaceAll(it[0], it[1]);
+ }
+ value = value.replaceAll('{:br:}', '
');
+ value = value.trim().replaceAll(/
$/g, '');
+ console.log(value);
+ console.log(tags);
+ console.log('----');
+ return value;
+ },
+}
app.overlay = {
hideAll: function() {
diff --git a/web/src/app/js/pages/meet.js b/web/src/app/js/pages/meet.js
index 2efb639..48bf6ef 100644
--- a/web/src/app/js/pages/meet.js
+++ b/web/src/app/js/pages/meet.js
@@ -56,7 +56,7 @@ app.pages.meet = {
var tpl = app.template.fill(item, app.template.get('meet.item'),
function (k,v) {
- if (k === 'text') return html2text(v);
+ if (k === 'text') return app.post.prepare4html(item.text, item.tags);
if (k === 'account.name') return capitalize(v);
if (k === 'date') return dayjs(v).fromNow(true);
});