RosterList: Disconnect handlers on widget destroy

Fixes #119
This commit is contained in:
fiaxh 2017-08-09 22:58:36 +02:00
parent b29d52fdda
commit dd88db7556

View file

@ -11,6 +11,7 @@ protected class RosterList : FilterableList {
public signal void conversation_selected(Conversation? conversation); public signal void conversation_selected(Conversation? conversation);
private StreamInteractor stream_interactor; private StreamInteractor stream_interactor;
private Gee.List<Account> accounts; private Gee.List<Account> accounts;
private ulong[] handler_ids = new ulong[0];
private HashMap<Account, HashMap<Jid, ListRow>> rows = new HashMap<Account, HashMap<Jid, ListRow>>(Account.hash_func, Account.equals_func); private HashMap<Account, HashMap<Jid, ListRow>> rows = new HashMap<Account, HashMap<Jid, ListRow>>(Account.hash_func, Account.equals_func);
@ -22,13 +23,18 @@ protected class RosterList : FilterableList {
set_header_func(header); set_header_func(header);
set_sort_func(sort); set_sort_func(sort);
stream_interactor.get_module(RosterManager.IDENTITY).removed_roster_item.connect( (account, jid, roster_item) => { handler_ids += stream_interactor.get_module(RosterManager.IDENTITY).removed_roster_item.connect( (account, jid, roster_item) => {
if (accounts.contains(account)) if (accounts.contains(account)) {
Idle.add(() => { on_removed_roster_item(account, jid, roster_item); return false;}); Idle.add(() => { on_removed_roster_item(account, jid, roster_item); return false;});
}
}); });
stream_interactor.get_module(RosterManager.IDENTITY).updated_roster_item.connect( (account, jid, roster_item) => { handler_ids += stream_interactor.get_module(RosterManager.IDENTITY).updated_roster_item.connect( (account, jid, roster_item) => {
if (accounts.contains(account)) if (accounts.contains(account)) {
Idle.add(() => { on_updated_roster_item(account, jid, roster_item); return false;}); Idle.add(() => { on_updated_roster_item(account, jid, roster_item); return false;});
}
});
destroy.connect(() => {
foreach (ulong handler_id in handler_ids) stream_interactor.get_module(RosterManager.IDENTITY).disconnect(handler_id);
}); });
foreach (Account a in accounts) fetch_roster_items(a); foreach (Account a in accounts) fetch_roster_items(a);