This repository has been archived by the owner on Jul 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
AdminUnsubscribeCommandHandler.java
61 lines (48 loc) · 1.75 KB
/
AdminUnsubscribeCommandHandler.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright 2011 Google Inc. All Rights Reserved.
package info.persistent.pushbot.commands;
import com.google.appengine.api.xmpp.JID;
import info.persistent.pushbot.data.Subscription;
import info.persistent.pushbot.util.Hubs;
import info.persistent.pushbot.util.Persistence;
import info.persistent.pushbot.util.Xmpp;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.jdo.PersistenceManager;
/**
* Remove another user's subscription.
*/
public class AdminUnsubscribeCommandHandler extends AdminCommandHandler {
private static final Logger logger =
Logger.getLogger(AdminUnsubscribeCommandHandler.class.getName());
@Override
public void handle(JID adminUser, JID targetUser, String... args) {
if (args.length != 1) {
Xmpp.sendMessage(adminUser, "No feed URL not specified");
return;
}
URL feedUrl;
try {
feedUrl = new URL(args[0]);
} catch (MalformedURLException err) {
logger.log(Level.INFO, "URL parse exception", err);
Xmpp.sendMessage(adminUser, "Feed URL is malformed");
return;
}
final List<Subscription> subscriptions =
Subscription.getSubscriptionsForUserAndFeedUrl(targetUser, feedUrl);
if (subscriptions.isEmpty()) {
Xmpp.sendMessage(adminUser, "No subscriptions match.");
}
for (Subscription subscription : subscriptions) {
Hubs.sendRequestToHub(targetUser, subscription.getHubUrl(), feedUrl, false);
}
Persistence.withManager(new Persistence.Closure() {
@Override public void run(PersistenceManager manager) {
manager.deletePersistentAll(subscriptions);
}
});
}
}