Fix not requesting roster on empty cache.db

The purpose of

`if version and not gajim.contacts.get_contacts_jid_list()`

seemed to be that when cache.db is empty (maybe it was deleted)
`gajim.contacts.get_contacts_jid_list()` should come back empty.

So on an empty roster cache, version was set to None, so that we
request in any case a new roster.

The Problem is that `gajim.contacts.get_contacts_jid_list()` is not
a good indication for an empty cache.db. On start we trigger a
`RosterReceivedEvent` which does a DB query to get the roster. Even
if that DB query comes up empty, the Event is still pushed.

In the event handler `_nec_roster_received` in roster_window.py we
add then previously open controls and our self (if the option is set)
to the roster, making `gajim.contacts.get_contacts_jid_list()` return
these contacts and hence the condition in `request_roster()` always
False.

So the version is set in the roster request, and if there is no new
version on the server, we request no new roster even though we only
have ourself and previously open controls in our roster.

As a solution for this we delete the roster version from the config
in `RosterReceivedEvent` if the DB query comes back empty, which
triggers a new roster request.
This commit is contained in:
Philipp Hörist 2017-07-19 01:45:04 +02:00
parent e675df1803
commit cdc2ec9205
2 changed files with 4 additions and 6 deletions

View File

@ -2501,16 +2501,11 @@ class Connection(CommonConnection, ConnectionHandlers):
def request_roster(self):
version = None
features = self.connection.Dispatcher.Stream.features
features = self.connection.Dispatcher.Stream.features
if features and features.getTag('ver',
namespace=nbxmpp.NS_ROSTER_VER):
version = gajim.config.get_per('accounts', self.name,
'roster_version')
if version and not gajim.contacts.get_contacts_jid_list(
self.name):
gajim.config.set_per('accounts', self.name, 'roster_version',
'')
version = None
iq_id = self.connection.initRoster(version=version)
self.awaiting_answers[iq_id] = (ROSTER_ARRIVED, )

View File

@ -410,6 +410,9 @@ class RosterReceivedEvent(nec.NetworkIncomingEvent):
'roster_version')
self.roster = gajim.logger.get_roster(gajim.get_jid_from_account(
self.conn.name))
if not self.roster:
gajim.config.set_per(
'accounts', self.conn.name, 'roster_version', '')
return True
class RosterSetReceivedEvent(nec.NetworkIncomingEvent):