diff --git a/resources/misc/previewInterop.js b/resources/misc/previewInterop.js index c5993748..b77d2af2 100644 --- a/resources/misc/previewInterop.js +++ b/resources/misc/previewInterop.js @@ -77,12 +77,12 @@ function getPreviewInfo(messageId, url) { }) } -function parseMessage(messageId, message, showPreview) { +function parseMessage(messageId, message, showPreview, color='#0645AD') { var links = linkify.find(message) if (links.length === 0) { return } if (showPreview) getPreviewInfo(messageId, links[0].href) - window.jsbridge.emitLinkified(messageId, linkifyStr(message)) + window.jsbridge.emitLinkified(messageId, linkifyStr(message, color)) } diff --git a/src/app/commoncomponents/TextMessageDelegate.qml b/src/app/commoncomponents/TextMessageDelegate.qml index 7b1a9118..943f0845 100644 --- a/src/app/commoncomponents/TextMessageDelegate.qml +++ b/src/app/commoncomponents/TextMessageDelegate.qml @@ -33,6 +33,9 @@ SBSMessageBase { property bool isRemoteImage property bool isEmojiOnly: IsEmojiOnly property real maxMsgWidth: root.width - senderMargin - 2 * hPadding - avatarBlockWidth + property string colorUrl: UtilsAdapter.luma(bubble.color) ? + JamiTheme.chatviewLinkColorLight : + JamiTheme.chatviewLinkColorDark isOutgoing: Author === "" author: Author @@ -42,6 +45,7 @@ SBSMessageBase { formattedDay: MessagesAdapter.getFormattedDay(Timestamp) extraHeight: extraContent.active && !isRemoteImage ? msgRadius : -isRemoteImage + EditedPopup { id: editedPopup @@ -238,13 +242,11 @@ SBSMessageBase { wrapMode: Label.WrapAtWordBoundaryOrAnywhere renderType: Text.NativeRendering textFormat: TextEdit.RichText - color: UtilsAdapter.luma(bubble.color) ? - JamiTheme.chatviewTextColorLight : - JamiTheme.chatviewTextColorDark visible: LinkPreviewInfo.description !== null - text: '' + LinkPreviewInfo.description + '' + font.underline: root.hoveredLink + text: LinkPreviewInfo.description + color: root.colorUrl + } Label { width: parent.width @@ -267,7 +269,7 @@ SBSMessageBase { Behavior on opacity { NumberAnimation { duration: 100 } } Component.onCompleted: { if (!Linkified) { - MessagesAdapter.parseMessageUrls(Id, Body, UtilsAdapter.getAppValue(Settings.DisplayHyperlinkPreviews)) + MessagesAdapter.parseMessageUrls(Id, Body, UtilsAdapter.getAppValue(Settings.DisplayHyperlinkPreviews), root.colorUrl) } opacity = 1 } diff --git a/src/app/constant/JamiTheme.qml b/src/app/constant/JamiTheme.qml index d6dadc3c..34686dc9 100644 --- a/src/app/constant/JamiTheme.qml +++ b/src/app/constant/JamiTheme.qml @@ -191,6 +191,8 @@ Item { property color chatviewTextColor: darkTheme ? "#f0f0f0" : "#000000" property color chatviewTextColorLight: "#f0f0f0" property color chatviewTextColorDark: "#353637" + property color chatviewLinkColorLight: "#f0f0f0" + property color chatviewLinkColorDark: "#353637" property real chatviewFontSize: calcSize(15) property real chatviewEmojiSize: calcSize(60) property color timestampColor: darkTheme ? "#bbb" : "#777" diff --git a/src/app/messagesadapter.cpp b/src/app/messagesadapter.cpp index 4fcf25d8..f09348cc 100644 --- a/src/app/messagesadapter.cpp +++ b/src/app/messagesadapter.cpp @@ -510,9 +510,12 @@ MessagesAdapter::onConversationMessagesLoaded(uint32_t, const QString& convId) } void -MessagesAdapter::parseMessageUrls(const QString& messageId, const QString& msg, bool showPreview) +MessagesAdapter::parseMessageUrls(const QString& messageId, + const QString& msg, + bool showPreview, + QColor color) { - previewEngine_->parseMessage(messageId, msg, showPreview); + previewEngine_->parseMessage(messageId, msg, showPreview, color); } void diff --git a/src/app/messagesadapter.h b/src/app/messagesadapter.h index c8c21287..f3362cf3 100644 --- a/src/app/messagesadapter.h +++ b/src/app/messagesadapter.h @@ -92,7 +92,8 @@ protected: Q_INVOKABLE QString getFormattedTime(const quint64 timestamp); Q_INVOKABLE void parseMessageUrls(const QString& messageId, const QString& msg, - bool showPreview); + bool showPreview, + QColor color = "#0645AD"); Q_INVOKABLE void onPaste(); Q_INVOKABLE int getIndexOfMessage(const QString& messageId) const; Q_INVOKABLE QString getStatusString(int status); diff --git a/src/app/previewengine.cpp b/src/app/previewengine.cpp index 9d4f8a85..7808fe7b 100644 --- a/src/app/previewengine.cpp +++ b/src/app/previewengine.cpp @@ -70,10 +70,11 @@ public: QWebEngineScript::MainWorld); } - void parseMessage(const QString& messageId, const QString& msg, bool showPreview) + void parseMessage(const QString& messageId, const QString& msg, bool showPreview, QColor color) { - runJavaScript(QString("parseMessage(`%1`, `%2`, %3)") - .arg(messageId, msg, showPreview ? "true" : "false")); + QString colorStr = "'" + color.name() + "'"; + runJavaScript(QString("parseMessage(`%1`, `%2`, %3, %4)") + .arg(messageId, msg, showPreview ? "true" : "false", colorStr)); } }; @@ -85,9 +86,12 @@ PreviewEngine::PreviewEngine(QObject* parent) PreviewEngine::~PreviewEngine() {} void -PreviewEngine::parseMessage(const QString& messageId, const QString& msg, bool showPreview) +PreviewEngine::parseMessage(const QString& messageId, + const QString& msg, + bool showPreview, + QColor color) { - pimpl_->parseMessage(messageId, msg, showPreview); + pimpl_->parseMessage(messageId, msg, showPreview, color); } void diff --git a/src/app/previewengine.h b/src/app/previewengine.h index 1d37ffc7..d26a0dee 100644 --- a/src/app/previewengine.h +++ b/src/app/previewengine.h @@ -30,7 +30,10 @@ public: PreviewEngine(QObject* parent = nullptr); ~PreviewEngine(); - void parseMessage(const QString& messageId, const QString& msg, bool showPreview); + void parseMessage(const QString& messageId, + const QString& msg, + bool showPreview, + QColor color = "#0645AD"); Q_INVOKABLE void log(const QString& str); Q_INVOKABLE void emitInfoReady(const QString& messageId, const QVariantMap& info); diff --git a/src/libclient/web-chatview/linkify-string.js b/src/libclient/web-chatview/linkify-string.js index 699a94d1..78c83e52 100644 --- a/src/libclient/web-chatview/linkify-string.js +++ b/src/libclient/web-chatview/linkify-string.js @@ -56,7 +56,7 @@ return result.join(' '); } - function linkifyStr(str) { + function linkifyStr(str, color='#0645AD') { var opts = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; opts = new Options(opts); @@ -99,7 +99,7 @@ link += ' ' + attributesToString(attributes); } - link += '>' + escapeText(formatted) + ''; + link += ' style="color: '+color+';">' + escapeText(formatted) + ''; result.push(link); }