pubsub#itemreply
I implement pubsub#itemreply as in XEP-0060 12.16 Associating Events and Payloads with the Generating Entity. Here is my change. My test looks fine.
--- src/main/java/tigase/pubsub/AbstractNodeConfig.java.old 2009-05-01 21:38:35.000000000 -0400
+++ src/main/java/tigase/pubsub/AbstractNodeConfig.java 2009-06-24 01:03:44.914000000 -0400
@@ -32,6 +32,9 @@ import tigase.xml.Element;
public abstract class AbstractNodeConfig {
public static final String PUBSUB = "pubsub#";
+ public enum ItemReplyType {
+ owner, publisher
+ }
/**
* List with do-not-write elements
@@ -149,6 +152,15 @@ public abstract class AbstractNodeConfig
return form.getAsString("pubsub#title");
}
+ public ItemReplyType getItemReplyType() {
+ String tmp = form.getAsString("pubsub#itemreply");
+ if (tmp == null) {
+ return null;
+ } else {
+ return ItemReplyType.valueOf(tmp);
+ }
+ }
+
protected void init() {
form.addField(Field.fieldHidden("FORM_TYPE", "http://jabber.org/protocol/pubsub#node_config"));
@@ -188,6 +200,10 @@ public abstract class AbstractNodeConfig
"Roster groups allowed to subscribe"));
form.addField(Field.fieldBoolean(PUBSUB + "notify_sub_aff_state", true,
"Notify subscribers when owner change their subscription or affiliation state"));
+
+ form.addField(Field.fieldListSingle(PUBSUB + "itemreply", null,
+ "the per-item policy for replies", null, asStrinTable(ItemReplyType.values())));
+
}
public boolean isCollectionSet() {
--- src/main/java/tigase/pubsub/modules/PublishItemModule.java.old 2009-06-24 01:17:25.000000000 -0400
+++ src/main/java/tigase/pubsub/modules/PublishItemModule.java 2009-06-24 01:25:32.000000000 -0400
@@ -151,23 +151,29 @@ public class PublishItemModule extends A
items.addChild(item);
String[] subscribers = getValidBuddies(JIDUtils.getNodeID(senderJid));
- List
+ List
result.add(createResultIQ(element));
result.addAll(prepareNotification(new String[] { senderJid }, items, senderJid, null, publish.getAttribute("node"),
- null));
+ null, null));
return result;
}
- public List
+ public List
+ throws RepositoryException {
+ return prepareNotification(itemToSend, jidFrom, publisherNodeName, null, null, nodeConfig, nodeAffiliations,
+ nodesSubscriptions);
+ }
+
+ public List
AbstractNodeConfig nodeConfig, IAffiliations nodeAffiliations, ISubscriptions nodesSubscriptions)
throws RepositoryException {
- return prepareNotification(itemToSend, jidFrom, publisherNodeName, null, nodeConfig, nodeAffiliations,
+ return prepareNotification(itemToSend, jidFrom, publisherNodeName, null, replyTo, nodeConfig, nodeAffiliations,
nodesSubscriptions);
}
public List
- final Map
+ final Map
ISubscriptions nodesSubscriptions) throws RepositoryException {
String[] subscribers = getActiveSubscribers(nodeAffiliations, nodesSubscriptions);
if (nodeConfig.isDeliverPresenceBased()) {
@@ -180,11 +186,11 @@ public class PublishItemModule extends A
subscribers = s.toArray(new String[] {});
}
- return prepareNotification(subscribers, itemToSend, jidFrom, nodeConfig, publisherNodeName, headers);
+ return prepareNotification(subscribers, itemToSend, jidFrom, nodeConfig, publisherNodeName, headers, replyTo);
}
public List
- AbstractNodeConfig nodeConfig, final String publisherNodeName, final Map
+ AbstractNodeConfig nodeConfig, final String publisherNodeName, final Map
ArrayList
List
@@ -220,6 +226,15 @@ public class PublishItemModule extends A
}
message.addChild(headElem);
}
+ if(replyTo != null) {
+ Element addressElem = new Element("addresses", new String[] { "xmlns" },
+ new String[] { "http://jabber.org/protocol/address" });
+ Element h = new Element("address");
+ h.addAttribute("type", "replyto");
+ h.addAttribute("jid", replyTo);
+ addressElem.addChild(h);
+ message.addChild(addressElem);
+ }
result.add(message);
}
@@ -293,8 +308,24 @@ public class PublishItemModule extends A
items.addChildren(itemsToSend);
final ISubscriptions nodeSubscriptions = repository.getNodeSubscriptions(nodeName);
+
+ String replyTo = null;
+ if(nodeConfig.getItemReplyType() == AbstractNodeConfig.ItemReplyType.publisher){
+ String senderJid = element.getAttribute("from");
+ if( senderJid != null ) {
+ String senderUserId = JIDUtils.getNodeID(senderJid);
+ replyTo = senderUserId;
+ }
+ }else if (nodeConfig.getItemReplyType() == AbstractNodeConfig.ItemReplyType.owner) {
+ for (UsersAffiliation a : nodeAffiliations.getAffiliations()) {
+ if (a.getAffiliation() == Affiliation.owner) {
+ replyTo = a.getJid();
+ break;
+ }
+ }
+ }
- result.addAll(prepareNotification(items, element.getAttribute("to"), nodeName,
+ result.addAll(prepareNotification(items, element.getAttribute("to"), nodeName, replyTo,
this.repository.getNodeConfig(nodeName), nodeAffiliations, nodeSubscriptions));
List
if (parents != null && parents.size() > 0) {
@@ -304,7 +335,7 @@ public class PublishItemModule extends A
AbstractNodeConfig colNodeConfig = this.repository.getNodeConfig(collection);
ISubscriptions colNodeSubscriptions = this.repository.getNodeSubscriptions(collection);
IAffiliations colNodeAffiliations = this.repository.getNodeAffiliations(collection);
- result.addAll(prepareNotification(items, element.getAttribute("to"), nodeName, headers, colNodeConfig,
+ result.addAll(prepareNotification(items, element.getAttribute("to"), nodeName, replyTo, headers, colNodeConfig,
colNodeAffiliations, colNodeSubscriptions));
}
}
- 407 reads








Post new comment