From 2da5f56be0399f86ffbc31ad92d92f7107d590fc Mon Sep 17 00:00:00 2001 From: Julio Biason Date: Sat, 5 Dec 2009 18:43:16 -0200 Subject: [PATCH] Options now can be checked in a per network basis, so the username doesn't need to be exposed and compared. --- mitterlib/network/__init__.py | 18 ++++++++++++------ mitterlib/network/networkbase.py | 28 ++++++++++++++++++++++------ mitterlib/network/twitter.py | 22 +++++++++++++++------- mitterlib/ui/ui_pygtk.py | 12 ++++++------ 4 files changed, 55 insertions(+), 25 deletions(-) diff --git a/mitterlib/network/__init__.py b/mitterlib/network/__init__.py index bf9638b..bd0a412 100644 --- a/mitterlib/network/__init__.py +++ b/mitterlib/network/__init__.py @@ -147,12 +147,6 @@ class Networks(object): except KeyError: raise NetworksNoSuchNetworkError(shortcut) return name - - def is_self(self, message): - """Return True if the message belongs to the logged user.""" - if self.networks[message.network].username() == message.username: - return True - return False # This is basically a copy of all methods available in NetworkBase, with # the additional parameter "network" (to request data from just one @@ -220,3 +214,15 @@ class Networks(object): requests = self.networks[shortcut].available_requests() result[shortcut] = requests return result + + def can_delete(self, message): + """Return True if the message can be deleted; False otherwise.""" + return self.networks[message.network].can_delete(message) + + def can_reply(self, message): + """Return True if the message can be replied; False otherwise.""" + return self.networks[message.network].can_reply(message) + + def can_repost(self, message): + """Return True if the message can be resposted; False otherwise.""" + return self.networks[message.network].can_repost(message) \ No newline at end of file diff --git a/mitterlib/network/networkbase.py b/mitterlib/network/networkbase.py index 361be63..5cf0783 100644 --- a/mitterlib/network/networkbase.py +++ b/mitterlib/network/networkbase.py @@ -188,12 +188,6 @@ class NetworkBase(object): this function.""" return False - def username(self): - """Return the username of the logged user. This is used by the - interfaces to check if the message belongs to the logged user or - someone else.""" - return '' - def messages(self): """Return a list of :class:`NetworkData` objects for the main "timeline" (the default list presented to the user.)""" @@ -205,6 +199,16 @@ class NetworkBase(object): reply to another message, it could be a simple id or the :class:`NetworkData` object of the original data. Must return the id for the new status.""" + # TODO: All networks will return an id? If so, what we do with it + # anyway? + return None + + def repost(self, message): + """Repost a message in your current timeline. *message* must be a + valid :class:`NetworkData` object. Must return the id of the new + message.""" + # TODO: All networks will return an id? If so, what we do with it + # anyway? return None def delete_message(self, message): @@ -228,3 +232,15 @@ class NetworkBase(object): capped. If such limitation doesn't exist for the network, a negative number should be returned.""" return -1 + + def can_delete(self, message): + """Return True if the message can be deleted; False otherwise.""" + return False; + + def can_reply(self, message): + """Return True if the message can be replied; False otherwise.""" + return False; + + def can_repost(self, message): + """Return True if the message can be resposted; False otherwise.""" + return False; \ No newline at end of file diff --git a/mitterlib/network/twitter.py b/mitterlib/network/twitter.py index 615965a..2ccfcd5 100644 --- a/mitterlib/network/twitter.py +++ b/mitterlib/network/twitter.py @@ -144,13 +144,6 @@ class Connection(NetworkBase): else: return False - def username(self): - """Return the username of the logged user on Twitter.""" - username = self._options[self.NAMESPACE]['username'] - if not username: - return '' - return username - def __init__(self, options): self._options = options @@ -410,3 +403,18 @@ class Connection(NetworkBase): response = self._request(resource, body=body) _log.debug('Delete response: %s', response) return response + + def can_delete(self, message): + """Check if the message belongs to the user. If so, returns True; + False otherwise.""" + return (message.username == self._options[self.NAMESPACE]['username']) + + def can_reply(self, message): + """Always return True; Twitter allows replying to any messages, + including the ones from the user.""" + 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 diff --git a/mitterlib/ui/ui_pygtk.py b/mitterlib/ui/ui_pygtk.py index b66b2de..e6e9409 100644 --- a/mitterlib/ui/ui_pygtk.py +++ b/mitterlib/ui/ui_pygtk.py @@ -675,12 +675,12 @@ class Interface(object): (model, iter) = view.get_selection().get_selected() data = model.get_value(iter, 0) - user_owned = self._connection.is_self(data) - _log.debug('User message: %s', str(user_owned)) - - self._delete_action.set_property('sensitive', user_owned) - self._reply_action.set_property('sensitive', not user_owned) - self._repost_action.set_property('sensitive', not user_owned) + self._delete_action.set_property('sensitive', + self._connection.can_delete(data)) + self._reply_action.set_property('sensitive', + self._connection.can_reply(data)) + self._repost_action.set_property('sensitive', + self._connection.can_repost(data)) return 0