hupili / snsapi

Cross platform middleware for Social Networking Services: Twitter, Facebook, SinaWeibo, Renren, RSS, Email, Sqlite, ... (more coming)
http://snsapi.ie.cuhk.edu.hk
160 stars 53 forks source link

class Message comparable by time #49

Closed iptux closed 11 years ago

iptux commented 11 years ago

if more than one channel is available, home_timeline(count) return a MessageList contains count * channel_number Messages, but that intent to be exactly count Messages only.

MessageList should be sorted first and return the first count Messages

this requires Message class comparable by time, more recently Status should show first

hupili commented 11 years ago

Thanks for the point. Making Message class comparable is immediate. You can pass key=lambda x: x.parsed.time to the sort function.

I should consider what service home_timeline of SNSPocket is to provide. Original purpose of all methods of SNSPocket is to provide a way to batch execute corresponding methods of concrete platforms. There is no confusion with other methods, e.g. auth will authorize all the channels; update will update statuses on all channels; etc. Sticking to this semantic, home_timeline of SNSPocket invokes home_timeline of all channels with the same arguments. In this case, the current way of returning messages is reasonable.

Although the above explains the current behaviour, the count parameter is still misleading. Maybe a clearer description in the docstring helps. ( @uestcmy FYI. )

One reason not to mix the results of all channels, sort them and truncate to count number of messages is that:

As to the design, I think the meaning of methods of SNSPocket is different from that of plugins. When you pass parameters to methods of SNSPocket, you keep in mind that it is just a proxy which will invoke corresponding methods of all channels using the same argument (or possibly differently configured default values).

After we improve the docstring, please come back to see if there is still confusion.

In the app layer, if you want home_timeline return count Messages sorted by time, you can

SNSPocket.home_timeline = some wrapper function
iptux commented 11 years ago

got it, thanks

hupili commented 11 years ago

More notes on home_timeline of plugins.

The plugins only guarantee no more than count messages are returned. There can be less messages. The main reason is that this is the guarantee we get from the service providers. For example, when you retrieve renren feeds (especially for specific types), even there are enough feeds, the platform may return less than count messages.