Browse Source

Repost

master
Julio Biason 15 years ago
parent
commit
26e261bb12
  1. 12
      mitterlib/network/twitter.py
  2. 33
      mitterlib/ui/ui_pygtk.py

12
mitterlib/network/twitter.py

@ -403,6 +403,12 @@ class Connection(NetworkBase):
# too large. # too large.
return TwitterNetworkData(data) 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): def delete_message(self, message):
"""Delete a message.""" """Delete a message."""
if isinstance(message, NetworkData): if isinstance(message, NetworkData):
@ -427,6 +433,6 @@ class Connection(NetworkBase):
return True; return True;
def can_repost(self, message): def can_repost(self, message):
"""Always return True; Twitter allows reposting (retweeting) to """Twitter ignores retweets from the user."""
any messages, including the ones from the user.""" return not (message.username ==
return True; self._options[self.NAMESPACE]['username'])

33
mitterlib/ui/ui_pygtk.py

@ -407,9 +407,7 @@ class Interface(object):
"Put someone's else message on your timeline", "Put someone's else message on your timeline",
gtk.STOCK_CONVERT) gtk.STOCK_CONVERT)
self._repost_action.set_property('sensitive', False) self._repost_action.set_property('sensitive', False)
# TODO: Connect self._repost_action.connect('activate', self._repost_message)
# TODO: Connecting function should indicate in the status bar that
# a repost will be made.
action_group.add_action_with_accel(self._repost_action, '<Ctrl>p') action_group.add_action_with_accel(self._repost_action, '<Ctrl>p')
# Help actions # Help actions
@ -558,6 +556,8 @@ class Interface(object):
# unescape escaped entities that pango is not okay with # unescape escaped entities that pango is not okay with
message = re.sub(r'&', r'&amp;', message) message = re.sub(r'&', r'&amp;', message)
message = re.sub(r'<', r'&lt;', message)
message = re.sub(r'>', r'&gt;', message)
# highlight URLs # highlight URLs
mask = r'<span foreground="%s">\1</span>' % ( mask = r'<span foreground="%s">\1</span>' % (
@ -792,7 +792,7 @@ class Interface(object):
return return
def _reply_message(self, widget, user_data=None): 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() (model, iter) = self._grid.get_selection().get_selected()
message = model.get_value(iter, 0) message = model.get_value(iter, 0)
@ -802,6 +802,18 @@ class Interface(object):
return 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 # Network related functions
# ------------------------------------------------------------ # ------------------------------------------------------------
@ -896,6 +908,19 @@ class Interface(object):
_log.debug(str(exception)) _log.debug(str(exception))
return 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 # Required functions for all interfaces
# ------------------------------------------------------------ # ------------------------------------------------------------

Loading…
Cancel
Save