From 22b33885547c8fc3d2a5e21f84c1f3e4170c8015 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20H=C3=B6rist?= Date: Sat, 18 May 2019 01:30:37 +0200 Subject: [PATCH] Move roster methods into Roster module --- gajim/common/connection.py | 11 ----------- gajim/common/modules/roster.py | 11 +++++++++++ gajim/dialogs.py | 10 ++++++---- gajim/roster_window.py | 23 ++++++++++++++--------- 4 files changed, 31 insertions(+), 24 deletions(-) diff --git a/gajim/common/connection.py b/gajim/common/connection.py index f25e89ad5..632676894 100644 --- a/gajim/common/connection.py +++ b/gajim/common/connection.py @@ -355,17 +355,6 @@ class CommonConnection: additional_data=obj.additional_data, stanza_id=obj.stanza_id) - def update_contact(self, jid, name, groups): - if self.connection: - self.getRoster().set_item(jid=jid, name=name, groups=groups) - - def update_contacts(self, contacts): - """ - Update multiple roster items - """ - if self.connection: - self.getRoster().set_item_multi(contacts) - def new_account(self, name, config, sync=False): """ To be implemented by derived classes diff --git a/gajim/common/modules/roster.py b/gajim/common/modules/roster.py index 41ecb49c9..b95a6edcf 100644 --- a/gajim/common/modules/roster.py +++ b/gajim/common/modules/roster.py @@ -270,6 +270,17 @@ class Roster(BaseModule): """ return self._get_item_data(jid, 'name') + def update_contact(self, jid, name, groups): + if app.account_is_connected(self._account): + self.set_item(jid=jid, name=name, groups=groups) + + def update_contacts(self, contacts): + """ + Update multiple roster items + """ + if app.account_is_connected(self._account): + self.set_item_multi(contacts) + def set_item(self, jid, name=None, groups=None): """ Rename contact 'jid' and sets the groups list that it now belongs to diff --git a/gajim/dialogs.py b/gajim/dialogs.py index 1407a81cc..455905383 100644 --- a/gajim/dialogs.py +++ b/gajim/dialogs.py @@ -97,8 +97,9 @@ class EditGroupsDialog: self.dialog.show_all() if self.changes_made: for (contact, account) in self.list_: - app.connections[account].update_contact(contact.jid, - contact.name, contact.groups) + con = app.connections[account] + con.get_module('Roster').update_contact( + contact.jid, contact.name, contact.groups) def on_edit_groups_dialog_response(self, widget, response_id): if response_id == Gtk.ResponseType.CLOSE: @@ -1066,8 +1067,9 @@ class RosterItemExchangeWindow: groups = [] for u in app.contacts.get_contact(self.account, jid): u.name = model[iter_][2] - app.connections[self.account].update_contact(jid, - model[iter_][2], groups) + con = app.connections[self.account] + con.get_module('Roster').update_contact( + jid, model[iter_][2], groups) self.draw_contact(jid, self.account) # Update opened chat ctrl = app.interface.msg_win_mgr.get_control(jid, self.account) diff --git a/gajim/roster_window.py b/gajim/roster_window.py index 4175ce0ac..50841768a 100644 --- a/gajim/roster_window.py +++ b/gajim/roster_window.py @@ -898,7 +898,8 @@ class RosterWindow: changed_contacts.append({'jid': jid, 'name': contact.name, 'groups':contact.groups}) - app.connections[acc].update_contacts(changed_contacts) + app.connections[acc].get_module('Roster').update_contacts( + changed_contacts) for c in changed_contacts: self.add_contact(c['jid'], acc) @@ -929,8 +930,9 @@ class RosterWindow: # we might be dropped from meta to group contact.groups.append(group) if update: - app.connections[account].update_contact(jid, contact.name, - contact.groups) + con = app.connections[account] + con.get_module('Roster').update_contact( + jid, contact.name, contact.groups) self.add_contact(jid, account) @@ -957,8 +959,9 @@ class RosterWindow: # Needed when we remove from "General" or "Observers" contact.groups.remove(group) if update: - app.connections[account].update_contact(jid, contact.name, - contact.groups) + con = app.connections[account] + con.get_module('Roster').update_contact( + jid, contact.name, contact.groups) self.add_contact(jid, account) # Also redraw old groups @@ -2890,8 +2893,9 @@ class RosterWindow: contacts = app.contacts.get_contacts(account, jid) for contact in contacts: contact.name = new_text - app.connections[account].update_contact(jid, new_text, \ - contacts[0].groups) + con = app.connections[account] + con.get_module('Roster').update_contact( + jid, new_text, contacts[0].groups) self.draw_contact(jid, account) # Update opened chats for ctrl in app.interface.msg_win_mgr.get_controls(jid, @@ -4075,8 +4079,9 @@ class RosterWindow: _contact.groups = c_dest.groups[:] app.contacts.add_metacontact(account_dest, c_dest.jid, _account, _contact.jid, contacts) - app.connections[account_source].update_contact(_contact.jid, - _contact.name, _contact.groups) + con = app.connections[account_source] + con.get_module('Roster').update_contact( + _contact.jid, _contact.name, _contact.groups) # Re-add all and update GUI new_family = app.contacts.get_metacontacts_family(account_source,