mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-08-28 22:18:29 +00:00
support bot, bots: paginate chat scan (#6935)
* bots: document APIGetChats command and CRApiChats response * bots: regenerate API docs and TypeScript types * simplex-chat-nodejs: add apiGetChats * support bot: avoid OOM on large databases apiListGroups / apiListContacts return every record in one response and overflow V8's string allocation on large DBs. Replace list-then-find-by-id patterns with apiGetChat(type, id, 0) lookups, and the one genuine scan (refreshAllCards) with paginated apiGetChats, count=1000. * support bot: update test assertions to match current message text * bots: simplify PaginationByTime, expose only PTLast * simplex-chat-nodejs: bump types and nodejs versions
This commit is contained in:
@@ -14,7 +14,7 @@ Please share your use cases and implementations.
|
||||
## Quick start: a simple bot
|
||||
|
||||
```
|
||||
npm i simplex-chat@6.5.0-beta.10
|
||||
npm i simplex-chat@6.5.1
|
||||
```
|
||||
|
||||
Simple bot that replies with squares of numbers you send to it:
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "simplex-chat",
|
||||
"version": "6.5.0",
|
||||
"version": "6.5.1",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
"files": [
|
||||
@@ -24,7 +24,7 @@
|
||||
"docs": "typedoc"
|
||||
},
|
||||
"dependencies": {
|
||||
"@simplex-chat/types": "^0.5.0",
|
||||
"@simplex-chat/types": "^0.6.0",
|
||||
"extract-zip": "^2.0.1",
|
||||
"fast-deep-equal": "^3.1.3",
|
||||
"node-addon-api": "^8.5.0"
|
||||
|
||||
@@ -764,6 +764,25 @@ export class ChatApi {
|
||||
throw new ChatCommandError("error listing groups", r)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get chat previews (paginated).
|
||||
* Network usage: no.
|
||||
*
|
||||
* Prefer this over apiListContacts / apiListGroups for any scan: those
|
||||
* methods load every record into memory in a single response and will fail
|
||||
* on large databases.
|
||||
*/
|
||||
async apiGetChats(
|
||||
userId: number,
|
||||
pagination: T.PaginationByTime,
|
||||
query: T.ChatListQuery = {type: "filters", favorite: false, unread: false},
|
||||
pendingConnections = false,
|
||||
): Promise<T.AChat[]> {
|
||||
const r = await this.sendChatCmd(CC.APIGetChats.cmdString({userId, pendingConnections, pagination, query}))
|
||||
if (r.type === "apiChats") return r.chats
|
||||
throw new ChatCommandError("error getting chats", r)
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete chat.
|
||||
* Network usage: background.
|
||||
|
||||
@@ -4,7 +4,7 @@ const path = require('path');
|
||||
const extract = require('extract-zip');
|
||||
|
||||
const GITHUB_REPO = 'simplex-chat/simplex-chat-libs';
|
||||
const RELEASE_TAG = 'v6.5.0';
|
||||
const RELEASE_TAG = 'v6.5.1';
|
||||
const BACKEND = (process.env.SIMPLEX_BACKEND || process.env.npm_config_simplex_backend || 'sqlite').toLowerCase();
|
||||
|
||||
if (BACKEND !== 'sqlite' && BACKEND !== 'postgres') {
|
||||
|
||||
Reference in New Issue
Block a user