[twitter] fix storage system
This commit is contained in:
parent
e25d8cabc4
commit
d00822bfc6
2 changed files with 14 additions and 18 deletions
|
|
@ -17,8 +17,8 @@
|
||||||
# You should have received a copy of the GNU Affero General Public License
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
|
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
from datetime import time, datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
|
import time
|
||||||
from weboob.tools.value import Value, ValueBackendPassword
|
from weboob.tools.value import Value, ValueBackendPassword
|
||||||
from weboob.tools.backend import BaseBackend, BackendConfig
|
from weboob.tools.backend import BaseBackend, BackendConfig
|
||||||
from weboob.capabilities.messages import CapMessages, Thread, CapMessagesPost
|
from weboob.capabilities.messages import CapMessages, Thread, CapMessagesPost
|
||||||
|
|
@ -92,14 +92,12 @@ class TwitterBackend(BaseBackend, CapMessages, CapMessagesPost, CapCollection):
|
||||||
return self.get_thread(thread.id, thread, getseen)
|
return self.get_thread(thread.id, thread, getseen)
|
||||||
|
|
||||||
def set_message_read(self, message):
|
def set_message_read(self, message):
|
||||||
self.storage.set('seen', message.thread.id, 'comments',
|
self.storage.set('seen', message.thread.id, message.thread.date)
|
||||||
self.storage.get('seen',
|
|
||||||
message.thread.id,
|
|
||||||
'comments', default=[]) + [message.id])
|
|
||||||
self.storage.save()
|
self.storage.save()
|
||||||
self._purge_message_read()
|
self._purge_message_read()
|
||||||
|
|
||||||
def _purge_message_read(self):
|
def _purge_message_read(self):
|
||||||
|
|
||||||
lastpurge = self.storage.get('lastpurge', default=0)
|
lastpurge = self.storage.get('lastpurge', default=0)
|
||||||
|
|
||||||
if time.time() - lastpurge > 86400:
|
if time.time() - lastpurge > 86400:
|
||||||
|
|
@ -109,17 +107,14 @@ class TwitterBackend(BaseBackend, CapMessages, CapMessagesPost, CapCollection):
|
||||||
# we can't directly delete without a "RuntimeError: dictionary changed size during iteration"
|
# we can't directly delete without a "RuntimeError: dictionary changed size during iteration"
|
||||||
todelete = []
|
todelete = []
|
||||||
|
|
||||||
for id in self.storage.get('seen', default={}):
|
for id, date in self.storage.get('seen', default={}).iteritems():
|
||||||
date = self.storage.get('date', id, default=0)
|
|
||||||
# if no date available, create a new one (compatibility with "old" storage)
|
# if no date available, create a new one (compatibility with "old" storage)
|
||||||
if date == 0:
|
if not date:
|
||||||
self.storage.set('date', id, datetime.now())
|
self.storage.set('seen', id, datetime.now())
|
||||||
elif datetime.now() - date > timedelta(days=60):
|
elif datetime.now() - date > timedelta(days=60):
|
||||||
todelete.append(id)
|
todelete.append(id)
|
||||||
|
|
||||||
for id in todelete:
|
for id in todelete:
|
||||||
self.storage.delete('hash', id)
|
|
||||||
self.storage.delete('date', id)
|
|
||||||
self.storage.delete('seen', id)
|
self.storage.delete('seen', id)
|
||||||
self.storage.save()
|
self.storage.save()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -97,15 +97,16 @@ class TwitterBrowser(LoginBrowser):
|
||||||
children=[]
|
children=[]
|
||||||
)
|
)
|
||||||
|
|
||||||
if seen and splitted_id[1] not in seen:
|
if seen and (_id not in seen):
|
||||||
thread.root.flags = Message.IS_UNREAD
|
thread.root.flags = Message.IS_UNREAD
|
||||||
|
|
||||||
comments = self.thread_page.stay_or_go(_id=splitted_id[1].split('.')[-1], user=splitted_id[0]).iter_comments()
|
comments = self.thread_page.stay_or_go(_id=splitted_id[1].split('.')[-1], user=splitted_id[0]).iter_comments()
|
||||||
for comment in comments:
|
for comment in comments:
|
||||||
if seen and comment.id in seen:
|
|
||||||
comment.thread = thread
|
comment.thread = thread
|
||||||
comment.parent = thread.root
|
comment.parent = thread.root
|
||||||
|
if seen and comment.id not in seen.keys():
|
||||||
comment.flags = Message.IS_UNREAD
|
comment.flags = Message.IS_UNREAD
|
||||||
|
|
||||||
thread.root.children.append(comment)
|
thread.root.children.append(comment)
|
||||||
|
|
||||||
return thread
|
return thread
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue