use of com.applozic.mobicomkit.api.conversation.Message in project Applozic-Android-SDK by AppLozic.
the class MessageDatabaseService method getMessages.
public List<Message> getMessages(Long startTime, Long endTime, Contact contact, Channel channel, Integer conversationId) {
String structuredNameWhere = "";
List<String> structuredNameParamsList = new ArrayList<String>();
if (channel != null && channel.getKey() != null) {
structuredNameWhere += "channelKey = ? AND ";
structuredNameParamsList.add(String.valueOf(channel.getKey()));
} else {
structuredNameWhere += "channelKey = ? AND ";
structuredNameParamsList.add("0");
}
if (contact != null && !TextUtils.isEmpty(contact.getContactIds())) {
structuredNameWhere += "contactNumbers = ? AND ";
structuredNameParamsList.add(contact.getContactIds());
}
if (startTime != null) {
structuredNameWhere += "createdAt >= ? AND ";
structuredNameParamsList.add(String.valueOf(startTime));
}
if (endTime != null) {
structuredNameWhere += "createdAt < ? AND ";
structuredNameParamsList.add(String.valueOf(endTime));
}
if (BroadcastService.isContextBasedChatEnabled() && conversationId != null && conversationId != 0) {
structuredNameWhere += "conversationId = ? AND ";
structuredNameParamsList.add(String.valueOf(conversationId));
}
structuredNameWhere += "messageContentType not in ( ?,? ) AND ";
structuredNameParamsList.add(String.valueOf(Message.ContentType.HIDDEN.getValue()));
structuredNameParamsList.add(String.valueOf(Message.ContentType.VIDEO_CALL_NOTIFICATION_MSG.getValue()));
structuredNameWhere += "deleted = ? AND ";
structuredNameParamsList.add("0");
structuredNameWhere += "hidden = ? AND ";
structuredNameParamsList.add("0");
structuredNameWhere += "replyMessage != ? AND ";
structuredNameParamsList.add(String.valueOf(Message.ReplyMessage.HIDE_MESSAGE.getValue()));
MobiComUserPreference userPreferences = MobiComUserPreference.getInstance(context);
if (!userPreferences.isDisplayCallRecordEnable()) {
structuredNameWhere += "type != ? AND type != ? AND ";
structuredNameParamsList.add(String.valueOf(Message.MessageType.CALL_INCOMING.getValue()));
structuredNameParamsList.add(String.valueOf(Message.MessageType.CALL_OUTGOING.getValue()));
}
if (!TextUtils.isEmpty(structuredNameWhere)) {
structuredNameWhere = structuredNameWhere.substring(0, structuredNameWhere.length() - 5);
}
SQLiteDatabase db = dbHelper.getWritableDatabase();
Cursor cursor = db.query("sms", null, structuredNameWhere, structuredNameParamsList.toArray(new String[structuredNameParamsList.size()]), null, null, "createdAt asc");
List<Message> messageList = MessageDatabaseService.getMessageList(cursor);
dbHelper.close();
return messageList;
}
use of com.applozic.mobicomkit.api.conversation.Message in project Applozic-Android-SDK by AppLozic.
the class MessageDatabaseService method createMessage.
public synchronized long createMessage(final Message message) {
long id = -1;
if (message.getMessageId() != null) {
return message.getMessageId();
}
id = createSingleMessage(message);
message.setMessageId(id);
if (message.isSentToMany()) {
String[] toList = message.getTo().trim().replace("undefined,", "").split(",");
for (String tofield : toList) {
Message singleMessage = new Message(message);
singleMessage.setKeyString(message.getKeyString());
// singleMessage.setBroadcastGroupId(null);
singleMessage.setTo(tofield);
singleMessage.processContactIds(context);
singleMessage.setMessageId(createSingleMessage(singleMessage));
}
}
return id;
}
use of com.applozic.mobicomkit.api.conversation.Message in project Applozic-Android-SDK by AppLozic.
the class MessageDatabaseService method getMessage.
public static Message getMessage(Cursor cursor) {
Message message = new Message();
message.setMessageId(cursor.getLong(cursor.getColumnIndex("id")));
message.setKeyString(cursor.getString(cursor.getColumnIndex("keyString")));
message.setType(cursor.getShort(cursor.getColumnIndex("type")));
message.setSource(cursor.getShort(cursor.getColumnIndex("source")));
Long storeOnDevice = cursor.getLong(cursor.getColumnIndex("storeOnDevice"));
message.setStoreOnDevice(storeOnDevice != null && storeOnDevice.intValue() == 1);
String contactNumbers = cursor.getString(cursor.getColumnIndex("contactNumbers"));
message.setContactIds(contactNumbers);
message.setCreatedAtTime(cursor.getLong(cursor.getColumnIndex("createdAt")));
Long delivered = cursor.getLong(cursor.getColumnIndex("delivered"));
message.setDelivered(delivered != null && delivered.intValue() == 1);
Long canceled = cursor.getLong(cursor.getColumnIndex("canceled"));
message.setCanceled(canceled != null && canceled.intValue() == 1);
Long read = cursor.getLong(cursor.getColumnIndex("read"));
message.setRead(read != null && read.intValue() == 1);
message.setStatus(cursor.getShort(cursor.getColumnIndex(MobiComDatabaseHelper.STATUS)));
message.setClientGroupId(cursor.getString(cursor.getColumnIndex(MobiComDatabaseHelper.CLIENT_GROUP_ID)));
Long scheduledAt = cursor.getLong(cursor.getColumnIndex("scheduledAt"));
message.setScheduledAt(scheduledAt == null || scheduledAt.intValue() == 0 ? null : scheduledAt);
message.setMessage(cursor.getString(cursor.getColumnIndex("message")));
Long sentToServer = cursor.getLong(cursor.getColumnIndex("sentToServer"));
message.setSentToServer(sentToServer != null && sentToServer.intValue() == 1);
message.setTo(cursor.getString(cursor.getColumnIndex("toNumbers")));
int timeToLive = cursor.getInt(cursor.getColumnIndex("timeToLive"));
message.setReplyMessage(cursor.getInt(cursor.getColumnIndex("replyMessage")));
message.setTimeToLive(timeToLive != 0 ? timeToLive : null);
String fileMetaKeyStrings = cursor.getString(cursor.getColumnIndex("fileMetaKeyStrings"));
if (!TextUtils.isEmpty(fileMetaKeyStrings)) {
message.setFileMetaKeyStrings(fileMetaKeyStrings);
}
String filePaths = cursor.getString(cursor.getColumnIndex("filePaths"));
if (!TextUtils.isEmpty(filePaths)) {
message.setFilePaths(Arrays.asList(filePaths.split(",")));
}
message.setHidden(cursor.getInt(cursor.getColumnIndex(MobiComDatabaseHelper.HIDDEN)) == 1);
String metadata = cursor.getString(cursor.getColumnIndex(MobiComDatabaseHelper.MESSAGE_METADATA));
if (!TextUtils.isEmpty(metadata)) {
message.setMetadata(((Map<String, String>) GsonUtils.getObjectFromJson(metadata, Map.class)));
}
message.setApplicationId(cursor.getString(cursor.getColumnIndex("applicationId")));
message.setContentType(cursor.getShort(cursor.getColumnIndex(MobiComDatabaseHelper.MESSAGE_CONTENT_TYPE)));
int conversationId = cursor.getInt(cursor.getColumnIndex(MobiComDatabaseHelper.CONVERSATION_ID));
if (conversationId == 0) {
message.setConversationId(null);
} else {
message.setConversationId(conversationId);
}
message.setTopicId(cursor.getString(cursor.getColumnIndex(MobiComDatabaseHelper.TOPIC_ID)));
int channelKey = cursor.getInt(cursor.getColumnIndex(MobiComDatabaseHelper.CHANNEL_KEY));
if (channelKey == 0) {
message.setGroupId(null);
} else {
message.setGroupId(channelKey);
}
if (cursor.getString(cursor.getColumnIndex("blobKeyString")) == null) {
// file is not present... Don't set anything ...
} else {
FileMeta fileMeta = new FileMeta();
fileMeta.setKeyString(cursor.getString(cursor.getColumnIndex("metaFileKeyString")));
fileMeta.setBlobKeyString(cursor.getString(cursor.getColumnIndex("blobKeyString")));
fileMeta.setThumbnailUrl(cursor.getString(cursor.getColumnIndex("thumbnailUrl")));
fileMeta.setSize(cursor.getInt(cursor.getColumnIndex("size")));
fileMeta.setName(cursor.getString(cursor.getColumnIndex("name")));
fileMeta.setContentType(cursor.getString(cursor.getColumnIndex("contentType")));
fileMeta.setUrl(cursor.getString(cursor.getColumnIndex("url")));
message.setFileMetas(fileMeta);
}
return message;
}
use of com.applozic.mobicomkit.api.conversation.Message in project Applozic-Android-SDK by AppLozic.
the class ScheduleMessageService method onHandleIntent.
@Override
protected void onHandleIntent(Intent intent) {
Calendar c = Calendar.getInstance();
long time = c.getTimeInMillis();
MessageDatabaseService messageDatabaseService = new MessageDatabaseService(getApplicationContext());
MobiComConversationService conversationService = new MobiComConversationService(getApplicationContext());
List<Message> messages = messageDatabaseService.getScheduledMessages(time);
for (Message message : messages) {
message.setScheduledAt(null);
conversationService.sendMessage(message, MessageIntentService.class);
// Todo: broadcast for scheduled message fragment.
}
messageDatabaseService.deleteScheduledMessages(time);
}
use of com.applozic.mobicomkit.api.conversation.Message in project Applozic-Android-SDK by AppLozic.
the class ConversationUIService method checkForStartNewConversation.
public void checkForStartNewConversation(Intent intent) {
Contact contact = null;
Channel channel = null;
Integer conversationId = null;
if (Intent.ACTION_SEND.equals(intent.getAction()) && intent.getType() != null) {
if ("text/plain".equals(intent.getType())) {
String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
if (sharedText != null) {
startContactActivityForResult(null, sharedText);
}
} else if (intent.getType().startsWith("image/")) {
// Todo: use this for image forwarding
}
}
final Uri uri = intent.getData();
if (uri != null) {
// Note: This is used only for the device contacts
Long contactId = intent.getLongExtra(CONTACT_ID, 0);
if (contactId == 0) {
// Todo: show warning that the user doesn't have any number stored.
return;
}
contact = baseContactService.getContactById(String.valueOf(contactId));
}
Integer channelKey = intent.getIntExtra(GROUP_ID, -1);
String clientGroupId = intent.getStringExtra(CLIENT_GROUP_ID);
String channelName = intent.getStringExtra(GROUP_NAME);
if (!TextUtils.isEmpty(clientGroupId)) {
channel = ChannelService.getInstance(fragmentActivity).getChannelByClientGroupId(clientGroupId);
if (channel == null) {
return;
}
} else if (channelKey != -1 && channelKey != null && channelKey != 0) {
channel = ChannelService.getInstance(fragmentActivity).getChannel(channelKey);
}
if (channel != null && !TextUtils.isEmpty(channelName) && TextUtils.isEmpty(channel.getName())) {
channel.setName(channelName);
ChannelService.getInstance(fragmentActivity).updateChannel(channel);
}
String contactNumber = intent.getStringExtra(CONTACT_NUMBER);
boolean firstTimeMTexterFriend = intent.getBooleanExtra(FIRST_TIME_MTEXTER_FRIEND, false);
if (!TextUtils.isEmpty(contactNumber)) {
contact = baseContactService.getContactById(contactNumber);
if (BroadcastService.isIndividual()) {
getConversationFragment().setFirstTimeMTexterFriend(firstTimeMTexterFriend);
}
}
String userId = intent.getStringExtra(USER_ID);
if (TextUtils.isEmpty(userId)) {
userId = intent.getStringExtra("contactId");
}
if (!TextUtils.isEmpty(userId)) {
contact = baseContactService.getContactById(userId);
}
String searchString = intent.getStringExtra(SEARCH_STRING);
String applicationId = intent.getStringExtra(APPLICATION_ID);
if (contact != null) {
contact.setApplicationId(applicationId);
baseContactService.upsert(contact);
}
String fullName = intent.getStringExtra(DISPLAY_NAME);
if (contact != null && TextUtils.isEmpty(contact.getFullName()) && !TextUtils.isEmpty(fullName)) {
contact.setFullName(fullName);
baseContactService.upsert(contact);
new UserClientService(fragmentActivity).updateUserDisplayName(userId, fullName);
}
String messageJson = intent.getStringExtra(MobiComKitConstants.MESSAGE_JSON_INTENT);
if (!TextUtils.isEmpty(messageJson)) {
Message message = (Message) GsonUtils.getObjectFromJson(messageJson, Message.class);
if (message.getGroupId() != null) {
channel = ChannelService.getInstance(fragmentActivity).getChannelByChannelKey(message.getGroupId());
} else {
contact = baseContactService.getContactById(message.getContactIds());
}
conversationId = message.getConversationId();
}
if (conversationId == null) {
conversationId = intent.getIntExtra(CONVERSATION_ID, 0);
}
if (conversationId != 0 && conversationId != null) {
getConversationFragment().setConversationId(conversationId);
} else {
conversationId = null;
}
boolean support = intent.getBooleanExtra(Support.SUPPORT_INTENT_KEY, false);
if (support) {
contact = new Support(fragmentActivity).getSupportContact();
}
String defaultText = intent.getStringExtra(ConversationUIService.DEFAULT_TEXT);
if (!TextUtils.isEmpty(defaultText)) {
getConversationFragment().setDefaultText(defaultText);
}
String forwardMessage = intent.getStringExtra(MobiComKitPeopleActivity.FORWARD_MESSAGE);
if (!TextUtils.isEmpty(forwardMessage)) {
Message messageToForward = (Message) GsonUtils.getObjectFromJson(forwardMessage, Message.class);
getConversationFragment().forwardMessage(messageToForward, contact, channel);
}
if (contact != null) {
openConversationFragment(contact, conversationId, searchString);
}
if (channel != null) {
openConversationFragment(channel, conversationId, searchString);
}
String productTopicId = intent.getStringExtra(ConversationUIService.PRODUCT_TOPIC_ID);
String productImageUrl = intent.getStringExtra(ConversationUIService.PRODUCT_IMAGE_URL);
if (!TextUtils.isEmpty(productTopicId) && !TextUtils.isEmpty(productImageUrl)) {
try {
FileMeta fileMeta = new FileMeta();
fileMeta.setContentType("image");
fileMeta.setBlobKeyString(productImageUrl);
getConversationFragment().sendProductMessage(productTopicId, fileMeta, contact, Message.ContentType.TEXT_URL.getValue());
} catch (Exception e) {
}
}
String sharedText = intent.getStringExtra(MobiComKitPeopleActivity.SHARED_TEXT);
if (!TextUtils.isEmpty(sharedText)) {
getConversationFragment().sendMessage(sharedText);
}
}
Aggregations