use of com.applozic.mobicomkit.api.conversation.Message in project Applozic-Android-SDK by AppLozic.
the class MobiComConversationFragment method updateMessageList.
public synchronized boolean updateMessageList(Message message, boolean update) {
boolean toAdd = !messageList.contains(message);
loadMore = true;
if (update) {
messageList.remove(message);
messageList.add(message);
} else if (toAdd) {
Message firstDateMessage = new Message();
firstDateMessage.setTempDateType(Short.valueOf("100"));
firstDateMessage.setCreatedAtTime(message.getCreatedAtTime());
if (!messageList.contains(firstDateMessage)) {
messageList.add(firstDateMessage);
}
messageList.add(message);
}
return toAdd;
}
use of com.applozic.mobicomkit.api.conversation.Message in project Applozic-Android-SDK by AppLozic.
the class MobiComConversationFragment method updateMessageMetadata.
public void updateMessageMetadata(String keyString) {
int i = -1;
if (!messageList.isEmpty()) {
for (Message message : messageList) {
if (keyString.equals(message.getKeyString())) {
i = messageList.indexOf(message);
}
}
}
if (i != -1) {
messageList.get(i).setMetadata(messageDatabaseService.getMessage(keyString).getMetadata());
conversationAdapter.notifyDataSetChanged();
if (messageList.get(messageList.size() - 1).getMetadata().containsKey("isDoneWithClicking")) {
templateAdapter.setMessageList(new HashMap<String, String>());
templateAdapter.notifyDataSetChanged();
}
}
}
use of com.applozic.mobicomkit.api.conversation.Message in project Applozic-Android-SDK by AppLozic.
the class MobiComConversationFragment method sendBroadcastMessage.
public void sendBroadcastMessage(String message, String path) {
MobiComUserPreference userPreferences = MobiComUserPreference.getInstance(getActivity());
if (channelUserMapperList != null && channelUserMapperList.size() > 0) {
for (ChannelUserMapper channelUserMapper : channelUserMapperList) {
if (!userPreferences.getUserId().equals(channelUserMapper.getUserKey())) {
Message messageToSend = new Message();
messageToSend.setTo(channelUserMapper.getUserKey());
messageToSend.setContactIds(channelUserMapper.getUserKey());
messageToSend.setRead(Boolean.TRUE);
messageToSend.setStoreOnDevice(Boolean.TRUE);
if (messageToSend.getCreatedAtTime() == null) {
messageToSend.setCreatedAtTime(System.currentTimeMillis() + userPreferences.getDeviceTimeOffset());
}
if (currentConversationId != null && currentConversationId != 0) {
messageToSend.setConversationId(currentConversationId);
}
messageToSend.setSendToDevice(Boolean.FALSE);
messageToSend.setType(sendType.getSelectedItemId() == 1 ? Message.MessageType.MT_OUTBOX.getValue() : Message.MessageType.OUTBOX.getValue());
messageToSend.setTimeToLive(getTimeToLive());
messageToSend.setMessage(message);
messageToSend.setDeviceKeyString(userPreferences.getDeviceKeyString());
messageToSend.setScheduledAt(scheduledTimeHolder.getTimestamp());
messageToSend.setSource(Message.Source.MT_MOBILE_APP.getValue());
if (!TextUtils.isEmpty(path)) {
List<String> filePaths = new ArrayList<String>();
filePaths.add(path);
messageToSend.setFilePaths(filePaths);
}
conversationService.sendMessage(messageToSend, MessageIntentService.class);
if (selfDestructMessageSpinner != null) {
selfDestructMessageSpinner.setSelection(0);
}
attachmentLayout.setVisibility(View.GONE);
}
}
}
}
use of com.applozic.mobicomkit.api.conversation.Message in project Applozic-Android-SDK by AppLozic.
the class MobiComConversationFragment method deleteMessageFromDeviceList.
public void deleteMessageFromDeviceList(String messageKeyString) {
try {
int position;
boolean updateQuickConversation = false;
int index;
for (Message message : messageList) {
boolean value = message.getKeyString() != null ? message.getKeyString().equals(messageKeyString) : false;
if (value) {
index = messageList.indexOf(message);
if (index != -1) {
int aboveIndex = index - 1;
int belowIndex = index + 1;
Message aboveMessage = messageList.get(aboveIndex);
if (belowIndex != messageList.size()) {
Message belowMessage = messageList.get(belowIndex);
if (aboveMessage.isTempDateType() && belowMessage.isTempDateType()) {
messageList.remove(aboveMessage);
}
} else if (belowIndex == messageList.size() && aboveMessage.isTempDateType()) {
messageList.remove(aboveMessage);
}
}
}
if (message.getKeyString() != null && message.getKeyString().equals(messageKeyString)) {
position = messageList.indexOf(message);
if (position == messageList.size() - 1) {
updateQuickConversation = true;
}
if (message.getScheduledAt() != null && message.getScheduledAt() != 0) {
messageDatabaseService.deleteScheduledMessage(messageKeyString);
}
messageList.remove(position);
recyclerDetailConversationAdapter.notifyDataSetChanged();
if (messageList.isEmpty()) {
emptyTextView.setVisibility(VISIBLE);
((MobiComKitActivityInterface) getActivity()).removeConversation(message, channel != null ? String.valueOf(channel.getKey()) : contact.getFormattedContactNumber());
}
break;
}
}
int messageListSize = messageList.size();
if (messageListSize > 0 && updateQuickConversation) {
((MobiComKitActivityInterface) getActivity()).updateLatestMessage(messageList.get(messageListSize - 1), channel != null ? String.valueOf(channel.getKey()) : contact.getFormattedContactNumber());
}
} catch (Exception e) {
e.printStackTrace();
}
}
use of com.applozic.mobicomkit.api.conversation.Message in project Applozic-Android-SDK by AppLozic.
the class MobiComConversationFragment method sendProductMessage.
public void sendProductMessage(final String messageToSend, final FileMeta fileMeta, final Contact contact, final short messageContentType) {
final Message message = new Message();
new Thread(new Runnable() {
@Override
public void run() {
String topicId;
MobiComConversationService conversationService = new MobiComConversationService(getActivity());
MobiComUserPreference userPreferences = MobiComUserPreference.getInstance(getActivity());
topicId = new MessageClientService(getActivity()).getTopicId(currentConversationId);
if (getChannel() != null) {
message.setGroupId(channelKey);
} else {
message.setContactIds(contact.getUserId());
message.setTo(contact.getUserId());
}
message.setMessage(messageToSend);
message.setRead(Boolean.TRUE);
message.setStoreOnDevice(Boolean.TRUE);
message.setSendToDevice(Boolean.FALSE);
message.setContentType(messageContentType);
message.setType(Message.MessageType.MT_OUTBOX.getValue());
message.setDeviceKeyString(userPreferences.getDeviceKeyString());
message.setSource(Message.Source.MT_MOBILE_APP.getValue());
message.setTopicId(messageToSend);
message.setCreatedAtTime(System.currentTimeMillis() + userPreferences.getDeviceTimeOffset());
message.setTopicId(topicId);
message.setConversationId(currentConversationId);
message.setFileMetas(fileMeta);
conversationService.sendMessage(message, MessageIntentService.class);
}
}).start();
}
Aggregations