Skip to content
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

Closed
wants to merge 9 commits into from
Closed

Conversation

dragotin
Copy link
Contributor

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

@dragotin
Copy link
Contributor Author

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());
Copy link
Contributor

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?

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))
Copy link
Contributor

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"));
Copy link
Contributor

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]"))

@@ -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;
Copy link
Contributor

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.

@ogoffart
Copy link
Contributor

Why not a new button next to "Close" to open the link?

@guruz
Copy link
Contributor

guruz commented Feb 14, 2018

@dragotin nice PR! When do you want to continue on it?

Why not a new button next to "Close" to open the link?

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.
@dragotin
Copy link
Contributor Author

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

@@ -57,6 +57,7 @@ class Activity
QString _message;
QString _file;
QUrl _link;
QString _linkText;
Copy link
Contributor

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.

// 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 ) {
Copy link
Contributor

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("&nbsp;<a href=\"%1\">%2</a>")
.arg(activity._link.toString(QUrl::FullyEncoded),
lText.toHtmlEscaped() ));
Copy link
Contributor

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() {
Copy link
Contributor

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

Copy link
Contributor

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

_ui._subjectLabel->setTextFormat(Qt::RichText);
_ui._subjectLabel->setOpenExternalLinks(true);

}
_ui._subjectLabel->setText(activity._subject);
Copy link
Contributor

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!

@dragotin
Copy link
Contributor Author

dragotin commented Mar 7, 2018

Thanks @ogoffart, I fixed stuff accordingly.

With the test I would need more advise ;-)

Copy link
Contributor

@ogoffart ogoffart left a 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() {
Copy link
Contributor

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

@ogoffart
Copy link
Contributor

ogoffart commented Mar 9, 2018

I wanted to remove my "Request change" without "Approving" but apparently this is not possible.

@dragotin
Copy link
Contributor Author

Should be good now.

@guruz guruz added this to the 2.5.0 milestone Mar 19, 2018
@guruz guruz added the Feature label Mar 19, 2018
@guruz guruz self-requested a review April 7, 2018 07:55
@guruz guruz self-assigned this Apr 7, 2018
@guruz
Copy link
Contributor

guruz commented Apr 9, 2018

Works for me, but let's wait if the server guys are OK with the format. I'll ping them.

screen shot 2018-04-09 at 17 28 27

We can make it more beautiful later. Maybe the link should be in a newline?

guruz added a commit to owncloud/notifications that referenced this pull request Apr 9, 2018
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(' '));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fishy ....

Copy link
Contributor

@guruz guruz left a 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

guruz added a commit to owncloud/notifications that referenced this pull request Apr 12, 2018
@guruz
Copy link
Contributor

guruz commented Apr 13, 2018

Superseded by #6453 after discussion on server issue about link text. Sorry @dragotin

@guruz guruz closed this Apr 13, 2018
DeepDiver1975 pushed a commit to owncloud/notifications that referenced this pull request Apr 18, 2018
@TheOneRing TheOneRing deleted the fix_6236 branch December 6, 2019 14:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants