git ssb

0+

alanz / patchwork



forked from Matt McKegg / patchwork

Commit c042715aec13b2e61372d88ff17dea7e4cacecc1

fix handling of realtime channel adding (and channel suggest side effect)

Matt McKegg committed on 6/26/2017, 3:55:14 AM
Parent: a57d294d9379c382e44e72a14e760b7064123545

Files changed

plugs/channel/obs/recent.jschanged
sbot/channels.jschanged
plugs/channel/obs/recent.jsView
@@ -31,32 +31,23 @@
3131
3232 pull(
3333 api.sbot.pull.stream(sbot => sbot.patchwork.channels({live: true})),
3434 pull.drain(msg => {
35- if (!sync()) {
36- channelsLookup.transaction(() => {
37- for (var channel in msg) {
38- var obs = ChannelRef(channel)
39- obs.set({
40- id: channel,
41- updatedAt: msg[channel].timestamp,
42- count: msg[channel].count
43- })
35+ channelsLookup.transaction(() => {
36+ for (var channel in msg) {
37+ var obs = channelsLookup.get(channel)
38+ if (!obs) {
39+ obs = ChannelRef(channel)
4440 channelsLookup.put(channel, obs)
4541 }
46- sync.set(true)
47- })
48- } else {
49- var obs = channelsLookup.get(msg.channel)
50- if (!obs) {
51- obs = ChannelRef(msg.dest)
52- channelsLookup.put(msg.dest, obs)
42+ var count = msg.count != null ? msg.count : obs.count() + 1
43+ var updatedAt = msg[channel].timestamp
44+
45+ obs.set({ id: channel, updatedAt, count })
5346 }
54- obs.set({
55- id: msg.channel,
56- updatedAt: Math.max(resolve(obs.updatedAt), msg.timestamp),
57- count: resolve(obs.count) + 1
58- })
47+ })
48+ if (!sync()) {
49+ sync.set(true)
5950 }
6051 })
6152 )
6253
sbot/channels.jsView
@@ -5,28 +5,29 @@
55 }
66
77 function reduce (result, item) {
88 if (!result) result = {}
9- if (item) {
10- var value = result[item.channel]
11- if (!value) {
12- value = result[item.channel] = {count: 0, timestamp: 0}
9+ if (items) {
10+ for (var channel in item) {
11+ var value = result[channel]
12+ if (!value) {
13+ value = result[channel] = {count: 0, timestamp: 0}
14+ }
15+ value.count += 1
16+ if (item[channel].timestamp > value.timestamp) {
17+ value.timestamp = item[channel].timestamp
18+ }
1319 }
14- value.count += 1
15- if (item.timestamp > value.timestamp) {
16- value.timestamp = item.timestamp
17- }
1820 }
1921 return result
2022 }
2123
2224 function map (msg) {
2325 if (msg.value.content && typeof msg.value.content.channel === 'string') {
2426 var channel = msg.value.content.channel
2527 if (channel.length > 0 && channel.length < 30) {
26- return {
27- channel: channel.replace(/\s/g, ''),
28- timestamp: msg.timestamp
29- }
28+ return [{
29+ [channel.replace(/\s/g, '')]: {timestamp: msg.timestamp}
30+ }]
3031 }
3132 }
3233 }

Built with git-ssb-web