After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 607446 - Support the append hint for notifications
Support the append hint for notifications
Status: RESOLVED FIXED
Product: empathy
Classification: Core
Component: Notifications
2.29.x
Other Linux
: Normal enhancement
: ---
Assigned To: empathy-maint
: 589851 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2010-01-19 14:11 UTC by Ken VanDine
Modified: 2010-04-01 08:47 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Check for append capability (2.70 KB, patch)
2010-01-19 14:17 UTC, Ken VanDine
rejected Details | Review
Use built-in empathy function for checking caps (1.96 KB, patch)
2010-01-19 15:55 UTC, Ken VanDine
reviewed Details | Review
x-canonical-append.patch (3.08 KB, patch)
2010-03-23 16:43 UTC, Nicolò Chieffo
none Details | Review
new patch (6.67 KB, patch)
2010-03-24 08:36 UTC, Nicolò Chieffo
none Details | Review
git formatted patch (8.14 KB, patch)
2010-03-24 09:30 UTC, Nicolò Chieffo
none Details | Review
patch (4.45 KB, patch)
2010-03-24 12:01 UTC, Nicolò Chieffo
reviewed Details | Review
git diff (4.23 KB, patch)
2010-03-25 11:21 UTC, Nicolò Chieffo
none Details | Review
git diff (6.56 KB, patch)
2010-03-25 12:20 UTC, Nicolò Chieffo
none Details | Review
git diff (7.39 KB, patch)
2010-03-27 11:25 UTC, Nicolò Chieffo
reviewed Details | Review
git diff (8.47 KB, patch)
2010-03-31 14:25 UTC, Nicolò Chieffo
none Details | Review

Description Ken VanDine 2010-01-19 14:11:09 UTC
notify-osd in Ubuntu includes a notification hint "x-canonical-append" which tells the notification daemon to append the notification instead of creating a new notification.

https://wiki.ubuntu.com/NotifyOSD

In empathy, using this append hint, notifications from the same chat contact just gets appended to the same notification bubble while it is being displayed instead of just showing you another notification.
Comment 1 Ken VanDine 2010-01-19 14:17:12 UTC
Created attachment 151761 [details] [review]
Check for append capability

* Adds support for the "x-canonical-append" hint from notify-osd, which appends notifications when possible.  
* Only attach the notification to the status icon if the status icon is displayed.
Comment 2 Ken VanDine 2010-01-19 15:55:05 UTC
Created attachment 151773 [details] [review]
Use built-in empathy function for checking caps

 * Adds support for the "x-canonical-append" hint from notify-osd, which appends notifications when possible (using empathy_notify_manager_has_capability). 
 * Only attach the notification to the status icon if the status icon is displayed.
Comment 3 Guillaume Desmottes 2010-01-19 16:06:57 UTC
Review of attachment 151773 [details] [review]:

Hi Ken. Thanks for your patch; I inlined some comments.

::: src/empathy-status-icon.c
@@ +160,3 @@
 
+		if ((priv->notification) && (!empathy_notify_manager_has_capability (priv->notify_mgr,
+							EMPATHY_NOTIFY_MANAGER_CAP_X_CANONICAL_APPEND))) {

Shouldn't we check the standard "append" caps as well?

@@ +203,3 @@
+								EMPATHY_NOTIFY_MANAGER_CAP_X_CANONICAL_APPEND)) {
+			notify_notification_set_hint_string (priv->notification,
+				EMPATHY_NOTIFY_MANAGER_CAP_X_CANONICAL_APPEND, "");

Shouldn't you set this hint only if there is an existing notification regarding the same contact?
Btw, how is that different from the standard EMPATHY_NOTIFY_MANAGER_CAP_APPEND caps?
Comment 4 Guillaume Desmottes 2010-01-19 16:09:29 UTC
*** Bug 589851 has been marked as a duplicate of this bug. ***
Comment 5 Nicolò Chieffo 2010-03-23 14:27:44 UTC
Might this feature go into final 2.30?
Comment 6 Nicolò Chieffo 2010-03-23 15:02:17 UTC
Guillaume, I'll try to answer your questions:

> Shouldn't we check the standard "append" caps as well?

Where is the standard "append" definition and documentation? Which notification daemon supports it? 
I think that "append" was renamed to "x-canonical-append" and only notify-osd supports it.

> Shouldn't you set this hint only if there is an existing notification regarding
> the same contact?

What's strange is that this file contains only the status notification code. when users talk to each other, another file is used "empathy-chat-window.c" which has its own notification. So the real problem is that the patch needs to be completed, but nevermind, it's quite simple. I'll attach the complete patch soon

> Btw, how is that different from the standard 
> EMPATHY_NOTIFY_MANAGER_CAP_APPEND caps?

In my opinion the original name was "append", but it needed to be renamed to "x-canonical-append" because it was not standard. Did someone introduce it to the standard?
Comment 7 Nicolò Chieffo 2010-03-23 15:22:51 UTC
here is a link to a bug that might give credit to my opinion about "append": https://bugs.launchpad.net/ubuntu/+source/notify-osd/+bug/341565
Comment 8 Nicolò Chieffo 2010-03-23 16:43:05 UTC
Created attachment 156889 [details] [review]
x-canonical-append.patch

A few comments:
-) remove the support from empahty-status-icon.c since I don't think it's useful for status changes, but only in chat notifications
-) unref the old notification before creating a new one
-) add a GMutex to access priv->notification, since previously you had only 1 notification opened, but now there is more than one, and lots of threads that can do a mess :D
-) call notify_notification_set_hint_string only once per notification

