mirror of
https://github.com/fergalmoran/chrometophone.git
synced 2025-12-22 09:41:51 +00:00
Handle selection
This commit is contained in:
@@ -132,7 +132,7 @@ public class C2DMessaging {
|
||||
for (Object keyObj: params.keySet()) {
|
||||
String key = (String) keyObj;
|
||||
if (key.startsWith("data.")) {
|
||||
String[] values = (String[]) params.get(key);
|
||||
String[] values = params.get(key);
|
||||
postDataBuilder.append("&").append(key).append("=").
|
||||
append(URLEncoder.encode(values[0], UTF8));
|
||||
}
|
||||
@@ -224,12 +224,14 @@ public class C2DMessaging {
|
||||
* Retriable errors will cause the message to be scheduled for retry.
|
||||
*/
|
||||
public void sendWithRetry(String token, String collapseKey,
|
||||
String name1, String value1, String name2, String value2)
|
||||
String name1, String value1, String name2, String value2,
|
||||
String name3, String value3)
|
||||
throws IOException {
|
||||
|
||||
Map<String, String[]> params = new HashMap<String, String[]>();
|
||||
params.put("data." + name1, new String[] {value1});
|
||||
params.put("data." + name2, new String[] {value2});
|
||||
if (value1 != null) params.put("data." + name1, new String[] {value1});
|
||||
if (value2 != null) params.put("data." + name2, new String[] {value2});
|
||||
if (value3 != null) params.put("data." + name3, new String[] {value3});
|
||||
|
||||
boolean sentOk = sendNoRetry(token, collapseKey, params, true);
|
||||
if (!sentOk) {
|
||||
@@ -238,12 +240,14 @@ public class C2DMessaging {
|
||||
}
|
||||
|
||||
public boolean sendNoRetry(String token, String collapseKey,
|
||||
String name1, String value1, String name2, String value2)
|
||||
String name1, String value1, String name2, String value2,
|
||||
String name3, String value3)
|
||||
throws IOException {
|
||||
|
||||
Map<String, String[]> params = new HashMap<String, String[]>();
|
||||
params.put("data." + name1, new String[] {value1});
|
||||
params.put("data." + name2, new String[] {value2});
|
||||
if (value1 != null) params.put("data." + name1, new String[] {value1});
|
||||
if (value2 != null) params.put("data." + name2, new String[] {value2});
|
||||
if (value3 != null) params.put("data." + name3, new String[] {value3});
|
||||
|
||||
try {
|
||||
return sendNoRetry(token, collapseKey, params, true);
|
||||
@@ -264,7 +268,7 @@ public class C2DMessaging {
|
||||
url.param(PARAM_DELAY_WHILE_IDLE, "1");
|
||||
}
|
||||
for (String key: params.keySet()) {
|
||||
String[] values = (String[]) params.get(key);
|
||||
String[] values = params.get(key);
|
||||
url.param(key, URLEncoder.encode(values[0], UTF8));
|
||||
}
|
||||
|
||||
|
||||
@@ -40,6 +40,7 @@ public class SendServlet extends HttpServlet {
|
||||
private static final String OK_STATUS = "OK";
|
||||
private static final String ERROR_STATUS = "ERROR";
|
||||
|
||||
@Override
|
||||
public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
|
||||
doGet(req, resp);
|
||||
}
|
||||
@@ -49,6 +50,7 @@ public class SendServlet extends HttpServlet {
|
||||
resp.setContentType("text/plain");
|
||||
String url = req.getParameter("url");
|
||||
String title = req.getParameter("title");
|
||||
String sel = req.getParameter("sel"); // optional
|
||||
if (url == null && title == null) {
|
||||
resp.setStatus(400);
|
||||
resp.getWriter().println(ERROR_STATUS + " (Must specify url and title parameters)");
|
||||
@@ -58,17 +60,18 @@ public class SendServlet extends HttpServlet {
|
||||
UserService userService = UserServiceFactory.getUserService();
|
||||
User user = userService.getCurrentUser();
|
||||
if (user != null) {
|
||||
doSendToPhone(url, title, user.getEmail(), resp);
|
||||
doSendToPhone(url, title, sel, user.getEmail(), resp);
|
||||
} else {
|
||||
String followOnURL = req.getRequestURI() + "?title=" +
|
||||
URLEncoder.encode(req.getParameter("title"), "UTF-8") +
|
||||
"&url=" + URLEncoder.encode(req.getParameter("url"), "UTF-8");
|
||||
"&url=" + URLEncoder.encode(req.getParameter("url"), "UTF-8") +
|
||||
"&sel=" + URLEncoder.encode(req.getParameter("sel"), "UTF-8");
|
||||
resp.sendRedirect(userService.createLoginURL(followOnURL));
|
||||
}
|
||||
}
|
||||
|
||||
private boolean doSendToPhone(String url, String title, String userAccount,
|
||||
HttpServletResponse resp) throws IOException {
|
||||
private boolean doSendToPhone(String url, String title, String sel,
|
||||
String userAccount, HttpServletResponse resp) throws IOException {
|
||||
// Get device info
|
||||
DeviceInfo deviceInfo = null;
|
||||
// Shared PMF
|
||||
@@ -91,7 +94,8 @@ public class SendServlet extends HttpServlet {
|
||||
// Send push message to phone
|
||||
C2DMessaging push = C2DMessaging.get(getServletContext());
|
||||
if (push.sendNoRetry(deviceInfo.getDeviceRegistrationID(),
|
||||
"" + url.hashCode(), "url", url, "title", title)) {
|
||||
"" + url.hashCode(), "url", url, "title", title,
|
||||
"sel", sel)) {
|
||||
log.info("Link sent to phone!");
|
||||
resp.getWriter().println(OK_STATUS);
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user