diff --git a/mitterlib/network/twitter.py b/mitterlib/network/twitter.py index 65bdc5e..6e8779a 100644 --- a/mitterlib/network/twitter.py +++ b/mitterlib/network/twitter.py @@ -403,6 +403,12 @@ class Connection(NetworkBase): # too large. return TwitterNetworkData(data) + def repost(self, message): + """Repost a message.""" + body = {'id': message.id} # Force a body to make it a POST. + data = self._request('/statuses/retweet.json', body=body) + return TwitterNetworkData(data) + def delete_message(self, message): """Delete a message.""" if isinstance(message, NetworkData): @@ -427,6 +433,6 @@ class Connection(NetworkBase): return True; def can_repost(self, message): - """Always return True; Twitter allows reposting (retweeting) to - any messages, including the ones from the user.""" - return True; \ No newline at end of file + """Twitter ignores retweets from the user.""" + return not (message.username == + self._options[self.NAMESPACE]['username']) \ No newline at end of file diff --git a/mitterlib/ui/ui_pygtk.py b/mitterlib/ui/ui_pygtk.py index 3e7774f..51d4d5e 100644 --- a/mitterlib/ui/ui_pygtk.py +++ b/mitterlib/ui/ui_pygtk.py @@ -407,9 +407,7 @@ class Interface(object): "Put someone's else message on your timeline", gtk.STOCK_CONVERT) self._repost_action.set_property('sensitive', False) - # TODO: Connect - # TODO: Connecting function should indicate in the status bar that - # a repost will be made. + self._repost_action.connect('activate', self._repost_message) action_group.add_action_with_accel(self._repost_action, 'p') # Help actions @@ -558,6 +556,8 @@ class Interface(object): # unescape escaped entities that pango is not okay with message = re.sub(r'&', r'&', message) + message = re.sub(r'<', r'<', message) + message = re.sub(r'>', r'>', message) # highlight URLs mask = r'\1' % ( @@ -792,7 +792,7 @@ class Interface(object): return def _reply_message(self, widget, user_data=None): - """Reply to someone's else message.""" + """Reply to someone else's message.""" (model, iter) = self._grid.get_selection().get_selected() message = model.get_value(iter, 0) @@ -802,6 +802,18 @@ class Interface(object): return + def _repost_message(self, widget, user_data=None): + """Repost someone else's message on your timeline.""" + (model, iter)= self._grid.get_selection().get_selected() + message = model.get_value(iter, 0) + self._update_statusbar('Reposting %s message...' % + (message.username)) + self._threads.add_work(self._post_repost_message, + self._exception_repost_message, + self._connection.repost, + message) + return + # ------------------------------------------------------------ # Network related functions # ------------------------------------------------------------ @@ -896,6 +908,19 @@ class Interface(object): _log.debug(str(exception)) return + ### Results for the repost message call + def _post_repost_message(self, widget, data): + """Called when the message is reposted successfully.""" + _log.debug('Repost successful') + self._update_statusbar('Message reposted') + return + + def _exception_repost_message(self, widget, exception): + """Called when the message cannot be reposted.""" + _log.debug('Repost error.') + _log.debug(str(exception)) + return + # ------------------------------------------------------------ # Required functions for all interfaces # ------------------------------------------------------------