Vue.component('tf-message', { props: ['message', 'messages', 'votes'], data: function() { return { showRaw: false } }, computed: { content_json: function() { try { return JSON.parse(this.message.content); } catch { return undefined; } }, sub_messages: function() { var id = this.message.id; return this.messages.filter(function (x) { try { return JSON.parse(x.content).root == id; } catch {} }); }, votes2: function() { var id = this.message.id; var votes = this.votes[id] || []; return votes.reduce(function (accum, value) { var expression = JSON.parse(value.content).vote.expression; if (!accum[expression]) { accum[expression] = []; } accum[expression].push(value); return accum; }, {}); } }, methods: { markdown: function(md) { var reader = new commonmark.Parser({safe: true}); var writer = new commonmark.HtmlRenderer(); return writer.render(reader.parse(md)); }, json: function(message) { try { return JSON.parse(message.content); } catch { return undefined; } }, }, template: `

{{new Date(message.timestamp)}}
more_vert View Raw View Message
{{message.content}}
{{content_json.name || 'tildefriends-app'}}
{{content_json.following ? '==>' : '=/=>'}}
{{message.content}}
{{vote + (votes2[vote].length > 1 ? ' (' + votes2[vote].length + ')' : '')}}
`, });