@Override protected Void doInBackground(ApptentiveMessage... messages) { final ApptentiveMessage message = messages[0]; message.setRead(true); JSONObject data = new JSONObject(); try { data.put("message_id", message.getId()); data.put("message_type", message.getMessageType().name()); } catch (JSONException e) { logException(e); } fragment.engageInternal(MessageCenterInteraction.EVENT_NAME_READ, data.toString()); dispatchConversationTask(new ConversationDispatchTask() { @Override protected boolean execute(Conversation conversation) { MessageManager mgr = conversation.getMessageManager(); if (mgr != null) { mgr.updateMessage(message); mgr.notifyHostUnreadMessagesListeners(mgr.getUnreadMessageCount()); } return false; } }, "update message"); return null; }
public static ApptentiveMessage fromJson(String json) { try { // If KEY_TYPE is set to CompoundMessage or not set, treat them as CompoundMessage ApptentiveMessage.Type type = ApptentiveMessage.Type.CompoundMessage; JSONObject root = new JSONObject(json); if (!root.isNull(ApptentiveMessage.KEY_TYPE)) { String typeStr = root.getString(ApptentiveMessage.KEY_TYPE); if (!StringUtils.isNullOrEmpty(typeStr)) { type = ApptentiveMessage.Type.valueOf(typeStr); } } switch (type) { case CompoundMessage: return new CompoundMessage(json); case unknown: break; default: break; } } catch (JSONException e) { ApptentiveLog.v(MESSAGES, e, "Error parsing json as Message: %s", json); logException(e); } catch (IllegalArgumentException e) { // Exception treated as unknown type logException(e); } return null; } }
protected void setType(Type type) { put(KEY_TYPE, type.name()); }
public static Type parse(String rawType) { try { return Type.valueOf(rawType); } catch (IllegalArgumentException e) { ApptentiveLog.v(MESSAGES, "Error parsing unknown ApptentiveMessage.Type: " + rawType); logException(e); } return unknown; } }
public Type getMessageType() { if (isNull(KEY_TYPE)) { return Type.CompoundMessage; } String typeString = optString(KEY_TYPE, null); return typeString == null ? Type.unknown : Type.parse(typeString); }