From 32378533bc8514e24b1a823cddfd89b69b435b74 Mon Sep 17 00:00:00 2001 From: Julio Biason Date: Wed, 2 Dec 2009 18:56:54 -0200 Subject: [PATCH] We now can detect if a message belongs to the logged user --- mitterlib/network/__init__.py | 6 ++++++ mitterlib/network/networkbase.py | 6 ++++++ mitterlib/network/twitter.py | 8 ++++++++ 3 files changed, 20 insertions(+) diff --git a/mitterlib/network/__init__.py b/mitterlib/network/__init__.py index 711aa9e..bf9638b 100644 --- a/mitterlib/network/__init__.py +++ b/mitterlib/network/__init__.py @@ -147,6 +147,12 @@ 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 diff --git a/mitterlib/network/networkbase.py b/mitterlib/network/networkbase.py index f49bf9a..361be63 100644 --- a/mitterlib/network/networkbase.py +++ b/mitterlib/network/networkbase.py @@ -187,6 +187,12 @@ class NetworkBase(object): :class:`Networks` won't send requests to networks that return False to 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 diff --git a/mitterlib/network/twitter.py b/mitterlib/network/twitter.py index 4a00f1c..615965a 100644 --- a/mitterlib/network/twitter.py +++ b/mitterlib/network/twitter.py @@ -143,6 +143,13 @@ class Connection(NetworkBase): return True 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 @@ -293,6 +300,7 @@ class Connection(NetworkBase): high_id = 0 while response: # Not the cleanest code + # TODO: How the interfaces can interrupt this? if page > 1: params['page'] = page