Handle conference bookmarks w/o nick

This commit is contained in:
fiaxh 2017-04-17 22:46:12 +02:00
parent 653c361420
commit c6ff3387fa
7 changed files with 77 additions and 75 deletions

View File

@ -14,7 +14,6 @@ public class MucManager : StreamInteractionModule, Object {
public signal void bookmarks_updated(Account account, ArrayList<Xep.Bookmarks.Conference> conferences);
private StreamInteractor stream_interactor;
protected HashMap<Jid, Xep.Bookmarks.Conference> conference_bookmarks = new HashMap<Jid, Xep.Bookmarks.Conference>();
public static void start(StreamInteractor stream_interactor) {
MucManager m = new MucManager(stream_interactor);
@ -28,10 +27,11 @@ public class MucManager : StreamInteractionModule, Object {
stream_interactor.get_module(MessageProcessor.IDENTITY).pre_message_received.connect(on_pre_message_received);
}
public void join(Account account, Jid jid, string nick, string? password = null) {
public void join(Account account, Jid jid, string? nick, string? password) {
Core.XmppStream stream = stream_interactor.get_stream(account);
if (stream == null) return;
stream.get_module(Xep.Muc.Module.IDENTITY).enter(stream, jid.bare_jid.to_string(), nick, password);
string nick_ = nick ?? account.bare_jid.localpart ?? account.bare_jid.domainpart;
stream.get_module(Xep.Muc.Module.IDENTITY).enter(stream, jid.bare_jid.to_string(), nick_, password);
}
public void part(Account account, Jid jid) {
@ -169,9 +169,8 @@ public class MucManager : StreamInteractionModule, Object {
Account account_ = tuple.b;
foreach (Xep.Bookmarks.Conference bookmark in conferences) {
Jid jid = new Jid(bookmark.jid);
outer_.conference_bookmarks[jid] = bookmark;
if (bookmark.autojoin) {
outer_.join(account_, jid, bookmark.nick);
outer_.join(account_, jid, bookmark.nick, bookmark.password);
}
}
}, Tuple.create(this, account));

View File

@ -44,7 +44,7 @@ protected class AddGroupchatDialog : Gtk.Dialog {
accounts_stack.set_visible_child_name("label");
account_label.label = account.bare_jid.to_string();
jid_entry.text = conference.jid;
nick_entry.text = conference.nick;
nick_entry.text = conference.nick ?? "";
autojoin_checkbutton.active = conference.autojoin;
alias_entry.text = conference.name;
}
@ -60,14 +60,13 @@ protected class AddGroupchatDialog : Gtk.Dialog {
private bool check_ok() {
Jid? parsed_jid = Jid.parse(jid_entry.text);
ok_button.sensitive = parsed_jid != null && parsed_jid.localpart != null && parsed_jid.resourcepart == null &&
nick_entry.text != "" && alias_entry.text != null;
ok_button.sensitive = parsed_jid != null && parsed_jid.localpart != null && parsed_jid.resourcepart == null;
return false;
}
private void on_ok_button_clicked() {
Xmpp.Xep.Bookmarks.Conference conference = new Xmpp.Xep.Bookmarks.Conference(jid_entry.text);
conference.nick = nick_entry.text;
conference.nick = nick_entry.text != "" ? nick_entry.text : null;
conference.name = alias_entry.text;
conference.autojoin = autojoin_checkbutton.active;
if (edit_confrence == null) {

View File

@ -31,14 +31,14 @@ protected class ConferenceDetailsFragment : Box {
jid_entry.text = value;
}
}
public string nick {
get { return nick_entry.text; }
public string? nick {
get { return nick_entry.text != "" ? nick_entry.text : null; }
set {
nick_label.label = value;
nick_entry.text = value;
nick_label.label = value ?? "";
nick_entry.text = value ?? "";
}
}
public string password {
public string? password {
get { return password_entry.text == "" ? null : password_entry.text; }
set {
password_label.label = value;

View File

@ -13,7 +13,7 @@ class SmileyConverter {
private static HashMap<string, string> smiley_translations = new HashMap<string, string>();
static construct {
smiley_translations[":)"] = "🙂";
smiley_translations[":)"] = "";
smiley_translations[":D"] = "😀";
smiley_translations[";)"] = "😉";
smiley_translations["O:)"] = "😇";
@ -22,7 +22,7 @@ class SmileyConverter {
smiley_translations[":o"] = "😮";
smiley_translations[":P"] = "😛";
smiley_translations[";P"] = "😜";
smiley_translations[":("] = "🙁";
smiley_translations[":("] = "";
smiley_translations[":'("] = "😢";
smiley_translations[":/"] = "😕";
}

View File

@ -149,7 +149,7 @@ public class List : ListBox {
ListBoxRow? index_m1 = get_row_at_index(index - 1);
if (index_m1 != null) {
select_row(index_m1);
row_activated(index_p1);
row_activated(index_m1);
}
}
}

View File

@ -38,10 +38,15 @@ public class Conference : Object {
}
set {
StanzaNode? nick_node = stanza_node.get_subnode(NODE_NICK);
if (value == null) {
if (nick_node != null) stanza_node.sub_nodes.remove(nick_node);
return;
}
if (nick_node == null) {
nick_node = new StanzaNode.build(NODE_NICK, NS_URI);
stanza_node.put_node(nick_node);
}
nick_node.sub_nodes.clear();
nick_node.put_node(new StanzaNode.text(value));
}
}
@ -61,14 +66,21 @@ public class Conference : Object {
}
}
public Conference.from_stanza_node(StanzaNode stanza_node) {
this.stanza_node = stanza_node;
}
public Conference(string jid) {
this.stanza_node = new StanzaNode.build("conference", NS_URI);
this.jid = jid;
}
public static Conference? create_from_stanza_node(StanzaNode stanza_node) {
if (stanza_node.get_attribute(ATTRIBUTE_JID) != null) {
return new Conference.from_stanza_node(stanza_node);
}
return null;
}
private Conference.from_stanza_node(StanzaNode stanza_node) {
this.stanza_node = stanza_node;
}
}
}

View File

@ -13,13 +13,11 @@ public class Module : XmppStreamModule {
[CCode (has_target = false)] public delegate void OnResult(XmppStream stream, ArrayList<Conference> conferences, Object? reference);
public void get_conferences(XmppStream stream, OnResult listener, Object? store) {
StanzaNode get_node = new StanzaNode.build("storage", NS_URI).add_self_xmlns();
stream.get_module(PrivateXmlStorage.Module.IDENTITY).retrieve(stream, get_node, on_conferences_received, Tuple.create(listener, store));
}
private static void on_conferences_received(XmppStream stream, StanzaNode node, Object? o) {
Tuple<OnResult, Object?> tuple = o as Tuple<OnResult, Object?>;
OnResult on_result = tuple.a;
on_result(stream, get_conferences_from_stanza(node), tuple.b);
stream.get_module(PrivateXmlStorage.Module.IDENTITY).retrieve(stream, get_node, (stream, node, o) => {
Tuple<OnResult, Object?> tuple = o as Tuple<OnResult, Object?>;
OnResult on_result = tuple.a;
on_result(stream, get_conferences_from_stanza(node), tuple.b);
}, Tuple.create(listener, store));
}
public void set_conferences(XmppStream stream, ArrayList<Conference> conferences) {
@ -27,58 +25,51 @@ public class Module : XmppStreamModule {
foreach (Conference conference in conferences) {
storage_node.put_node(conference.stanza_node);
}
stream.get_module(PrivateXmlStorage.Module.IDENTITY).store(stream, storage_node, on_set_conferences_response, conferences);
stream.get_module(PrivateXmlStorage.Module.IDENTITY).store(stream, storage_node, (stream, o) => {
stream.get_module(Module.IDENTITY).conferences_updated(stream, o as ArrayList<Conference>);
}, conferences);
}
private static void on_set_conferences_response(XmppStream stream, Object? o) {
ArrayList<Conference> conferences = o as ArrayList<Conference>;
stream.get_module(Module.IDENTITY).conferences_updated(stream, conferences);
public void add_conference(XmppStream stream, Conference add_) {
get_conferences(stream, (stream, conferences, o) => {
Conference add = o as Conference;
conferences.add(add);
stream.get_module(Module.IDENTITY).set_conferences(stream, conferences);
}, add_);
}
public void add_conference(XmppStream stream, Conference add) {
get_conferences(stream, on_add_conference_response, add);
}
private static void on_add_conference_response(XmppStream stream, ArrayList<Conference> conferences, Object? o) {
Conference add = o as Conference;
conferences.add(add);
stream.get_module(Module.IDENTITY).set_conferences(stream, conferences);
}
public void replace_conference(XmppStream stream, Conference was, Conference modified) {
get_conferences(stream, on_replace_conference_response, Tuple.create(was, modified));
}
private static void on_replace_conference_response(XmppStream stream, ArrayList<Conference> conferences, Object? o) {
Tuple<Conference, Conference> tuple = o as Tuple<Conference, Conference>;
Conference was = tuple.a;
Conference modified = tuple.b;
foreach (Conference conference in conferences) {
if (conference.name == was.name && conference.jid == was.jid && conference.autojoin == was.autojoin) {
conference.autojoin = modified.autojoin;
conference.name = modified.name;
conference.jid = modified.jid;
break;
}
}
stream.get_module(Module.IDENTITY).set_conferences(stream, conferences);
}
public void remove_conference(XmppStream stream, Conference conference) {
get_conferences(stream, on_remove_conference_response, conference);
}
private static void on_remove_conference_response(XmppStream stream, ArrayList<Conference> conferences, Object? o) {
Conference remove = o as Conference;
Conference? rem = null;
foreach (Conference conference in conferences) {
if (conference.name == remove.name && conference.jid == remove.jid && conference.autojoin == remove.autojoin) {
rem = conference;
public void replace_conference(XmppStream stream, Conference was_, Conference modified_) {
get_conferences(stream, (stream, conferences, o) => {
Tuple<Conference, Conference> tuple = o as Tuple<Conference, Conference>;
Conference was = tuple.a;
Conference modified = tuple.b;
foreach (Conference conference in conferences) {
if (conference.autojoin == was.autojoin && conference.jid == was.jid &&
conference.name == was.name && conference.nick == was.nick) {
conference.autojoin = modified.autojoin;
conference.jid = modified.jid;
conference.name = modified.name;
conference.nick = modified.nick;
break;
}
}
}
if (rem != null) conferences.remove(rem);
stream.get_module(Module.IDENTITY).set_conferences(stream, conferences);
stream.get_module(Module.IDENTITY).set_conferences(stream, conferences);
}, Tuple.create(was_, modified_));
}
public void remove_conference(XmppStream stream, Conference conference_) {
get_conferences(stream, (stream, conferences, o) => {
Conference remove = o as Conference;
Conference? rem = null;
foreach (Conference conference in conferences) {
if (conference.name == remove.name && conference.jid == remove.jid && conference.autojoin == remove.autojoin) {
rem = conference;
break;
}
}
if (rem != null) conferences.remove(rem);
stream.get_module(Module.IDENTITY).set_conferences(stream, conferences);
}, conference_);
}
public override void attach(XmppStream stream) { }
@ -96,7 +87,8 @@ public class Module : XmppStreamModule {
ArrayList<Conference> conferences = new ArrayList<Conference>();
ArrayList<StanzaNode> conferenceNodes = node.get_subnode("storage", NS_URI).get_subnodes("conference", NS_URI);
foreach (StanzaNode conferenceNode in conferenceNodes) {
conferences.add(new Conference.from_stanza_node(conferenceNode));
Conference? conference = Conference.create_from_stanza_node(conferenceNode);
conferences.add(conference);
}
return conferences;
}