diff options
author | fiaxh <git@mx.ax.lt> | 2017-05-18 23:14:44 +0200 |
---|---|---|
committer | fiaxh <git@mx.ax.lt> | 2017-05-18 23:14:44 +0200 |
commit | 4247922e8cc85b488997ebef2121e6f3055e1e26 (patch) | |
tree | cf0837eb98a5e0dedf9deaa2fe8ba480c7098f0f /main/src | |
parent | b09a056a13de131a4f2f072ffa2f795a0bb2abe7 (diff) | |
download | dino-4247922e8cc85b488997ebef2121e6f3055e1e26.tar.gz dino-4247922e8cc85b488997ebef2121e6f3055e1e26.zip |
Member affiliation in occupant list
Diffstat (limited to 'main/src')
-rw-r--r-- | main/src/ui/occupant_menu/list.vala | 53 |
1 files changed, 50 insertions, 3 deletions
diff --git a/main/src/ui/occupant_menu/list.vala b/main/src/ui/occupant_menu/list.vala index 1e96ece4..ff30b180 100644 --- a/main/src/ui/occupant_menu/list.vala +++ b/main/src/ui/occupant_menu/list.vala @@ -83,9 +83,39 @@ public class List : Box { } private void header(ListBoxRow row, ListBoxRow? before_row) { - if (row.get_header() == null && before_row != null) { - row.set_header(new Separator(Orientation.HORIZONTAL)); + ListRow c1 = row as ListRow; + Xmpp.Xep.Muc.Affiliation a1 = stream_interactor.get_module(MucManager.IDENTITY).get_affiliation(conversation.counterpart, c1.jid, c1.account); + if (before_row != null) { + ListRow c2 = before_row as ListRow; + Xmpp.Xep.Muc.Affiliation a2 = stream_interactor.get_module(MucManager.IDENTITY).get_affiliation(conversation.counterpart, c2.jid, c2.account); + if (a1 != a2) { + row.set_header(generate_header_widget(a1, false)); + } else if (row.get_header() != null){ + row.set_header(null); + } + } else { + row.set_header(generate_header_widget(a1, true)); + } + } + + private Widget generate_header_widget(Xmpp.Xep.Muc.Affiliation affiliation, bool top) { + string aff_str; + switch (affiliation) { + case Xmpp.Xep.Muc.Affiliation.OWNER: + aff_str = _("Owner"); break; + case Xmpp.Xep.Muc.Affiliation.ADMIN: + aff_str = _("Admin"); break; + case Xmpp.Xep.Muc.Affiliation.MEMBER: + aff_str = _("Member"); break; + default: + aff_str = _("User"); break; } + Box box = new Box(Orientation.VERTICAL, 0) { visible=true }; + Label label = new Label("") { margin_left=10, margin_top=top?5:15, xalign=0, visible=true }; + label.set_markup(@"<b>$(Markup.escape_text(aff_str))</b>"); + box.add(label); + box.add(new Separator(Orientation.HORIZONTAL) { visible=true }); + return box; } private bool filter(ListBoxRow r) { @@ -102,10 +132,27 @@ public class List : Box { if (row1.get_type().is_a(typeof(ListRow)) && row2.get_type().is_a(typeof(ListRow))) { ListRow c1 = row1 as ListRow; ListRow c2 = row2 as ListRow; - return c1.name_label.label.collate(c2.name_label.label); + int affiliation1 = get_affiliation_ranking(stream_interactor.get_module(MucManager.IDENTITY).get_affiliation(conversation.counterpart, c1.jid, c1.account) ?? Xmpp.Xep.Muc.Affiliation.NONE); + int affiliation2 = get_affiliation_ranking(stream_interactor.get_module(MucManager.IDENTITY).get_affiliation(conversation.counterpart, c2.jid, c2.account) ?? Xmpp.Xep.Muc.Affiliation.NONE); + if (affiliation1 < affiliation2) return -1; + else if (affiliation1 > affiliation2) return 1; + else return c1.name_label.label.collate(c2.name_label.label); } return 0; } + + private int get_affiliation_ranking(Xmpp.Xep.Muc.Affiliation affiliation) { + switch (affiliation) { + case Xmpp.Xep.Muc.Affiliation.OWNER: + return 1; + case Xmpp.Xep.Muc.Affiliation.ADMIN: + return 2; + case Xmpp.Xep.Muc.Affiliation.MEMBER: + return 3; + default: + return 4; + } + } } }
\ No newline at end of file |