Browse Source

Options now can be checked in a per network basis, so the username doesn't need to be exposed and compared.

master
Julio Biason 15 years ago
parent
commit
2da5f56be0
  1. 18
      mitterlib/network/__init__.py
  2. 28
      mitterlib/network/networkbase.py
  3. 22
      mitterlib/network/twitter.py
  4. 12
      mitterlib/ui/ui_pygtk.py

18
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)

28
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;

22
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;

12
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

Loading…
Cancel
Save