Display room name in conversation selector and conversation titlebar

This commit is contained in:
codedust 2018-08-20 02:59:58 +02:00 committed by fiaxh
parent 4ad07fea47
commit 1e54a442ba
6 changed files with 42 additions and 16 deletions

View file

@ -12,6 +12,7 @@ public class MucManager : StreamInteractionModule, Object {
public signal void enter_error(Account account, Jid jid, Xep.Muc.MucEnterError error);
public signal void left(Account account, Jid jid);
public signal void subject_set(Account account, Jid jid, string? subject);
public signal void room_name_set(Account account, Jid jid, string? room_name);
public signal void bookmarks_updated(Account account, Gee.List<Xep.Bookmarks.Conference> conferences);
private StreamInteractor stream_interactor;
@ -242,6 +243,9 @@ public class MucManager : StreamInteractionModule, Object {
stream_interactor.module_manager.get_module(account, Xep.Muc.Module.IDENTITY).subject_set.connect( (stream, subject, jid) => {
subject_set(account, jid, subject);
});
stream_interactor.module_manager.get_module(account, Xep.Muc.Module.IDENTITY).room_name_set.connect( (stream, jid, room_name) => {
room_name_set(account, jid, room_name);
});
stream_interactor.module_manager.get_module(account, Xep.Bookmarks.Module.IDENTITY).received_conferences.connect( (stream, conferences) => {
sync_autojoin_active(account, conferences);
bookmarks_updated(account, conferences);

View file

@ -61,7 +61,7 @@ public abstract class ConversationRow : ListBoxRow {
update_read();
}
protected void update_name_label(string? new_name = null) {
protected void update_name_label() {
name_label.label = Util.get_conversation_display_name(stream_interactor, conversation);
}

View file

@ -12,6 +12,12 @@ public class GroupchatRow : ConversationRow {
closed.connect(() => {
stream_interactor.get_module(MucManager.IDENTITY).part(conversation.account, conversation.counterpart);
});
stream_interactor.get_module(MucManager.IDENTITY).room_name_set.connect((account, jid, room_name) => {
if (conversation != null && conversation.counterpart.equals_bare(jid) && conversation.account.equals(account)) {
update_name_label();
}
});
}
protected override void update_message_label() {

View file

@ -36,9 +36,15 @@ public class ConversationTitlebar : Gtk.HeaderBar {
}
stream_interactor.get_module(MucManager.IDENTITY).room_name_set.connect((account, jid, room_name) => {
if (conversation != null && conversation.counterpart.equals_bare(jid) && conversation.account.equals(account)) {
update_title();
}
});
stream_interactor.get_module(MucManager.IDENTITY).subject_set.connect((account, jid, subject) => {
if (conversation != null && conversation.counterpart.equals_bare(jid) && conversation.account.equals(account)) {
update_subtitle(subject);
update_subtitle();
}
});
}
@ -57,17 +63,10 @@ public class ConversationTitlebar : Gtk.HeaderBar {
set_title(Util.get_conversation_display_name(stream_interactor, conversation));
}
private void update_subtitle(string? subtitle = null) {
if (subtitle != null) {
set_subtitle(subtitle);
} else if (conversation.type_ == Conversation.Type.GROUPCHAT) {
string? subject = stream_interactor.get_module(MucManager.IDENTITY).get_groupchat_subject(conversation.counterpart, conversation.account);
if (subject != null) {
subject = (new Regex("\\s+")).replace_literal(subject, -1, 0, " ");
}
set_subtitle(subject != "" ? subject : null);
} else {
set_subtitle(null);
private void update_subtitle() {
if (conversation.type_ == Conversation.Type.GROUPCHAT) {
string groupchat_subject = stream_interactor.get_module(MucManager.IDENTITY).get_groupchat_subject(conversation.counterpart, conversation.account);
set_subtitle(groupchat_subject);
}
}
}

View file

@ -59,7 +59,13 @@ public static string get_conversation_display_name(StreamInteractor stream_inter
}
public static string get_display_name(StreamInteractor stream_interactor, Jid jid, Account account) {
if (stream_interactor.get_module(MucManager.IDENTITY).is_groupchat_occupant(jid, account)) {
if (stream_interactor.get_module(MucManager.IDENTITY).is_groupchat(jid, account)) {
string room_name = stream_interactor.get_module(MucManager.IDENTITY).get_room_name(account, jid);
if (room_name != null) {
return room_name;
}
return jid.bare_jid.to_string();
} else if (stream_interactor.get_module(MucManager.IDENTITY).is_groupchat_occupant(jid, account)) {
return jid.resourcepart;
} else {
if (jid.equals_bare(account.bare_jid)) {

View file

@ -60,7 +60,7 @@ public class Module : XmppStreamModule {
public signal void received_occupant_jid(XmppStream stream, Jid jid, Jid? real_jid);
public signal void received_occupant_role(XmppStream stream, Jid jid, Role? role);
public signal void subject_set(XmppStream stream, string? subject, Jid jid);
public signal void room_configuration_changed(XmppStream stream, Jid jid, StatusCode code);
public signal void room_name_set(XmppStream stream, Jid jid, string? room_name);
public signal void room_entered(XmppStream stream, Jid jid, string nick);
public signal void room_enter_error(XmppStream stream, Jid jid, MucEnterError? error); // TODO "?" shoudln't be necessary (vala bug), remove someday
@ -207,6 +207,16 @@ public class Module : XmppStreamModule {
stream.get_flag(Flag.IDENTITY).set_muc_subject(message.from, subject);
subject_set(stream, subject, message.from);
}
StanzaNode? x_node = message.stanza.get_subnode("x", NS_URI_USER);
if (x_node != null) {
StanzaNode? status_node = x_node.get_subnode("status", NS_URI_USER);
if (status_node != null && status_node.get_attribute_int("code") == 104) {
// room configuration has changed (e.g. room name)
// https://xmpp.org/extensions/xep-0045.html#roomconfig-notify
query_room_info(stream, message.from.bare_jid);
}
}
}
}
@ -320,6 +330,7 @@ public class Module : XmppStreamModule {
foreach (ServiceDiscovery.Identity identity in query_result.identities) {
if (identity.category == "conference") {
stream.get_flag(Flag.IDENTITY).set_room_name(jid, identity.name);
room_name_set(stream, jid, identity.name);
}
}