diff src/core/sat_main.py @ 346:ca3a041fed30

core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
author Goffi <goffi@goffi.org>
date Sat, 28 May 2011 20:28:21 +0200
parents 9eebdc655b8b
children ea3e1b82dd79
line wrap: on
line diff
--- a/src/core/sat_main.py	Sat May 28 20:24:02 2011 +0200
+++ b/src/core/sat_main.py	Sat May 28 20:28:21 2011 +0200
@@ -34,6 +34,7 @@
 from twisted.internet import reactor
 
 from wokkel import compat
+from wokkel.xmppim import RosterItem
 
 from sat.bridge.DBus import DBusBridge
 import logging
@@ -128,6 +129,7 @@
         self.bridge.register("setPresence", self.setPresence)
         self.bridge.register("subscription", self.subscription)
         self.bridge.register("addContact", self.addContact)
+        self.bridge.register("updateContact", self.updateContact)
         self.bridge.register("delContact", self.delContact)
         self.bridge.register("isConnected", self.isConnected)
         self.bridge.register("launchAction", self.launchAction)
@@ -235,7 +237,7 @@
 
         current.startService()
 
-    def disconnect(self, profile_key='@DEFAULT@'):
+    def disconnect(self, profile_key):
         """disconnect from jabber server"""
         if (not self.isConnected(profile_key)):
             info(_("not connected !"))
@@ -322,7 +324,7 @@
         else:
             self.actionResult(action_id, "SUPPRESS", {})
 
-    def submitForm(self, action, target, fields, profile_key='@DEFAULT@'):
+    def submitForm(self, action, target, fields, profile_key):
         """submit a form
         @param target: target jid where we are submitting
         @param fields: list of tuples (name, value)
@@ -351,12 +353,12 @@
 
     ## Client management ##
 
-    def setParam(self, name, value, category, profile_key='@DEFAULT@'):
+    def setParam(self, name, value, category, profile_key):
         """set wanted paramater and notice observers"""
         info (_("setting param: %(name)s=%(value)s in category %(category)s") % {'name':name, 'value':value, 'category':category})
         self.memory.setParam(name, value, category, profile_key)
 
-    def isConnected(self, profile_key='@DEFAULT@'):
+    def isConnected(self, profile_key):
         """Return connection status of profile
         @param profile_key: key_word or profile name to determine profile name
         @return True if connected
@@ -369,7 +371,7 @@
             return False
         return self.profiles[profile].isConnected()
 
-    def launchAction(self, type, data, profile_key='@DEFAULT@'):
+    def launchAction(self, type, data, profile_key):
         """Launch a specific action asked by client
         @param type: action type (button)
         @param data: needed data to launch the action
@@ -429,7 +431,7 @@
                 int(priority), statuses, profile)
         
     
-    def subscription(self, subs_type, raw_jid, profile_key='@DEFAULT@'):
+    def subscription(self, subs_type, raw_jid, profile_key):
         """Called to manage subscription
         @param subs_type: subsciption type (cf RFC 3921)
         @param raw_jid: unicode entity's jid
@@ -442,17 +444,12 @@
             self.profiles[profile].presence.subscribe(to_jid)
         elif subs_type=="subscribed":
             self.profiles[profile].presence.subscribed(to_jid)
-            contact = self.memory.getContact(to_jid) 
-            if not contact or not bool(contact['to']): #we automatically subscribe to 'to' presence
-                debug(_('sending automatic "to" subscription request'))
-                self.subscription('subscribe', to_jid.userhost())
         elif subs_type=="unsubscribe":
             self.profiles[profile].presence.unsubscribe(to_jid)
         elif subs_type=="unsubscribed":
             self.profiles[profile].presence.unsubscribed(to_jid)
 
-
-    def addContact(self, to, profile_key='@DEFAULT@'):
+    def addContact(self, to, profile_key):
         """Add a contact in roster list"""
         profile = self.memory.getProfileName(profile_key)
         assert(profile)
@@ -460,7 +457,18 @@
         #self.profiles[profile].roster.addItem(to_jid) XXX: disabled (cf http://wokkel.ik.nu/ticket/56))
         self.profiles[profile].presence.subscribe(to_jid)
 
-    def delContact(self, to, profile_key='@DEFAULT@'):
+    def updateContact(self, to, name, groups, profile_key):
+        """update a contact in roster list"""
+        profile = self.memory.getProfileName(profile_key)
+        assert(profile)
+        to_jid = jid.JID(to)
+        groups = set(groups)
+        roster_item = RosterItem(to_jid)
+        roster_item.name = name or None
+        roster_item.groups = set(groups)
+        self.profiles[profile].roster.updateItem(roster_item)
+
+    def delContact(self, to, profile_key):
         """Remove contact from roster list"""
         profile = self.memory.getProfileName(profile_key)
         assert(profile)