git ssb

1+

punkmonk.termux / mvd



forked from ev / mvd

Commit 7cef8be38fc2c78136c3f41f4660b0f3fc977aa6

tentatively working mutable message workflow

Ev Bogue committed on 5/27/2018, 7:04:36 PM
Parent: 7d5a6c42f951bd0c0058b63df1d23c59abe68941

Files changed

compose.jschanged
index.jschanged
render.jschanged
compose.jsView
@@ -36,34 +36,35 @@
3636 }
3737 }))
3838 }
3939
40-module.exports = function (opts, buttons) {
40+module.exports = function (opts, fallback) {
4141 var files = []
4242 var filesById = {}
4343
44- console.log(opts)
45-
4644 var composer = h('div.composer')
4745 var container = h('div.container')
4846
49- if (opts.messageText)
50- var textarea = h('textarea.compose', opts.messageText)
47+ if (opts.type == 'post')
48+ var textarea = h('textarea.compose', {placeholder: opts.placeholder || 'Write a message'})
5149 else
52- var textarea = h('textarea.compose', {placeholder: opts.placeholder || 'Write a message'})
50+ var textarea = h('textarea.compose', {placeholder: opts.placeholder || 'Write a message'}, fallback.messageText)
5351
5452 var cancelBtn = h('button.btn', 'Cancel', {
5553 onclick: function () {
5654 var cancel
57- if (opts.updated) {
58- cancel = document.getElementById(opts.updated.substring(0,10))
59- var oldMessage = h('div.message__body', tools.markdown(opts.messageText))
55+ console.log(opts)
56+ if (opts.type == 'edit') {
57+ cancel = document.getElementById('edit:' + opts.branch.substring(0,44))
58+ var oldMessage = h('div.message__body', tools.markdown(fallback.messageText))
6059 cancel.parentNode.replaceChild(oldMessage, cancel)
61- oldMessage.parentNode.appendChild(buttons)
60+ oldMessage.parentNode.appendChild(fallback.buttons)
6261 } else if (opts.branch) {
63- cancel = document.getElementById(opts.branch.substring(0,10))
62+ //cancel reply composer
63+ cancel = document.getElementById('re:' + opts.branch.substring(0,44))
6464 cancel.parentNode.removeChild(cancel)
6565 } else {
66+ // cancel generic composer
6667 cancel = document.getElementById('composer')
6768 cancel.parentNode.removeChild(cancel)
6869 }
6970 }
@@ -103,20 +104,21 @@
103104 if (msg.value.content) {
104105 sbot.publish(msg.value.content, function (err, msg) {
105106 if(err) throw err
106107 console.log('Published!', msg)
107- if (opts.type == 'update') {
108- var originalMessage = document.getElementById(opts.updated.substring(0,10))
109- opts.messageText = msg.value.content.text
110- var newMessage = h('div.message__body',
108+ if (opts.type == 'edit') {
109+ var message = document.getElementById(opts.branch.substring(0,44))
110+ fallback.messageText = msg.value.content.text
111+ var editBody = h('div.message__body',
111112 tools.timestamp(msg, {edited: true}),
112113 h('div', tools.markdown(msg.value.content.text))
113114 )
114- originalMessage.parentNode.replaceChild(newMessage, originalMessage)
115- newMessage.parentNode.appendChild(buttons)
115+
116+ message.replaceChild(editBody, message.childNodes[message.childNodes.length - 1])
117+ editBody.parentNode.appendChild(fallback.buttons)
116118 } else {
117119 if (opts.branch)
118- cancel = document.getElementById(opts.branch.substring(0,10))
120+ cancel = document.getElementById('re:' + opts.branch.substring(0,44))
119121 else
120122 cancel = document.getElementById('composer')
121123 cancel.parentNode.removeChild(cancel)
122124 }
index.jsView
@@ -21,9 +21,13 @@
2121 var currentScreen = document.getElementById('screen')
2222 var opts = {}
2323 opts.type = 'post'
2424 var composer = h('div.content#composer', h('div.message', compose(opts)))
25- currentScreen.firstChild.insertBefore(composer, currentScreen.firstChild.firstChild)
25+ if (currentScreen.firstChild.firstChild) {
26+ currentScreen.firstChild.insertBefore(composer, currentScreen.firstChild.firstChild)
27+ } else {
28+ currentScreen.firstChild.appendChild(composer)
29+ }
2630 }
2731 }
2832 })),
2933 h('li', h('a', {href: '#'}, 'Public')),
render.jsView
@@ -8,72 +8,73 @@
88
99 var config = require('./config')()
1010 var id = require('./keys').id
1111
12+
1213 module.exports = function (msg) {
13- var edit = {}
14- var reply = {}
14+ console.log(msg)
15+ var message = h('div.message#' + msg.key.substring(0, 44))
16+ if (msg.value.content.type == 'post') {
17+ var opts = {}
18+ var fallback = {}
1519
16- var message = h('div.message')
20+ opts.type = 'post'
21+ opts.branch = msg.key
1722
18- if (msg.value.content.type == 'post') {
19- reply.type = 'post'
20- reply.branch = msg.key
21-
2223 if (msg.value.content.root)
23- reply.root = msg.value.content.root
24+ opts.root = msg.value.content.root
2425 else
25- reply.root = msg.key
26-
27- if (msg.value.author == id)
28- edit.original = msg.key
29- edit.type = 'update'
30- edit.updated = msg.key
31- edit.messageText = msg.value.content.text
26+ opts.root = msg.key
3227
3328 message.appendChild(tools.header(msg))
3429
35- if (msg.value.content.root) {
30+ if (msg.value.content.root)
3631 message.appendChild(h('span', 're: ', tools.messageLink(msg.value.content.root)))
37- }
3832
39- message.appendChild(
40- h('div.message__body', tools.markdown(msg.value.content.text))
41- )
33+ message.appendChild(h('div.message__body', tools.markdown(msg.value.content.text)))
4234
35+
4336 pull(
44- sbot.query({query: [{$filter: {value: {content: {type: 'update', updated: msg.key}}}}]}),
37+ sbot.query({query: [{$filter: {value: {content: {type: 'edit', original: msg.key}}}}]}),
4538 pull.drain(function (update) {
4639 var newMessage = h('div', tools.markdown(update.value.content.text))
4740 var latest = h('div.message__body',
48- tools.timestamp(msg, {edited: true}),
41+ tools.timestamp(update, {edited: true}),
4942 newMessage
5043 )
51- var r = message.childNodes.length - 2
52- message.replaceChild(latest, message.childNodes[r])
53- edit.messageText = update.value.content.text
54- edit.original = msg.value.content.original
44+ message.replaceChild(latest, message.childNodes[message.childNodes.length - 2])
45+ fallback.messageText = update.value.content.text
46+ opts.updated = update.key
47+ opts.original = msg.key
5548 })
5649 )
50+
5751 var buttons = h('div.buttons')
5852 buttons.appendChild(h('button.btn', 'Reply', {
5953 onclick: function () {
6054 var r = message.childNodes.length - 1
61- buttons = message.childNodes[r]
62- //fallback = message.lastElementChild
63- //console.log(fallback)
64- var compose = h('div.message#' + reply.branch.substring(0, 10), composer(reply, buttons))
65- message.parentNode.appendChild(compose)
66- //message.replaceChild(compose, message.lastElementChild)
55+
56+ fallback.buttons = message.childNodes[r]
57+ var compose = h('div.message#re:' + msg.key.substring(0, 44), composer(opts, fallback))
58+ message.parentNode.insertBefore(compose, message.nextSibling)
6759 }
6860 }))
61+
6962 if (msg.value.author == id)
7063 buttons.appendChild(h('button.btn', 'Edit', {
7164 onclick: function () {
65+ opts.type = 'edit'
66+ if (!fallback.messageText)
67+ fallback.messageText = msg.value.content.text
68+
69+ if (!opts.updated)
70+ opts.updated = msg.key
71+ opts.original = msg.key
72+
7273 var r = message.childNodes.length - 1
73- buttons = message.childNodes[r]
74+ fallback.buttons = message.childNodes[r]
7475 message.removeChild(message.childNodes[r])
75- var compose = h('div#' + edit.updated.substring(0, 10), composer(edit, buttons))
76+ var compose = h('div#edit:' + msg.key.substring(0, 44), composer(opts, fallback))
7677 message.replaceChild(compose, message.lastElementChild)
7778 }
7879 }))
7980
@@ -105,7 +106,7 @@
105106 } else {
106107 //message.appendChild(tools.header(msg))
107108 //message.appendChild(h('pre', tools.rawJSON(msg.value.content)))
108109 //return message
109- return
110+ return h('div.invisibleMessage')
110111 }
111112 }

Built with git-ssb-web