git ssb

1+

punkmonk.termux / mvd



forked from ev / mvd

Commit b4f3d8695bb224e2683bb219880b958f524416eb

add queue functionality

Ev Bogue committed on 10/13/2018, 3:03:07 PM
Parent: 8ff58551ced7bc06366af38dfc920847013609a6

Files changed

index.jschanged
render.jschanged
tools.jschanged
views.jschanged
index.jsView
@@ -50,8 +50,9 @@
5050 })),
5151 h('li', h('a', {href: '#' }, 'All')),
5252 h('li', h('a', {href: '#private' }, 'Private')),
5353 h('li', h('a', {href: '#mentions' }, 'Mentions')),
54+ h('li', h('a', {href: '#queue'}, 'Queue')),
5455 h('li', h('a', {href: '#key' }, 'Key')),
5556 h('li.right', h('a', {href: '#about'}, '?')),
5657 h('form.search', {
5758 onsubmit: function (e) {
render.jsView
@@ -28,18 +28,31 @@
2828 if (cache.mute == true) {
2929 var muted = h('span', ' muted')
3030 message.appendChild(tools.mini(msg, muted))
3131 return message
32- }
32+ }
33+
34+ else if (msg.value.content.type == 'queue') {
35+ if (msg.value.content.queue == true) {
36+ var content = h('span', ' added ', tools.messageLink(msg.value.content.message), ' to their ', h('a', {href: '#queue'}, 'queue'))
37+ message.appendChild(tools.mini(msg, content))
38+ }
39+ if (msg.value.content.queue == false) {
40+ var content = h('span', ' removed ', tools.messageLink(msg.value.content.message), ' from their ', h('a', {href: '#queue'}, 'queue'))
41+ message.appendChild(tools.mini(msg, content))
42+
43+ }
44+ return message
45+ }
46+
3347 else if (msg.value.content.type == 'edit') {
3448 message.appendChild(tools.header(msg))
3549 var current = msg.value.content.text
3650 sbot.get(msg.value.content.updated, function (err, updated) {
3751 if (updated) {
3852 fragment = document.createDocumentFragment()
3953 var previous = updated.content.text
4054 var ready = diff.diffWords(previous, current)
41- console.log(ready)
4255 ready.forEach(function (part) {
4356 if (part.added === true) {
4457 color = 'cyan'
4558 } else if (part.removed === true) {
@@ -305,8 +318,9 @@
305318 message.replaceChild(compose, message.lastElementChild)
306319 }
307320 }))
308321
322+ buttons.appendChild(tools.queueButton(msg))
309323 buttons.appendChild(tools.star(msg))
310324 message.appendChild(buttons)
311325 return message
312326
@@ -323,13 +337,13 @@
323337 return message
324338 } else {
325339
326340 //FULL FALLBACK
327- //message.appendChild(tools.header(msg))
328- //message.appendChild(h('pre', tools.rawJSON(msg.value.content)))
341+ message.appendChild(tools.header(msg))
342+ message.appendChild(h('pre', tools.rawJSON(msg.value.content)))
329343
330344 //MINI FALLBACK
331- var fallback = h('span', ' ' + msg.value.content.type)
332- message.appendChild(tools.mini(msg, fallback))
345+ //var fallback = h('span', ' ' + msg.value.content.type)
346+ //message.appendChild(tools.mini(msg, fallback))
333347 return message
334348 }
335349 }
tools.jsView
@@ -69,12 +69,8 @@
6969 return blocked
7070
7171 }
7272
73-
74-
75-
76-
7773 module.exports.getFollowing = function (src) {
7874 var followingCount = 0
7975
8076 var following = h('div.following', 'Following: ')
@@ -108,8 +104,9 @@
108104 })
109105 )
110106 return following
111107 }
108+
112109 module.exports.getFollowers = function (src) {
113110 var followerCount = 0
114111
115112 var followers = h('div.followers', 'Followers: ')
@@ -145,8 +142,67 @@
145142
146143 return followers
147144 }
148145
146+module.exports.queueButton = function (src) {
147+ var queueButton = h('span.queue:' + src.key.substring(0,44))
148+
149+ var addToQueue = h('button.btn.right', 'Queue', {
150+ onclick: function () {
151+ var content = {
152+ type: 'queue',
153+ message: src.key,
154+ queue: true
155+ }
156+ sbot.publish(content, function (err, publish) {
157+ if (err) throw err
158+ console.log(publish)
159+ })
160+ }
161+ })
162+
163+ var removeFromQueue = h('button.btn.right#', 'Done', {
164+ onclick: function () {
165+ var content = {
166+ type: 'queue',
167+ message: src.key,
168+ queue: false
169+ }
170+ sbot.publish(content, function (err, publish) {
171+ if (err) throw err
172+ console.log(publish)
173+ if (window.location.hash.substring(1) == 'queue') {
174+ setTimeout(function () {
175+ var gotIt = document.getElementById(src.key.substring(0,44))
176+ if (gotIt != null) {
177+ gotIt.outerHTML = ''
178+ }
179+ }, 100)
180+
181+ }
182+ })
183+ }
184+ })
185+
186+ pull(
187+ sbot.query({query: [{$filter: { value: { author: id, content: {type: 'queue', message: src.key}}}}], live: true}),
188+ pull.drain(function (msg) {
189+ if (msg.value) {
190+ if (msg.value.content.queue == true) {
191+ queueButton.replaceChild(removeFromQueue, addToQueue)
192+ }
193+ if (msg.value.content.queue == false) {
194+ queueButton.replaceChild(addToQueue, removeFromQueue)
195+ }
196+ }
197+ })
198+ )
199+
200+ queueButton.appendChild(addToQueue)
201+
202+ return queueButton
203+}
204+
149205 module.exports.follow = function (src) {
150206 var button = h('span.button')
151207
152208 var followButton = h('button.btn', 'Follow ', avatar.name(src), {
views.jsView
@@ -71,8 +71,42 @@
7171 stream.bottom(content)
7272 )
7373 }
7474
75+var queueStream = function () {
76+ var content = h('div.content')
77+ var screen = document.getElementById('screen')
78+ screen.appendChild(hyperscroll(content))
79+
80+ pull(
81+ sbot.query({query: [{$filter: { value: {author: id, content: {type: 'queue'}}}}]}),
82+ pull.drain(function (msg) {
83+ if (msg.value) {
84+ if (ref.isMsg(msg.value.content.message)) {
85+ if (msg.value.content.queue == true) {
86+ sbot.get(msg.value.content.message, function (err, data) {
87+ if (data) {
88+ var message = {}
89+ message.value = data
90+ message.key = msg.value.content.message
91+ content.appendChild(render(message))
92+ }
93+ })
94+ }
95+ if (msg.value.content.queue == false) {
96+ setTimeout(function () {
97+ var gotIt = document.getElementById(msg.value.content.message.substring(0,44))
98+ if (gotIt != null) {
99+ gotIt.outerHTML = ''
100+ }
101+ }, 100)
102+ }
103+ }
104+ }
105+ })
106+ )
107+}
108+
75109 var mentionsStream = function () {
76110 var content = h('div.content')
77111
78112 var screen = document.getElementById('screen')
@@ -544,8 +578,10 @@
544578 } else if (ref.isMsg(src)) {
545579 msgThread(src)
546580 } else if (src == 'mentions') {
547581 mentionsStream()
582+ } else if (src == 'queue') {
583+ queueStream()
548584 } else if (src == 'about') {
549585 about()
550586 } else if (src == 'backchannel') {
551587 backchannel()

Built with git-ssb-web