@@ -73,7 +73,7 @@ const subscribeInternal = (topic, persist, delaySec) => {
73
73
eventSource . onmessage = ( e ) => {
74
74
const event = JSON . parse ( e . data ) ;
75
75
topics [ topic ] [ 'messages' ] . push ( event ) ;
76
- topics [ topic ] [ 'messages' ] . sort ( ( a , b ) => { return a . time < b . time ; } ) // Newest first
76
+ topics [ topic ] [ 'messages' ] . sort ( ( a , b ) => { return a . time < b . time ? 1 : - 1 ; } ) ; // Newest first
77
77
if ( currentTopic === topic ) {
78
78
rerenderDetailView ( ) ;
79
79
}
@@ -123,7 +123,7 @@ const fetchCachedMessages = async (topic) => {
123
123
const message = JSON . parse ( line ) ;
124
124
topics [ topic ] [ 'messages' ] . push ( message ) ;
125
125
}
126
- topics [ topic ] [ 'messages' ] . sort ( ( a , b ) => { return a . time < b . time ; } ) // Newest first
126
+ topics [ topic ] [ 'messages' ] . sort ( ( a , b ) => { return a . time < b . time ? 1 : - 1 ; } ) ; // Newest first
127
127
} ;
128
128
129
129
const showDetail = ( topic ) => {
@@ -258,27 +258,23 @@ if (!window["Notification"] || !window["EventSource"]) {
258
258
// Reset UI
259
259
topicField . value = "" ;
260
260
261
- // (Temporarily) subscribe topic if we navigated to /sometopic URL
262
- const match = location . pathname . match ( / ^ \/ ( [ - _ a - z A - Z 0 - 9 ] { 1 , 64 } ) $ / ) // Regex must match Go & Android app!
263
- if ( match ) {
264
- currentTopic = match [ 1 ] ;
265
- subscribeInternal ( currentTopic , false , 0 ) ;
266
- }
267
-
268
261
// Restore topics
269
- const storedTopics = localStorage . getItem ( 'topics' ) ;
262
+ const storedTopics = JSON . parse ( localStorage . getItem ( 'topics' ) || "[]" ) ;
270
263
if ( storedTopics ) {
271
- const storedTopicsArray = JSON . parse ( storedTopics ) ;
272
- storedTopicsArray . forEach ( ( topic ) => { subscribeInternal ( topic , true , 0 ) ; } ) ;
273
- if ( storedTopicsArray . length === 0 ) {
264
+ storedTopics . forEach ( ( topic ) => { subscribeInternal ( topic , true , 0 ) ; } ) ;
265
+ if ( storedTopics . length === 0 ) {
274
266
topicsHeader . style . display = 'none' ;
275
267
}
276
- if ( currentTopic ) {
277
- currentTopicUnsubscribeOnClose = ! storedTopicsArray . includes ( currentTopic ) ;
278
- }
279
268
} else {
280
269
topicsHeader . style . display = 'none' ;
281
- if ( currentTopic ) {
270
+ }
271
+
272
+ // (Temporarily) subscribe topic if we navigated to /sometopic URL
273
+ const match = location . pathname . match ( / ^ \/ ( [ - _ a - z A - Z 0 - 9 ] { 1 , 64 } ) $ / ) // Regex must match Go & Android app!
274
+ if ( match ) {
275
+ currentTopic = match [ 1 ] ;
276
+ if ( ! storedTopics . includes ( currentTopic ) ) {
277
+ subscribeInternal ( currentTopic , false , 0 ) ;
282
278
currentTopicUnsubscribeOnClose = true ;
283
279
}
284
280
}
0 commit comments