Skip to content

Commit

Permalink
Use retries to make conversations work better
Browse files Browse the repository at this point in the history
  • Loading branch information
rakoo committed Dec 10, 2023
1 parent 56b64d0 commit d0129d7
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/pages/conversations.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import './conversations.css';

import { useEffect, useReducer, useRef, useState } from 'preact/hooks';
import pRetry from 'p-retry';

import Icon from '../components/icon';
import Link from '../components/link';
Expand All @@ -25,21 +26,23 @@ function Conversations({instance}) {
setUIState('loading');
(async () => {
try {
const conversationsRaw = await masto.v1.conversations.list({
limit: LIMIT
});
const conversationsFetch = () =>
pRetry(() => masto.v1.conversations.list({limit: LIMIT}), {
retries: 4
})
const cc = [];

const conversationsRaw = await conversationsFetch();
conversationsRaw.forEach(u => {
u.accounts.forEach((account) => states.accounts[account.id] = account)
u.accounts.forEach((account) => states.accounts[account.id] = account)
const conversation = {
actors: u.accounts.map(account => account.id),
id: u.lastStatus?.id,
date: u.lastStatus?.editedAt || u.lastStatus?.createdAt,
}
const withSameActorsIndex = cc.findIndex(c => c.actors.join(',') == conversation.actors.join(','));
if (withSameActorsIndex == -1) {
cc.push(conversation)
cc.push(conversation)
} else if (cc[withSameActorsIndex].date < conversation.date) {
cc.set(withSameActorsIndex, conversation)
}
Expand Down

0 comments on commit d0129d7

Please sign in to comment.