git ssb

2+

ev / mvd



Commit 6bd197c0cc188a18da533f350d325a6b093eb085

first stab at diff messages

Ev Bogue committed on 8/8/2018, 8:01:33 PM
Parent: b30c4cc0dca27a87a4ff0e701383c4d9c13ea4c6

Files changed

render.jschanged
render.jsView
@@ -9,15 +9,18 @@
99 var config = require('./config')()
1010 var id = require('./keys').id
1111 var avatar = require('./avatar')
1212
13 +var diff = require('diff')
14 +
1315 function hash () {
1416 return window.location.hash.substring(1)
1517 }
1618
1719 module.exports = function (msg) {
1820 var message = h('div.message#' + msg.key.substring(0, 44))
1921
22 +
2023 if (!localStorage[msg.value.author])
2124 var cache = {mute: false}
2225 else
2326 var cache = JSON.parse(localStorage[msg.value.author])
@@ -26,8 +29,36 @@
2629 var muted = h('span', ' muted')
2730 message.appendChild(tools.mini(msg, muted))
2831 return message
2932 }
33 + else if (msg.value.content.type == 'edit') {
34 + message.appendChild(tools.header(msg))
35 + var current = msg.value.content.text
36 + sbot.get(msg.value.content.updated, function (err, updated) {
37 + if (updated) {
38 + fragment = document.createDocumentFragment()
39 + var previous = updated.content.text
40 + var ready = diff.diffWords(previous, current)
41 + console.log(ready)
42 + ready.forEach(function (part) {
43 + if (part.added === true) {
44 + color = 'cyan'
45 + } else if (part.removed === true) {
46 + color = 'gray'
47 + } else {color = 'white'}
48 + var span = h('span')
49 + span.style.color = color
50 + span.appendChild(document.createTextNode(part.value))
51 + fragment.appendChild(span)
52 + })
53 + message.appendChild(h('code', fragment))
54 + }
55 + })
56 + return message
57 + }
58 +
59 +
60 +
3061 else if (msg.value.content.type == 'scat_message') {
3162 var src = hash()
3263 if (src != 'backchannel') {
3364 message.appendChild(h('button.btn.right', h('a', {href: '#backchannel'}, 'Chat')))
@@ -77,12 +108,14 @@
77108 )
78109 message.appendChild(cloneurl)
79110
80111 var commits = h('ul')
112 + if (msg.value.content.commits[0]) {
113 + msg.value.content.commits.map(function (commit) {
114 + commits.appendChild(h('li', h('code', commit.sha1), ' - ', commit.title))
115 + })
81116
82- msg.value.content.commits.map(function (commit) {
83- commits.appendChild(h('li', h('code', commit.sha1), ' - ', commit.title))
84- })
117 + }
85118
86119 message.appendChild(commits)
87120
88121 return message

Built with git-ssb-web