aboutsummaryrefslogtreecommitdiff
path: root/lib/render-msg.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/render-msg.js')
-rw-r--r--lib/render-msg.js78
1 files changed, 58 insertions, 20 deletions
diff --git a/lib/render-msg.js b/lib/render-msg.js
index 72b8015..8346baf 100644
--- a/lib/render-msg.js
+++ b/lib/render-msg.js
@@ -147,8 +147,14 @@ RenderMsg.prototype.actions = function () {
h('a', {href: '?gt=' + this.msg.timestamp}, '↓'), ' '] : '',
this.c.type === 'gathering' ? [
h('a', {href: this.render.toUrl('/about/' + encodeURIComponent(this.msg.key))}, 'about'), ' '] : '',
- h('a', {href: this.toUrl(this.msg.key) + '?raw'}, 'raw'), ' ',
- this.voteFormInner('dig')
+ typeof this.c.text === 'string' ? [
+ h('a', {href: this.toUrl(this.msg.key) + '?raw=md',
+ title: 'view markdown source'}, 'md'), ' '] : '',
+ h('a', {href: this.toUrl(this.msg.key) + '?raw',
+ title: 'view raw message'}, 'raw'), ' ',
+ this.buttonsCommon(),
+ this.c.type === 'gathering' ? [this.attendButton(), ' '] : '',
+ this.voteButton('dig')
) : [
this.msg.rel ? [this.msg.rel, ' '] : ''
]
@@ -175,16 +181,29 @@ RenderMsg.prototype.recpsIds = function () {
: []
}
-RenderMsg.prototype.voteFormInner = function (expression) {
+RenderMsg.prototype.buttonsCommon = function () {
var chan = this.msg.value.content.channel
+ var recps = this.recpsIds()
return [
- h('input', {type: 'hidden', name: 'action', value: 'vote'}),
- h('input', {type: 'hidden', name: 'recps',
- value: this.recpsIds().join(',')}),
chan ? h('input', {type: 'hidden', name: 'channel', value: chan}) : '',
h('input', {type: 'hidden', name: 'link', value: this.msg.key}),
- h('input', {type: 'hidden', name: 'value', value: 1}),
- h('input', {type: 'submit', name: 'expression', value: expression})]
+ h('input', {type: 'hidden', name: 'recps', value: recps.join(',')})
+ ]
+}
+
+RenderMsg.prototype.voteButton = function (expression) {
+ var chan = this.msg.value.content.channel
+ return [
+ h('input', {type: 'hidden', name: 'vote_value', value: 1}),
+ h('input', {type: 'hidden', name: 'vote_expression', value: expression}),
+ h('input', {type: 'submit', name: 'action_vote', value: expression})]
+}
+
+RenderMsg.prototype.attendButton = function () {
+ var chan = this.msg.value.content.channel
+ return [
+ h('input', {type: 'submit', name: 'action_attend', value: 'attend'})
+ ]
}
RenderMsg.prototype.message = function (cb) {
@@ -231,9 +250,21 @@ RenderMsg.prototype.encrypted = function (cb) {
}
RenderMsg.prototype.markdown = function (cb) {
+ if (this.opts.markdownSource)
+ return this.markdownSource(this.c.text, this.c.mentions)
return this.render.markdown(this.c.text, this.c.mentions)
}
+RenderMsg.prototype.markdownSource = function (text, mentions) {
+ return h('div',
+ h('pre', String(text)),
+ mentions ? [
+ h('div', h('em', 'mentions:')),
+ this.valueTable(mentions, function () {})
+ ] : ''
+ ).innerHTML
+}
+
RenderMsg.prototype.post = function (cb) {
var self = this
var done = multicb({pluck: 1, spread: true})
@@ -360,15 +391,27 @@ RenderMsg.prototype.link1 = function (link, cb) {
function dateTime(d) {
var date = new Date(d.epoch)
- return date.toUTCString()
+ return date.toString()
// d.bias
// d.epoch
}
RenderMsg.prototype.about = function (cb) {
- var img = u.linkDest(this.c.image)
var done = multicb({pluck: 1, spread: true})
var elCb = done()
+
+ var isAttendingMsg = u.linkDest(this.c.attendee) === this.msg.value.author
+ && Object.keys(this.c).sort().join() === 'about,attendee,type'
+ if (isAttendingMsg) {
+ var attending = !this.c.attendee.remove
+ this.wrapMini([
+ attending ? ' is attending' : ' is not attending', ' ',
+ this.link1(this.c.about, done())
+ ], elCb)
+ return done(cb)
+ }
+
+ var img = u.linkDest(this.c.image)
// if there is a description, it is likely to be multi-line
var hasDescription = this.c.description != null
var wrap = hasDescription ? this.wrap : this.wrapMini
@@ -493,13 +536,16 @@ RenderMsg.prototype.gitUpdate = function (cb) {
return h('li', h('a', {href: self.render.toUrl(path)},
h('code', String(commit.sha1).substr(0, 8))), ' ',
self.linkify(String(commit.title)),
- self.gitCommitBody(commit.body)
+ self.render.gitCommitBody(commit.body)
)
})) : '',
Array.isArray(self.c.tags) ?
h('ul', self.c.tags.map(function (tag) {
+ var path = '/git/tag/' + encodeURIComponent(tag.sha1)
+ + '?msg=' + encodeURIComponent(self.msg.key)
return h('li',
- h('code', String(tag.sha1).substr(0, 8)), ' ',
+ h('a', {href: self.render.toUrl(path)},
+ h('code', String(tag.sha1).substr(0, 8))), ' ',
'tagged ', String(tag.type), ' ',
h('code', String(tag.object).substr(0, 8)), ' ',
String(tag.tag)
@@ -513,14 +559,6 @@ RenderMsg.prototype.gitUpdate = function (cb) {
})
}
-RenderMsg.prototype.gitCommitBody = function (body) {
- if (!body) return ''
- var isMarkdown = !/^# Conflicts:$/m.test(body)
- return isMarkdown
- ? h('div', {innerHTML: this.render.markdown('\n' + body)})
- : h('pre', this.linkify('\n' + body))
-}
-
RenderMsg.prototype.gitPullRequest = function (cb) {
var self = this
var done = multicb({pluck: 1, spread: true})