app/html/sideNav/sideNavDiscovery.jsView |
---|
71 | 71 | cache.delete(msg.key) |
72 | 72 | } |
73 | 73 | |
74 | 74 | function updateUnreadMsgsCache (msg) { |
75 | | - updateCache(getUnreadMsgsCache(msg.value.author), msg) |
76 | | - updateCache(getUnreadMsgsCache(msg.value.content.root || msg.key), msg) |
| 75 | + const participantsKey = getParticipants(msg).key |
| 76 | + updateCache(getUnreadMsgsCache(participantsKey), msg) |
| 77 | + |
| 78 | + const rootKey = get(msg, 'value.content.root', msg.key) |
| 79 | + updateCache(getUnreadMsgsCache(rootKey), msg) |
77 | 80 | } |
78 | 81 | |
79 | 82 | pull( |
80 | 83 | next(api.feed.pull.private, {reverse: true, limit: 1000, live: false, property: ['value', 'timestamp']}), |
161 | 164 | filter: privateMsgFilter, |
162 | 165 | store: recentMsgCache, |
163 | 166 | updateTop: updateRecentMsgCache, |
164 | 167 | updateBottom: updateRecentMsgCache, |
165 | | - render: (msgObs) => { |
166 | | - const msg = resolve(msgObs) |
167 | | - const participants = getParticipants(msg) |
168 | | - |
| 168 | + render |
| 169 | + }) |
| 170 | + |
| 171 | + function render (msgObs) { |
| 172 | + const msg = resolve(msgObs) |
| 173 | + const participants = getParticipants(msg) |
| 174 | + |
169 | 175 | |
170 | | - if (participants.length === 1 && nearby.has(participants.key)) return |
171 | | - const locParticipantsKey = get(location, 'participants', []).join(' ') |
| 176 | + if (participants.length === 1 && nearby.has(participants.key)) return |
| 177 | + const locParticipantsKey = get(location, 'participants', []).join(' ') |
172 | 178 | |
173 | | - if (participants.length === 1) { |
174 | | - const author = participants.key |
175 | | - return Option({ |
176 | | - |
177 | | - notifications: notifications(author), |
178 | | - imageEl: api.about.html.avatar(author), |
179 | | - label: api.about.obs.name(author), |
180 | | - selected: locParticipantsKey === author, |
181 | | - location: Object.assign({}, msg, { participants }) |
182 | | - }) |
183 | | - } |
184 | | - else { |
185 | | - return Option({ |
186 | | - |
187 | | - notifications: notifications(participants), |
188 | | - imageEl: participants.map(p => api.about.html.avatar(p, 'halfSmall')), |
189 | | - label: getSubject(msg), |
190 | | - selected: locParticipantsKey === participants.key, |
191 | | - location: Object.assign({}, msg, { participants }) |
192 | | - }) |
193 | | - |
194 | | - function getSubject (msg) { |
195 | | - var subject = get(msg, 'value.content.subject') |
196 | | - |
197 | | - if (!subject) subject = msg.value.content.text.splice(0, 24) |
198 | | - return subject |
199 | | - } |
200 | | - } |
| 179 | + if (participants.length === 1) { |
| 180 | + const author = participants[0] |
| 181 | + return Option({ |
| 182 | + |
| 183 | + notifications: notifications(author), |
| 184 | + imageEl: api.about.html.avatar(author), |
| 185 | + label: api.about.obs.name(author), |
| 186 | + selected: locParticipantsKey === author, |
| 187 | + location: Object.assign({}, msg, { participants }) |
| 188 | + }) |
201 | 189 | } |
202 | | - }) |
| 190 | + else { |
| 191 | + const rootMsg = get(msg, 'value.content.root', msg) |
| 192 | + return Option({ |
| 193 | + |
| 194 | + notifications: notifications(participants), |
| 195 | + imageEl: participants.map(p => api.about.html.avatar(p, 'halfSmall')), |
| 196 | + label: api.message.html.subject(rootMsg), |
| 197 | + selected: locParticipantsKey === participants.key, |
| 198 | + location: Object.assign({}, msg, { participants }) |
| 199 | + }) |
| 200 | + } |
| 201 | + } |
203 | 202 | |
204 | 203 | function updateRecentMsgCache (soFar, newMsg) { |
205 | 204 | soFar.transaction(() => { |
206 | 205 | const { timestamp } = newMsg.value |
241 | 240 | return cache |
242 | 241 | } |
243 | 242 | |
244 | 243 | function notifications (key) { |
| 244 | + key = typeof key === 'string' |
| 245 | + ? key |
| 246 | + : key.key |
245 | 247 | return computed(getUnreadMsgsCache(key), cache => cache.length) |
246 | 248 | } |
247 | 249 | |
248 | 250 | function LevelTwoSideNav () { |
275 | 277 | ), |
276 | 278 | store: userLastMsgCache, |
277 | 279 | updateTop: updateLastMsgCache, |
278 | 280 | updateBottom: updateLastMsgCache, |
279 | | - render: (rootMsgObs) => { |
280 | | - const rootMsg = resolve(rootMsgObs) |
281 | | - const participants = getParticipants(rootMsg) |
282 | | - return Option({ |
283 | | - notifications: notifications(rootMsg.key), |
284 | | - label: api.message.html.subject(rootMsg), |
285 | | - selected: rootMsg.key === root, |
286 | | - location: Object.assign(rootMsg, { participants }), |
287 | | - }) |
288 | | - } |
| 281 | + render |
289 | 282 | }) |
290 | 283 | |
| 284 | + function render (rootMsgObs) { |
| 285 | + const rootMsg = resolve(rootMsgObs) |
| 286 | + const participants = getParticipants(rootMsg) |
| 287 | + return Option({ |
| 288 | + notifications: notifications(rootMsg.key), |
| 289 | + label: api.message.html.subject(rootMsg), |
| 290 | + selected: rootMsg.key === root, |
| 291 | + location: Object.assign(rootMsg, { participants }), |
| 292 | + }) |
| 293 | + } |
| 294 | + |
291 | 295 | function updateLastMsgCache (soFar, newMsg) { |
292 | 296 | soFar.transaction(() => { |
293 | 297 | const { timestamp } = newMsg.value |
294 | 298 | const index = indexOf(soFar, (msg) => timestamp === resolve(msg).value.timestamp) |
339 | 343 | pull.filter(msg => msg.value.content.type === 'post'), |
340 | 344 | pull.filter(msg => msg.value.content.recps) |
341 | 345 | ) |
342 | 346 | } |
343 | | - |
344 | 347 | } |
345 | 348 | } |
346 | 349 | |
347 | 350 | function indexOf (array, fn) { |