Commit b4f3d8695bb224e2683bb219880b958f524416eb
add queue functionality
Ev Bogue committed on 10/13/2018, 3:03:07 PMParent: 8ff58551ced7bc06366af38dfc920847013609a6
Files changed
index.js | changed |
render.js | changed |
tools.js | changed |
views.js | changed |
index.js | ||
---|---|---|
@@ -50,8 +50,9 @@ | ||
50 | 50 | })), |
51 | 51 | h('li', h('a', {href: '#' }, 'All')), |
52 | 52 | h('li', h('a', {href: '#private' }, 'Private')), |
53 | 53 | h('li', h('a', {href: '#mentions' }, 'Mentions')), |
54 | + h('li', h('a', {href: '#queue'}, 'Queue')), | |
54 | 55 | h('li', h('a', {href: '#key' }, 'Key')), |
55 | 56 | h('li.right', h('a', {href: '#about'}, '?')), |
56 | 57 | h('form.search', { |
57 | 58 | onsubmit: function (e) { |
render.js | ||
---|---|---|
@@ -28,18 +28,31 @@ | ||
28 | 28 | if (cache.mute == true) { |
29 | 29 | var muted = h('span', ' muted') |
30 | 30 | message.appendChild(tools.mini(msg, muted)) |
31 | 31 | 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 | + | |
33 | 47 | else if (msg.value.content.type == 'edit') { |
34 | 48 | message.appendChild(tools.header(msg)) |
35 | 49 | var current = msg.value.content.text |
36 | 50 | sbot.get(msg.value.content.updated, function (err, updated) { |
37 | 51 | if (updated) { |
38 | 52 | fragment = document.createDocumentFragment() |
39 | 53 | var previous = updated.content.text |
40 | 54 | var ready = diff.diffWords(previous, current) |
41 | - console.log(ready) | |
42 | 55 | ready.forEach(function (part) { |
43 | 56 | if (part.added === true) { |
44 | 57 | color = 'cyan' |
45 | 58 | } else if (part.removed === true) { |
@@ -305,8 +318,9 @@ | ||
305 | 318 | message.replaceChild(compose, message.lastElementChild) |
306 | 319 | } |
307 | 320 | })) |
308 | 321 | |
322 | + buttons.appendChild(tools.queueButton(msg)) | |
309 | 323 | buttons.appendChild(tools.star(msg)) |
310 | 324 | message.appendChild(buttons) |
311 | 325 | return message |
312 | 326 | |
@@ -323,13 +337,13 @@ | ||
323 | 337 | return message |
324 | 338 | } else { |
325 | 339 | |
326 | 340 | //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))) | |
329 | 343 | |
330 | 344 | //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)) | |
333 | 347 | return message |
334 | 348 | } |
335 | 349 | } |
tools.js | ||
---|---|---|
@@ -69,12 +69,8 @@ | ||
69 | 69 | return blocked |
70 | 70 | |
71 | 71 | } |
72 | 72 | |
73 | - | |
74 | - | |
75 | - | |
76 | - | |
77 | 73 | module.exports.getFollowing = function (src) { |
78 | 74 | var followingCount = 0 |
79 | 75 | |
80 | 76 | var following = h('div.following', 'Following: ') |
@@ -108,8 +104,9 @@ | ||
108 | 104 | }) |
109 | 105 | ) |
110 | 106 | return following |
111 | 107 | } |
108 | + | |
112 | 109 | module.exports.getFollowers = function (src) { |
113 | 110 | var followerCount = 0 |
114 | 111 | |
115 | 112 | var followers = h('div.followers', 'Followers: ') |
@@ -145,8 +142,67 @@ | ||
145 | 142 | |
146 | 143 | return followers |
147 | 144 | } |
148 | 145 | |
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 | + | |
149 | 205 | module.exports.follow = function (src) { |
150 | 206 | var button = h('span.button') |
151 | 207 | |
152 | 208 | var followButton = h('button.btn', 'Follow ', avatar.name(src), { |
views.js | ||
---|---|---|
@@ -71,8 +71,42 @@ | ||
71 | 71 | stream.bottom(content) |
72 | 72 | ) |
73 | 73 | } |
74 | 74 | |
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 | + | |
75 | 109 | var mentionsStream = function () { |
76 | 110 | var content = h('div.content') |
77 | 111 | |
78 | 112 | var screen = document.getElementById('screen') |
@@ -544,8 +578,10 @@ | ||
544 | 578 | } else if (ref.isMsg(src)) { |
545 | 579 | msgThread(src) |
546 | 580 | } else if (src == 'mentions') { |
547 | 581 | mentionsStream() |
582 | + } else if (src == 'queue') { | |
583 | + queueStream() | |
548 | 584 | } else if (src == 'about') { |
549 | 585 | about() |
550 | 586 | } else if (src == 'backchannel') { |
551 | 587 | backchannel() |
Built with git-ssb-web