| 55 | |
| 56 | export default class FeedService { |
| 57 | static async get({ lastReplyAt }: { lastReplyAt?: number }) { |
| 58 | let accounts: accountsType[] = []; |
| 59 | let ids: string[] = []; |
| 60 | |
| 61 | const queryResult = await fetch({ lastReplyAt }); |
| 62 | |
| 63 | const threads = queryResult |
| 64 | .filter((thread) => |
| 65 | thread.messages.every( |
| 66 | (m) => |
| 67 | // we filter threads with messages from bots here instead of through query |
| 68 | !m.author?.isBot || |
| 69 | // except linenBot messages from feed channel |
| 70 | (m.author.externalUserId === config.linen.bot.externalId && |
| 71 | thread.channelId === config.linen.feedChannelId) |
| 72 | ) |
| 73 | ) |
| 74 | .map((thread) => { |
| 75 | const { account } = thread.channel; |
| 76 | if (account && !ids.includes(account.id)) { |
| 77 | ids.push(account.id); |
| 78 | accounts.push(account); |
| 79 | } |
| 80 | return serializeThread(thread); |
| 81 | }); |
| 82 | |
| 83 | let cursor; |
| 84 | try { |
| 85 | // using queryResult because it was not filtered on code |
| 86 | cursor = queryResult[queryResult.length - 1].lastReplyAt?.toString(); |
| 87 | } catch (error) {} |
| 88 | |
| 89 | return { |
| 90 | threads, |
| 91 | settings: accounts.map(serializeSettings), |
| 92 | communities: accounts.map(serializeAccount), |
| 93 | cursor, |
| 94 | }; |
| 95 | } |
| 96 | |
| 97 | static async mark() { |
| 98 | const threads = await prisma.threads.findMany({ |