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();
}
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;
}
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));
}
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));
}
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);
}
Aggregations