Skip to content

Commit

Permalink
Notifications: Display the link in the subject line.
Browse files Browse the repository at this point in the history
Added a new data called linkText. If the link in the activity JSON
has a space in it, the part before that is considered the link text.
If it does not contain a space, the word [link] is used.

This is maybe a solution for #6236
  • Loading branch information
dragotin committed Dec 13, 2017
1 parent 8a963a6 commit a2b3510
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/gui/activitydata.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class Activity
QString _message;
QString _file;
QUrl _link;
QString _linkText;
QDateTime _dateTime;
QString _accName;

Expand Down
10 changes: 10 additions & 0 deletions src/gui/notificationwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ void NotificationWidget::setActivity(const Activity &activity)
_ui._subjectLabel->setVisible(!activity._subject.isEmpty());
_ui._messageLabel->setVisible(!activity._message.isEmpty());

QString subject = activity._subject;
if( !activity._link.isEmpty() ) {
// append a link to the message, if that is empty, to subject
subject.append(QString("&nbsp;<a href=\"%1\">%2</a>")
.arg(activity._link.toString(QUrl::FullyEncoded))
.arg(activity._linkText));
_ui._subjectLabel->setTextFormat(Qt::RichText);
_ui._subjectLabel->setOpenExternalLinks(true);

}
_ui._subjectLabel->setText(activity._subject);
_ui._messageLabel->setText(activity._message);

Expand Down
11 changes: 10 additions & 1 deletion src/gui/servernotificationhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,16 @@ void ServerNotificationHandler::slotNotificationsReceived(const QJsonDocument &j
a._message = json.value("message").toString();
QString s = json.value("link").toString();
if (!s.isEmpty()) {
a._link = QUrl(s);
// if there is a real whitespace in the link, the part before the space
// is rendered as a link text
if( s.contains(QChar(' '))) {
const QStringList li = s.split(QChar(' '));
a._link = QUrl(li.at(1));
a._linkText = li.at(0);
} else {
a._link = QUrl(s);
a._linkText = QString("[%1]").arg(tr("link"));
}
}
a._dateTime = QDateTime::fromString(json.value("datetime").toString(), Qt::ISODate);

Expand Down

0 comments on commit a2b3510

Please sign in to comment.