Search in sources :

Example 11 with Contact

use of com.applozic.mobicommons.people.contact.Contact in project Applozic-Android-SDK by AppLozic.

the class UserService method updateDisplayNameORImageLink.

// internal methods >>>
/**
 * Internal. Do not use.
 */
// Cleanup: private
public String updateDisplayNameORImageLink(String displayName, String profileImageLink, String localURL, String status, String contactNumber, String emailId, Map<String, String> metadata, String userId) {
    ApiResponse response = userClientService.updateDisplayNameORImageLink(displayName, profileImageLink, status, contactNumber, emailId, metadata, userId);
    if (response == null) {
        return null;
    }
    if (response.isSuccess()) {
        Contact contact = baseContactService.getContactById(!TextUtils.isEmpty(userId) ? userId : MobiComUserPreference.getInstance(context).getUserId());
        if (!TextUtils.isEmpty(displayName)) {
            contact.setFullName(displayName);
        }
        if (!TextUtils.isEmpty(profileImageLink)) {
            contact.setImageURL(profileImageLink);
        }
        contact.setLocalImageUrl(localURL);
        if (!TextUtils.isEmpty(status)) {
            contact.setStatus(status);
        }
        if (!TextUtils.isEmpty(contactNumber)) {
            contact.setContactNumber(contactNumber);
        }
        if (!TextUtils.isEmpty(emailId)) {
            contact.setEmailId(emailId);
        }
        if (metadata != null && !metadata.isEmpty()) {
            Map<String, String> existingMetadata = contact.getMetadata();
            if (existingMetadata == null) {
                existingMetadata = new HashMap<>();
            }
            existingMetadata.putAll(metadata);
            contact.setMetadata(existingMetadata);
        }
        baseContactService.upsert(contact);
        Contact contact1 = baseContactService.getContactById(!TextUtils.isEmpty(userId) ? userId : MobiComUserPreference.getInstance(context).getUserId());
        Utils.printLog(context, TAG, contact1.getImageURL() + ", " + contact1.getDisplayName() + "," + contact1.getStatus() + "," + contact1.getStatus() + "," + contact1.getMetadata() + "," + contact1.getEmailId() + "," + contact1.getContactNumber());
    }
    return response.getStatus();
}
Also used : RegisteredUsersApiResponse(com.applozic.mobicomkit.feed.RegisteredUsersApiResponse) ApiResponse(com.applozic.mobicomkit.feed.ApiResponse) SyncBlockUserApiResponse(com.applozic.mobicomkit.feed.SyncBlockUserApiResponse) Contact(com.applozic.mobicommons.people.contact.Contact)

Example 12 with Contact

use of com.applozic.mobicommons.people.contact.Contact in project Applozic-Android-SDK by AppLozic.

the class UserService method getUserListBySearch.

/**
 * Will return and sync a list of contacts matching the search term, from the server.
 *
 * <p>Note: The local contacts are also updated locally.</p>
 *
 * <p>Note: This method has database and network operation. Run it asynchronously.</p>
 *
 * @param searchString the search term
 * @return a list of users (as Contact objects)
 * @throws ApplozicException when the backend returns an error response
 */
@Nullable
public List<Contact> getUserListBySearch(@Nullable String searchString) throws ApplozicException {
    try {
        ApiResponse response = userClientService.getUsersBySearchString(searchString);
        if (response == null) {
            return null;
        }
        if (response.isSuccess()) {
            UserDetail[] userDetails = (UserDetail[]) GsonUtils.getObjectFromJson(GsonUtils.getJsonFromObject(response.getResponse(), List.class), UserDetail[].class);
            List<Contact> contactList = new ArrayList<>();
            for (UserDetail userDetail : userDetails) {
                contactList.add(getContactFromUserDetail(userDetail));
            }
            return contactList;
        } else {
            if (response.getErrorResponse() != null && !response.getErrorResponse().isEmpty()) {
                throw new ApplozicException(GsonUtils.getJsonFromObject(response.getErrorResponse(), List.class));
            }
        }
    } catch (Exception e) {
        throw new ApplozicException(e.getMessage());
    }
    return null;
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) RegisteredUsersApiResponse(com.applozic.mobicomkit.feed.RegisteredUsersApiResponse) ApiResponse(com.applozic.mobicomkit.feed.ApiResponse) SyncBlockUserApiResponse(com.applozic.mobicomkit.feed.SyncBlockUserApiResponse) ApplozicException(com.applozic.mobicomkit.exception.ApplozicException) Contact(com.applozic.mobicommons.people.contact.Contact) ApplozicException(com.applozic.mobicomkit.exception.ApplozicException) Nullable(androidx.annotation.Nullable)

