/** * {@inheritDoc} * * Post a message for a set of users. */ public Future<Void> createMessage(UserId userId, String appId, String msgCollId, Message message, SecurityToken token) throws ProtocolException { if (message.getId() == null) { // Assign a new ID to the message message.setId(UUID.randomUUID().toString()); } try { JSONObject messagesTable = db.getJSONObject(MESSAGE_TABLE); JSONObject messageObject = convertToJson(message); for (String recipient : message.getRecipients()) { JSONObject collection = messagesTable.getJSONObject(recipient).getJSONObject(msgCollId); JSONArray outbox = collection.getJSONArray(MESSAGES_ARRAY); if (outbox == null) { outbox = new JSONArray(); collection.put(MESSAGES_ARRAY, outbox); } outbox.put(messageObject); } } catch (JSONException je) { throw new ProtocolException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, je.getMessage(), je); } return Futures.immediateFuture(null); }
/** * {@inheritDoc} * * Post a message for a set of users. */ public Future<Void> createMessage(UserId userId, String appId, String msgCollId, Message message, SecurityToken token) throws ProtocolException { if (message.getId() == null) { // Assign a new ID to the message message.setId(UUID.randomUUID().toString()); } try { JSONObject messagesTable = db.getJSONObject(MESSAGE_TABLE); JSONObject messageObject = convertToJson(message); for (String recipient : message.getRecipients()) { JSONObject collection = messagesTable.getJSONObject(recipient).getJSONObject(msgCollId); JSONArray outbox = collection.getJSONArray(MESSAGES_ARRAY); if (outbox == null) { outbox = new JSONArray(); collection.put(MESSAGES_ARRAY, outbox); } outbox.put(messageObject); } } catch (JSONException je) { throw new ProtocolException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, je.getMessage(), je); } return Futures.immediateFuture(null); }