From 117f19381233207e4b5aef03c82e7dd4b2d1debd Mon Sep 17 00:00:00 2001 From: fiaxh Date: Mon, 22 Aug 2022 13:08:31 +0200 Subject: Fix crashes and warning in Join Conference dialog fixes #1262 --- main/src/ui/add_conversation/conference_list.vala | 26 +++++++++++++++++----- .../ui/add_conversation/select_jid_fragment.vala | 6 ++++- 2 files changed, 25 insertions(+), 7 deletions(-) (limited to 'main/src') diff --git a/main/src/ui/add_conversation/conference_list.vala b/main/src/ui/add_conversation/conference_list.vala index 181c6219..454362d0 100644 --- a/main/src/ui/add_conversation/conference_list.vala +++ b/main/src/ui/add_conversation/conference_list.vala @@ -15,12 +15,14 @@ protected class ConferenceList { private ListBox list_box = new ListBox(); private HashMap> lists = new HashMap>(Account.hash_func, Account.equals_func); - private HashMap> widgets = new HashMap>(Account.hash_func, Account.equals_func); + private HashMap> widgets = new HashMap>(Account.hash_func, Account.equals_func); + + ulong bookmarks_updated_handler_id = -1; public ConferenceList(StreamInteractor stream_interactor) { this.stream_interactor = stream_interactor; - stream_interactor.get_module(MucManager.IDENTITY).bookmarks_updated.connect((account, conferences) => { + bookmarks_updated_handler_id = stream_interactor.get_module(MucManager.IDENTITY).bookmarks_updated.connect((account, conferences) => { lists[account] = conferences; refresh_conferences(); }); @@ -36,13 +38,21 @@ protected class ConferenceList { stream_interactor.get_module(MucManager.IDENTITY).conference_removed.connect(remove_conference); } + ~ConferenceList() { + stream_interactor.get_module(MucManager.IDENTITY).disconnect(bookmarks_updated_handler_id); + stream_interactor.get_module(MucManager.IDENTITY).conference_added.disconnect(add_conference); + stream_interactor.get_module(MucManager.IDENTITY).conference_removed.disconnect(remove_conference); + } + private void add_conference(Account account, Conference conference) { if (!widgets.has_key(account)) { - widgets[account] = new HashMap(Jid.hash_func, Jid.equals_func); + widgets[account] = new HashMap(Jid.hash_func, Jid.equals_func); } var widget = new ConferenceListRow(stream_interactor, conference, account); - widgets[account][conference.jid] = widget; - list_box.append(widget); + var list_box_row = new ListBoxRow(); + list_box_row.set_child(widget); + widgets[account][conference.jid] = list_box_row; + list_box.append(list_box_row); } private void remove_conference(Account account, Jid jid) { @@ -54,7 +64,11 @@ protected class ConferenceList { public void refresh_conferences() { foreach (Account account in widgets.keys) { - foreach (Jid jid in widgets[account].keys) { + + var account_widgets_cpy = new HashMap(); + account_widgets_cpy.set_all(widgets[account]); + + foreach (Jid jid in account_widgets_cpy.keys) { remove_conference(account, jid); } } diff --git a/main/src/ui/add_conversation/select_jid_fragment.vala b/main/src/ui/add_conversation/select_jid_fragment.vala index a6cf0864..25b0b11f 100644 --- a/main/src/ui/add_conversation/select_jid_fragment.vala +++ b/main/src/ui/add_conversation/select_jid_fragment.vala @@ -44,7 +44,11 @@ public class SelectJidFragment : Gtk.Box { list.row_selected.connect(() => { done = true; }); // just for notifying entry.changed.connect(() => { set_filter(entry.text); }); add_button.clicked.connect(() => { add_jid(); }); - remove_button.clicked.connect(() => { remove_jid(list.get_selected_row() as ListRow); }); + remove_button.clicked.connect(() => { + var list_row = list.get_selected_row(); + if (list_row == null) return; + remove_jid(list_row.child as ListRow); + }); } public void set_filter(string str) { -- cgit v1.2.3-70-g09d2