Example 13 with Contact

use of com.applozic.mobicommons.people.contact.Contact in project Applozic-Android-SDK by AppLozic.

the class UserServiceTest method processUserDetails.

@Test
public void processUserDetails() {
    Set<String> userIdSet = new HashSet<>();
    userIdSet.add(userId1);
    userIdSet.add(userId2);
    Mockito.when(userClientService.getUserDetails(userIdSet)).thenReturn(userDetailsApiResponse);
    userService.processUserDetails(userIdSet);
    UserDetail[] expectedUserDetails = (UserDetail[]) GsonUtils.getObjectFromJson(userDetailsApiResponse, UserDetail[].class);
    Mockito.verify(appContactService, Mockito.times(2)).upsert(ArgumentMatchers.any(Contact.class));
    Mockito.doAnswer(invocation -> {
        Contact contact = invocation.getArgument(0);
        Truth.assertThat(contact.getUserId()).isAnyOf(expectedUserDetails[0].getUserId(), expectedUserDetails[1].getUserId());
        return null;
    }).when(appContactService).upsert(ArgumentMatchers.any(Contact.class));
}
Also used : UserDetail(com.applozic.mobicomkit.api.account.user.UserDetail) HashSet(java.util.HashSet) Contact(com.applozic.mobicommons.people.contact.Contact) Test(org.junit.Test)

Example 14 with Contact

use of com.applozic.mobicommons.people.contact.Contact in project Applozic-Android-SDK by AppLozic.

the class UserServiceTest method updateUserWithResponse.

@Test
public void updateUserWithResponse() {
    ApiResponse expectedApiResponse = new ApiResponse();
    expectedApiResponse.setStatus("success");
    Mockito.when(userClientService.updateDisplayNameORImageLink("displayName", "profileImageLink", "status", "contactNumber", "emailId", null, "userId")).thenReturn(expectedApiResponse);
    Mockito.when(appContactService.getContactById(ArgumentMatchers.anyString())).thenReturn(new Contact());
    ApiResponse apiResponse = userService.updateUserWithResponse("displayName", "profileImageLink", "localURL", "status", "contactNumber", "emailId", null, "userId");
    Truth.assertThat(apiResponse).isEqualTo(expectedApiResponse);
    Mockito.verify(appContactService, Mockito.times(1)).upsert(ArgumentMatchers.any(Contact.class));
}
Also used : MockedConstants.userDetailsApiResponse(com.applozic.mobicomkit.MockedConstants.userDetailsApiResponse) RegisteredUsersApiResponse(com.applozic.mobicomkit.feed.RegisteredUsersApiResponse) ApiResponse(com.applozic.mobicomkit.feed.ApiResponse) SyncBlockUserApiResponse(com.applozic.mobicomkit.feed.SyncBlockUserApiResponse) Contact(com.applozic.mobicommons.people.contact.Contact) Test(org.junit.Test)

Example 15 with Contact

use of com.applozic.mobicommons.people.contact.Contact in project Applozic-Android-SDK by AppLozic.

the class UserServiceTest method getContactFromUserDetails.

@Test
public void getContactFromUserDetails() {
    UserDetail[] expectedUserDetails = (UserDetail[]) GsonUtils.getObjectFromJson(userDetailsApiResponse, UserDetail[].class);
    Contact actualContact = userService.getContactFromUserDetail(expectedUserDetails[0]);
    Mockito.verify(appContactService, Mockito.times(1)).upsert(ArgumentMatchers.any(Contact.class));
    Truth.assertThat(actualContact.getUserId()).isEqualTo(expectedUserDetails[0].getUserId());
    Truth.assertThat(actualContact.getDisplayName()).isEqualTo(expectedUserDetails[0].getDisplayName());
    Truth.assertThat(actualContact.isConnected()).isEqualTo(expectedUserDetails[0].isConnected());
    Truth.assertThat(actualContact.getLastSeenAt()).isEqualTo(expectedUserDetails[0].getLastSeenAtTime());
    Truth.assertThat(actualContact.getImageURL()).isEqualTo(expectedUserDetails[0].getImageLink());
    // needs to be fixed
    Truth.assertThat(actualContact.getUnreadCount()).isAnyOf(expectedUserDetails[0].getUnreadCount(), 0);
}
Also used : UserDetail(com.applozic.mobicomkit.api.account.user.UserDetail) Contact(com.applozic.mobicommons.people.contact.Contact) Test(org.junit.Test)

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