Fix pubsub item listener notifying
This commit is contained in:
parent
df3716622a
commit
7adb0e82fb
|
@ -29,7 +29,7 @@ public class StreamModule : XmppStreamModule {
|
||||||
|
|
||||||
this.store = Plugin.get_context().create_store();
|
this.store = Plugin.get_context().create_store();
|
||||||
store_created(store);
|
store_created(store);
|
||||||
stream.get_module(Pubsub.Module.IDENTITY).add_filtered_notification(stream, NODE_DEVICELIST, (stream, jid, id, node) => parse_device_list(stream, jid, id, node));
|
stream.get_module(Pubsub.Module.IDENTITY).add_filtered_notification(stream, NODE_DEVICELIST, (stream, jid, id, node) => parse_device_list(stream, jid, id, node), null);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,11 +14,19 @@ namespace Xmpp.Xep.Pubsub {
|
||||||
public class Module : XmppStreamModule {
|
public class Module : XmppStreamModule {
|
||||||
public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, "0060_pubsub_module");
|
public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, "0060_pubsub_module");
|
||||||
|
|
||||||
private HashMap<string, EventListenerDelegate> event_listeners = new HashMap<string, EventListenerDelegate>();
|
private HashMap<string, ItemListenerDelegate> item_listeners = new HashMap<string, ItemListenerDelegate>();
|
||||||
|
private HashMap<string, RetractListenerDelegate> retract_listeners = new HashMap<string, RetractListenerDelegate>();
|
||||||
|
|
||||||
public void add_filtered_notification(XmppStream stream, string node, owned EventListenerDelegate.ResultFunc listener) {
|
public void add_filtered_notification(XmppStream stream, string node,
|
||||||
|
owned ItemListenerDelegate.ResultFunc? item_listener,
|
||||||
|
owned RetractListenerDelegate.ResultFunc? retract_listener) {
|
||||||
stream.get_module(ServiceDiscovery.Module.IDENTITY).add_feature_notify(stream, node);
|
stream.get_module(ServiceDiscovery.Module.IDENTITY).add_feature_notify(stream, node);
|
||||||
event_listeners[node] = new EventListenerDelegate((owned)listener);
|
if (item_listener != null) {
|
||||||
|
item_listeners[node] = new ItemListenerDelegate((owned)item_listener);
|
||||||
|
}
|
||||||
|
if (retract_listener != null) {
|
||||||
|
retract_listeners[node] = new RetractListenerDelegate((owned)retract_listener);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Gee.List<StanzaNode>? request_all(XmppStream stream, Jid jid, string node) { // TODO multiple nodes gehen auch
|
public async Gee.List<StanzaNode>? request_all(XmppStream stream, Jid jid, string node) { // TODO multiple nodes gehen auch
|
||||||
|
@ -140,8 +148,8 @@ namespace Xmpp.Xep.Pubsub {
|
||||||
if (item_node != null) {
|
if (item_node != null) {
|
||||||
string id = item_node.get_attribute("id", NS_URI_EVENT);
|
string id = item_node.get_attribute("id", NS_URI_EVENT);
|
||||||
|
|
||||||
if (event_listeners.has_key(node)) {
|
if (item_listeners.has_key(node)) {
|
||||||
event_listeners[node].on_result(stream, message.from, id, item_node);
|
item_listeners[node].on_result(stream, message.from, id, item_node.sub_nodes[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,20 +157,30 @@ namespace Xmpp.Xep.Pubsub {
|
||||||
if (retract_node != null) {
|
if (retract_node != null) {
|
||||||
string id = retract_node.get_attribute("id", NS_URI_EVENT);
|
string id = retract_node.get_attribute("id", NS_URI_EVENT);
|
||||||
|
|
||||||
if (event_listeners.has_key(node)) {
|
if (retract_listeners.has_key(node)) {
|
||||||
event_listeners[node].on_result(stream, message.from, id, retract_node);
|
retract_listeners[node].on_result(stream, message.from, id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class EventListenerDelegate {
|
public class ItemListenerDelegate {
|
||||||
public delegate void ResultFunc(XmppStream stream, Jid jid, string id, StanzaNode? node);
|
public delegate void ResultFunc(XmppStream stream, Jid jid, string id, StanzaNode? node);
|
||||||
public ResultFunc on_result { get; private owned set; }
|
public ResultFunc on_result { get; private owned set; }
|
||||||
|
|
||||||
public EventListenerDelegate(owned ResultFunc on_result) {
|
public ItemListenerDelegate(owned ResultFunc on_result) {
|
||||||
this.on_result = (owned) on_result;
|
this.on_result = (owned) on_result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class RetractListenerDelegate {
|
||||||
|
public delegate void ResultFunc(XmppStream stream, Jid jid, string id);
|
||||||
|
public ResultFunc on_result { get; private owned set; }
|
||||||
|
|
||||||
|
public RetractListenerDelegate(owned ResultFunc on_result) {
|
||||||
|
this.on_result = (owned) on_result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@ namespace Xmpp.Xep.UserAvatars {
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void attach(XmppStream stream) {
|
public override void attach(XmppStream stream) {
|
||||||
stream.get_module(Pubsub.Module.IDENTITY).add_filtered_notification(stream, NS_URI_METADATA, on_pupsub_event);
|
stream.get_module(Pubsub.Module.IDENTITY).add_filtered_notification(stream, NS_URI_METADATA, on_pupsub_event, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void detach(XmppStream stream) { }
|
public override void detach(XmppStream stream) { }
|
||||||
|
@ -59,7 +59,7 @@ namespace Xmpp.Xep.UserAvatars {
|
||||||
Bytes image = new Bytes.take(Base64.decode(node.get_string_content()));
|
Bytes image = new Bytes.take(Base64.decode(node.get_string_content()));
|
||||||
string sha1 = Checksum.compute_for_bytes(ChecksumType.SHA1, image);
|
string sha1 = Checksum.compute_for_bytes(ChecksumType.SHA1, image);
|
||||||
if (sha1 != id) {
|
if (sha1 != id) {
|
||||||
warning("sha sum did not match for avatar from "+jid.to_string()+" expected="+id+", actual="+sha1);
|
warning("sha sum did not match for avatar from %s expected=%s actual=%s", jid.to_string(), id, sha1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
storage.store(id, image);
|
storage.store(id, image);
|
||||||
|
|
|
@ -18,7 +18,7 @@ public class Module : BookmarksProvider, XmppStreamModule {
|
||||||
|
|
||||||
hm = new HashMap<Jid, Conference>(Jid.hash_func, Jid.equals_func);
|
hm = new HashMap<Jid, Conference>(Jid.hash_func, Jid.equals_func);
|
||||||
foreach (StanzaNode item_node in items) {
|
foreach (StanzaNode item_node in items) {
|
||||||
Conference? conference = parse_item_node(item_node, item_node.get_attribute("id"));
|
Conference? conference = parse_item_node(item_node.sub_nodes[0], item_node.get_attribute("id"));
|
||||||
if (conference == null) continue;
|
if (conference == null) continue;
|
||||||
hm[conference.jid] = conference;
|
hm[conference.jid] = conference;
|
||||||
}
|
}
|
||||||
|
@ -56,33 +56,31 @@ public class Module : BookmarksProvider, XmppStreamModule {
|
||||||
conference.jid.to_string());
|
conference.jid.to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void on_pupsub_event(XmppStream stream, Jid jid, string id, StanzaNode? node) {
|
private void on_pupsub_item(XmppStream stream, Jid jid, string id, StanzaNode? node) {
|
||||||
if (node.name == "item") {
|
|
||||||
Conference conference = parse_item_node(node, id);
|
Conference conference = parse_item_node(node, id);
|
||||||
Flag? flag = stream.get_flag(Flag.IDENTITY);
|
Flag? flag = stream.get_flag(Flag.IDENTITY);
|
||||||
if (flag != null) {
|
if (flag != null) {
|
||||||
flag.conferences[conference.jid] = conference;
|
flag.conferences[conference.jid] = conference;
|
||||||
}
|
}
|
||||||
conference_added(stream, conference);
|
conference_added(stream, conference);
|
||||||
} else if (node.name == "retract") {
|
}
|
||||||
string jid_str = node.get_attribute("id");
|
|
||||||
Jid jid_parsed = Jid.parse(jid_str);
|
private void on_pupsub_retract(XmppStream stream, Jid jid, string id) {
|
||||||
|
Jid jid_parsed = Jid.parse(id);
|
||||||
Flag? flag = stream.get_flag(Flag.IDENTITY);
|
Flag? flag = stream.get_flag(Flag.IDENTITY);
|
||||||
if (flag != null) {
|
if (flag != null) {
|
||||||
flag.conferences.unset(jid_parsed);
|
flag.conferences.unset(jid_parsed);
|
||||||
}
|
}
|
||||||
conference_removed(stream, jid_parsed);
|
conference_removed(stream, jid_parsed);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private Conference? parse_item_node(StanzaNode item_node, string id) {
|
private Conference? parse_item_node(StanzaNode conference_node, string id) {
|
||||||
Conference conference = new Conference();
|
Conference conference = new Conference();
|
||||||
Jid? jid_parsed = Jid.parse(id);
|
Jid? jid_parsed = Jid.parse(id);
|
||||||
if (jid_parsed == null || jid_parsed.resourcepart != null) return null;
|
if (jid_parsed == null || jid_parsed.resourcepart != null) return null;
|
||||||
conference.jid = jid_parsed;
|
conference.jid = jid_parsed;
|
||||||
|
|
||||||
StanzaNode? conference_node = item_node.get_subnode("conference", NS_URI);
|
if (conference_node.name != "conference" || conference_node.ns_uri != NS_URI) return null;
|
||||||
if (conference_node == null) return null;
|
|
||||||
|
|
||||||
conference.name = conference_node.get_attribute("name", NS_URI);
|
conference.name = conference_node.get_attribute("name", NS_URI);
|
||||||
conference.autojoin = conference_node.get_attribute("autojoin", NS_URI) == "true";
|
conference.autojoin = conference_node.get_attribute("autojoin", NS_URI) == "true";
|
||||||
|
@ -91,7 +89,7 @@ public class Module : BookmarksProvider, XmppStreamModule {
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void attach(XmppStream stream) {
|
public override void attach(XmppStream stream) {
|
||||||
stream.get_module(Pubsub.Module.IDENTITY).add_filtered_notification(stream, NS_URI, on_pupsub_event);
|
stream.get_module(Pubsub.Module.IDENTITY).add_filtered_notification(stream, NS_URI, on_pupsub_item, on_pupsub_retract);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void detach(XmppStream stream) { }
|
public override void detach(XmppStream stream) { }
|
||||||
|
|
Loading…
Reference in a new issue