| 419 | }; |
| 420 | |
| 421 | const getNextOptimisticPinOrder = (queryClient: QueryClient): number => { |
| 422 | let maxPinOrder = 0; |
| 423 | const queries = queryClient.getQueriesData< |
| 424 | TypesGen.Chat[] | { pages: TypesGen.Chat[][]; pageParams: unknown[] } |
| 425 | >({ |
| 426 | queryKey: chatsKey, |
| 427 | predicate: isChatListQuery, |
| 428 | }); |
| 429 | |
| 430 | for (const [, data] of queries) { |
| 431 | if (!data) { |
| 432 | continue; |
| 433 | } |
| 434 | |
| 435 | if (Array.isArray(data)) { |
| 436 | for (const chat of data) { |
| 437 | maxPinOrder = Math.max(maxPinOrder, chat.pin_order); |
| 438 | } |
| 439 | continue; |
| 440 | } |
| 441 | |
| 442 | for (const page of data.pages) { |
| 443 | for (const chat of page) { |
| 444 | maxPinOrder = Math.max(maxPinOrder, chat.pin_order); |
| 445 | } |
| 446 | } |
| 447 | } |
| 448 | |
| 449 | return maxPinOrder + 1; |
| 450 | }; |
| 451 | |
| 452 | /** |
| 453 | * Predicate that matches only chat-list queries (the sidebar), not |