Move roster methods into Roster module
This commit is contained in:
parent
f601ca0d7b
commit
22b3388554
4 changed files with 31 additions and 24 deletions
|
@ -355,17 +355,6 @@ class CommonConnection:
|
||||||
additional_data=obj.additional_data,
|
additional_data=obj.additional_data,
|
||||||
stanza_id=obj.stanza_id)
|
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):
|
def new_account(self, name, config, sync=False):
|
||||||
"""
|
"""
|
||||||
To be implemented by derived classes
|
To be implemented by derived classes
|
||||||
|
|
|
@ -270,6 +270,17 @@ class Roster(BaseModule):
|
||||||
"""
|
"""
|
||||||
return self._get_item_data(jid, 'name')
|
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):
|
def set_item(self, jid, name=None, groups=None):
|
||||||
"""
|
"""
|
||||||
Rename contact 'jid' and sets the groups list that it now belongs to
|
Rename contact 'jid' and sets the groups list that it now belongs to
|
||||||
|
|
|
@ -97,8 +97,9 @@ class EditGroupsDialog:
|
||||||
self.dialog.show_all()
|
self.dialog.show_all()
|
||||||
if self.changes_made:
|
if self.changes_made:
|
||||||
for (contact, account) in self.list_:
|
for (contact, account) in self.list_:
|
||||||
app.connections[account].update_contact(contact.jid,
|
con = app.connections[account]
|
||||||
contact.name, contact.groups)
|
con.get_module('Roster').update_contact(
|
||||||
|
contact.jid, contact.name, contact.groups)
|
||||||
|
|
||||||
def on_edit_groups_dialog_response(self, widget, response_id):
|
def on_edit_groups_dialog_response(self, widget, response_id):
|
||||||
if response_id == Gtk.ResponseType.CLOSE:
|
if response_id == Gtk.ResponseType.CLOSE:
|
||||||
|
@ -1066,8 +1067,9 @@ class RosterItemExchangeWindow:
|
||||||
groups = []
|
groups = []
|
||||||
for u in app.contacts.get_contact(self.account, jid):
|
for u in app.contacts.get_contact(self.account, jid):
|
||||||
u.name = model[iter_][2]
|
u.name = model[iter_][2]
|
||||||
app.connections[self.account].update_contact(jid,
|
con = app.connections[self.account]
|
||||||
model[iter_][2], groups)
|
con.get_module('Roster').update_contact(
|
||||||
|
jid, model[iter_][2], groups)
|
||||||
self.draw_contact(jid, self.account)
|
self.draw_contact(jid, self.account)
|
||||||
# Update opened chat
|
# Update opened chat
|
||||||
ctrl = app.interface.msg_win_mgr.get_control(jid, self.account)
|
ctrl = app.interface.msg_win_mgr.get_control(jid, self.account)
|
||||||
|
|
|
@ -898,7 +898,8 @@ class RosterWindow:
|
||||||
changed_contacts.append({'jid': jid, 'name': contact.name,
|
changed_contacts.append({'jid': jid, 'name': contact.name,
|
||||||
'groups':contact.groups})
|
'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:
|
for c in changed_contacts:
|
||||||
self.add_contact(c['jid'], acc)
|
self.add_contact(c['jid'], acc)
|
||||||
|
@ -929,8 +930,9 @@ class RosterWindow:
|
||||||
# we might be dropped from meta to group
|
# we might be dropped from meta to group
|
||||||
contact.groups.append(group)
|
contact.groups.append(group)
|
||||||
if update:
|
if update:
|
||||||
app.connections[account].update_contact(jid, contact.name,
|
con = app.connections[account]
|
||||||
contact.groups)
|
con.get_module('Roster').update_contact(
|
||||||
|
jid, contact.name, contact.groups)
|
||||||
|
|
||||||
self.add_contact(jid, account)
|
self.add_contact(jid, account)
|
||||||
|
|
||||||
|
@ -957,8 +959,9 @@ class RosterWindow:
|
||||||
# Needed when we remove from "General" or "Observers"
|
# Needed when we remove from "General" or "Observers"
|
||||||
contact.groups.remove(group)
|
contact.groups.remove(group)
|
||||||
if update:
|
if update:
|
||||||
app.connections[account].update_contact(jid, contact.name,
|
con = app.connections[account]
|
||||||
contact.groups)
|
con.get_module('Roster').update_contact(
|
||||||
|
jid, contact.name, contact.groups)
|
||||||
self.add_contact(jid, account)
|
self.add_contact(jid, account)
|
||||||
|
|
||||||
# Also redraw old groups
|
# Also redraw old groups
|
||||||
|
@ -2890,8 +2893,9 @@ class RosterWindow:
|
||||||
contacts = app.contacts.get_contacts(account, jid)
|
contacts = app.contacts.get_contacts(account, jid)
|
||||||
for contact in contacts:
|
for contact in contacts:
|
||||||
contact.name = new_text
|
contact.name = new_text
|
||||||
app.connections[account].update_contact(jid, new_text, \
|
con = app.connections[account]
|
||||||
contacts[0].groups)
|
con.get_module('Roster').update_contact(
|
||||||
|
jid, new_text, contacts[0].groups)
|
||||||
self.draw_contact(jid, account)
|
self.draw_contact(jid, account)
|
||||||
# Update opened chats
|
# Update opened chats
|
||||||
for ctrl in app.interface.msg_win_mgr.get_controls(jid,
|
for ctrl in app.interface.msg_win_mgr.get_controls(jid,
|
||||||
|
@ -4075,8 +4079,9 @@ class RosterWindow:
|
||||||
_contact.groups = c_dest.groups[:]
|
_contact.groups = c_dest.groups[:]
|
||||||
app.contacts.add_metacontact(account_dest, c_dest.jid,
|
app.contacts.add_metacontact(account_dest, c_dest.jid,
|
||||||
_account, _contact.jid, contacts)
|
_account, _contact.jid, contacts)
|
||||||
app.connections[account_source].update_contact(_contact.jid,
|
con = app.connections[account_source]
|
||||||
_contact.name, _contact.groups)
|
con.get_module('Roster').update_contact(
|
||||||
|
_contact.jid, _contact.name, _contact.groups)
|
||||||
|
|
||||||
# Re-add all and update GUI
|
# Re-add all and update GUI
|
||||||
new_family = app.contacts.get_metacontacts_family(account_source,
|
new_family = app.contacts.get_metacontacts_family(account_source,
|
||||||
|
|
Loading…
Add table
Reference in a new issue