Please review ASAP to go to 2.30 release.
I have briefly tested it, and it works (with notify-osd)
Comment 9 Nicolò Chieffo 2010-03-24 08:36:23 UTC
Created attachment 156950 [details] [review]
new patch

This new patch tries to address some problems detected by ken, and brings the same logic to empathy-status-icon.c which seems to be needed when the chat window is closed.

Still not heavily tested
Comment 10 Guillaume Desmottes 2010-03-24 09:10:24 UTC
(In reply to comment #6)
> Guillaume, I'll try to answer your questions:
> 
> > Shouldn't we check the standard "append" caps as well?
> 
> Where is the standard "append" definition and documentation? Which notification
> daemon supports it? 
> I think that "append" was renamed to "x-canonical-append" and only notify-osd
> supports it.


"append" is implemented in notify-osd see:
https://bugzilla.gnome.org/show_bug.cgi?id=601691#c2

I didn't know it was the old name, thanks for the info!
Comment 11 Guillaume Desmottes 2010-03-24 09:19:28 UTC
(In reply to comment #8)
> Created an attachment (id=156889) [details] [review]
> x-canonical-append.patch
> 
> A few comments:
> -) remove the support from empahty-status-icon.c since I don't think it's
> useful for status changes, but only in chat notifications
> -) unref the old notification before creating a new one
> -) add a GMutex to access priv->notification, since previously you had only 1
> notification opened, but now there is more than one, and lots of threads that
> can do a mess :D

Where are threads invovled here? This code is not threaded.

> -) call notify_notification_set_hint_string only once per notification
> 
> Please review ASAP to go to 2.30 release.

We are no in hardcode freeze so that's too late for 2.30

> I have briefly tested it, and it works (with notify-osd)

Would be great if you could use "git format-patch" when attaching patches btw.
Comment 12 Nicolò Chieffo 2010-03-24 09:25:08 UTC
> Where are threads invovled here? This code is not threaded.

Well, the notification closed callback is executed in a separate thread. Isn't it?
Comment 13 Nicolò Chieffo 2010-03-24 09:30:38 UTC
Created attachment 156954 [details] [review]
git formatted patch

