fix(links): fix sending links plus images (#15352)

Fixes #15290
This commit is contained in:
Jonathan Rainville 2024-06-27 09:42:45 -04:00 committed by GitHub
parent 6e276b605f
commit 775df8097c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 35 additions and 19 deletions

View File

@ -107,7 +107,8 @@ type
msg: string
replyTo: string
preferredUsername: string
linkPreviews: JsonNode
standardLinkPreviews: JsonNode
statusLinkPreviews: JsonNode
const asyncSendImagesTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.} =
let arg = decode[AsyncSendImagesTaskArg](argEncoded)
@ -120,8 +121,15 @@ const asyncSendImagesTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.} =
if imagePath != "":
imagePaths.add(imagePath)
let response = status_chat.sendImages(arg.chatId, imagePaths, arg.msg, arg.replyTo, arg.preferredUsername,
arg.linkPreviews)
let response = status_chat.sendImages(
arg.chatId,
imagePaths,
arg.msg,
arg.replyTo,
arg.preferredUsername,
arg.standardLinkPreviews,
arg.statusLinkPreviews,
)
for imagePath in imagePaths:
removeFile(imagePath)

View File

@ -431,22 +431,28 @@ QtObject:
replyTo: string,
preferredUsername: string = "",
linkPreviews: seq[LinkPreview] = @[]) =
try:
let (standardLinkPreviews, statusLinkPreviews) = extractLinkPreviewsLists(linkPreviews)
let arg = AsyncSendImagesTaskArg(
tptr: asyncSendImagesTask,
vptr: cast[ByteAddress](self.vptr),
slot: "onAsyncSendImagesDone",
chatId: chatId,
imagePathsAndDataJson: imagePathsAndDataJson,
tempDir: TMPDIR,
msg: msg,
replyTo: replyTo,
preferredUsername: preferredUsername,
standardLinkPreviews: %standardLinkPreviews,
statusLinkPreviews: %statusLinkPreviews,
)
let arg = AsyncSendImagesTaskArg(
tptr: asyncSendImagesTask,
vptr: cast[ByteAddress](self.vptr),
slot: "onAsyncSendImagesDone",
chatId: chatId,
imagePathsAndDataJson: imagePathsAndDataJson,
tempDir: TMPDIR,
msg: msg,
replyTo: replyTo,
preferredUsername: preferredUsername,
linkPreviews: %linkPreviews,
)
self.threadpool.start(arg)
except Exception as e:
error "Error sending images", msg = e.msg
self.events.emit(SIGNAL_SENDING_FAILED, MessageSendingFailure(chatId: chatId, error: e.msg))
self.threadpool.start(arg)
proc onAsyncSendImagesDone*(self: Service, rpcResponseJson: string) {.slot.} =
let rpcResponseObj = rpcResponseJson.parseJson

View File

@ -75,7 +75,7 @@ proc sendChatMessage*(
"contentType": contentType,
"communityId": communityId,
"linkPreviews": standardLinkPreviews,
"statusLinkPreviews": statusLinkPreviews
"statusLinkPreviews": statusLinkPreviews,
}
])
@ -84,7 +84,8 @@ proc sendImages*(chatId: string,
msg: string,
replyTo: string,
preferredUsername: string,
linkPreviews: JsonNode,
standardLinkPreviews: JsonNode,
statusLinkPreviews: JsonNode,
): RpcResponse[JsonNode] =
let imagesJson = %* images.map(image => %*
{
@ -94,7 +95,8 @@ proc sendImages*(chatId: string,
"ensName": preferredUsername,
"text": msg,
"responseTo": replyTo,
"linkPreviews": linkPreviews
"linkPreviews": standardLinkPreviews,
"statusLinkPreviews": statusLinkPreviews,
}
)
callPrivateRPC("sendChatMessages".prefix, %* [imagesJson])