From f97cda0d14184878c8466409c588de39a7651b15 Mon Sep 17 00:00:00 2001 From: cel Date: Tue, 24 Mar 2020 14:11:12 -0400 Subject: Reduce mentions Save message size by changing {link: id} to id --- lib/serve.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'lib/serve.js') diff --git a/lib/serve.js b/lib/serve.js index 452cad4..e05cc56 100644 --- a/lib/serve.js +++ b/lib/serve.js @@ -60,6 +60,14 @@ function uniques() { } } +function reduceLink(link) { + return link + && typeof link.link === 'string' + && typeof link.name === 'undefined' + && Object.keys(link).length === 1 + ? link.link : link +} + function Serve(app, req, res) { this.app = app this.req = req @@ -1462,7 +1470,7 @@ Serve.prototype.editGathering = function (url) { // don't mention ids already mentioned in the thread textMentions.forEach(function (link) { if (mentions.indexOf(link.link) === -1) { - mentions.push(link) + mentions.push(reduceLink(link)) } }) } @@ -1611,6 +1619,7 @@ Serve.prototype.newGathering = function () { if (description) { content.description = description var mentions = ssbMentions(description, {bareFeedNames: false, emoji: false}) + .map(reduceLink) if (mentions.length) content.mentions = mentions } if (startDateTime) content.startDateTime = startDateTime @@ -4501,6 +4510,8 @@ Serve.prototype.composer = function (opts, cb) { } return true }) + .map(reduceLink) + if (mentions.length) content.mentions = mentions if (data.recps != null) { if (opts.recps) return cb(new Error('got recps in opts and data')) @@ -4555,7 +4566,7 @@ Serve.prototype.composer = function (opts, cb) { alreadyMentioned[id] = true }) attendeeLinks.forEach(function (link) { - if (!alreadyMentioned[link.link]) content.mentions.push(link) + if (!alreadyMentioned[link]) content.mentions.push(link) }) } } -- cgit v1.2.3