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); public signal void bookmarks_updated(Account account, ArrayList<Xep.Bookmarks.Conference> conferences);
private StreamInteractor stream_interactor; 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) { public static void start(StreamInteractor stream_interactor) {
MucManager m = new MucManager(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); 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); Core.XmppStream stream = stream_interactor.get_stream(account);
if (stream == null) return; 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) { public void part(Account account, Jid jid) {
@ -169,9 +169,8 @@ public class MucManager : StreamInteractionModule, Object {
Account account_ = tuple.b; Account account_ = tuple.b;
foreach (Xep.Bookmarks.Conference bookmark in conferences) { foreach (Xep.Bookmarks.Conference bookmark in conferences) {
Jid jid = new Jid(bookmark.jid); Jid jid = new Jid(bookmark.jid);
outer_.conference_bookmarks[jid] = bookmark;
if (bookmark.autojoin) { if (bookmark.autojoin) {
outer_.join(account_, jid, bookmark.nick); outer_.join(account_, jid, bookmark.nick, bookmark.password);
} }
} }
}, Tuple.create(this, account)); }, Tuple.create(this, account));

View file

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

View file

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

View file

@ -13,7 +13,7 @@ class SmileyConverter {
private static HashMap<string, string> smiley_translations = new HashMap<string, string>(); private static HashMap<string, string> smiley_translations = new HashMap<string, string>();
static construct { static construct {
smiley_translations[":)"] = "🙂"; smiley_translations[":)"] = "";
smiley_translations[":D"] = "😀"; smiley_translations[":D"] = "😀";
smiley_translations[";)"] = "😉"; smiley_translations[";)"] = "😉";
smiley_translations["O:)"] = "😇"; smiley_translations["O:)"] = "😇";
@ -22,7 +22,7 @@ class SmileyConverter {
smiley_translations[":o"] = "😮"; smiley_translations[":o"] = "😮";
smiley_translations[":P"] = "😛"; smiley_translations[":P"] = "😛";
smiley_translations[";P"] = "😜"; smiley_translations[";P"] = "😜";
smiley_translations[":("] = "🙁"; smiley_translations[":("] = "";
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); ListBoxRow? index_m1 = get_row_at_index(index - 1);
if (index_m1 != null) { if (index_m1 != null) {
select_row(index_m1); select_row(index_m1);
row_activated(index_p1); row_activated(index_m1);
} }
} }
} }

View file

@ -38,10 +38,15 @@ public class Conference : Object {
} }
set { set {
StanzaNode? nick_node = stanza_node.get_subnode(NODE_NICK); 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) { if (nick_node == null) {
nick_node = new StanzaNode.build(NODE_NICK, NS_URI); nick_node = new StanzaNode.build(NODE_NICK, NS_URI);
stanza_node.put_node(nick_node); stanza_node.put_node(nick_node);
} }
nick_node.sub_nodes.clear();
nick_node.put_node(new StanzaNode.text(value)); 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) { public Conference(string jid) {
this.stanza_node = new StanzaNode.build("conference", NS_URI); this.stanza_node = new StanzaNode.build("conference", NS_URI);
this.jid = jid; 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); [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) { public void get_conferences(XmppStream stream, OnResult listener, Object? store) {
StanzaNode get_node = new StanzaNode.build("storage", NS_URI).add_self_xmlns(); 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)); stream.get_module(PrivateXmlStorage.Module.IDENTITY).retrieve(stream, get_node, (stream, node, o) => {
}
private static void on_conferences_received(XmppStream stream, StanzaNode node, Object? o) {
Tuple<OnResult, Object?> tuple = o as Tuple<OnResult, Object?>; Tuple<OnResult, Object?> tuple = o as Tuple<OnResult, Object?>;
OnResult on_result = tuple.a; OnResult on_result = tuple.a;
on_result(stream, get_conferences_from_stanza(node), tuple.b); on_result(stream, get_conferences_from_stanza(node), tuple.b);
}, Tuple.create(listener, store));
} }
public void set_conferences(XmppStream stream, ArrayList<Conference> conferences) { public void set_conferences(XmppStream stream, ArrayList<Conference> conferences) {
@ -27,48 +25,40 @@ public class Module : XmppStreamModule {
foreach (Conference conference in conferences) { foreach (Conference conference in conferences) {
storage_node.put_node(conference.stanza_node); 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) { public void add_conference(XmppStream stream, Conference add_) {
ArrayList<Conference> conferences = o as ArrayList<Conference>; get_conferences(stream, (stream, conferences, o) => {
stream.get_module(Module.IDENTITY).conferences_updated(stream, conferences);
}
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; Conference add = o as Conference;
conferences.add(add); conferences.add(add);
stream.get_module(Module.IDENTITY).set_conferences(stream, conferences); stream.get_module(Module.IDENTITY).set_conferences(stream, conferences);
}, add_);
} }
public void replace_conference(XmppStream stream, Conference was, Conference modified) { public void replace_conference(XmppStream stream, Conference was_, Conference modified_) {
get_conferences(stream, on_replace_conference_response, Tuple.create(was, modified)); get_conferences(stream, (stream, conferences, o) => {
}
private static void on_replace_conference_response(XmppStream stream, ArrayList<Conference> conferences, Object? o) {
Tuple<Conference, Conference> tuple = o as Tuple<Conference, Conference>; Tuple<Conference, Conference> tuple = o as Tuple<Conference, Conference>;
Conference was = tuple.a; Conference was = tuple.a;
Conference modified = tuple.b; Conference modified = tuple.b;
foreach (Conference conference in conferences) { foreach (Conference conference in conferences) {
if (conference.name == was.name && conference.jid == was.jid && conference.autojoin == was.autojoin) { if (conference.autojoin == was.autojoin && conference.jid == was.jid &&
conference.name == was.name && conference.nick == was.nick) {
conference.autojoin = modified.autojoin; conference.autojoin = modified.autojoin;
conference.name = modified.name;
conference.jid = modified.jid; conference.jid = modified.jid;
conference.name = modified.name;
conference.nick = modified.nick;
break; break;
} }
} }
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) { public void remove_conference(XmppStream stream, Conference conference_) {
get_conferences(stream, on_remove_conference_response, conference); get_conferences(stream, (stream, conferences, o) => {
}
private static void on_remove_conference_response(XmppStream stream, ArrayList<Conference> conferences, Object? o) {
Conference remove = o as Conference; Conference remove = o as Conference;
Conference? rem = null; Conference? rem = null;
foreach (Conference conference in conferences) { foreach (Conference conference in conferences) {
@ -79,6 +69,7 @@ public class Module : XmppStreamModule {
} }
if (rem != null) conferences.remove(rem); if (rem != null) conferences.remove(rem);
stream.get_module(Module.IDENTITY).set_conferences(stream, conferences); stream.get_module(Module.IDENTITY).set_conferences(stream, conferences);
}, conference_);
} }
public override void attach(XmppStream stream) { } public override void attach(XmppStream stream) { }
@ -96,7 +87,8 @@ public class Module : XmppStreamModule {
ArrayList<Conference> conferences = new ArrayList<Conference>(); ArrayList<Conference> conferences = new ArrayList<Conference>();
ArrayList<StanzaNode> conferenceNodes = node.get_subnode("storage", NS_URI).get_subnodes("conference", NS_URI); ArrayList<StanzaNode> conferenceNodes = node.get_subnode("storage", NS_URI).get_subnodes("conference", NS_URI);
foreach (StanzaNode conferenceNode in conferenceNodes) { 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; return conferences;
} }