Search in sources :

Example 36 with Contact

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();
    }
}
Also used : MockitoException(org.mockito.exceptions.base.MockitoException) Contact(com.applozic.mobicommons.people.contact.Contact) Test(org.junit.Test)

Example 37 with Contact

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();
    }
}
Also used : UserDetail(com.applozic.mobicomkit.api.account.user.UserDetail) SyncUserDetailsResponse(com.applozic.mobicomkit.sync.SyncUserDetailsResponse) ArrayList(java.util.ArrayList) MockitoException(org.mockito.exceptions.base.MockitoException) Contact(com.applozic.mobicommons.people.contact.Contact) Test(org.junit.Test)

Example 38 with Contact

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;
}
Also used : AppContactService(com.applozic.mobicomkit.contact.AppContactService) ArrayList(java.util.ArrayList) SpannableString(android.text.SpannableString) ChannelUserMapper(com.applozic.mobicommons.people.channel.ChannelUserMapper) ChannelDatabaseService(com.applozic.mobicomkit.channel.database.ChannelDatabaseService) Contact(com.applozic.mobicommons.people.contact.Contact) NonNull(androidx.annotation.NonNull)

Example 39 with Contact

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();
    }
}
Also used : AppContactService(com.applozic.mobicomkit.contact.AppContactService) Channel(com.applozic.mobicommons.people.channel.Channel) ApplozicException(com.applozic.mobicomkit.exception.ApplozicException) Contact(com.applozic.mobicommons.people.contact.Contact) MessageDatabaseService(com.applozic.mobicomkit.api.conversation.database.MessageDatabaseService)

Example 40 with Contact

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.");
    }
}
Also used : MessageResponse(com.applozic.mobicomkit.feed.MessageResponse) MobiComUserPreference(com.applozic.mobicomkit.api.account.user.MobiComUserPreference) ApplozicException(com.applozic.mobicomkit.exception.ApplozicException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Contact(com.applozic.mobicommons.people.contact.Contact)

Aggregations

Contact (com.applozic.mobicommons.people.contact.Contact)107 Channel (com.applozic.mobicommons.people.channel.Channel)26 Message (com.applozic.mobicomkit.api.conversation.Message)18 Intent (android.content.Intent)17 AppContactService (com.applozic.mobicomkit.contact.AppContactService)17 ArrayList (java.util.ArrayList)15 ApplozicException (com.applozic.mobicomkit.exception.ApplozicException)14 UserDetail (com.applozic.mobicomkit.api.account.user.UserDetail)12 Test (org.junit.Test)12 Bitmap (android.graphics.Bitmap)11 MobiComUserPreference (com.applozic.mobicomkit.api.account.user.MobiComUserPreference)10 Context (android.content.Context)9 SpannableString (android.text.SpannableString)8 NonNull (androidx.annotation.NonNull)8 FileMeta (com.applozic.mobicomkit.api.attachment.FileMeta)8 ApiResponse (com.applozic.mobicomkit.feed.ApiResponse)8 SyncBlockUserApiResponse (com.applozic.mobicomkit.feed.SyncBlockUserApiResponse)8 FileClientService (com.applozic.mobicomkit.api.attachment.FileClientService)7 ContactDatabase (com.applozic.mobicomkit.contact.database.ContactDatabase)7 RegisteredUsersApiResponse (com.applozic.mobicomkit.feed.RegisteredUsersApiResponse)7