Selaa lähdekoodia

fix params/conditions for backtracking

Mike L 3 vuotta sitten
vanhempi
commit
eb591762d3
2 muutettua tiedostoa jossa 14 lisäystä ja 11 poistoa
  1. 8 6
      dist/twitter.js
  2. 6 5
      src/twitter.ts

+ 8 - 6
dist/twitter.js

@@ -276,7 +276,7 @@ class default_1 {
                     const offset = lock.threads[currentFeed].offset;
                     if (offset > 0)
                         config.since_id = offset;
-                    const getMore = (gotTweets = []) => this.client.get(endpoint, config, (error, tweets) => {
+                    const getMore = (lastTweets = []) => this.client.get(endpoint, config, (error, tweets) => {
                         if (error) {
                             if (error instanceof Array && error.length > 0 && error[0].code === 34) {
                                 logger.warn(`error on fetching tweets for ${currentFeed}: ${JSON.stringify(error)}`);
@@ -289,10 +289,12 @@ class default_1 {
                                 logger.error(`unhandled error on fetching tweets for ${currentFeed}: ${JSON.stringify(error)}`);
                             }
                         }
-                        if (!tweets || tweets.length <= 1)
-                            return resolve(gotTweets);
-                        config.max_id = tweets.slice(-1)[0].id_str;
-                        getMore(gotTweets.concat(tweets));
+                        if (!(tweets instanceof Array) || tweets.length === 0)
+                            return resolve(lastTweets);
+                        if (offset <= 0)
+                            return resolve(lastTweets.concat(tweets));
+                        config.max_id = utils_1.BigNumOps.plus(tweets.slice(-1)[0].id_str, '-1');
+                        getMore(lastTweets.concat(tweets));
                     });
                     getMore();
                 }
@@ -301,7 +303,7 @@ class default_1 {
                 logger.debug(`api returned ${JSON.stringify(tweets)} for feed ${currentFeed}`);
                 const currentThread = lock.threads[currentFeed];
                 const updateDate = () => currentThread.updatedAt = new Date().toString();
-                if (!tweets || tweets.length === 0) {
+                if (tweets.length === 0) {
                     updateDate();
                     return;
                 }

+ 6 - 5
src/twitter.ts

@@ -439,7 +439,7 @@ export default class {
       if (endpoint) {
         const offset = lock.threads[currentFeed].offset;
         if (offset as unknown as number > 0) config.since_id = offset;
-        const getMore = (gotTweets: Tweet[] = []) => this.client.get(
+        const getMore = (lastTweets: Tweet[] = []) => this.client.get(
           endpoint, config, (error: {[key: string]: any}[], tweets: Tweet[]
         ) => {
           if (error) {
@@ -453,9 +453,10 @@ export default class {
               logger.error(`unhandled error on fetching tweets for ${currentFeed}: ${JSON.stringify(error)}`);
             }
           }
-          if (!tweets || tweets.length <= 1) return resolve(gotTweets);
-          config.max_id = tweets.slice(-1)[0].id_str;
-          getMore(gotTweets.concat(tweets));
+          if (!(tweets instanceof Array) || tweets.length === 0) return resolve(lastTweets);
+          if (offset as unknown as number <= 0) return resolve(lastTweets.concat(tweets));
+          config.max_id = BigNumOps.plus(tweets.slice(-1)[0].id_str, '-1');
+          getMore(lastTweets.concat(tweets));
         });
         getMore();
       }
@@ -466,7 +467,7 @@ export default class {
       const currentThread = lock.threads[currentFeed];
 
       const updateDate = () => currentThread.updatedAt = new Date().toString();
-      if (!tweets || tweets.length === 0) { updateDate(); return; }
+      if (tweets.length === 0) { updateDate(); return; }
 
       const topOfFeed = tweets[0].id_str;
       const updateOffset = () => currentThread.offset = topOfFeed;