aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/app.js20
-rw-r--r--lib/serve.js58
2 files changed, 78 insertions, 0 deletions
diff --git a/lib/app.js b/lib/app.js
index 9cc80e4..0eb576e 100644
--- a/lib/app.js
+++ b/lib/app.js
@@ -1334,6 +1334,26 @@ App.prototype.getLinks = function (id) {
})
}
+App.prototype.getLinks2 = function (id, relOrType) {
+ return this.sbot.backlinks ? this.sbot.backlinks.read({
+ query: [
+ {$filter: {
+ dest: id,
+ value: {
+ content: {
+ type: relOrType
+ }
+ }
+ }}
+ ]
+ }) : this.sbotLinks({
+ dest: id,
+ meta: false,
+ values: true,
+ rel: relOrType
+ })
+}
+
App.prototype.getShard = function (id, cb) {
var self = this
this.getMsgDecrypted(id, function (err, msg) {
diff --git a/lib/serve.js b/lib/serve.js
index f037783..b5ca5a3 100644
--- a/lib/serve.js
+++ b/lib/serve.js
@@ -1403,6 +1403,7 @@ Serve.prototype.streamThreadWithComposer = function (opts) {
root: threadRootId,
post: id,
branches: branches,
+ links: links,
postBranches: threadRootId !== id && threadHeads(links, id, threadHeadsOpts),
placeholder: opts.placeholder,
channel: channel,
@@ -3418,6 +3419,7 @@ Serve.prototype.wrapThread = function (opts) {
branches: opts.branches,
postBranches: opts.postBranches,
recps: recps,
+ links: opts.links,
private: opts.recps != null,
}, function (err, composer) {
if (err) return cb(err)
@@ -3562,6 +3564,7 @@ Serve.prototype.composer = function (opts, cb) {
opts = opts || {}
var data = self.data
var myId = self.app.sbot.id
+ var links = opts.links || []
if (opts.id && data.composer_id && opts.id !== data.composer_id) {
// don't share data between multiple composers
@@ -3908,6 +3911,20 @@ Serve.prototype.composer = function (opts, cb) {
})
if (Object.keys(reply).length > 0) content.reply = reply
}
+
+ if (data.mention_attendees) {
+ var attendeeLinks = u.toLinkArray(String(data.attendees || '').split(','))
+ if (!content.mentions) content.mentions = attendeeLinks
+ else {
+ var alreadyMentioned = {}
+ content.mentions.map(u.linkDest).forEach(function (id) {
+ alreadyMentioned[id] = true
+ })
+ attendeeLinks.forEach(function (link) {
+ if (!alreadyMentioned[link.link]) content.mentions.push(link)
+ })
+ }
+ }
if (data.content_warning) content.contentWarning = String(data.content_warning)
if (channel) content.channel = data.channel
@@ -3936,6 +3953,47 @@ Serve.prototype.composer = function (opts, cb) {
return container
}
+ function mentionAttendeesCheckbox(cb) {
+ var container = h('div')
+ if (opts.root) self.getMsgDecryptedMaybeOoo(opts.root, function (err, rootMsg) {
+ if (err) return console.trace(err), cb(null)
+ var rootC = rootMsg && rootMsg.value.content && rootMsg.value.content
+ if (!rootC) return cb(null)
+ var canMentionAttendees = rootC.type === 'gathering'
+ if (!canMentionAttendees) return cb(null)
+ if (opts.id === opts.root) gotLinks(null, links)
+ else pull(
+ self.app.getLinks2(opts.root, 'about'),
+ pull.unique('key'),
+ self.app.unboxMessages(),
+ pull.collect(gotLinks)
+ )
+ function gotLinks(err, links2) {
+ if (err) console.trace(err), links2 = links
+ var attendees = {}
+ links2.forEach(function (link) {
+ var c = link && link.value && link.value.content
+ var attendee = c && c.type === 'about' && c.about === opts.root
+ && u.toLink(c.attendee)
+ if (!attendee) return
+ var author = link.value.author
+ if (attendee.link !== author) return
+ if (attendee.remove) delete attendees[author]
+ else attendees[author] = true
+ })
+ var attendeeIds = Object.keys(attendees)
+ container.appendChild(h('label', {for: 'mention_attendees'},
+ h('input', {id: 'mention_attendees', type: 'checkbox', name: 'mention_attendees', value: 'post', checked: data.mention_attendees || undefined}),
+ ' mention attendees (' + attendeeIds.length + ')',
+ h('input', {type: 'hidden', name: 'attendees', value: attendeeIds.join(',')})
+ ))
+ cb(null)
+ }
+ })
+ else cb(null)
+ return container
+ }
+
function preview(raw, cb) {
var msgContainer = h('table.ssb-msgs')
var contentInput = h('input', {type: 'hidden', name: 'content'})