Search in sources :

Example 81 with Contact

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;
}
Also used : Contact(com.applozic.mobicommons.people.contact.Contact) NonNull(androidx.annotation.NonNull)

Example 82 with 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;
}
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 83 with Contact

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);
}
Also used : Contact(com.applozic.mobicommons.people.contact.Contact)

Example 84 with 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();
    }
}
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 85 with Contact

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));
    }
}
Also used : UserLoginTask(com.applozic.mobicomkit.api.account.user.UserLoginTask) RegistrationResponse(com.applozic.mobicomkit.api.account.register.RegistrationResponse) ContactDatabase(com.applozic.mobicomkit.contact.database.ContactDatabase) 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