use of com.applozic.mobicommons.people.contact.Contact in project Applozic-Android-SDK by AppLozic.
the class UserService method getContactFromUserDetail.
// Cleanup: private
/**
* Internal. Use {@link #getContactFromUserDetail(UserDetail)}.
*/
@NonNull
public synchronized Contact getContactFromUserDetail(@NonNull UserDetail userDetail, @NonNull Contact.ContactType contactType) {
Contact contact = new Contact();
contact.setUserId(userDetail.getUserId());
contact.setContactNumber(userDetail.getPhoneNumber());
contact.setConnected(userDetail.isConnected());
contact.setStatus(userDetail.getStatusMessage());
if (!TextUtils.isEmpty(userDetail.getDisplayName())) {
contact.setFullName(userDetail.getDisplayName());
}
contact.setLastSeenAt(userDetail.getLastSeenAtTime());
contact.setUserTypeId(userDetail.getUserTypeId());
contact.setUnreadCount(0);
contact.setLastMessageAtTime(userDetail.getLastMessageAtTime());
contact.setMetadata(userDetail.getMetadata());
contact.setRoleType(userDetail.getRoleType());
contact.setDeletedAtTime(userDetail.getDeletedAtTime());
contact.setEmailId(userDetail.getEmailId());
if (!TextUtils.isEmpty(userDetail.getImageLink())) {
contact.setImageURL(userDetail.getImageLink());
}
contact.setContactType(contactType.getValue());
baseContactService.upsert(contact);
return contact;
}
use of com.applozic.mobicommons.people.contact.Contact in project Applozic-Android-SDK by AppLozic.
the class UserService method updateUserWithResponse.
// Cleanup: private
/**
* Internal. Do not use.
*/
public ApiResponse updateUserWithResponse(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);
}
return response;
}
use of com.applozic.mobicommons.people.contact.Contact in project Applozic-Android-SDK by AppLozic.
the class UserService method processMuteUserResponse.
/**
* Internal. Do not use.
*/
// Cleanup: private
public synchronized void processMuteUserResponse(MuteUserResponse response) {
Contact contact = new Contact();
contact.setUserId(response.getUserId());
BroadcastService.sendMuteUserBroadcast(context, BroadcastService.INTENT_ACTIONS.MUTE_USER_CHAT.toString(), true, response.getUserId());
if (!TextUtils.isEmpty(response.getImageLink())) {
contact.setImageURL(response.getImageLink());
}
contact.setUnreadCount(response.getUnreadCount());
if (response.getNotificationAfterTime() != null && response.getNotificationAfterTime() != 0) {
contact.setNotificationAfterTime(response.getNotificationAfterTime());
}
contact.setConnected(response.isConnected());
baseContactService.upsert(contact);
}
use of com.applozic.mobicommons.people.contact.Contact in project Applozic-Android-SDK by AppLozic.
the class ConversationServiceTest 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);
Mockito.when(messageClientService.getUserDetailsList(ArgumentMatchers.anyString())).thenReturn(response);
Mockito.when(appContactService.getContactById("")).thenReturn(new Contact());
Mockito.doNothing().when(appContactService).upsert(ArgumentMatchers.any(Contact.class));
mobiComConversationService.processLastSeenAtStatus();
Assert.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 Applozic method connectUser.
// old api >>>
/**
* Use this method to log-in or register your {@link User}. This must be done before using any other SDK method.
*
* <p>Before calling this method, make sure that {@link User#isValidUserId()} returns <i>true</i>.</p>
*
* <p>If the user (<code>userId</code>) is not present in the servers, a new
* one will be created and registered. Otherwise the existing user will be authenticated and logged in.</p>
*
* <p><i><b>Note:</b>Check if <code>registrationResponse</code> is non-null and {@link RegistrationResponse#isRegistrationSuccess()} is true to confirm a successful login.</i></p>
*
* <p>After a successful login, you'll be able to access:
* <ul>
* <li>{@link MobiComUserPreference#getUserId() your user-id}.</li>
* <li>{@link com.applozic.mobicomkit.contact.AppContactService#getContactById(String) your contact object}.</li>
* <li>Your messages, contacts, channels and other freshly synced data to your local database for your user.</li>
* </ul></p>
*
* <p>Other users will be able to see your status as "online".</p>
*
* <p>Next steps:</p>
* <ol>
* <li>To set up push notifications - {@link #registerForPushNotification(Context, String)}. This is required for receiving messages.</li>
* <li>To send your first message - {@link com.applozic.mobicomkit.api.conversation.MessageBuilder}</li>
* </ol>
*/
public static void connectUser(@NonNull Context context, @NonNull User user, @Nullable AlLoginHandler loginHandler) {
if (isConnected(context)) {
RegistrationResponse registrationResponse = new RegistrationResponse();
registrationResponse.setMessage("User already Logged in");
Contact contact = new ContactDatabase(context).getContactById(MobiComUserPreference.getInstance(context).getUserId());
if (contact != null) {
registrationResponse.setUserId(contact.getUserId());
registrationResponse.setContactNumber(contact.getContactNumber());
registrationResponse.setRoleType(contact.getRoleType());
registrationResponse.setImageLink(contact.getImageURL());
registrationResponse.setDisplayName(contact.getDisplayName());
registrationResponse.setStatusMessage(contact.getStatus());
}
if (loginHandler != null) {
loginHandler.onSuccess(registrationResponse, context);
}
} else {
AlTask.execute(new UserLoginTask(user, loginHandler, context));
}
}
Aggregations