* added another table to handle roster group
* we now handle roster push and roster reception * changed version number in src/common/defs.py
This commit is contained in:
parent
9133960fbc
commit
0a3d26e5d4
|
@ -98,9 +98,18 @@ def create_log_db():
|
|||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS roster_entry(
|
||||
account_jid_id INTEGER PRIMARY KEY,
|
||||
account_jid_id INTEGER,
|
||||
jid_id INTEGER,
|
||||
subscription INTEGER
|
||||
name TEXT,
|
||||
subscription INTEGER,
|
||||
PRIMARY KEY (account_jid_id, jid_id)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS roster_group(
|
||||
account_jid_id INTEGER,
|
||||
jid_id INTEGER,
|
||||
group_name TEXT,
|
||||
PRIMARY KEY (account_jid_id, jid_id, group_name)
|
||||
);
|
||||
'''
|
||||
)
|
||||
|
|
|
@ -1542,6 +1542,7 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco,
|
|||
|
||||
def _rosterSetCB(self, con, iq_obj):
|
||||
log.debug('rosterSetCB')
|
||||
version = iq_obj.getTagAttr('query', 'ver')
|
||||
for item in iq_obj.getTag('query').getChildren():
|
||||
jid = helpers.parse_jid(item.getAttr('jid'))
|
||||
name = item.getAttr('name')
|
||||
|
@ -1551,6 +1552,14 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco,
|
|||
for group in item.getTags('group'):
|
||||
groups.append(group.getData())
|
||||
self.dispatch('ROSTER_INFO', (jid, name, sub, ask, groups))
|
||||
if version:
|
||||
account_jid = '%s@%s' % (
|
||||
gajim.config.get_per('accounts', self.name, 'name'),
|
||||
gajim.config.get_per('accounts', self.name, 'hostname'))
|
||||
gajim.logger.add_or_update_contact(account_jid, jid, name, sub,
|
||||
groups)
|
||||
gajim.config.set_per('accounts', self.name, 'roster_version',
|
||||
version)
|
||||
if not self.connection or self.connected < 2:
|
||||
raise common.xmpp.NodeProcessed
|
||||
reply = common.xmpp.Iq(typ='result', attrs={'id': iq_obj.getID()},
|
||||
|
|
|
@ -27,7 +27,7 @@ docdir = '../'
|
|||
datadir = '../'
|
||||
localedir = '../po'
|
||||
|
||||
version = '0.12.1.5-svn'
|
||||
version = '0.12.1.6-hg'
|
||||
|
||||
import sys, os.path
|
||||
for base in ('.', 'common'):
|
||||
|
|
|
@ -92,6 +92,13 @@ class Constants:
|
|||
self.TYPE_MRIM,
|
||||
) = range(14)
|
||||
|
||||
(
|
||||
self.SUBSCRIPTION_NONE,
|
||||
self.SUBSCRIPTION_TO,
|
||||
self.SUBSCRIPTION_FROM,
|
||||
self.SUBSCRIPTION_BOTH,
|
||||
) = range(4)
|
||||
|
||||
constants = Constants()
|
||||
|
||||
class Logger:
|
||||
|
@ -331,6 +338,16 @@ class Logger:
|
|||
if type_id == constants.TYPE_MRIM:
|
||||
return 'mrim'
|
||||
|
||||
def convert_human_subscription_values_to_db_api_values(self, sub):
|
||||
if sub == 'none':
|
||||
return constants.SUBSCRIPTION_NONE
|
||||
if sub == 'to':
|
||||
return constants.SUBSCRIPTION_TO
|
||||
if sub == 'from':
|
||||
return constants.SUBSCRIPTION_FROM
|
||||
if sub == 'both':
|
||||
return constants.SUBSCRIPTION_BOTH
|
||||
|
||||
def commit_to_db(self, values, write_unread = False):
|
||||
sql = 'INSERT INTO logs (jid_id, contact_name, time, kind, show, message, subject) VALUES (?, ?, ?, ?, ?, ?, ?)'
|
||||
try:
|
||||
|
@ -799,4 +816,39 @@ class Logger:
|
|||
except sqlite.OperationalError, e:
|
||||
print >> sys.stderr, str(e)
|
||||
|
||||
def del_contact(self, account_jid, jid):
|
||||
try:
|
||||
account_jid_id = self.get_jid_id(account_jid)
|
||||
jid_id = self.get_jid_id(jid)
|
||||
except exceptions.PysqliteOperationalError, e:
|
||||
raise exceptions.PysqliteOperationalError(str(e))
|
||||
sql = 'DELETE FROM roster_entry WHERE account_jid_id = %d AND jid_id = %d' % (account_jid_id, jid_id)
|
||||
self.simple_commit(sql)
|
||||
|
||||
def add_or_update_contact(self, account_jid, jid, name, sub, groups):
|
||||
if sub == 'remove':
|
||||
self.del_contact(account_jid, jid)
|
||||
return
|
||||
|
||||
try:
|
||||
account_jid_id = self.get_jid_id(account_jid)
|
||||
jid_id = self.get_jid_id(jid)
|
||||
except exceptions.PysqliteOperationalError, e:
|
||||
raise exceptions.PysqliteOperationalError(str(e))
|
||||
|
||||
# update groups information
|
||||
# first we delete all previous groups information
|
||||
sql = 'DELETE FROM roster_group WHERE account_jid_id = %d AND jid_id = %d' % (account_jid_id, jid_id)
|
||||
self.cur.execute(sql)
|
||||
# then we add all new groups information
|
||||
for group in groups:
|
||||
sql = 'INSERT INTO roster_group VALUES("%d", "%d", "%s")' % (
|
||||
account_jid_id, jid_id, group)
|
||||
self.cur.execute(sql)
|
||||
|
||||
sql = 'REPLACE INTO roster_entry VALUES("%d", "%d", "%s", "%d")' % (
|
||||
account_jid_id, jid_id, name,
|
||||
self.convert_human_subscription_values_to_db_api_values(sub))
|
||||
self.simple_commit(sql)
|
||||
|
||||
# vim: se ts=3:
|
||||
|
|
|
@ -198,6 +198,8 @@ class OptionsParser:
|
|||
self.update_config_to_01214()
|
||||
if old < [0, 12, 1, 5] and new >= [0, 12, 1, 5]:
|
||||
self.update_config_to_01215()
|
||||
if old < [0, 12, 1, 6] and new >= [0, 12, 1, 6]:
|
||||
self.update_config_to_01216()
|
||||
|
||||
gajim.logger.init_vars()
|
||||
gajim.config.set('version', new_version)
|
||||
|
@ -681,9 +683,18 @@ class OptionsParser:
|
|||
cur.executescript(
|
||||
'''
|
||||
CREATE TABLE IF NOT EXISTS roster_entry(
|
||||
account_jid_id INTEGER PRIMARY KEY,
|
||||
account_jid_id INTEGER,
|
||||
jid_id INTEGER,
|
||||
subscription INTEGER
|
||||
name TEXT,
|
||||
subscription INTEGER,
|
||||
PRIMARY KEY (account_jid_id, jid_id)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS roster_group(
|
||||
account_jid_id INTEGER,
|
||||
jid_id INTEGER,
|
||||
group_name TEXT,
|
||||
PRIMARY KEY (account_jid_id, jid_id, group_name)
|
||||
);
|
||||
'''
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue