| ... |
... |
@@ -177,7 +177,7 @@ class Logger: |
|
177
|
177
|
con.close()
|
|
178
|
178
|
|
|
179
|
179
|
@staticmethod
|
|
180
|
|
- def _get_user_version(con) -> int:
|
|
|
180
|
+ def _get_user_version(con: sqlite.Connection) -> int:
|
|
181
|
181
|
""" Return the value of PRAGMA user_version. """
|
|
182
|
182
|
return con.execute('PRAGMA user_version').fetchone()[0]
|
|
183
|
183
|
|
| ... |
... |
@@ -547,7 +547,7 @@ class Logger: |
|
547
|
547
|
if type_id == TypeConstant.NO_TRANSPORT:
|
|
548
|
548
|
return 'jabber'
|
|
549
|
549
|
|
|
550
|
|
- def convert_human_subscription_values_to_db_api_values(self, sub):
|
|
|
550
|
+ def convert_xmpp_sub(self, sub):
|
|
551
|
551
|
"""
|
|
552
|
552
|
Convert from string style to constant ints for db
|
|
553
|
553
|
"""
|
| ... |
... |
@@ -560,7 +560,7 @@ class Logger: |
|
560
|
560
|
if sub == 'both':
|
|
561
|
561
|
return SubscriptionConstant.BOTH
|
|
562
|
562
|
|
|
563
|
|
- def convert_db_api_values_to_human_subscription_values(self, sub):
|
|
|
563
|
+ def convert_db_sub(self, sub):
|
|
564
|
564
|
"""
|
|
565
|
565
|
Convert from constant ints for db to string style
|
|
566
|
566
|
"""
|
| ... |
... |
@@ -577,9 +577,10 @@ class Logger: |
|
577
|
577
|
"""
|
|
578
|
578
|
Add unread message with id: message_id
|
|
579
|
579
|
"""
|
|
580
|
|
- sql = 'INSERT INTO unread_messages VALUES (%d, %d, 0)' % (message_id,
|
|
581
|
|
- jid_id)
|
|
582
|
|
- self.simple_commit(sql)
|
|
|
580
|
+ sql = '''INSERT INTO unread_messages (message_id, jid_id, shown)
|
|
|
581
|
+ VALUES (?, ?, 0)'''
|
|
|
582
|
+ self._con.execute(sql, (message_id, jid_id))
|
|
|
583
|
+ self._timeout_commit()
|
|
583
|
584
|
|
|
584
|
585
|
def set_read_messages(self, message_ids):
|
|
585
|
586
|
"""
|
| ... |
... |
@@ -947,8 +948,9 @@ class Logger: |
|
947
|
948
|
(type_id, jid)
|
|
948
|
949
|
self.simple_commit(sql)
|
|
949
|
950
|
return
|
|
950
|
|
- sql = 'INSERT INTO transports_cache VALUES ("%s", %d)' % (jid, type_id)
|
|
951
|
|
- self.simple_commit(sql)
|
|
|
951
|
+ sql = 'INSERT INTO transports_cache (transport, type) VALUES (?, ?)'
|
|
|
952
|
+ self._con.execute(sql, (jid, type_id))
|
|
|
953
|
+ self._timeout_commit()
|
|
952
|
954
|
|
|
953
|
955
|
def get_transports_type(self):
|
|
954
|
956
|
"""
|
| ... |
... |
@@ -1113,7 +1115,7 @@ class Logger: |
|
1113
|
1115
|
self._timeout_commit()
|
|
1114
|
1116
|
|
|
1115
|
1117
|
def add_or_update_contact(self, account_jid, jid, name, sub, ask, groups,
|
|
1116
|
|
- commit=True):
|
|
|
1118
|
+ commit=True):
|
|
1117
|
1119
|
"""
|
|
1118
|
1120
|
Add or update a contact from account_jid roster
|
|
1119
|
1121
|
"""
|
| ... |
... |
@@ -1124,29 +1126,30 @@ class Logger: |
|
1124
|
1126
|
try:
|
|
1125
|
1127
|
account_jid_id = self.get_jid_id(account_jid)
|
|
1126
|
1128
|
jid_id = self.get_jid_id(jid, type_=JIDConstant.NORMAL_TYPE)
|
|
1127
|
|
- except exceptions.PysqliteOperationalError as e:
|
|
1128
|
|
- raise exceptions.PysqliteOperationalError(str(e))
|
|
|
1129
|
+ except exceptions.PysqliteOperationalError as error:
|
|
|
1130
|
+ raise exceptions.PysqliteOperationalError(str(error))
|
|
1129
|
1131
|
|
|
1130
|
1132
|
# Update groups information
|
|
1131
|
1133
|
# First we delete all previous groups information
|
|
1132
|
|
- self._con.execute(
|
|
1133
|
|
- 'DELETE FROM roster_group WHERE account_jid_id=? AND jid_id=?',
|
|
1134
|
|
- (account_jid_id, jid_id))
|
|
|
1134
|
+ sql = 'DELETE FROM roster_group WHERE account_jid_id=? AND jid_id=?'
|
|
|
1135
|
+ self._con.execute(sql, (account_jid_id, jid_id))
|
|
1135
|
1136
|
# Then we add all new groups information
|
|
|
1137
|
+ sql = '''INSERT INTO roster_group (account_jid_id, jid_id, group_name)
|
|
|
1138
|
+ VALUES (?, ?, ?)'''
|
|
1136
|
1139
|
for group in groups:
|
|
1137
|
|
- self._con.execute('INSERT INTO roster_group VALUES(?, ?, ?)',
|
|
1138
|
|
- (account_jid_id, jid_id, group))
|
|
|
1140
|
+ self._con.execute(sql, (account_jid_id, jid_id, group))
|
|
1139
|
1141
|
|
|
1140
|
1142
|
if name is None:
|
|
1141
|
1143
|
name = ''
|
|
1142
|
1144
|
|
|
1143
|
|
- self._con.execute('''
|
|
1144
|
|
- REPLACE INTO roster_entry
|
|
1145
|
|
- (account_jid_id, jid_id, name, subscription, ask)
|
|
1146
|
|
- VALUES(?, ?, ?, ?, ?)''', (
|
|
1147
|
|
- account_jid_id, jid_id, name,
|
|
1148
|
|
- self.convert_human_subscription_values_to_db_api_values(sub),
|
|
1149
|
|
- bool(ask)))
|
|
|
1145
|
+ sql = '''REPLACE INTO roster_entry
|
|
|
1146
|
+ (account_jid_id, jid_id, name, subscription, ask)
|
|
|
1147
|
+ VALUES(?, ?, ?, ?, ?)'''
|
|
|
1148
|
+ self._con.execute(sql, (account_jid_id,
|
|
|
1149
|
+ jid_id,
|
|
|
1150
|
+ name,
|
|
|
1151
|
+ self.convert_xmpp_sub(sub),
|
|
|
1152
|
+ bool(ask)))
|
|
1150
|
1153
|
if commit:
|
|
1151
|
1154
|
self._timeout_commit()
|
|
1152
|
1155
|
|
| ... |
... |
@@ -1172,9 +1175,7 @@ class Logger: |
|
1172
|
1175
|
data[jid]['name'] = name
|
|
1173
|
1176
|
else:
|
|
1174
|
1177
|
data[jid]['name'] = None
|
|
1175
|
|
- data[jid]['subscription'] = \
|
|
1176
|
|
- self.convert_db_api_values_to_human_subscription_values(
|
|
1177
|
|
- row.subscription)
|
|
|
1178
|
+ data[jid]['subscription'] = self.convert_db_sub(row.subscription)
|
|
1178
|
1179
|
data[jid]['groups'] = []
|
|
1179
|
1180
|
data[jid]['resources'] = {}
|
|
1180
|
1181
|
if row.ask:
|