use of com.applozic.mobicommons.people.contact.Contact in project Applozic-Android-SDK by AppLozic.
the class MessageServiceTest method testDeleteSync_withContact_returnSuccess.
@Test
public void testDeleteSync_withContact_returnSuccess() {
try {
Contact contact = new Contact();
contact.setUserId("testUserId");
when(messageClientService.syncDeleteConversationThreadFromServer(contact, null)).thenReturn("success");
assertEquals("success", mobiComConversationService.deleteSync(contact, null, null));
// Check if method is called...
Mockito.verify(messageDatabaseService, Mockito.times(1)).deleteConversation(anyString());
} catch (Exception e) {
e.printStackTrace();
}
}
use of com.applozic.mobicommons.people.contact.Contact in project Applozic-Android-SDK by AppLozic.
the class MessageServiceTest method processUserDetails.
@Test
public void processUserDetails() {
try {
List<UserDetail> userDetails = new ArrayList<UserDetail>();
userDetails.add(new UserDetail());
SyncUserDetailsResponse response = new SyncUserDetailsResponse();
response.setGeneratedAt("GEneratedAtString");
response.setStatus("success");
response.setResponse(userDetails);
when(messageClientService.getUserDetailsList(anyString())).thenReturn(response);
when(appContactService.getContactById("")).thenReturn(new Contact());
// Mockito.doNothing().when(appContactService).upsert(any(Contact.class));
mobiComConversationService.processLastSeenAtStatus();
assertEquals(response.getGeneratedAt(), MobiComUserPreference.getInstance(context).getLastSeenAtSyncTime());
} catch (Exception e) {
e.printStackTrace();
}
}
use of com.applozic.mobicommons.people.contact.Contact in project Applozic-Android-SDK by AppLozic.
the class MentionHelper method getMentionsListForChannel.
@NonNull
public static List<Mention> getMentionsListForChannel(Context context, Integer channelKey) {
ChannelDatabaseService channelDatabaseService = ChannelDatabaseService.getInstance(context);
List<ChannelUserMapper> channelUserMapperList = channelDatabaseService.getChannelUserList(channelKey);
if (channelUserMapperList == null) {
return new ArrayList<>();
}
List<Mention> mentionUsersList = new ArrayList<>();
AppContactService appContactService = new AppContactService(context);
String currentUserId = MobiComUserPreference.getInstance(context).getUserId();
for (ChannelUserMapper channelUserMapper : channelUserMapperList) {
Contact contact = appContactService.getContactById(channelUserMapper.getUserKey());
if (channelUserMapper.getUserKey().equals(currentUserId)) {
continue;
}
if (contact != null && !TextUtils.isEmpty(contact.getUserId())) {
mentionUsersList.add(new Mention(contact.getUserId(), contact.getDisplayName(), !TextUtils.isEmpty(contact.getLocalImageUrl()) ? contact.getLocalImageUrl() : contact.getImageURL()));
} else {
mentionUsersList.add(new Mention(channelUserMapper.getUserKey()));
}
}
return mentionUsersList;
}
use of com.applozic.mobicommons.people.contact.Contact in project Applozic-Android-SDK by AppLozic.
the class ApplozicConversation method markAsRead.
/**
* Mark a conversation as read. Either one of the <i>userId</i> or the <i>groupId</i> can be null.
*
* @param pairedMessageKey not used. pass null
* @param userId for one-to-one conversation
* @param groupId for group conversation
*/
public static void markAsRead(@NonNull Context context, @Nullable String pairedMessageKey, @Nullable String userId, @Nullable Integer groupId) {
try {
int unreadCount = 0;
Contact contact = null;
Channel channel = null;
if (userId != null) {
contact = new AppContactService(context).getContactById(userId);
unreadCount = contact.getUnreadCount();
new MessageDatabaseService(context).updateReadStatusForContact(userId);
} else if (groupId != null && groupId != 0) {
channel = ChannelService.getInstance(context).getChannelByChannelKey(groupId);
unreadCount = channel.getUnreadCount();
new MessageDatabaseService(context).updateReadStatusForChannel(String.valueOf(groupId));
}
UserWorker.enqueueWork(context, null, contact, channel, pairedMessageKey, unreadCount, false);
} catch (Exception exception) {
exception.printStackTrace();
}
}
use of com.applozic.mobicommons.people.contact.Contact in project Applozic-Android-SDK by AppLozic.
the class MessageClientService method sendPendingMessageToServer.
// Cleanup: private
public void sendPendingMessageToServer(Message message, boolean broadcast) {
try {
if (message.isContactMessage()) {
try {
this.processMessage(message, null, null);
} catch (Exception e) {
Utils.printLog(context, TAG, "Exception while sending contact message.");
}
return;
}
if (message.hasAttachment()) {
return;
}
MobiComUserPreference mobiComUserPreference = MobiComUserPreference.getInstance(context);
message.setDeviceKeyString(mobiComUserPreference.getDeviceKeyString());
message.setSuUserKeyString(mobiComUserPreference.getSuUserKeyString());
String response = sendMessage(message);
if (TextUtils.isEmpty(response) || response.contains("<html>") || response.equals("error")) {
Utils.printLog(context, TAG, "Error while sending pending messages.");
return;
}
MessageResponse messageResponse = (MessageResponse) GsonUtils.getObjectFromJson(response, MessageResponse.class);
String keyString = messageResponse.getMessageKey();
String createdAt = messageResponse.getCreatedAtTime();
message.setSentMessageTimeAtServer(Long.parseLong(createdAt));
message.setKeyString(keyString);
message.setSentToServer(true);
if (broadcast) {
BroadcastService.sendMessageUpdateBroadcast(context, BroadcastService.INTENT_ACTIONS.MESSAGE_SYNC_ACK_FROM_SERVER.toString(), message);
}
messageDatabaseService.updateMessageSyncStatus(message, keyString);
if (message.getGroupId() == null && TextUtils.isEmpty(message.getContactIds())) {
Contact contact = contactDatabase.getContactById(message.getContactIds());
if (contact != null && contact.isUserDisplayUpdateRequired()) {
UserService.getInstance(context).updateUserDisplayName(contact.getUserId(), contact.getDisplayName());
}
}
} catch (Exception e) {
Utils.printLog(context, TAG, "Error while sending pending messages.");
}
}
Aggregations