This patch should be git formatted (tell me if I did wrong things)
Comment 14 Guillaume Desmottes 2010-03-24 11:34:28 UTC
(In reply to comment #12)
> > Where are threads invovled here? This code is not threaded.
> 
> Well, the notification closed callback is executed in a separate thread. Isn't
> it?

No, libnotify is not threaded.
Comment 15 Nicolò Chieffo 2010-03-24 11:44:01 UTC
So there can't be concurrent access to chat_window_notification_closed_cb and any other function in this file? (and vice-versa of course)
Comment 16 Guillaume Desmottes 2010-03-24 11:48:44 UTC
Indeed.
Comment 17 Nicolò Chieffo 2010-03-24 11:54:53 UTC
I'm sorry, I need to learn lots of things!

how can I obtain a single patch from 2 git commits?
git format-patch -2
gives me 2 patches, but I need only one to attach here
Comment 18 Nicolò Chieffo 2010-03-24 12:01:08 UTC
Created attachment 156965 [details] [review]
patch

I removed all the mutex variables and calls

I used "git diff master" I hope it's ok.
Comment 19 Guillaume Desmottes 2010-03-25 09:06:31 UTC
Review of attachment 156965 [details] [review]:

::: src/empathy-status-icon.c
@@ +148,3 @@
 	EmpathyStatusIconPriv *priv = GET_PRIV (icon);
 	GdkPixbuf *pixbuf = NULL;
+	gboolean has_x_canonical_append;

This variable should be defined in the if block.

@@ +162,3 @@
 			message_esc = g_markup_escape_text (priv->event->message, -1);
 
+		has_x_canonical_append = empathy_notify_manager_has_capability (priv->notify_mgr,

This line is longer than 80 chars.

@@ +165,3 @@
+					EMPATHY_NOTIFY_MANAGER_CAP_X_CANONICAL_APPEND);
+
+		if (priv->notification != NULL && ! has_x_canonical_append) {

I don't like how this changes the semantic priv->notification. It used the be "the running notification, if any". Now it's "the last notification created". When creating a new notification, we just replace priv->notification and so loose the reference of the older notification which isn't great.

How this x-cannonical-append work exactly? Is it documented somewhere?
Comment 20 Nicolò Chieffo 2010-03-25 09:22:09 UTC
How do you prefer the line to be splitted? after the = or before the ( ?

I thought exactly the same thing: in this way you loose the reference to all the previous notifications. I don't know how they work exactly, because I couldn't find any documentation. Only this site: https://wiki.ubuntu.com/NotificationDevelopmentGuidelines but it doesn't say anything special. I also looked at the source example in "bzr branch lp:notify-osd", the only different thing there is that they unref the notification immediately after showing it, which is different from what we do, that is unref it in the close callback.
Comment 21 Guillaume Desmottes 2010-03-25 10:14:50 UTC
(In reply to comment #20)
> How do you prefer the line to be splitted? after the = or before the ( ?

I'd say after the '='.

> I thought exactly the same thing: in this way you loose the reference to all
> the previous notifications. I don't know how they work exactly, because I
> couldn't find any documentation. Only this site:
> https://wiki.ubuntu.com/NotificationDevelopmentGuidelines but it doesn't say
> anything special. I also looked at the source example in "bzr branch
> lp:notify-osd", the only different thing there is that they unref the
> notification immediately after showing it, which is different from what we do,
> that is unref it in the close callback.

Humm, maybe we don't need to keep a ref actually, maybe libnotify does it for us. Could you check that in libnotify's code please?
Comment 22 Nicolò Chieffo 2010-03-25 11:21:03 UTC
Created attachment 157051 [details] [review]
git diff

I fixed the variable and line length problem.

I still need to verify the notify-osd code (now I don't have time), but I don't think you need to keep all references, since the g_object_unref is done in the callbak, to which you always give the correct pointer.
Comment 23 Nicolò Chieffo 2010-03-25 11:57:15 UTC
notify-osd automatically unrefs the CURRENT bubble. So the best thing would be to keep track of the first created bubble.

if (new_bubble && bubble_is_append_allowed(bubble)) {
  app_bubble = find_bubble_for_append(self, bubble);

  /* Appending to an old bubble */
    if (app_bubble != NULL) {
      g_object_unref(bubble);
      bubble = app_bubble;
Comment 24 Nicolò Chieffo 2010-03-25 12:20:06 UTC
Created attachment 157055 [details] [review]
git diff

done
Comment 25 Guillaume Desmottes 2010-03-26 10:26:45 UTC
You missunderstand how things work here. We have two separated processes: Empathy (linked on libnotify) and notify-osd (or the notification-daemon).
These 2 processes don't share any memory, they just communicate together over D-Bus (Empathy uses libnotify which offer a more convenient API hidding the D-Bus bits). So an object created in Empathy does *not* exist in the address space of notify-osd.
What you have to check here is how libnotify manages NotifyNotification objects.

I did it for you and it seems that unreffing the object in the closed_cb is the good thing to do.

Do we really have to create a new NotifyNotification object when using the append hint? Can't we just reuse the existing one?
Comment 26 Nicolò Chieffo 2010-03-26 10:39:06 UTC
> I did it for you and it seems that unreffing the object in the closed_cb is the
> good thing to do.

Thanks for having done this, I didn't understand, sorry.
After having analyzed the libnotify code, do you think it's better to keep track of the last created notification, or the first?

> Do we really have to create a new NotifyNotification object when using the
> append hint? Can't we just reuse the existing one?

Yes, that's how it is supposed to work. Here's a quote from the notify-osd ubuntu page [1]:
"Notify OSD should merge two notifications into a single notification if all of the following are true:
  [....]
  * the second notification is not specified as a replacement of any other notification."
Since there's no NotifyNotification method to change the body (unless _update which sets the replaces_id) the only way is to create new notifications.

[1]: https://wiki.ubuntu.com/NotifyOSD#merging
Comment 27 Guillaume Desmottes 2010-03-26 15:36:07 UTC
(In reply to comment #26)
> > I did it for you and it seems that unreffing the object in the closed_cb is the
> > good thing to do.
> 
> Thanks for having done this, I didn't understand, sorry.
> After having analyzed the libnotify code, do you think it's better to keep
> track of the last created notification, or the first?

We have to unref all the notifications, if not we leak them.

Could you check what happen if we always create a new notification rather than using notify_notification_update? Maybe we could just stop using priv->notification and unref notification in the closed_cb (assuming this callback is always called only once).
Comment 28 Nicolò Chieffo 2010-03-26 16:09:07 UTC
I didn't check, but I'm quite sure that notification-daemon creates another bubble which is "appended" under the current showing bubbles.
With notification-daemon the only way to handle this is using _update, otherwise your screen will be flooded by notifications.

I didn't understand the problem of priv->notification. It's used only for _update and to destroy the notification when the window is closed. It doesn't cause memory leaks, since the unref is done in the callback using an argument. If you prefer it is also possible to unref it immediately after having shown it (only if x-canonical-append is enabled).
Comment 29 Nicolò Chieffo 2010-03-27 10:06:26 UTC
I've tested it now and I confirm what I've said in the previous post.
Comment 30 Nicolò Chieffo 2010-03-27 11:25:59 UTC
Created attachment 157271 [details] [review]
git diff

I did some code refactoring, and returned to the old logic: keep the reference to the latest created notification.
Comment 31 Nicolò Chieffo 2010-03-27 11:48:18 UTC
While I was testing my patch I found a bizarre emapthy behavior about notifications (when the chat windows are closed): only the notifications from one contact are show.

Scenario:
- ALL chat windows closed
- message received from A: "test1" -> notification shown
- message received from B: "test2" -> NO notification
- message received from A: "test3" -> notification shown
[....]
The notifications from B are shown as soon as I click on the status icon.
Should I file a new bug or this is normal for you?
Comment 32 Nicolò Chieffo 2010-03-30 16:13:48 UTC
Guillaume, is there anything else I can do to improve the patch?
Comment 33 Guillaume Desmottes 2010-03-31 13:46:05 UTC
Review of attachment 157271 [details] [review]:

Sorry for the late reply, I've been pretty busy with the 2.30 release. :)
This looks much better to me.

The patch doesn't apply on top of master. Could you update it please?

::: src/empathy-status-icon.c
@@ +166,3 @@
+					EMPATHY_NOTIFY_MANAGER_CAP_X_CANONICAL_APPEND);
+
+		if (notification != NULL && ! has_x_canonical_append) {

Would be cool if you could add a comment here.

@@ +171,3 @@
 						    NULL);
 		} else {
+			notification = notify_notification_new_with_status_icon

and here (just to explain the 2 ways to handle notifications.
Comment 34 Nicolò Chieffo 2010-03-31 14:25:09 UTC
Created attachment 157589 [details] [review]
git diff

I added the comments, I hope they are clear (I'm not native English speaker).

Does the patch apply to master now? To tell the truth I didn't have any conflicts when running git pull to my branch (tracking master)...
Comment 35 Guillaume Desmottes 2010-04-01 08:44:40 UTC
I'm not really happy about the code duplication but that's not your fault. I hope to refactor that during this cycle.
I merged your branch to master; thanks a lot for your work on this.

This problem has been fixed in the development version. The fix will be available in the next major software release. Thank you for your bug report.
Comment 36 Nicolò Chieffo 2010-04-01 08:47:32 UTC
> I'm not really happy about the code duplication

I was about to open a new bug