-
Notifications
You must be signed in to change notification settings - Fork 663
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Notifications: Display the link in the subject line. #6240
Conversation
DISCLAIMER: I did not have a ownCloud available that can do notifications, so this is PR is untested. Thus label "DO NOT MERGE YET" with the kind request to review/comment and maybe test. |
// is rendered as a link text | ||
if( s.contains(QChar(' '))) { | ||
const QStringList li = s.split(QChar(' ')); | ||
a._link = QUrl::fromEncoded(li.at(1).toLocal8Bit()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ToLatin1 or toUtf8.
toLocal8bit is for path on the filesystem, or things that we want to expose in stderr
There can only be one space?
src/gui/notificationwidget.cpp
Outdated
if( !activity._link.isEmpty() ) { | ||
// append a link to the message, if that is empty, to subject | ||
subject.append(QString(" <a href=\"%1\">%2</a>") | ||
.arg(activity._link.toString(QUrl::FullyEncoded)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use arg(... , ...) with two arguments. In general this is better because it works even if the first string contains a %1 or a %2.
Also, please use escapeXml to the _linkText
a._linkText = li.at(0); | ||
} else { | ||
a._link = QUrl(s); | ||
a._linkText = QString("[%1]").arg(tr("link")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(nitpick: i'd use tr("[link]"))
src/gui/notificationwidget.cpp
Outdated
@@ -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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needs to be xml escaped.
Why not a new button next to "Close" to open the link? |
@dragotin nice PR! When do you want to continue on it?
If there is a long link text, this might look odd. But if you just want to have a button "Open" then I think it's fine.. |
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
As the URL has to be encoded to make the whitespace-trick work, the url has to be properly assigned to QUrl.
If the Notification contains a link, it is parsed by this method. It takes care on the Link text that might be prepended. Including unittest.
Fixed all the outstanding things (I hope) and added a unit test for splitting of the url from the link text. Thanks @ogoffart for review. I do not like the idea of a button, because a link should not be a button, but a link. Also please note that it is already possible to add additional buttons that trigger a link via the notification specification, see here: https://github.com/owncloud/client/blob/master/src/gui/notificationwidget.cpp#L72 |
src/gui/activitydata.h
Outdated
@@ -57,6 +57,7 @@ class Activity | |||
QString _message; | |||
QString _file; | |||
QUrl _link; | |||
QString _linkText; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe document which field are html escaped.
Personally, i'd keep all these string unescaped. and escape them right before putting them in some html text.
src/gui/activitydata.h
Outdated
// if there is a real whitespace in the link, the part before the space | ||
// is rendered as a link text | ||
int charPos = s.lastIndexOf(QChar(' ')); | ||
if( charPos > -1 ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(style: we don't put spaces inside the parentheses, the space is before. You could run git-clang-format, to fix all style issues.)
} | ||
subject.append( QString(" <a href=\"%1\">%2</a>") | ||
.arg(activity._link.toString(QUrl::FullyEncoded), | ||
lText.toHtmlEscaped() )); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Am I wrong that you double html escape?
|
||
private slots: | ||
|
||
void testLinkSplitEmpty() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this kind of test would be much shorter using a testLink_data() thing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_data tests, like for example TestFolder::testFolder or TestUtility::testSanitizeForFileName_data or ...
And also QCOMPARE instead of QVERIFY
src/gui/notificationwidget.cpp
Outdated
_ui._subjectLabel->setTextFormat(Qt::RichText); | ||
_ui._subjectLabel->setOpenExternalLinks(true); | ||
|
||
} | ||
_ui._subjectLabel->setText(activity._subject); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you mean just "subject" here!
Thanks @ogoffart, I fixed stuff accordingly. With the test I would need more advise ;-) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looks good.
Have you been testing that this works.
Should the notification also not include the actual text from the notificication? (or is that something else?)
|
||
private slots: | ||
|
||
void testLinkSplitEmpty() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_data tests, like for example TestFolder::testFolder or TestUtility::testSanitizeForFileName_data or ...
And also QCOMPARE instead of QVERIFY
I wanted to remove my "Request change" without "Approving" but apparently this is not possible. |
Should be good now. |
if (!s.isEmpty()) { | ||
// if there is a real whitespace in the link, the part before the space | ||
// is rendered as a link text | ||
int charPos = s.lastIndexOf(QChar(' ')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's fishy ....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll take back my review too for now too
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.
Note that the idea to separate the link and the link text with a space needed because the original specification does not contain a link text, just the link. I am not seeing a downside as long as spaces in the real link are encoded with %20.
This is may be a solution for #6236