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

View File

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

View File

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