fix: attach link previews in `SendImages` (#12402)
This commit is contained in:
parent
834753351c
commit
ac8fb8ffdb
|
@ -90,26 +90,37 @@ proc getChatId*(self: Controller): string =
|
|||
proc belongsToCommunity*(self: Controller): bool =
|
||||
return self.belongsToCommunity
|
||||
|
||||
proc sendImages*(self: Controller, imagePathsAndDataJson: string, msg: string, replyTo: string): string =
|
||||
self.chatService.sendImages(self.chatId, imagePathsAndDataJson, msg, replyTo)
|
||||
|
||||
proc sendChatMessage*(
|
||||
self: Controller,
|
||||
msg: string,
|
||||
replyTo: string,
|
||||
contentType: int,
|
||||
preferredUsername: string = "") =
|
||||
|
||||
let urls = self.messageService.getTextUrls(msg)
|
||||
proc gatherLinkPreviews(self: Controller, messsageText: string): seq[LinkPreview] =
|
||||
let urls = self.messageService.getTextUrls(messsageText)
|
||||
let linkPreviews = self.linkPreviewCache.linkPreviewsSeq(urls)
|
||||
let unfurledLinkPreviews = filter(linkPreviews, proc(x: LinkPreview): bool = x.hostname.len > 0)
|
||||
return filter(linkPreviews, proc(x: LinkPreview): bool = x.hostname.len > 0)
|
||||
|
||||
self.chatService.sendChatMessage(self.chatId,
|
||||
proc sendImages*(self: Controller,
|
||||
imagePathsAndDataJson: string,
|
||||
msg: string,
|
||||
replyTo: string,
|
||||
preferredUsername: string = ""): string =
|
||||
self.chatService.sendImages(
|
||||
self.chatId,
|
||||
imagePathsAndDataJson,
|
||||
msg,
|
||||
replyTo,
|
||||
preferredUsername,
|
||||
self.gatherLinkPreviews(msg)
|
||||
)
|
||||
|
||||
proc sendChatMessage*(self: Controller,
|
||||
msg: string,
|
||||
replyTo: string,
|
||||
contentType: int,
|
||||
preferredUsername: string = "") =
|
||||
self.chatService.sendChatMessage(
|
||||
self.chatId,
|
||||
msg,
|
||||
replyTo,
|
||||
contentType,
|
||||
preferredUsername,
|
||||
unfurledLinkPreviews
|
||||
self.gatherLinkPreviews(msg)
|
||||
)
|
||||
|
||||
proc requestAddressForTransaction*(self: Controller, fromAddress: string, amount: string, tokenAddress: string) =
|
||||
|
|
|
@ -66,7 +66,7 @@ proc getChatId*(self: Module): string =
|
|||
return self.controller.getChatId()
|
||||
|
||||
method sendImages*(self: Module, imagePathsAndDataJson: string, msg: string, replyTo: string): string =
|
||||
self.controller.sendImages(imagePathsAndDataJson, msg, replyTo)
|
||||
self.controller.sendImages(imagePathsAndDataJson, msg, replyTo, singletonInstance.userProfile.getPreferredName())
|
||||
|
||||
method sendChatMessage*(
|
||||
self: Module,
|
||||
|
|
|
@ -499,7 +499,13 @@ QtObject:
|
|||
error "Error deleting channel", chatId, msg = e.msg
|
||||
return
|
||||
|
||||
proc sendImages*(self: Service, chatId: string, imagePathsAndDataJson: string, msg: string, replyTo: string): string =
|
||||
proc sendImages*(self: Service,
|
||||
chatId: string,
|
||||
imagePathsAndDataJson: string,
|
||||
msg: string,
|
||||
replyTo: string,
|
||||
preferredUsername: string = "",
|
||||
linkPreviews: seq[LinkPreview] = @[]): string =
|
||||
result = ""
|
||||
try:
|
||||
var images = Json.decode(imagePathsAndDataJson, seq[string])
|
||||
|
@ -511,7 +517,7 @@ QtObject:
|
|||
if imagePath != "":
|
||||
imagePaths.add(imagePath)
|
||||
|
||||
let response = status_chat.sendImages(chatId, imagePaths, msg, replyTo)
|
||||
let response = status_chat.sendImages(chatId, imagePaths, msg, replyTo, preferredUsername, linkPreviews)
|
||||
|
||||
for imagePath in imagePaths:
|
||||
removeFile(imagePath)
|
||||
|
|
|
@ -82,16 +82,22 @@ proc sendChatMessage*(
|
|||
}
|
||||
])
|
||||
|
||||
proc sendImages*(chatId: string, images: var seq[string], msg: string, replyTo: string): RpcResponse[JsonNode] {.raises: [Exception].} =
|
||||
proc sendImages*(chatId: string,
|
||||
images: var seq[string],
|
||||
msg: string,
|
||||
replyTo: string,
|
||||
preferredUsername: string,
|
||||
linkPreviews: seq[LinkPreview],
|
||||
): RpcResponse[JsonNode] {.raises: [Exception].} =
|
||||
let imagesJson = %* images.map(image => %*
|
||||
{
|
||||
"chatId": chatId,
|
||||
"contentType": 7, # TODO how do we unhardcode this
|
||||
"imagePath": image,
|
||||
# TODO is this still needed
|
||||
# "ensName": preferredUsername,
|
||||
"ensName": preferredUsername,
|
||||
"text": msg,
|
||||
"responseTo": replyTo,
|
||||
"linkPreviews": linkPreviews
|
||||
}
|
||||
)
|
||||
callPrivateRPC("sendChatMessages".prefix, %* [imagesJson])
|
||||
|
|
Loading…
Reference in New Issue