use of com.facebook.react.bridge.WritableArray in project stringee-react-native by stringeecom.
the class Utils method getConversationMap.
public static WritableMap getConversationMap(Conversation conversation) {
WritableMap conversationMap = Arguments.createMap();
conversationMap.putString("id", conversation.getId());
conversationMap.putString("localId", conversation.getLocalId());
conversationMap.putString("name", conversation.getName());
conversationMap.putBoolean("isDistinct", conversation.isDistinct());
conversationMap.putBoolean("isGroup", conversation.isGroup());
conversationMap.putDouble("updatedAt", conversation.getUpdateAt());
conversationMap.putString("lastMsgSender", conversation.getLastMsgSender());
conversationMap.putString("text", conversation.getText());
conversationMap.putInt("lastMsgType", conversation.getLastMsgType().getValue());
conversationMap.putInt("unreadCount", conversation.getTotalUnread());
conversationMap.putString("lastMsgId", conversation.getLastMsgId());
conversationMap.putString("creator", conversation.getCreator());
conversationMap.putDouble("created", conversation.getCreateAt());
conversationMap.putDouble("lastMsgSeq", conversation.getLastMsgSeqReceived());
conversationMap.putDouble("lastMsgCreatedAt", conversation.getLastTimeNewMsg());
conversationMap.putInt("lastMsgState", conversation.getLastMsgState().getValue());
if (conversation.getLastMsg() != null) {
try {
Bundle bundle = jsonToBundle(conversation.getLastMsg());
WritableMap lastMsgMap = Arguments.fromBundle(bundle);
conversationMap.putMap("text", lastMsgMap);
} catch (JSONException e) {
e.printStackTrace();
}
}
List<User> participants = conversation.getParticipants();
WritableArray participantsMap = Arguments.createArray();
for (int j = 0; j < participants.size(); j++) {
WritableMap userMap = getUserMap(participants.get(j));
participantsMap.pushMap(userMap);
}
conversationMap.putArray("participants", participantsMap);
String pinMsgId = conversation.getPinnedMsgId();
if (pinMsgId != null) {
if (!TextUtils.isEmpty(pinMsgId)) {
conversationMap.putString("pinMsgId", pinMsgId);
} else {
conversationMap.putString("pinMsgId", null);
}
} else {
conversationMap.putString("pinMsgId", null);
}
return conversationMap;
}
use of com.facebook.react.bridge.WritableArray in project stringee-react-native by stringeecom.
the class Utils method getChatProfileMap.
public static WritableMap getChatProfileMap(ChatProfile chatProfile) {
WritableMap conversationMap = Arguments.createMap();
conversationMap.putString("id", chatProfile.getId());
conversationMap.putString("background", chatProfile.getBackground());
conversationMap.putString("hour", chatProfile.getBusinessHour());
conversationMap.putString("language", chatProfile.getLanguage());
conversationMap.putString("logoUrl", chatProfile.getLogoUrl());
conversationMap.putString("popupAnswerUrl", chatProfile.getPopupAnswerUrl());
conversationMap.putString("portal", chatProfile.getPortalId());
conversationMap.putBoolean("autoCreateTicket", chatProfile.isAutoCreateTicket());
conversationMap.putBoolean("enabled", chatProfile.isEnabledBusinessHour());
conversationMap.putBoolean("facebookAsLivechat", chatProfile.isFacebookAsLivechat());
conversationMap.putInt("projectId", chatProfile.getProjectId());
conversationMap.putBoolean("zaloAsLivechat", chatProfile.isZaloAsLivechat());
List<Queue> queues = chatProfile.getQueues();
WritableArray queuesMap = Arguments.createArray();
for (int j = 0; j < queues.size(); j++) {
WritableMap queueMap = getQueueMap(queues.get(j));
queuesMap.pushMap(queueMap);
}
conversationMap.putArray("queues", queuesMap);
return conversationMap;
}
use of com.facebook.react.bridge.WritableArray in project stringee-react-native by stringeecom.
the class RNStringeeClientModule method getLastUnreadConversations.
@ReactMethod
public void getLastUnreadConversations(final String instanceId, final int count, final Callback callback) {
StringeeClient mClient = StringeeManager.getInstance().getClientsMap().get(instanceId);
if (mClient == null) {
callback.invoke(false, -1, "StringeeClient is not initialized");
return;
}
mClient.getLastUnreadConversations(count, new CallbackListener<List<Conversation>>() {
@Override
public void onSuccess(List<Conversation> conversations) {
WritableArray params = Arguments.createArray();
for (int i = 0; i < conversations.size(); i++) {
WritableMap param = Utils.getConversationMap(conversations.get(i));
params.pushMap(param);
}
callback.invoke(true, 0, "Success", params);
}
@Override
public void onError(StringeeError error) {
callback.invoke(false, error.getCode(), error.getMessage());
}
});
}
use of com.facebook.react.bridge.WritableArray in project stringee-react-native by stringeecom.
the class RNStringeeClientModule method getUnreadConversationsAfter.
@ReactMethod
public void getUnreadConversationsAfter(final String instanceId, final double datetime, final int count, final Callback callback) {
StringeeClient mClient = StringeeManager.getInstance().getClientsMap().get(instanceId);
if (mClient == null) {
callback.invoke(false, -1, "StringeeClient is not initialized");
return;
}
mClient.getUnreadConversationsAfter((long) datetime, count, new CallbackListener<List<Conversation>>() {
@Override
public void onSuccess(List<Conversation> conversations) {
WritableArray params = Arguments.createArray();
for (int i = 0; i < conversations.size(); i++) {
WritableMap param = Utils.getConversationMap(conversations.get(i));
params.pushMap(param);
}
callback.invoke(true, 0, "Success", params);
}
@Override
public void onError(StringeeError error) {
callback.invoke(false, error.getCode(), error.getMessage());
}
});
}
use of com.facebook.react.bridge.WritableArray in project stringee-react-native by stringeecom.
the class RNStringeeClientModule method getLocalMessages.
@ReactMethod
public void getLocalMessages(final String instanceId, final String convId, final int count, final Callback callback) {
StringeeClient mClient = StringeeManager.getInstance().getClientsMap().get(instanceId);
if (mClient == null) {
callback.invoke(false, -1, "StringeeClient is not initialized");
return;
}
if (convId == null) {
callback.invoke(false, -2, "Conversation id can not be null");
return;
}
mClient.getConversationFromServer(convId, new CallbackListener<Conversation>() {
@Override
public void onSuccess(Conversation conversation) {
conversation.getLocalMessages(mClient, count, new CallbackListener<List<Message>>() {
@Override
public void onSuccess(List<Message> messages) {
WritableArray params = Arguments.createArray();
for (int i = 0; i < messages.size(); i++) {
WritableMap param = Utils.getMessageMap(messages.get(i));
params.pushMap(param);
}
callback.invoke(true, 0, "Success", params);
}
@Override
public void onError(StringeeError error) {
callback.invoke(false, error.getCode(), error.getMessage());
}
});
}
@Override
public void onError(StringeeError error) {
callback.invoke(false, error.getCode(), error.getMessage());
}
});
}
Aggregations