Skip to content

Commit

Permalink
fix: ignore following items when checking new item
Browse files Browse the repository at this point in the history
  • Loading branch information
fengkx committed Nov 20, 2020
1 parent 4268b01 commit a1d87f1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
23 changes: 9 additions & 14 deletions source/utils/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import logger, { logHttpError } from './logger';
import { findFeed } from './feed';
import { config } from '../config';
import { Feed, FeedItem } from '../types/feed';
import { Optional, Option, isNone, none, isSome, Some } from '../types/option';
import { Optional, Option, isNone, none, isSome } from '../types/option';
import { parseString } from '../parser/parse';
import {
getAllFeeds,
Expand Down Expand Up @@ -106,19 +106,14 @@ const queue = fastQueue(async (eachFeed: Feed, cb) => {
}
)
);
const newItems = await Promise.all(
fetchedItems.value.map(
async (item: FeedItem): Promise<Option<FeedItem>> => {
const hash = await hashFeed(item);
if (oldHashList.indexOf(hash) === -1)
return Optional(item);
else return none;
}
)
);
sendItems = newItems
.filter(isSome)
.map((some: Some<FeedItem>) => some.value);
for (let i = 0; i < fetchedItems.value.length; i++) {
const item = fetchedItems.value[i];
if (!oldHashList.includes(newHashList[i])) {
sendItems.push(item);
} else {
break; // ignore the following items
}
}
if (sendItems.length > 0) {
await updateHashList(eachFeed.feed_id, newHashList);
}
Expand Down
2 changes: 1 addition & 1 deletion source/utils/send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { isNone } from '../types/option';
*/
async function handlerSendError(e: any, userId: number): Promise<boolean> {
// bot was blocked or chat is deleted
logger.error(e.description);
logger.error(e);
const re = new RegExp(
'chat not found|bot was blocked by the user|bot was kicked'
);
Expand Down

0 comments on commit a1d87f1

Please sign in to comment.