Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reverting online/offline addings #68

Merged
merged 1 commit into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions main/data/occupant_list_item.ui
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,5 @@
</layout>
</object>
</child>
<child>
<object class="GtkImage" id="status_image">
<property name="pixel-size">12</property>
<layout>
<property name="column">2</property>
<property name="row">0</property>
</layout>
</object>
</child>
</object>
</interface>
69 changes: 62 additions & 7 deletions main/src/ui/occupant_menu/list.vala
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public class List : Box {
list_box.set_filter_func(filter);
search_entry.search_changed.connect(refilter);

stream_interactor.get_module(PresenceManager.IDENTITY).show_received.connect(on_received_online_presence);
stream_interactor.get_module(PresenceManager.IDENTITY).received_offline_presence.connect(on_received_offline_presence);
stream_interactor.get_module(PresenceManager.IDENTITY).show_received.connect(on_show_received);
stream_interactor.get_module(PresenceManager.IDENTITY).received_offline_presence.connect(on_quit_received);

initialize_for_conversation(conversation);
}
Expand Down Expand Up @@ -63,12 +63,11 @@ public class List : Box {
this.conversation = conversation;

var identity = stream_interactor.get_module(MucManager.IDENTITY);
Gee.List<Jid>? members = identity.get_all_members(conversation.counterpart, conversation.account);
Gee.List<Jid>? members = identity.get_members(conversation.counterpart, conversation.account);
if (members != null) {
// Add all members and their status to the list
foreach (Jid member in members) {
bool online = get_status(member, conversation.account);
add_member(member, online);
add_member(member); //use add_member_with_status if you want to get online/offline statuses
}
}
list_box.invalidate_filter();
Expand All @@ -83,7 +82,7 @@ public class List : Box {
list_box.invalidate_filter();
}

public void add_member(Jid jid, bool online) {
public void add_member_with_status(Jid jid, bool online) {
// HACK:
// Here we track members based on their names (not jids)
// Sometimes the same member can be referenced with different jids, for example:
Expand Down Expand Up @@ -124,6 +123,35 @@ public class List : Box {
}
}

public void add_member(Jid jid) {
var row_wrapper = new ListRow(stream_interactor, conversation, jid);
var widget = row_wrapper.get_widget();

string member_name = null;
if (jid.resourcepart != null) {
member_name = jid.resourcepart;
} else {
member_name = jid.localpart;
}

if (member_name == null) {
return;
}

row_wrappers[widget] = row_wrapper;
rows[member_name] = widget;
list_box.append(widget);
}

public void remove_member(Jid jid) {
var member_name = jid.resourcepart;
if (member_name == null) {
return;
}
list_box.remove(rows[member_name]);
rows.unset(member_name);
}

private void on_received_offline_presence(Jid jid, Account account) {
if (conversation != null && conversation.counterpart.equals_bare(jid) && jid.is_full()) {
var member_name = jid.resourcepart;
Expand All @@ -139,6 +167,19 @@ public class List : Box {
}
}

private void on_quit_received(Jid jid, Account account) {
if (conversation != null && conversation.counterpart.equals_bare(jid) && jid.is_full()) {
var member_name = jid.resourcepart;
if (member_name == null) {
return;
}
if (rows.has_key(member_name)) {
remove_member(jid);
}
list_box.invalidate_filter();
}
}

private void on_received_online_presence(Jid jid, Account account) {
if (conversation != null && conversation.counterpart.equals_bare(jid) && jid.is_full()) {
var member_name = jid.resourcepart;
Expand All @@ -147,7 +188,7 @@ public class List : Box {
}

if (!rows.has_key(member_name)) {
add_member(jid, true);
add_member_with_status(jid, true);
}

row_wrappers[rows[member_name]].set_online();
Expand All @@ -156,6 +197,20 @@ public class List : Box {
}
}

private void on_show_received(Jid jid, Account account) {
if (conversation != null && conversation.counterpart.equals_bare(jid) && jid.is_full()) {
var member_name = jid.resourcepart;
if (member_name == null) {
return;
}
if (!rows.has_key(member_name)) {
add_member(jid);
}
list_box.invalidate_filter();
}
}


private void header(ListBoxRow row, ListBoxRow? before_row) {
ListRow row_wrapper1 = row_wrappers[row.get_child()];
Xmpp.Xep.Muc.Affiliation? a1 = stream_interactor.get_module(MucManager.IDENTITY).get_affiliation(conversation.counterpart, row_wrapper1.jid, row_wrapper1.conversation.account);
Expand Down
4 changes: 0 additions & 4 deletions main/src/ui/occupant_menu/list_row.vala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ public class ListRow : Object {
private Grid main_grid;
private AvatarPicture picture;
public Label name_label;
public Image status_image;
public Conversation? conversation;
public Jid? jid;

Expand All @@ -19,7 +18,6 @@ public class ListRow : Object {
main_grid = (Grid) builder.get_object("main_grid");
picture = (AvatarPicture) builder.get_object("picture");
name_label = (Label) builder.get_object("name_label");
status_image = (Image) builder.get_object("status_image");
main_grid.set_column_spacing(10);
main_grid.set_column_homogeneous(false);
main_grid.set_baseline_row(1);
Expand All @@ -43,11 +41,9 @@ public class ListRow : Object {
}

public void set_online() {
status_image.icon_name = "dino-status-online-bright";
}

public void set_offline() {
status_image.icon_name = "dino-status-offline";
}
}

Expand Down
Loading