From c6ff3387fa7b23678bbfe644c9e1b668ac92a731 Mon Sep 17 00:00:00 2001 From: fiaxh Date: Mon, 17 Apr 2017 22:46:12 +0200 Subject: Handle conference bookmarks w/o nick --- .../src/module/xep/0048_bookmarks/conference.vala | 20 ++++- .../src/module/xep/0048_bookmarks/module.vala | 96 ++++++++++------------ 2 files changed, 60 insertions(+), 56 deletions(-) (limited to 'xmpp-vala/src/module') diff --git a/xmpp-vala/src/module/xep/0048_bookmarks/conference.vala b/xmpp-vala/src/module/xep/0048_bookmarks/conference.vala index e0988041..21072c3f 100644 --- a/xmpp-vala/src/module/xep/0048_bookmarks/conference.vala +++ b/xmpp-vala/src/module/xep/0048_bookmarks/conference.vala @@ -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; + } } } \ No newline at end of file diff --git a/xmpp-vala/src/module/xep/0048_bookmarks/module.vala b/xmpp-vala/src/module/xep/0048_bookmarks/module.vala index 4cb91a5b..5170c80a 100644 --- a/xmpp-vala/src/module/xep/0048_bookmarks/module.vala +++ b/xmpp-vala/src/module/xep/0048_bookmarks/module.vala @@ -13,13 +13,11 @@ public class Module : XmppStreamModule { [CCode (has_target = false)] public delegate void OnResult(XmppStream stream, ArrayList 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 tuple = o as Tuple; - 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 tuple = o as Tuple; + 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 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); - } - - private static void on_set_conferences_response(XmppStream stream, Object? o) { - ArrayList conferences = o as ArrayList; - 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 conferences, Object? o) { - Conference add = o as Conference; - conferences.add(add); - stream.get_module(Module.IDENTITY).set_conferences(stream, conferences); + stream.get_module(PrivateXmlStorage.Module.IDENTITY).store(stream, storage_node, (stream, o) => { + stream.get_module(Module.IDENTITY).conferences_updated(stream, o as ArrayList); + }, conferences); } - public void replace_conference(XmppStream stream, Conference was, Conference modified) { - get_conferences(stream, on_replace_conference_response, Tuple.create(was, modified)); + 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_); } - private static void on_replace_conference_response(XmppStream stream, ArrayList conferences, Object? o) { - Tuple tuple = o as Tuple; - 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; + public void replace_conference(XmppStream stream, Conference was_, Conference modified_) { + get_conferences(stream, (stream, conferences, o) => { + Tuple tuple = o as Tuple; + 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; + } } - } - 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); + stream.get_module(Module.IDENTITY).set_conferences(stream, conferences); + }, Tuple.create(was_, modified_)); } - private static void on_remove_conference_response(XmppStream stream, ArrayList 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; - break; + 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); + 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 conferences = new ArrayList(); ArrayList 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; } -- cgit v1.2.3-70-g09d2