OverviewFilesCommitsIssuesDocsReleasesPeers

apds commits / d55f0d2

add a sort algorithm
d55f0d2370553a09cabd9ea09508b82180ff9a61
by Ev Bogue <ev@evbogue.com> · 2024-12-21T00:27:27.000Z

Changed files (1) +34 -0

bogbot.js +34 -0
……@@ -134,6 +134,7 @@ bogbot.add = async (msg) => {
134134 if (!log.includes(hash)) {
135135 log.push(hash)
136136 newMessages = true
137 sort = true
137138 }
138139 }
139140}
……@@ -149,3 +150,36 @@ bogbot.human = async (ts) => {
149150bogbot.visual = async (pubkey) => {
150151 return vb(decode(pubkey), 256)
151152}
153
154let sort = true
155
156setInterval(async () => {
157 if (sort) {
158 const newArray = []
159
160 await Promise.all(log.map(async (hash) => {
161 const obj = {
162 hash,
163 sig: await bogbot.find(hash)
164 }
165 obj.opened = await bogbot.open(obj.sig)
166 console.log(obj)
167 obj.ts = obj.opened.substring(0, 13)
168 newArray.push(obj)
169 }))
170
171 await newArray.sort((a,b) => a.ts - b.ts)
172 console.log(newArray)
173
174 const newLog = []
175
176 await newArray.forEach(msg => {
177 newLog.push(msg.hash)
178 })
179
180 console.log(newLog)
181 log = newLog
182 newMessages = true
183 sort = false
184 }
185}, 20000)