aboutsummaryrefslogtreecommitdiff
path: root/xmpp-vala/src/module/xep/0048_bookmarks
diff options
context:
space:
mode:
Diffstat (limited to 'xmpp-vala/src/module/xep/0048_bookmarks')
-rw-r--r--xmpp-vala/src/module/xep/0048_bookmarks/conference.vala92
-rw-r--r--xmpp-vala/src/module/xep/0048_bookmarks/module.vala89
2 files changed, 0 insertions, 181 deletions
diff --git a/xmpp-vala/src/module/xep/0048_bookmarks/conference.vala b/xmpp-vala/src/module/xep/0048_bookmarks/conference.vala
deleted file mode 100644
index 7f80490b..00000000
--- a/xmpp-vala/src/module/xep/0048_bookmarks/conference.vala
+++ /dev/null
@@ -1,92 +0,0 @@
-namespace Xmpp.Xep.Bookmarks {
-
-public class Conference : Object {
-
- public const string ATTRIBUTE_AUTOJOIN = "autojoin";
- public const string ATTRIBUTE_JID = "jid";
- public const string ATTRIBUTE_NAME = "name";
-
- public const string NODE_NICK = "nick";
- public const string NODE_PASSWORD = "password";
-
- public StanzaNode stanza_node;
-
- public bool autojoin {
- get {
- string? attr = stanza_node.get_attribute(ATTRIBUTE_AUTOJOIN);
- return attr == "true" || attr == "1";
- }
- set { stanza_node.set_attribute(ATTRIBUTE_AUTOJOIN, value.to_string()); }
- }
-
- private Jid jid_;
- public Jid jid {
- get { return jid_ ?? (jid_ = Jid.parse(stanza_node.get_attribute(ATTRIBUTE_JID))); }
- set { stanza_node.set_attribute(ATTRIBUTE_JID, value.to_string()); }
- }
-
- public string? name {
- get { return stanza_node.get_attribute(ATTRIBUTE_NAME); }
- set {
- if (value == null) return; // TODO actually remove
- stanza_node.set_attribute(ATTRIBUTE_NAME, value);
- }
- }
-
- public string? nick {
- get {
- StanzaNode? nick_node = stanza_node.get_subnode(NODE_NICK);
- return nick_node == null ? null : nick_node.get_string_content();
- }
- 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));
- }
- }
-
- public string? password {
- get {
- StanzaNode? password_node = stanza_node.get_subnode(NODE_PASSWORD);
- return password_node == null ? null : password_node.get_string_content();
- }
- set {
- StanzaNode? password_node = stanza_node.get_subnode(NODE_PASSWORD);
- if (value == null) {
- if (password_node != null) stanza_node.sub_nodes.remove(password_node);
- return;
- }
- if (password_node == null) {
- password_node = new StanzaNode.build(NODE_PASSWORD);
- stanza_node.put_node(password_node);
- }
- password_node.put_node(new StanzaNode.text(value));
- }
- }
-
- public Conference(Jid 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;
- }
-}
-
-}
diff --git a/xmpp-vala/src/module/xep/0048_bookmarks/module.vala b/xmpp-vala/src/module/xep/0048_bookmarks/module.vala
deleted file mode 100644
index 2c16f5f0..00000000
--- a/xmpp-vala/src/module/xep/0048_bookmarks/module.vala
+++ /dev/null
@@ -1,89 +0,0 @@
-using Gee;
-
-namespace Xmpp.Xep.Bookmarks {
-private const string NS_URI = "storage:bookmarks";
-
-public class Module : XmppStreamModule {
- public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, "0048_bookmarks_module");
-
- public signal void received_conferences(XmppStream stream, Gee.List<Conference> conferences);
-
- public delegate void OnResult(XmppStream stream, Gee.List<Conference>? conferences);
- public void get_conferences(XmppStream stream, owned OnResult listener) {
- StanzaNode get_node = new StanzaNode.build("storage", NS_URI).add_self_xmlns();
- stream.get_module(PrivateXmlStorage.Module.IDENTITY).retrieve(stream, get_node, (stream, node) => {
- if (node == null) {
- listener(stream, null);
- } else {
- Gee.List<Conference> conferences = get_conferences_from_stanza(node);
- listener(stream, conferences);
- }
- });
- }
-
- public void set_conferences(XmppStream stream, Gee.List<Conference> conferences) {
- StanzaNode storage_node = (new StanzaNode.build("storage", NS_URI)).add_self_xmlns();
- foreach (Conference conference in conferences) {
- storage_node.put_node(conference.stanza_node);
- }
- stream.get_module(PrivateXmlStorage.Module.IDENTITY).store(stream, storage_node, (stream) => {
- stream.get_module(Module.IDENTITY).received_conferences(stream, conferences);
- });
- }
-
- public void add_conference(XmppStream stream, Conference conference) {
- get_conferences(stream, (stream, conferences) => {
- conferences.add(conference);
- stream.get_module(Module.IDENTITY).set_conferences(stream, conferences);
- });
- }
-
- public void replace_conference(XmppStream stream, Conference orig_conference, Conference modified_conference) {
- get_conferences(stream, (stream, conferences) => {
- foreach (Conference conference in conferences) {
- if (conference.autojoin == orig_conference.autojoin && conference.jid.equals(orig_conference.jid) &&
- conference.name == orig_conference.name && conference.nick == orig_conference.nick) {
- conference.autojoin = modified_conference.autojoin;
- conference.jid = modified_conference.jid;
- conference.name = modified_conference.name;
- conference.nick = modified_conference.nick;
- break;
- }
- }
- stream.get_module(Module.IDENTITY).set_conferences(stream, conferences);
- });
- }
-
- public void remove_conference(XmppStream stream, Conference conference_remove) {
- get_conferences(stream, (stream, conferences) => {
- Conference? rem = null;
- foreach (Conference conference in conferences) {
- if (conference.name == conference_remove.name && conference.jid.equals(conference_remove.jid) && conference.autojoin == conference_remove.autojoin) {
- rem = conference;
- break;
- }
- }
- if (rem != null) conferences.remove(rem);
- stream.get_module(Module.IDENTITY).set_conferences(stream, conferences);
- });
- }
-
- public override void attach(XmppStream stream) { }
-
- public override void detach(XmppStream stream) { }
-
- public override string get_ns() { return NS_URI; }
- public override string get_id() { return IDENTITY.id; }
-
- private static Gee.List<Conference> get_conferences_from_stanza(StanzaNode node) {
- Gee.List<Conference> conferences = new ArrayList<Conference>();
- Gee.List<StanzaNode> conferenceNodes = node.get_subnode("storage", NS_URI).get_subnodes("conference", NS_URI);
- foreach (StanzaNode conferenceNode in conferenceNodes) {
- Conference? conference = Conference.create_from_stanza_node(conferenceNode);
- conferences.add(conference);
- }
- return conferences;
- }
-}
-
-}