diff libervia.py @ 282:ae3ec654836d

browser_side: added blog item modification/deletion
author souliane <souliane@mailoo.org>
date Tue, 10 Dec 2013 09:07:03 +0100
parents 1ccdc34cfb60
children 4f0c2fea358a
line wrap: on
line diff
--- a/libervia.py	Mon Dec 09 15:34:03 2013 +0100
+++ b/libervia.py	Tue Dec 10 09:07:03 2013 +0100
@@ -119,7 +119,8 @@
                          "tarotGameContratChoosed", "tarotGamePlayCards", "launchRadioCollective",
                          "getWaitingSub", "subscription", "delContact", "updateContact", "getCard",
                          "getEntityData", "getParamsUI", "asyncGetParamA", "setParam", "launchAction",
-                         "disconnect", "chatStateComposing", "getNewAccountDomain", "confirmationAnswer"
+                         "disconnect", "chatStateComposing", "getNewAccountDomain", "confirmationAnswer",
+                         "syntaxConvert"
                         ])
 
 
@@ -458,6 +459,7 @@
         if not self.initialised:
             self.init_cache.append((sender, event_type, data))
             return
+        sender = JID(sender).bare
         if event_type == "MICROBLOG":
             if not 'content' in data:
                 print ("WARNING: No content found in microblog data")
@@ -473,9 +475,30 @@
                     self.addBlogEntry(lib_wid, sender, _groups, mblog_entry)
 
             if sender == self.whoami.bare:
-                self.mblog_cache.append((_groups, mblog_entry))
-                if len(self.mblog_cache) > MAX_MBLOG_CACHE:
-                    del self.mblog_cache[0:len(self.mblog_cache - MAX_MBLOG_CACHE)]
+                found = False
+                for index in xrange(0, len(self.mblog_cache)):
+                    entry = self.mblog_cache[index]
+                    if entry[1].id == mblog_entry.id:
+                        # replace existing entry
+                        self.mblog_cache.remove(entry)
+                        self.mblog_cache.insert(index, (_groups, mblog_entry))
+                        found = True
+                        break
+                if not found:
+                    self.mblog_cache.append((_groups, mblog_entry))
+                    if len(self.mblog_cache) > MAX_MBLOG_CACHE:
+                        del self.mblog_cache[0:len(self.mblog_cache - MAX_MBLOG_CACHE)]
+        elif event_type == 'MICROBLOG_DELETE':
+            for lib_wid in self.libervia_widgets:
+                if isinstance(lib_wid, panels.MicroblogPanel):
+                    lib_wid.removeEntry(data['type'], data['id'])
+            print self.whoami.bare, sender, data['type']
+            if sender == self.whoami.bare and data['type'] == 'main_item':
+                for index in xrange(0, len(self.mblog_cache)):
+                    entry = self.mblog_cache[index]
+                    if entry[1].id == data['id']:
+                        self.mblog_cache.remove(entry)
+                        break
 
     def addBlogEntry(self, mblog_panel, sender, _groups, mblog_entry):
         """Check if an entry can go in MicroblogPanel and add to it