mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-06-04 23:21:55 +00:00
core: add custom data commands, fix groups parser (#6691)
* core: add custom data commands, fix groups parser
- Add APISetGroupCustomData and APISetContactCustomData to ChatCommand,
with parsers (/_set custom #, /_set custom @) and processors
following the APISetChatUIThemes pattern
- Fix APIListGroups parser missing space ("/_groups" -> "/_groups ")
to align with auto-generated cmdString
- Add chatCommandsDocsData entries for APISetGroupCustomData,
APISetContactCustomData, and APISetUserAutoAcceptMemberContacts
* core: named fields for codegen, run codegen
- Use named record fields for APISetGroupCustomData,
APISetContactCustomData, APISetUserAutoAcceptMemberContacts
(required for chatCommandsDocsData field resolution)
- Fix OnOff field name to "onOff" (avoids clash with User field)
- Remove APISetUserAutoAcceptMemberContacts from undocumentedCommands
- Regenerate COMMANDS.md and commands.ts
* nodejs: add ChatApi wrappers for custom data and apiGetChat
- apiSetGroupCustomData, apiSetContactCustomData
- apiSetAutoAcceptMemberContacts
- apiGetChat (manual wrapper, APIGetChat undocumented)
This commit is contained in:
@@ -747,6 +747,47 @@ export class ChatApi {
|
||||
throw new ChatCommandError("error deleting chat", r)
|
||||
}
|
||||
|
||||
/**
|
||||
* Set group custom data.
|
||||
* Network usage: no.
|
||||
*/
|
||||
async apiSetGroupCustomData(groupId: number, customData?: object): Promise<void> {
|
||||
const r = await this.sendChatCmd(CC.APISetGroupCustomData.cmdString({groupId, customData}))
|
||||
if (r.type === "cmdOk") return
|
||||
throw new ChatCommandError("error setting group custom data", r)
|
||||
}
|
||||
|
||||
/**
|
||||
* Set contact custom data.
|
||||
* Network usage: no.
|
||||
*/
|
||||
async apiSetContactCustomData(contactId: number, customData?: object): Promise<void> {
|
||||
const r = await this.sendChatCmd(CC.APISetContactCustomData.cmdString({contactId, customData}))
|
||||
if (r.type === "cmdOk") return
|
||||
throw new ChatCommandError("error setting contact custom data", r)
|
||||
}
|
||||
|
||||
/**
|
||||
* Set auto-accept member contacts.
|
||||
* Network usage: no.
|
||||
*/
|
||||
async apiSetAutoAcceptMemberContacts(userId: number, onOff: boolean): Promise<void> {
|
||||
const r = await this.sendChatCmd(CC.APISetUserAutoAcceptMemberContacts.cmdString({userId, onOff}))
|
||||
if (r.type === "cmdOk") return
|
||||
throw new ChatCommandError("error setting auto-accept member contacts", r)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get chat items.
|
||||
* Network usage: no.
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
async apiGetChat(chatType: T.ChatType, chatId: number, count: number): Promise<any> {
|
||||
const r: any = await this.sendChatCmd(`/_get chat ${T.ChatType.cmdString(chatType)}${chatId} count=${count}`)
|
||||
if (r.type === "apiChat") return r.chat
|
||||
throw new ChatCommandError("error getting chat", r)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get active user profile
|
||||
* Network usage: no.
|
||||
|
||||
Reference in New Issue
Block a user