use of com.applozic.mobicommons.people.channel.Channel in project Applozic-Android-SDK by AppLozic.
the class ChannelServiceTest method createChannel_withSuccess.
@Test
public void createChannel_withSuccess() {
ChannelInfo channelInfo = new ChannelInfo();
try {
ChannelFeedApiResponse apiResponse = (ChannelFeedApiResponse) GsonUtils.getObjectFromJson(MockConstants.channelSuccessResponse, ChannelFeedApiResponse.class);
when(channelClientService.createChannelWithResponse(channelInfo)).thenReturn(apiResponse);
AlResponse response = channelService.createChannel(channelInfo);
assertTrue(response.isSuccess() && (response.getResponse() instanceof Channel));
} catch (Exception e) {
e.printStackTrace();
}
}
use of com.applozic.mobicommons.people.channel.Channel in project Applozic-Android-SDK by AppLozic.
the class ChannelDatabaseServiceTest method createDb.
@Before
public void createDb() {
Context context = ApplicationProvider.getApplicationContext();
dbHelper = new MobiComDatabaseHelper(ApplicationProvider.getApplicationContext(), null, null, MobiComDatabaseHelper.DB_VERSION);
channelDatabaseService = ChannelDatabaseService.getTestInstance(context, dbHelper);
messageDatabaseService = new MessageDatabaseService(context, dbHelper);
channel = new Channel();
Map<String, String> metadata = new HashMap<>();
metadata.put("met1", "1");
metadata.put("met2", "2");
channel.setMetadata(metadata);
channel.setKey(12345);
channel.setParentKey(123);
channel.setParentClientGroupId("parentId");
channel.setClientGroupId("clientId");
channel.setName("dname");
channel.setAdminKey("adminKey");
channel.setType((short) 1);
channel.setUnreadCount(10);
channel.setImageUrl("imageUrl");
channel.setLocalImageUri("localImageUri");
channel.setNotificationAfterTime(123456L);
channel.setDeletedAtTime(123456L);
channel.setKmStatus(1);
channel1 = new Channel();
Map<String, String> metadata1 = new HashMap<>();
metadata.put("met11", "1");
metadata.put("met21", "2");
channel1.setMetadata(metadata1);
channel1.setKey(123451);
channel1.setParentKey(1231);
channel1.setParentClientGroupId("parentId1");
channel1.setClientGroupId("clientId");
channel1.setName("bname1");
channel1.setAdminKey("adminKey1");
channel1.setType((short) 11);
channel1.setUnreadCount(101);
channel1.setImageUrl("imageUrl1");
channel1.setLocalImageUri("localImageUri1");
channel1.setNotificationAfterTime(12345L);
channel1.setDeletedAtTime(12345L);
channel1.setKmStatus(11);
channel2 = new Channel();
Map<String, String> metadata2 = new HashMap<>();
metadata.put("met12", "1");
metadata.put("met22", "2");
channel2.setMetadata(metadata2);
channel2.setKey(123452);
channel2.setParentKey(1232);
channel2.setParentClientGroupId("parentId2");
channel2.setClientGroupId("clientId2");
channel2.setName("aname2");
channel2.setAdminKey("adminKey2");
channel2.setType((short) 12);
channel2.setUnreadCount(102);
channel2.setImageUrl("imageUrl2");
channel2.setLocalImageUri("localImageUri2");
channel2.setNotificationAfterTime(1234L);
channel2.setDeletedAtTime(1234L);
channel2.setKmStatus(12);
channel3 = new Channel();
Map<String, String> metadata3 = new HashMap<>();
metadata.put("met13", "1");
metadata.put("met23", "2");
channel3.setMetadata(metadata3);
channel3.setKey(123453);
channel3.setParentKey(1233);
channel3.setParentClientGroupId("parentId3");
channel3.setClientGroupId("clientId3");
channel3.setName("cname3");
channel3.setAdminKey("adminKey3");
channel3.setType((short) 13);
channel3.setUnreadCount(103);
channel3.setImageUrl("imageUrl3");
channel3.setLocalImageUri("localImageUri3");
channel3.setNotificationAfterTime(123L);
channel3.setDeletedAtTime(123L);
channel3.setKmStatus(13);
// ChannelUserMapper objects
channelUserMapper = new ChannelUserMapper();
// for channel1
channelUserMapper.setKey(123451);
channelUserMapper.setUserKey("clientId");
channelUserMapper.setUnreadCount(20);
channelUserMapper.setStatus((short) 2);
channelUserMapper.setParentKey(123);
channelUserMapper.setRole(4);
channelUserMapper1 = new ChannelUserMapper();
// for channel1
channelUserMapper1.setKey(123451);
channelUserMapper1.setUserKey("clientId1");
channelUserMapper1.setUnreadCount(201);
channelUserMapper1.setStatus((short) 2);
channelUserMapper1.setParentKey(1231);
channelUserMapper1.setRole(41);
channelUserMapper2 = new ChannelUserMapper();
// for channel2
channelUserMapper2.setKey(123452);
channelUserMapper2.setUserKey("clientId2");
channelUserMapper2.setUnreadCount(202);
channelUserMapper2.setStatus((short) 3);
channelUserMapper2.setParentKey(1232);
channelUserMapper2.setRole(42);
}
use of com.applozic.mobicommons.people.channel.Channel in project Applozic-Android-SDK by AppLozic.
the class MessageServiceTest method testDeleteSync_withChannel_returnSuccess.
@Test
public void testDeleteSync_withChannel_returnSuccess() {
try {
Channel channel = new Channel();
channel.setKey(000);
when(messageClientService.syncDeleteConversationThreadFromServer(null, channel)).thenReturn("success");
assertEquals("success", mobiComConversationService.deleteSync(null, channel, null));
Mockito.verify(messageDatabaseService, Mockito.times(1)).deleteChannelConversation(anyInt());
} catch (Exception e) {
e.printStackTrace();
}
}
use of com.applozic.mobicommons.people.channel.Channel in project Applozic-Android-SDK by AppLozic.
the class MobiComConversationService method getAlConversationList.
/**
* @deprecated This method is no longer used and will be deprecated soon.
*/
@Deprecated
public synchronized List<Message> getAlConversationList(int status, int pageSize, Long lastFetchTime, boolean makeServerCall) throws Exception {
List<Message> conversationList = new ArrayList<>();
List<Message> cachedConversationList = messageDatabaseService.getAlConversationList(status, lastFetchTime);
if (!makeServerCall && !cachedConversationList.isEmpty()) {
return cachedConversationList;
}
AlConversationResponse alConversationResponse = null;
try {
ApiResponse<AlConversationResponse> apiResponse = (ApiResponse<AlConversationResponse>) GsonUtils.getObjectFromJson(messageClientService.getAlConversationList(status, pageSize, lastFetchTime), new TypeToken<ApiResponse<AlConversationResponse>>() {
}.getType());
if (apiResponse != null) {
alConversationResponse = apiResponse.getResponse();
}
} catch (Exception e) {
e.printStackTrace();
throw e;
}
if (alConversationResponse == null) {
return null;
}
try {
if (alConversationResponse.getUserDetails() != null) {
processUserDetails(alConversationResponse.getUserDetails());
}
if (alConversationResponse.getGroupFeeds() != null) {
ChannelService.getInstance(context).processChannelFeedList(alConversationResponse.getGroupFeeds(), false);
}
Message[] messages = alConversationResponse.getMessage();
MobiComUserPreference userPreferences = MobiComUserPreference.getInstance(context);
if (messages != null && messages.length > 0 && cachedConversationList.size() > 0 && cachedConversationList.get(0).isLocalMessage()) {
if (cachedConversationList.get(0).equals(messages[0])) {
Utils.printLog(context, TAG, "Both messages are same.");
deleteMessage(cachedConversationList.get(0));
}
}
for (Message message : messages) {
if (!message.isCall() || userPreferences.isDisplayCallRecordEnable()) {
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 (isHideActionMessage && message.isActionMessage()) {
message.setHidden(true);
}
if (messageDatabaseService.isMessagePresent(message.getKeyString(), Message.ReplyMessage.HIDE_MESSAGE.getValue())) {
messageDatabaseService.updateMessageReplyType(message.getKeyString(), Message.ReplyMessage.NON_HIDDEN.getValue());
} else {
messageDatabaseService.createMessage(message);
}
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, false);
}
} else {
getMessagesWithNetworkMetaData(null, null, new Contact(message.getContactIds()), null, null, true, false);
}
}
}
conversationList.add(message);
}
Intent intent = new Intent(MobiComKitConstants.APPLOZIC_UNREAD_COUNT);
LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
List<Message> finalMessageList = messageDatabaseService.getAlConversationList(status, lastFetchTime);
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());
messageDatabaseService.createMessage(replyMessage);
}
}
}
if (!conversationList.isEmpty()) {
Collections.sort(conversationList, new Comparator<Message>() {
@Override
public int compare(Message lhs, Message rhs) {
return lhs.getCreatedAtTime().compareTo(rhs.getCreatedAtTime());
}
});
}
return finalMessageList;
}
use of com.applozic.mobicommons.people.channel.Channel in project Applozic-Android-SDK by AppLozic.
the class ApplozicConversation method deleteConversation.
/**
* Delete a group (<i>channelKey</i>) or 1-to-1 conversation (<i>contact</i>) or both. Use with caution.
*
* <p>Will return true for a successful delete.</p>
*/
@NonNull
private static AlAsyncTask<Void, Boolean> deleteConversation(@NonNull Context context, @Nullable Integer channelKey, @Nullable Contact contact) {
return new AlAsyncTask<Void, Boolean>() {
@Override
protected Boolean doInBackground() {
if ((channelKey == null || channelKey == 0) && contact == null) {
return false;
}
Channel channel = (channelKey != null && channelKey != 0) ? new Channel(channelKey) : null;
String response = new MobiComConversationService(context).deleteSync(contact, channel, null);
return !TextUtils.isEmpty(response) && MobiComKitConstants.SUCCESS.equals(response);
}
};
}
Aggregations