Merge branch 'stable'

This commit is contained in:
Evgeny Poberezkin
2025-07-08 12:22:57 +01:00
3 changed files with 29 additions and 16 deletions

View File

@@ -17,7 +17,6 @@ import Control.Monad.Reader
import Data.Aeson (FromJSON, ToJSON (..))
import qualified Data.Aeson as J
import qualified Data.Aeson.TH as JQ
import Data.Bifunctor (first)
import Data.Text (Text)
import Data.Text.Encoding (encodeUtf8)
import GHC.Generics (Generic)
@@ -50,13 +49,15 @@ $(JQ.deriveToJSON (taggedObjectJSON $ dropPrefix "Obj") ''ObjChatCmdError)
$(JQ.deriveToJSON (taggedObjectJSON $ dropPrefix "Obj") ''ObjChatError)
-- this encoding preserves the websocket API format when ChatError was sent either with type: "chatError" or type: "chatCmdError"
instance ToJSON (CSRBody ChatResponse) where
toJSON = toJSON . first ObjChatCmdError . csrBody
toEncoding = toEncoding . first ObjChatCmdError . csrBody
toJSON = either (toJSON . ObjChatCmdError) toJSON . csrBody
toEncoding = either (toEncoding . ObjChatCmdError) toEncoding . csrBody
-- this encoding preserves the websocket API format when ChatError was sent either with type: "chatError" or type: "chatCmdError"
instance ToJSON (CSRBody ChatEvent) where
toJSON = toJSON . first ObjChatError . csrBody
toEncoding = toEncoding . first ObjChatError . csrBody
toJSON = either (toJSON . ObjChatError) toJSON . csrBody
toEncoding = either (toEncoding . ObjChatError) toEncoding . csrBody
data AChatSrvResponse = forall r. ToJSON (ChatSrvResponse r) => ACR (ChatSrvResponse r)

View File

@@ -79,8 +79,9 @@ export class ChatClient {
sendChatCmdStr(cmd: string): Promise<ChatResponse> {
const corrId = `${++this.clientCorrId}`
const t: ChatSrvRequest = {corrId, cmd}
const p = new Promise<ChatResponse>((resolve, reject) => this.sentCommands.set(corrId, {resolve, reject}))
this.transport.write(t).then(noop, noop)
return new Promise((resolve, reject) => this.sentCommands.set(corrId, {resolve, reject}))
return p
}
sendChatCommand(command: ChatCommand): Promise<ChatResponse> {
@@ -189,7 +190,10 @@ export class ChatClient {
async apiCreateLink(): Promise<string> {
const r = await this.sendChatCommand({type: "addContact"})
if (r.type === "invitation") return r.connReqInvitation
if (r.type === "invitation") {
const link = r.connLinkInvitation
return link.connShortLink || link.connFullLink
}
throw new ChatCommandError("error creating link", r)
}
@@ -247,7 +251,10 @@ export class ChatClient {
async apiCreateUserAddress(): Promise<string> {
const r = await this.sendChatCommand({type: "createMyAddress"})
if (r.type === "userContactLinkCreated") return r.connReqContact
if (r.type === "userContactLinkCreated") {
const link = r.connLinkContact
return link.connShortLink || link.connFullLink
}
throw new ChatCommandError("error creating user address", r)
}
@@ -260,8 +267,10 @@ export class ChatClient {
async apiGetUserAddress(): Promise<string | undefined> {
const r = await this.sendChatCommand({type: "showMyAddress"})
switch (r.type) {
case "userContactLink":
return r.contactLink.connReqContact
case "userContactLink": {
const link = r.contactLink.connLinkContact
return link.connShortLink || link.connFullLink
}
default:
if (r.type === "chatCmdError" && r.chatError.type === "errorStore" && r.chatError.storeError.type === "userContactLinkNotFound") {
return undefined

View File

@@ -299,9 +299,7 @@ export interface CRUserContactLink extends CR {
export interface CRUserContactLinkUpdated extends CR {
type: "userContactLinkUpdated"
user: User
connReqContact: string
autoAccept: boolean
autoReply?: MsgContent
contactLink: UserContactLink
}
export interface CRContactRequestRejected extends CR {
@@ -337,7 +335,7 @@ export interface CRContactAliasUpdated extends CR {
export interface CRInvitation extends CR {
type: "invitation"
user: User
connReqInvitation: string
connLinkInvitation: CreatedConnLink
}
export interface CRSentConfirmation extends CR {
@@ -379,7 +377,7 @@ export interface CRChatCleared extends CR {
export interface CRUserContactLinkCreated extends CR {
type: "userContactLinkCreated"
user: User
connReqContact: string
connLinkContact: CreatedConnLink
}
export interface CRUserContactLinkDeleted extends CR {
@@ -994,10 +992,15 @@ interface FileTransferMeta {
}
interface UserContactLink {
connReqContact: string
connLinkContact: CreatedConnLink
autoAccept?: AutoAccept
}
interface CreatedConnLink {
connFullLink: string
connShortLink?: string
}
interface AutoAccept {
acceptIncognito: boolean
autoReply?: MsgContent