use of com.applozic.mobicomkit.api.attachment.FileClientService in project Applozic-Android-SDK by AppLozic.
the class MessageClientService method processMessage.
public void processMessage(Message message, Handler handler) throws Exception {
boolean isBroadcast = (message.getMessageId() == null);
MobiComUserPreference userPreferences = MobiComUserPreference.getInstance(context);
message.setSent(Boolean.TRUE);
message.setSendToDevice(Boolean.FALSE);
message.setSuUserKeyString(userPreferences.getSuUserKeyString());
message.processContactIds(context);
Contact contact = null;
Channel channel = null;
boolean isBroadcastOneByOneGroupType = false;
boolean isOpenGroup = false;
boolean skipMessage = false;
if (message.getGroupId() == null) {
contact = baseContactService.getContactById(message.getContactIds());
} else {
channel = ChannelService.getInstance(context).getChannel(message.getGroupId());
isOpenGroup = Channel.GroupType.OPEN.getValue().equals(channel.getType());
isBroadcastOneByOneGroupType = Channel.GroupType.BROADCAST_ONE_BY_ONE.getValue().equals(channel.getType());
}
long messageId = -1;
List<String> fileKeys = new ArrayList<String>();
String keyString = null;
if (!isBroadcastOneByOneGroupType) {
keyString = UUID.randomUUID().toString();
message.setKeyString(keyString);
message.setSentToServer(false);
} else {
message.setSentToServer(true);
}
if (Message.MetaDataType.HIDDEN.getValue().equals(message.getMetaDataValueForKey(Message.MetaDataType.KEY.getValue())) || Message.MetaDataType.PUSHNOTIFICATION.getValue().equals(message.getMetaDataValueForKey(Message.MetaDataType.KEY.getValue()))) {
skipMessage = true;
}
if (!skipMessage && !isOpenGroup) {
messageId = messageDatabaseService.createMessage(message);
}
if (isBroadcast && !skipMessage) {
BroadcastService.sendMessageUpdateBroadcast(context, BroadcastService.INTENT_ACTIONS.SYNC_MESSAGE.toString(), message);
}
if (!isBroadcastOneByOneGroupType && message.isUploadRequired() && !isOpenGroup) {
for (String filePath : message.getFilePaths()) {
try {
String fileMetaResponse = new FileClientService(context).uploadBlobImage(filePath, handler);
if (fileMetaResponse == null) {
if (skipMessage) {
return;
}
if (handler != null) {
android.os.Message msg = handler.obtainMessage();
msg.what = MobiComConversationService.UPLOAD_COMPLETED;
msg.getData().putString("error", "Error while uploading");
msg.sendToTarget();
}
if (!message.isContactMessage()) {
messageDatabaseService.updateCanceledFlag(messageId, 1);
}
BroadcastService.sendMessageUpdateBroadcast(context, BroadcastService.INTENT_ACTIONS.UPLOAD_ATTACHMENT_FAILED.toString(), message);
return;
}
if (ApplozicClient.getInstance(context).isCustomStorageServiceEnabled()) {
if (!TextUtils.isEmpty(fileMetaResponse)) {
message.setFileMetas((FileMeta) GsonUtils.getObjectFromJson(fileMetaResponse, FileMeta.class));
if (handler != null) {
android.os.Message msg = handler.obtainMessage();
msg.what = MobiComConversationService.UPLOAD_COMPLETED;
msg.getData().putString("error", null);
msg.sendToTarget();
}
}
} else {
JsonParser jsonParser = new JsonParser();
JsonObject jsonObject = jsonParser.parse(fileMetaResponse).getAsJsonObject();
if (jsonObject.has(FILE_META)) {
Gson gson = new Gson();
message.setFileMetas(gson.fromJson(jsonObject.get(FILE_META), FileMeta.class));
if (handler != null) {
android.os.Message msg = handler.obtainMessage();
msg.what = MobiComConversationService.UPLOAD_COMPLETED;
msg.getData().putString("error", null);
msg.sendToTarget();
}
}
}
} catch (Exception ex) {
Utils.printLog(context, TAG, "Error uploading file to server: " + filePath);
if (handler != null) {
android.os.Message msg = handler.obtainMessage();
msg.what = MobiComConversationService.UPLOAD_COMPLETED;
msg.getData().putString("error", "Error uploading file to server: " + filePath);
msg.sendToTarget();
}
/* recentMessageSentToServer.remove(message);*/
if (!message.isContactMessage() && !skipMessage) {
messageDatabaseService.updateCanceledFlag(messageId, 1);
}
if (!skipMessage) {
BroadcastService.sendMessageUpdateBroadcast(context, BroadcastService.INTENT_ACTIONS.UPLOAD_ATTACHMENT_FAILED.toString(), message);
}
return;
}
}
if (messageId != -1 && !skipMessage) {
messageDatabaseService.updateMessageFileMetas(messageId, message);
}
}
Message newMessage = new Message();
newMessage.setTo(message.getTo());
newMessage.setKeyString(message.getKeyString());
newMessage.setMessage(message.getMessage());
newMessage.setFileMetas(message.getFileMetas());
newMessage.setCreatedAtTime(message.getCreatedAtTime());
newMessage.setRead(Boolean.TRUE);
newMessage.setDeviceKeyString(message.getDeviceKeyString());
newMessage.setSuUserKeyString(message.getSuUserKeyString());
newMessage.setSent(message.isSent());
newMessage.setType(message.getType());
newMessage.setTimeToLive(message.getTimeToLive());
newMessage.setSource(message.getSource());
newMessage.setScheduledAt(message.getScheduledAt());
newMessage.setStoreOnDevice(message.isStoreOnDevice());
newMessage.setDelivered(message.getDelivered());
newMessage.setStatus(message.getStatus());
newMessage.setMetadata(message.getMetadata());
newMessage.setSendToDevice(message.isSendToDevice());
newMessage.setContentType(message.getContentType());
newMessage.setConversationId(message.getConversationId());
if (message.getGroupId() != null) {
newMessage.setGroupId(message.getGroupId());
}
if (!TextUtils.isEmpty(message.getClientGroupId())) {
newMessage.setClientGroupId(message.getClientGroupId());
}
if (contact != null && !TextUtils.isEmpty(contact.getApplicationId())) {
newMessage.setApplicationId(contact.getApplicationId());
} else {
newMessage.setApplicationId(getApplicationKey(context));
}
try {
if (!isBroadcastOneByOneGroupType) {
String response = sendMessage(newMessage);
if (message.hasAttachment() && TextUtils.isEmpty(response) && !message.isContactMessage() && !skipMessage && !isOpenGroup) {
messageDatabaseService.updateCanceledFlag(messageId, 1);
if (handler != null) {
android.os.Message msg = handler.obtainMessage();
msg.what = MobiComConversationService.UPLOAD_COMPLETED;
msg.getData().putString("error", "Error uploading file to server");
msg.sendToTarget();
}
BroadcastService.sendMessageUpdateBroadcast(context, BroadcastService.INTENT_ACTIONS.UPLOAD_ATTACHMENT_FAILED.toString(), message);
}
MessageResponse messageResponse = (MessageResponse) GsonUtils.getObjectFromJson(response, MessageResponse.class);
keyString = messageResponse.getMessageKey();
if (!TextUtils.isEmpty(keyString)) {
message.setSentMessageTimeAtServer(Long.parseLong(messageResponse.getCreatedAtTime()));
message.setConversationId(messageResponse.getConversationId());
message.setSentToServer(true);
message.setKeyString(keyString);
}
if (!skipMessage && !isOpenGroup) {
messageDatabaseService.updateMessage(messageId, message.getSentMessageTimeAtServer(), keyString, message.isSentToServer());
}
} else {
message.setSentMessageTimeAtServer(message.getCreatedAtTime());
messageDatabaseService.updateMessage(messageId, message.getSentMessageTimeAtServer(), keyString, message.isSentToServer());
}
if (message.isSentToServer()) {
if (handler != null) {
android.os.Message msg = handler.obtainMessage();
msg.what = MobiComConversationService.MESSAGE_SENT;
msg.getData().putString("message", message.getKeyString());
msg.sendToTarget();
}
}
if (!TextUtils.isEmpty(keyString)) {
// Todo: Handle server message add failure due to internet disconnect.
} else {
// Todo: If message type is mtext, tell user that internet is not working, else send update with db id.
}
if (!skipMessage || isOpenGroup) {
BroadcastService.sendMessageUpdateBroadcast(context, BroadcastService.INTENT_ACTIONS.MESSAGE_SYNC_ACK_FROM_SERVER.toString(), message);
}
} catch (Exception e) {
if (handler != null) {
android.os.Message msg = handler.obtainMessage();
msg.what = MobiComConversationService.UPLOAD_COMPLETED;
msg.getData().putString("error", "Error uploading file");
msg.sendToTarget();
// handler.onCompleted(new ApplozicException("Error uploading file"));
}
}
/* if (recentMessageSentToServer.size() > 20) {
recentMessageSentToServer.subList(0, 10).clear();
}*/
}
use of com.applozic.mobicomkit.api.attachment.FileClientService in project Applozic-Android-SDK by AppLozic.
the class MobiComAttachmentSelectorActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mobicom_multi_attachment_activity);
String jsonString = FileUtils.loadSettingsJsonFile(getApplicationContext());
if (!TextUtils.isEmpty(jsonString)) {
alCustomizationSettings = (AlCustomizationSettings) GsonUtils.getObjectFromJson(jsonString, AlCustomizationSettings.class);
} else {
alCustomizationSettings = new AlCustomizationSettings();
}
restrictedWords = FileUtils.loadRestrictedWordsFile(this);
choosenOption = getFilterOptions();
fileClientService = new FileClientService(this);
userPreferences = MobiComUserPreference.getInstance(this);
Intent intent = getIntent();
if (intent.getExtras() != null) {
userID = intent.getExtras().getString(USER_ID);
displayName = intent.getExtras().getString(DISPLAY_NAME);
groupID = intent.getExtras().getInt(GROUP_ID, 0);
groupName = intent.getExtras().getString(GROUP_NAME);
imageUri = (Uri) intent.getParcelableExtra(URI_LIST);
if (imageUri != null) {
attachmentFileList.add(imageUri);
}
}
initViews();
setUpGridView();
fileClientService = new FileClientService(this);
if (imageUri == null) {
Intent getContentIntent = FileUtils.createGetContentIntent(getFilterOptions(), getPackageManager());
getContentIntent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
startActivityForResult(getContentIntent, REQUEST_CODE_ATTACH_PHOTO);
}
connectivityReceiver = new ConnectivityReceiver();
registerReceiver(connectivityReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
}
use of com.applozic.mobicomkit.api.attachment.FileClientService in project Applozic-Android-SDK by AppLozic.
the class ChannelCreateActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.channel_create_activty_layout);
Toolbar toolbar = (Toolbar) findViewById(R.id.my_toolbar);
setSupportActionBar(toolbar);
String jsonString = FileUtils.loadSettingsJsonFile(getApplicationContext());
if (!TextUtils.isEmpty(jsonString)) {
alCustomizationSettings = (AlCustomizationSettings) GsonUtils.getObjectFromJson(jsonString, AlCustomizationSettings.class);
} else {
alCustomizationSettings = new AlCustomizationSettings();
}
connectivityReceiver = new ConnectivityReceiver();
userPreference = MobiComUserPreference.getInstance(ChannelCreateActivity.this);
mActionBar = getSupportActionBar();
if (!TextUtils.isEmpty(alCustomizationSettings.getThemeColorPrimary()) && !TextUtils.isEmpty(alCustomizationSettings.getThemeColorPrimaryDark())) {
mActionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor(alCustomizationSettings.getThemeColorPrimary())));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().setStatusBarColor(Color.parseColor(alCustomizationSettings.getThemeColorPrimaryDark()));
}
}
mActionBar.setTitle(R.string.channel_create_title);
mActionBar.setDisplayShowHomeEnabled(true);
mActionBar.setDisplayHomeAsUpEnabled(true);
finishActivityReceiver = new FinishActivityReceiver();
registerReceiver(finishActivityReceiver, new IntentFilter(ACTION_FINISH_CHANNEL_CREATE));
layout = (LinearLayout) findViewById(R.id.footerAd);
applozicPermissions = new ApplozicPermissions(this, layout);
channelName = (EditText) findViewById(R.id.channelName);
circleImageView = (CircleImageView) findViewById(R.id.channelIcon);
uploadImageButton = (CircleImageView) findViewById(R.id.applozic_channel_profile_camera);
uploadImageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
processImagePicker();
}
});
int drawableResourceId = getResources().getIdentifier(alCustomizationSettings.getAttachCameraIconName(), "drawable", getPackageName());
uploadImageButton.setImageResource(drawableResourceId);
fileClientService = new FileClientService(this);
if (getIntent() != null) {
groupType = getIntent().getIntExtra(GROUP_TYPE, Channel.GroupType.PUBLIC.getValue().intValue());
}
/* groupType = getIntent().getIntExtra(GROUP_TYPE, Channel.GroupType.PRIVATE.getValue().intValue());
if(groupType.equals(Channel.GroupType.BROADCAST.getValue().intValue())){
circleImageView.setImageResource(R.drawable.applozic_ic_applozic_broadcast);
uploadImageButton.setVisibility(View.GONE);
}*/
registerReceiver(connectivityReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
}
use of com.applozic.mobicomkit.api.attachment.FileClientService in project Applozic-Android-SDK by AppLozic.
the class MobiComConversationService method getMessagesForParticularThreadWithNetworkMetaData.
// Cleanup: private
public synchronized NetworkListDecorator<Message> getMessagesForParticularThreadWithNetworkMetaData(Long startTime, Long endTime, Contact contact, Channel channel, Integer conversationId, boolean isSkipRead) {
String data = null;
try {
data = messageClientService.getMessages(contact, channel, startTime, endTime, conversationId, isSkipRead);
Utils.printLog(context, TAG, "Received response from server for Messages: " + data);
} catch (Exception ex) {
ex.printStackTrace();
}
if (data == null || TextUtils.isEmpty(data) || data.equals("UnAuthorized Access") || !data.contains("{")) {
return new NetworkListDecorator<>(null, true);
}
AlConversationResponse alConversationResponse = null;
// for determining network fail in case of exception
boolean wasNetworkFail = false;
try {
alConversationResponse = (AlConversationResponse) GsonUtils.getObjectFromJson(messageClientService.getMessages(contact, channel, startTime, endTime, conversationId, isSkipRead), AlConversationResponse.class);
} catch (Exception e) {
e.printStackTrace();
wasNetworkFail = true;
}
if (alConversationResponse == null) {
return new NetworkListDecorator<>(null, wasNetworkFail);
}
List<Message> messageList = new ArrayList<>();
try {
if (alConversationResponse.getUserDetails() != null) {
MessageSearchCache.processUserDetails(alConversationResponse.getUserDetails());
}
if (alConversationResponse.getGroupFeeds() != null) {
MessageSearchCache.processChannelFeeds(alConversationResponse.getGroupFeeds());
}
List<String> messageKeys = new ArrayList<>();
for (Message message : alConversationResponse.getMessage()) {
if (message.getTo() == null) {
continue;
}
if (message.hasAttachment() && !(message.getContentType() == Message.ContentType.TEXT_URL.getValue())) {
setFilePathifExist(message);
}
if (message.getContentType() == Message.ContentType.CONTACT_MSG.getValue()) {
FileClientService fileClientService = new FileClientService(context);
fileClientService.loadContactsvCard(message);
}
if (Message.MetaDataType.HIDDEN.getValue().equals(message.getMetaDataValueForKey(Message.MetaDataType.KEY.getValue())) || Message.MetaDataType.PUSHNOTIFICATION.getValue().equals(message.getMetaDataValueForKey(Message.MetaDataType.KEY.getValue()))) {
continue;
}
if (message.getMetadata() != null && Message.GroupMessageMetaData.TRUE.getValue().equals(message.getMetadata().get(Message.GroupMessageMetaData.HIDE_KEY.getValue()))) {
continue;
}
if (isHideActionMessage && message.isActionMessage()) {
message.setHidden(true);
}
messageList.add(message);
if (message.getMetadata() != null && message.getMetaDataValueForKey(Message.MetaDataType.AL_REPLY.getValue()) != null) {
messageKeys.add(message.getMetaDataValueForKey(Message.MetaDataType.AL_REPLY.getValue()));
}
}
if (alConversationResponse.getMessage() != null) {
Collections.reverse(messageList);
MessageSearchCache.setMessageList(messageList);
}
} catch (Exception e) {
e.printStackTrace();
}
return new NetworkListDecorator<>(messageList, wasNetworkFail);
}
use of com.applozic.mobicomkit.api.attachment.FileClientService in project Applozic-Android-SDK by AppLozic.
the class MobiComConversationService method getMessagesWithNetworkMetaData.
// Cleanup: try to get to default
public synchronized NetworkListDecorator<Message> getMessagesWithNetworkMetaData(Long startTime, Long endTime, Contact contact, Channel channel, Integer conversationId, boolean isSkipRead, boolean isForSearch) {
if (isForSearch) {
return getMessagesForParticularThreadWithNetworkMetaData(startTime, endTime, contact, channel, conversationId, isSkipRead);
}
List<Message> messageList = new ArrayList<Message>();
List<Message> cachedMessageList = messageDatabaseService.getMessages(startTime, endTime, contact, channel, conversationId);
boolean isServerCallNotRequired = false;
if (channel != null) {
Channel newChannel = ChannelService.getInstance(context).getChannelByChannelKey(channel.getKey());
isServerCallNotRequired = (newChannel != null && !Channel.GroupType.OPEN.getValue().equals(newChannel.getType()));
} else if (contact != null) {
isServerCallNotRequired = true;
}
if (isServerCallNotRequired && (!cachedMessageList.isEmpty() && ApplozicClient.getInstance(context).wasServerCallDoneBefore(contact, channel, conversationId) || (contact == null && channel == null && cachedMessageList.isEmpty() && ApplozicClient.getInstance(context).wasServerCallDoneBefore(contact, channel, conversationId)))) {
Utils.printLog(context, TAG, "cachedMessageList size is : " + cachedMessageList.size());
return new NetworkListDecorator<>(cachedMessageList, false);
}
String data;
try {
data = messageClientService.getMessages(contact, channel, startTime, endTime, conversationId, isSkipRead);
Utils.printLog(context, TAG, "Received response from server for Messages: " + data);
} catch (Exception ex) {
ex.printStackTrace();
return new NetworkListDecorator<>(cachedMessageList, true);
}
if (data == null || TextUtils.isEmpty(data) || data.equals("UnAuthorized Access") || !data.contains("{")) {
// Note: currently not supporting syncing old channel messages from server
if (channel != null && channel.getKey() != null) {
return new NetworkListDecorator<>(cachedMessageList, true);
}
return new NetworkListDecorator<>(cachedMessageList, true);
}
ApplozicClient.getInstance(context).updateServerCallDoneStatus(contact, channel, conversationId);
// for the try catch
boolean wasNetworkFail = false;
try {
Gson gson = new GsonBuilder().registerTypeAdapterFactory(new ArrayAdapterFactory()).setExclusionStrategies(new AnnotationExclusionStrategy()).create();
JsonParser parser = new JsonParser();
JSONObject jsonObject = new JSONObject(data);
String channelFeedResponse = "";
String conversationPxyResponse = "";
String element = parser.parse(data).getAsJsonObject().get("message").toString();
String userDetailsElement = parser.parse(data).getAsJsonObject().get("userDetails").toString();
if (!TextUtils.isEmpty(userDetailsElement)) {
UserDetail[] userDetails = (UserDetail[]) GsonUtils.getObjectFromJson(userDetailsElement, UserDetail[].class);
processUserDetails(userDetails);
}
if (jsonObject.has("groupFeeds")) {
channelFeedResponse = parser.parse(data).getAsJsonObject().get("groupFeeds").toString();
ChannelFeed[] channelFeeds = (ChannelFeed[]) GsonUtils.getObjectFromJson(channelFeedResponse, ChannelFeed[].class);
ChannelService.getInstance(context).processChannelFeedList(channelFeeds, false);
if (channel != null && !isServerCallNotRequired) {
BroadcastService.sendUpdate(context, BroadcastService.INTENT_ACTIONS.UPDATE_TITLE_SUBTITLE.toString());
}
}
if (jsonObject.has("conversationPxys")) {
conversationPxyResponse = parser.parse(data).getAsJsonObject().get("conversationPxys").toString();
Conversation[] conversationPxy = (Conversation[]) GsonUtils.getObjectFromJson(conversationPxyResponse, Conversation[].class);
ConversationService.getInstance(context).processConversationArray(conversationPxy, channel, contact);
}
Message[] messages = gson.fromJson(element, Message[].class);
MobiComUserPreference userPreferences = MobiComUserPreference.getInstance(context);
if (messages != null && messages.length > 0 && cachedMessageList.size() > 0 && cachedMessageList.get(0).isLocalMessage()) {
if (cachedMessageList.get(0).equals(messages[0])) {
Utils.printLog(context, TAG, "Both messages are same.");
deleteMessage(cachedMessageList.get(0));
}
}
for (Message message : messages) {
if (!message.isCall() || userPreferences.isDisplayCallRecordEnable()) {
// we have to figure out if it is a parsing problem or response from server.
if (message.getTo() == null) {
continue;
}
if (message.hasAttachment() && !(message.getContentType() == Message.ContentType.TEXT_URL.getValue())) {
setFilePathifExist(message);
}
if (message.getContentType() == Message.ContentType.CONTACT_MSG.getValue()) {
FileClientService fileClientService = new FileClientService(context);
fileClientService.loadContactsvCard(message);
}
if (Message.MetaDataType.HIDDEN.getValue().equals(message.getMetaDataValueForKey(Message.MetaDataType.KEY.getValue())) || Message.MetaDataType.PUSHNOTIFICATION.getValue().equals(message.getMetaDataValueForKey(Message.MetaDataType.KEY.getValue()))) {
continue;
}
message.setHidden(isHideActionMessage && message.isActionMessage());
if (messageDatabaseService.isMessagePresent(message.getKeyString(), Message.ReplyMessage.HIDE_MESSAGE.getValue())) {
messageDatabaseService.updateMessageReplyType(message.getKeyString(), Message.ReplyMessage.NON_HIDDEN.getValue());
} else {
if (isServerCallNotRequired || contact == null && channel == null) {
messageDatabaseService.createMessage(message);
}
}
if (contact == null && channel == null) {
if (message.hasHideKey()) {
if (message.getGroupId() != null) {
Channel newChannel = ChannelService.getInstance(context).getChannelByChannelKey(message.getGroupId());
if (newChannel != null) {
getMessagesWithNetworkMetaData(null, null, null, newChannel, null, true, isForSearch);
}
} else {
getMessagesWithNetworkMetaData(null, null, new Contact(message.getContactIds()), null, null, true, isForSearch);
}
}
}
}
if (!isServerCallNotRequired && !message.isHidden()) {
messageList.add(message);
}
}
if (contact == null && channel == null) {
Intent intent = new Intent(MobiComKitConstants.APPLOZIC_UNREAD_COUNT);
LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
}
} catch (JsonSyntaxException | JSONException jsonException) {
jsonException.printStackTrace();
wasNetworkFail = true;
} catch (Exception exception) {
exception.printStackTrace();
}
List<Message> finalMessageList = messageDatabaseService.getMessages(startTime, endTime, contact, channel, conversationId);
List<String> messageKeys = new ArrayList<>();
for (Message msg : finalMessageList) {
if (msg.getTo() == null) {
continue;
}
if (Message.MetaDataType.HIDDEN.getValue().equals(msg.getMetaDataValueForKey(Message.MetaDataType.KEY.getValue())) || Message.MetaDataType.PUSHNOTIFICATION.getValue().equals(msg.getMetaDataValueForKey(Message.MetaDataType.KEY.getValue()))) {
continue;
}
if (msg.getMetadata() != null && msg.getMetaDataValueForKey(Message.MetaDataType.AL_REPLY.getValue()) != null && !messageDatabaseService.isMessagePresent(msg.getMetaDataValueForKey(Message.MetaDataType.AL_REPLY.getValue()))) {
messageKeys.add(msg.getMetaDataValueForKey(Message.MetaDataType.AL_REPLY.getValue()));
}
}
if (messageKeys != null && messageKeys.size() > 0) {
Message[] replyMessageList = getMessageListByKeyList(messageKeys);
if (replyMessageList != null) {
for (Message replyMessage : replyMessageList) {
if (replyMessage.getTo() == null) {
continue;
}
if (Message.MetaDataType.HIDDEN.getValue().equals(replyMessage.getMetaDataValueForKey(Message.MetaDataType.KEY.getValue())) || Message.MetaDataType.PUSHNOTIFICATION.getValue().equals(replyMessage.getMetaDataValueForKey(Message.MetaDataType.KEY.getValue()))) {
continue;
}
if (replyMessage.hasAttachment() && !(replyMessage.getContentType() == Message.ContentType.TEXT_URL.getValue())) {
setFilePathifExist(replyMessage);
}
if (replyMessage.getContentType() == Message.ContentType.CONTACT_MSG.getValue()) {
FileClientService fileClientService = new FileClientService(context);
fileClientService.loadContactsvCard(replyMessage);
}
replyMessage.setReplyMessage(Message.ReplyMessage.HIDE_MESSAGE.getValue());
if (isServerCallNotRequired || contact == null && channel == null) {
messageDatabaseService.createMessage(replyMessage);
}
}
}
}
if (messageList != null && !messageList.isEmpty()) {
Collections.sort(messageList, new Comparator<Message>() {
@Override
public int compare(Message lhs, Message rhs) {
return lhs.getCreatedAtTime().compareTo(rhs.getCreatedAtTime());
}
});
}
return new NetworkListDecorator<>(channel != null && Channel.GroupType.OPEN.getValue().equals(channel.getType()) ? messageList : finalMessageList, wasNetworkFail);
}
Aggregations