Bug 27201

Summary: implement Messages interface
Product: Telepathy Reporter: Olivier Le Thanh Duong <olivier>
Component: butterflyAssignee: Telepathy bugs list <telepathy-bugs>
Status: RESOLVED FIXED QA Contact: Telepathy bugs list <telepathy-bugs>
Severity: normal    
Priority: medium Keywords: patch
Version: unspecified   
Hardware: Other   
OS: All   
URL: http://git.collabora.co.uk/?p=user/olethanh/telepathy-butterfly.git;a=shortlog;h=refs/heads/messages_iface
Whiteboard: review+
i915 platform: i915 features:

Description Olivier Le Thanh Duong 2010-03-19 10:33:48 UTC
We need to implement the Messages interface. It seems needed particularly for the PendingMessagesRemoved signals

17:24 < istaz> sjoerd: why? should we ? (I figure we will need it anyway when we will want to implement msn handwritting) 
17:24 < sjoerd> istaz: logger, everything.. Yes
17:26 < sjoerd> istaz: because it needs PendingMessagesRemoved
17:27 < sjoerd> istaz: and observers that want to show the pending message count also want that signal
Comment 2 Jonny Lamb 2010-03-30 08:44:47 UTC
I had a quick look over the code. Here are some comments to get you started:

-    def Send(self, message_type, text):
+    def _send_text_message(self, message_type, text):

I think it might have been me, but I was far too keen to use an underscore to prefix method names, even though they are being called from other classes. butterfly is not a library, so having do_this and do_that methods (sans underscore) really doesn't matter. Louis-Francis' webcam work did this nicer, for example.

I want to have a good look over butterfly (and perhaps tp-python too, but later) and fix this all over the place, but let's not introduce it more.

Does that make sense? (I'm basically asking for s/_send_text_message/send_text_message/g)

+        self._pending_messages2 = {}

Can this have a more useful name for this please? :-)

+        "Send a simple text message, return true if send correctly"""

Mismatched quotes and it's past tense, so s/send correctly/sent correctly/.

+    def _signal_text_sent(self, timestamp, message_type, text):
+            headers = {'message-sent' : timestamp,

Indented once too.

+    def GetPendingMessageContent(self, Message_ID, Parts):

I realise you copied these from the spec, but argument names Message_ID and Parts are not very pythonic. Can we rename to message_id and parts instead?

+    @dbus.service.signal('org.freedesktop.Telepathy.Channel.Interface.Messages', signature='aa{sv}')
+    def MessageReceived(self, Message):

Why did you add the decorator?

I need to read the Messages interface again and take another look at your branch.
Comment 3 Olivier Le Thanh Duong 2010-03-30 16:10:04 UTC
(In reply to comment #2)
> I had a quick look over the code. Here are some comments to get you started:
> 
> -    def Send(self, message_type, text):
> +    def _send_text_message(self, message_type, text):
> 
> I think it might have been me, but I was far too keen to use an underscore to
> prefix method names, even though they are being called from other classes.
> butterfly is not a library, so having do_this and do_that methods (sans
> underscore) really doesn't matter. Louis-Francis' webcam work did this nicer,
> for example.
> 
> I want to have a good look over butterfly (and perhaps tp-python too, but
> later) and fix this all over the place, but let's not introduce it more.
> 
> Does that make sense? (I'm basically asking for
> s/_send_text_message/send_text_message/g)
> 
I fell add the _ only when the method is called by the class and subclasses but if you fell strongly about it why not.

> +        self._pending_messages2 = {}
> 
> Can this have a more useful name for this please? :-)
Well the spec call it PendingMessage but self._pending_messages is already defined by ChannelTypeText in tp-python and I couldn't find any better names, any suggestion?

> 
> +        "Send a simple text message, return true if send correctly"""
> 
> Mismatched quotes and it's past tense, so s/send correctly/sent correctly/.
Corrected

> 
> +    def _signal_text_sent(self, timestamp, message_type, text):
> +            headers = {'message-sent' : timestamp,
> 
> Indented once too.
Corrected

> 
> +    def GetPendingMessageContent(self, Message_ID, Parts):
> 
> I realise you copied these from the spec, but argument names Message_ID and
> Parts are not very pythonic. Can we rename to message_id and parts instead?
> 
Corrected, and all the other methods which had non-lower case only arguments
> +   
> @dbus.service.signal('org.freedesktop.Telepathy.Channel.Interface.Messages',
> signature='aa{sv}')
> +    def MessageReceived(self, Message):
> 
> Why did you add the decorator?
> 
All the signals redefined in tp-python re-add the decorator, didn't actually test if that made a difference or not.

> I need to read the Messages interface again and take another look at your
> branch.
> 

Ok, I made another commit on top
Comment 4 Olivier Le Thanh Duong 2010-03-30 16:14:36 UTC
(In reply to comment #3)
> (In reply to comment #2)

> > +   
> > @dbus.service.signal('org.freedesktop.Telepathy.Channel.Interface.Messages',
> > signature='aa{sv}')
> > +    def MessageReceived(self, Message):
> > 
> > Why did you add the decorator?
> > 
> All the signals redefined in tp-python re-add the decorator, didn't actually
> test if that made a difference or not.
just tested, it doesn't emit it if we don't add the decorator
Comment 5 Jonny Lamb 2010-04-02 08:41:27 UTC
(In reply to comment #4)
> just tested, it doesn't emit it if we don't add the decorator

Odd. Well use the interface constant instead of "org.freedes..."

+    # run in an glib's idle so we emit the signal after either Send or SendMessage return
+    @async
+    def _signal_text_sent(self, timestamp, message_type, text):

dbus-python has a better way of doing this instead of throwing things in an idle. See CreateChannel in tp-python's ConnectionInterfaceRequests.

Other than that yeah let's go. Ping me when you've updated your branch.
Comment 6 Olivier Le Thanh Duong 2010-04-05 04:31:41 UTC
(In reply to comment #5)
> (In reply to comment #4)
> > just tested, it doesn't emit it if we don't add the decorator
> 
> Odd. Well use the interface constant instead of "org.freedes..."
> 
Done
> +    # run in an glib's idle so we emit the signal after either Send or
> SendMessage return
> +    @async
> +    def _signal_text_sent(self, timestamp, message_type, text):
> 
> dbus-python has a better way of doing this instead of throwing things in an
> idle. See CreateChannel in tp-python's ConnectionInterfaceRequests.
> 
> Other than that yeah let's go. Ping me when you've updated your branch.

I know about it but I actually found it far less readable than the simple async decorator. However if you feel strongly about it the top commit of the branche does that
Comment 7 Jonny Lamb 2010-04-06 08:42:34 UTC
Okay, fine, get merging.
Comment 8 Olivier Le Thanh Duong 2010-04-07 09:55:26 UTC
Merged thanks

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.