about summary refs log tree commit diff
path: root/src/state/models/feeds/posts.ts
diff options
context:
space:
mode:
authorPaul Frazee <pfrazee@gmail.com>2023-04-19 20:11:10 -0500
committerGitHub <noreply@github.com>2023-04-19 20:11:10 -0500
commit04e0ebe8fc4ec32501cc4138e0357308a171807c (patch)
tree23b6b56aa5517796f3352d59ca47aa4804270a39 /src/state/models/feeds/posts.ts
parentb24ba3adc93cf940eb936309ae73a2c205eaef24 (diff)
downloadvoidsky-04e0ebe8fc4ec32501cc4138e0357308a171807c.tar.zst
Feed and notifs improvements (#498)
* Reduce frequency of the notifications sync

* Reduce frequency of home feed polling

* Ensure loading spinner is visible in notifications

* Render notifications loading spinner in the flatlist

* Fixes and performance improvements to notifications

* Render 30+ on notifications if at max

* Fix issue with repeating posts in home feed

* Dont check for unread notifs if we're already at max
Diffstat (limited to 'src/state/models/feeds/posts.ts')
-rw-r--r--src/state/models/feeds/posts.ts47
1 files changed, 16 insertions, 31 deletions
diff --git a/src/state/models/feeds/posts.ts b/src/state/models/feeds/posts.ts
index e3328c71a..38faf658a 100644
--- a/src/state/models/feeds/posts.ts
+++ b/src/state/models/feeds/posts.ts
@@ -237,7 +237,6 @@ export class PostsFeedModel {
 
   // data
   slices: PostsFeedSliceModel[] = []
-  nextSlices: PostsFeedSliceModel[] = []
 
   constructor(
     public rootStore: RootStoreModel,
@@ -309,7 +308,6 @@ export class PostsFeedModel {
     this.loadMoreCursor = undefined
     this.pollCursor = undefined
     this.slices = []
-    this.nextSlices = []
     this.tuner.reset()
   }
 
@@ -461,30 +459,27 @@ export class PostsFeedModel {
     }
     const res = await this._getFeed({limit: PAGE_SIZE})
     const tuner = new FeedTuner()
-    const nextSlices = tuner.tune(res.data.feed, this.feedTuners)
-    if (nextSlices[0]?.uri !== this.slices[0]?.uri) {
-      const nextSlicesModels = nextSlices.map(
-        slice =>
-          new PostsFeedSliceModel(
-            this.rootStore,
-            `item-${_idCounter++}`,
-            slice,
-          ),
-      )
-      if (autoPrepend) {
+    const slices = tuner.tune(res.data.feed, this.feedTuners)
+    if (slices[0]?.uri !== this.slices[0]?.uri) {
+      if (!autoPrepend) {
+        this.setHasNewLatest(true)
+      } else {
+        this.setHasNewLatest(false)
         runInAction(() => {
-          this.slices = nextSlicesModels.concat(
+          const slicesModels = slices.map(
+            slice =>
+              new PostsFeedSliceModel(
+                this.rootStore,
+                `item-${_idCounter++}`,
+                slice,
+              ),
+          )
+          this.slices = slicesModels.concat(
             this.slices.filter(slice1 =>
-              nextSlicesModels.find(slice2 => slice1.uri === slice2.uri),
+              slicesModels.find(slice2 => slice1.uri === slice2.uri),
             ),
           )
-          this.setHasNewLatest(false)
-        })
-      } else {
-        runInAction(() => {
-          this.nextSlices = nextSlicesModels
         })
-        this.setHasNewLatest(true)
       }
     } else {
       this.setHasNewLatest(false)
@@ -492,16 +487,6 @@ export class PostsFeedModel {
   }
 
   /**
-   * Sets the current slices to the "next slices" loaded by checkForLatest
-   */
-  resetToLatest() {
-    if (this.nextSlices.length) {
-      this.slices = this.nextSlices
-    }
-    this.setHasNewLatest(false)
-  }
-
-  /**
    * Removes posts from the feed upon deletion.
    */
   onPostDeleted(uri: string) {