diff --git a/src/modules/statuses.js b/src/modules/statuses.js
index 6c760eedba..12e1bc29d9 100644
--- a/src/modules/statuses.js
+++ b/src/modules/statuses.js
@@ -83,6 +83,24 @@ export const defaultState = {
}
}
+const greentextify = (shtml) => {
+ let rows = []
+ const removeMastodon = shtml.replace(/
/g, '
')
+ .replace(/
/g, '')
+ .replace(/<\/p>/g, '
')
+ each(removeMastodon.split('
'), (row) => {
+ row = row.replace('\n', '').replace('', '').replace('', '')
+ if (row.match(/^[ ]?>/)) {
+ rows.push(`${row}
`)
+ } else if (row.match(/^[ ]?</)) {
+ rows.push(`${row}
`)
+ } else {
+ rows.push(`${row}
`)
+ }
+ })
+ return rows.join('').replace('
', '
')
+}
+
const isNsfw = (status) => {
const nsfwRegex = /#nsfw/i
return includes(status.tags, 'nsfw') || !!status.text.match(nsfwRegex)
@@ -94,6 +112,12 @@ export const prepareStatus = (status) => {
status.nsfw = isNsfw(status)
}
+ // add greentext
+ if (!status.greentextified) {
+ status.statusnet_html = greentextify(status.statusnet_html)
+ status.greentextified = true
+ }
+
// Set deleted flag
status.deleted = false
@@ -137,10 +161,13 @@ const mergeOrAdd = (arr, obj, item) => {
const oldItem = obj[item.id]
if (oldItem) {
+ // save the greentext to avoid re-processing
+ const greentext = oldItem.statusnet_html
// We already have this, so only merge the new info.
merge(oldItem, item)
// Reactivity fix.
oldItem.attachments.splice(oldItem.attachments.length)
+ oldItem.statusnet_html = greentext
return {item: oldItem, new: false}
} else {
// This is a new item, prepare it