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 =
|
proc belongsToCommunity*(self: Controller): bool =
|
||||||
return self.belongsToCommunity
|
return self.belongsToCommunity
|
||||||
|
|
||||||
proc sendImages*(self: Controller, imagePathsAndDataJson: string, msg: string, replyTo: string): string =
|
proc gatherLinkPreviews(self: Controller, messsageText: string): seq[LinkPreview] =
|
||||||
self.chatService.sendImages(self.chatId, imagePathsAndDataJson, msg, replyTo)
|
let urls = self.messageService.getTextUrls(messsageText)
|
||||||
|
|
||||||
proc sendChatMessage*(
|
|
||||||
self: Controller,
|
|
||||||
msg: string,
|
|
||||||
replyTo: string,
|
|
||||||
contentType: int,
|
|
||||||
preferredUsername: string = "") =
|
|
||||||
|
|
||||||
let urls = self.messageService.getTextUrls(msg)
|
|
||||||
let linkPreviews = self.linkPreviewCache.linkPreviewsSeq(urls)
|
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,
|
msg,
|
||||||
replyTo,
|
replyTo,
|
||||||
contentType,
|
contentType,
|
||||||
preferredUsername,
|
preferredUsername,
|
||||||
unfurledLinkPreviews
|
self.gatherLinkPreviews(msg)
|
||||||
)
|
)
|
||||||
|
|
||||||
proc requestAddressForTransaction*(self: Controller, fromAddress: string, amount: string, tokenAddress: string) =
|
proc requestAddressForTransaction*(self: Controller, fromAddress: string, amount: string, tokenAddress: string) =
|
||||||
|
|
|
@ -66,7 +66,7 @@ proc getChatId*(self: Module): string =
|
||||||
return self.controller.getChatId()
|
return self.controller.getChatId()
|
||||||
|
|
||||||
method sendImages*(self: Module, imagePathsAndDataJson: string, msg: string, replyTo: string): string =
|
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*(
|
method sendChatMessage*(
|
||||||
self: Module,
|
self: Module,
|
||||||
|
|
|
@ -499,7 +499,13 @@ QtObject:
|
||||||
error "Error deleting channel", chatId, msg = e.msg
|
error "Error deleting channel", chatId, msg = e.msg
|
||||||
return
|
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 = ""
|
result = ""
|
||||||
try:
|
try:
|
||||||
var images = Json.decode(imagePathsAndDataJson, seq[string])
|
var images = Json.decode(imagePathsAndDataJson, seq[string])
|
||||||
|
@ -511,7 +517,7 @@ QtObject:
|
||||||
if imagePath != "":
|
if imagePath != "":
|
||||||
imagePaths.add(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:
|
for imagePath in imagePaths:
|
||||||
removeFile(imagePath)
|
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 => %*
|
let imagesJson = %* images.map(image => %*
|
||||||
{
|
{
|
||||||
"chatId": chatId,
|
"chatId": chatId,
|
||||||
"contentType": 7, # TODO how do we unhardcode this
|
"contentType": 7, # TODO how do we unhardcode this
|
||||||
"imagePath": image,
|
"imagePath": image,
|
||||||
# TODO is this still needed
|
"ensName": preferredUsername,
|
||||||
# "ensName": preferredUsername,
|
|
||||||
"text": msg,
|
"text": msg,
|
||||||
"responseTo": replyTo,
|
"responseTo": replyTo,
|
||||||
|
"linkPreviews": linkPreviews
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
callPrivateRPC("sendChatMessages".prefix, %* [imagesJson])
|
callPrivateRPC("sendChatMessages".prefix, %* [imagesJson])
|
||||||
|
|
Loading…
Reference in New Issue