Skip to content

Notifications: Display the link in the subject line. - #6240

Closed
dragotin wants to merge 9 commits into
masterfrom
fix_6236
Closed

dragotin wants to merge 9 commits into
masterfrom
fix_6236

Conversation

@dragotin

Copy link
Copy Markdown
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
Copy Markdown
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.

Comment thread src/gui/servernotificationhandler.cpp Outdated
// 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
Copy Markdown
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?

Comment thread src/gui/notificationwidget.cpp Outdated
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
Copy Markdown
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

Comment thread src/gui/servernotificationhandler.cpp Outdated
a._linkText = li.at(0);
} else {
a._link = QUrl(s);
a._linkText = QString("[%1]").arg(tr("link"));

Copy link
Copy Markdown
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]"))

Comment thread src/gui/notificationwidget.cpp Outdated
_ui._subjectLabel->setVisible(!activity._subject.isEmpty());
_ui._messageLabel->setVisible(!activity._message.isEmpty());

QString subject = activity._subject;

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

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

@guruz

guruz commented Feb 14, 2018

Copy link
Copy Markdown
Contributor

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

Comment thread src/gui/activitydata.h Outdated
QString _message;
QString _file;
QUrl _link;
QString _linkText;

Copy link
Copy Markdown
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.

Comment thread 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 ) {

Copy link
Copy Markdown
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
Copy Markdown
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?

Comment thread test/testactivitydata.cpp

private slots:

void testLinkSplitEmpty() {

Copy link
Copy Markdown
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
Copy Markdown
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

Comment thread src/gui/notificationwidget.cpp Outdated
_ui._subjectLabel->setOpenExternalLinks(true);

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

Copy link
Copy Markdown
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

dragotin commented Mar 7, 2018

Copy link
Copy Markdown
Contributor Author

Thanks @ogoffart, I fixed stuff accordingly.

With the test I would need more advise ;-)

@ogoffart ogoffart left a comment

Copy link
Copy Markdown
Contributor

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?)

Comment thread test/testactivitydata.cpp

private slots:

void testLinkSplitEmpty() {

Copy link
Copy Markdown
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

ogoffart commented Mar 9, 2018

Copy link
Copy Markdown
Contributor

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

@dragotin

Copy link
Copy Markdown
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

guruz commented Apr 9, 2018

Copy link
Copy Markdown
Contributor

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
Comment thread src/gui/activitydata.h
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
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

That's fishy ....

@guruz guruz left a comment

Copy link
Copy Markdown
Contributor

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

guruz commented Apr 13, 2018

Copy link
Copy Markdown
Contributor

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