Commit 6bd197c0cc188a18da533f350d325a6b093eb085
first stab at diff messages
Ev Bogue committed on 8/8/2018, 8:01:33 PMParent: b30c4cc0dca27a87a4ff0e701383c4d9c13ea4c6
Files changed
render.js | changed |
render.js | ||
---|---|---|
@@ -9,15 +9,18 @@ | ||
9 | 9 | var config = require('./config')() |
10 | 10 | var id = require('./keys').id |
11 | 11 | var avatar = require('./avatar') |
12 | 12 | |
13 | +var diff = require('diff') | |
14 | + | |
13 | 15 | function hash () { |
14 | 16 | return window.location.hash.substring(1) |
15 | 17 | } |
16 | 18 | |
17 | 19 | module.exports = function (msg) { |
18 | 20 | var message = h('div.message#' + msg.key.substring(0, 44)) |
19 | 21 | |
22 | + | |
20 | 23 | if (!localStorage[msg.value.author]) |
21 | 24 | var cache = {mute: false} |
22 | 25 | else |
23 | 26 | var cache = JSON.parse(localStorage[msg.value.author]) |
@@ -26,8 +29,36 @@ | ||
26 | 29 | var muted = h('span', ' muted') |
27 | 30 | message.appendChild(tools.mini(msg, muted)) |
28 | 31 | return message |
29 | 32 | } |
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 | + | |
30 | 61 | else if (msg.value.content.type == 'scat_message') { |
31 | 62 | var src = hash() |
32 | 63 | if (src != 'backchannel') { |
33 | 64 | message.appendChild(h('button.btn.right', h('a', {href: '#backchannel'}, 'Chat'))) |
@@ -77,12 +108,14 @@ | ||
77 | 108 | ) |
78 | 109 | message.appendChild(cloneurl) |
79 | 110 | |
80 | 111 | 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 | + }) | |
81 | 116 | |
82 | - msg.value.content.commits.map(function (commit) { | |
83 | - commits.appendChild(h('li', h('code', commit.sha1), ' - ', commit.title)) | |
84 | - }) | |
117 | + } | |
85 | 118 | |
86 | 119 | message.appendChild(commits) |
87 | 120 | |
88 | 121 | return message |
Built with git-ssb-web