1
0
Fork 0
mirror of https://git.jami.net/savoirfairelinux/jami-client-qt.git synced 2025-04-21 21:52:03 +02:00

fix: Hyperlinks hard to see

Hyperlinks now adapt to bubble color

Change-Id: I8f45b5f0ae103a751d47bf1bc1844f481838caa0
Gitlab: #764
This commit is contained in:
Nicolas Vengeon 2022-12-06 16:37:22 -05:00
parent 6ac70c64c7
commit f7ce62bfab
8 changed files with 35 additions and 20 deletions

View file

@ -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))
}

View file

@ -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: '<a href=" " style="text-decoration: ' +
( hoveredLink ? 'underline' : 'none') + ';"' +
'>' + LinkPreviewInfo.description + '</a>'
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
}

View file

@ -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"

View file

@ -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

View file

@ -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);

View file

@ -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

View file

@ -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);

View file

@ -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) + '</' + tagName + '>';
link += ' style="color: '+color+';">' + escapeText(formatted) + '</' + tagName + '>';
result.push(link);
}