From c702928e1e66023f7d946450ab3a7ed1ab6b2ac4 Mon Sep 17 00:00:00 2001 From: Anthony Laibe Date: Fri, 28 Jan 2022 14:06:17 +0100 Subject: [PATCH] fix(@chat): display message with link fixes 4600 --- .../service/message/dto/message.nim | 18 +++++------------- src/app_service/service/message/service.nim | 8 +++++--- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/src/app_service/service/message/dto/message.nim b/src/app_service/service/message/dto/message.nim index c918a00c2f..92e98ead67 100644 --- a/src/app_service/service/message/dto/message.nim +++ b/src/app_service/service/message/dto/message.nim @@ -15,16 +15,13 @@ const PARSED_TEXT_CHILD_TYPE_STRONG_EMPH* = "strong-emph" const PARSED_TEXT_CHILD_TYPE_MENTION* = "mention" const PARSED_TEXT_CHILD_TYPE_STATUS_TAG* = "status-tag" const PARSED_TEXT_CHILD_TYPE_DEL* = "del" - -type ParsedTextChild* = object - `type`*: string - literal*: string - destination*: string +const PARSED_TEXT_CHILD_TYPE_LINK* = "link" type ParsedText* = object `type`*: string literal*: string - children*: seq[ParsedTextChild] + destination*: string + children*: seq[ParsedText] type QuotedMessage* = object `from`*: string @@ -67,21 +64,16 @@ type MessageDto* = object links*: seq[string] editedAt*: int -proc toParsedTextChild*(jsonObj: JsonNode): ParsedTextChild = - result = ParsedTextChild() - discard jsonObj.getProp("type", result.type) - discard jsonObj.getProp("literal", result.literal) - discard jsonObj.getProp("destination", result.destination) - proc toParsedText*(jsonObj: JsonNode): ParsedText = result = ParsedText() discard jsonObj.getProp("type", result.type) discard jsonObj.getProp("literal", result.literal) + discard jsonObj.getProp("destination", result.destination) var childrenArr: JsonNode if(jsonObj.getProp("children", childrenArr) and childrenArr.kind == JArray): for childObj in childrenArr: - result.children.add(toParsedTextChild(childObj)) + result.children.add(toParsedText(childObj)) proc toQuotedMessage*(jsonObj: JsonNode): QuotedMessage = result = QuotedMessage() diff --git a/src/app_service/service/message/service.nim b/src/app_service/service/message/service.nim index 79f53572f4..341265339e 100644 --- a/src/app_service/service/message/service.nim +++ b/src/app_service/service/message/service.nim @@ -555,13 +555,13 @@ QtObject: self.threadpool.start(arg) # See render-inline in status-react/src/status_im/ui/screens/chat/message/message.cljs -proc renderInline(self: Service, parsedTextChild: ParsedTextChild): string = - let value = escape_html(parsedTextChild.literal) +proc renderInline(self: Service, parsedText: ParsedText): string = + let value = escape_html(parsedText.literal) .multiReplace(("\r\n", "
")) .multiReplace(("\n", "
")) .multiReplace((" ", "  ")) - case parsedTextChild.type: + case parsedText.type: of "": result = value of PARSED_TEXT_CHILD_TYPE_CODE: @@ -579,6 +579,8 @@ proc renderInline(self: Service, parsedTextChild: ParsedTextChild): string = result = fmt("#{value}") of PARSED_TEXT_CHILD_TYPE_DEL: result = fmt("{value}") + of PARSED_TEXT_CHILD_TYPE_LINK: + result = fmt("{parsedText.destination}") else: result = fmt(" {value} ")