Search in sources :

Example 36 with ApiResponse

use of com.applozic.mobicomkit.feed.ApiResponse in project Applozic-Android-SDK by AppLozic.

the class UserClientService method muteUserNotifications.

/**
 * Sends a mute notification request for the given userId.
 *
 * <p>The current user will be taken from the user shared preferences.</p>
 *
 * <p>Note: This is a network method. Run it asynchronously.</p>
 *
 * @param userId the user id of the user to mute
 * @param notificationAfterTime the time (in milliseconds) to mute the user for
 * @return the api response, use {@link ApiResponse#isSuccess()} to check for success
 */
@Nullable
public ApiResponse muteUserNotifications(@Nullable String userId, @Nullable Long notificationAfterTime) {
    if (userId == null || notificationAfterTime == null) {
        return null;
    }
    JSONObject jsonFromObject = new JSONObject();
    try {
        String url = getMuteUserUrl() + "?userId=" + userId + "&notificationAfterTime=" + notificationAfterTime;
        String response = httpRequestUtils.postData(url, "application/json", "application/json", jsonFromObject.toString());
        Utils.printLog(context, TAG, "Mute user chat response : " + response);
        if (!TextUtils.isEmpty(response)) {
            return (ApiResponse) GsonUtils.getObjectFromJson(response, ApiResponse.class);
        }
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
    return null;
}
Also used : JSONObject(org.json.JSONObject) ApiResponse(com.applozic.mobicomkit.feed.ApiResponse) SyncBlockUserApiResponse(com.applozic.mobicomkit.feed.SyncBlockUserApiResponse) JSONException(org.json.JSONException) ApplozicException(com.applozic.mobicomkit.exception.ApplozicException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Nullable(androidx.annotation.Nullable)

Example 37 with ApiResponse

use of com.applozic.mobicomkit.feed.ApiResponse in project Applozic-Android-SDK by AppLozic.

the class UserClientService method userUnBlock.

// Cleanup: private
/**
 * @deprecated This method has been replaced with {@link #userBlock(String, boolean)}. Pass "false" in the second parameter.
 */
@Deprecated
public ApiResponse userUnBlock(String userId) {
    String response = "";
    ApiResponse apiResponse = null;
    try {
        if (!TextUtils.isEmpty(userId)) {
            response = httpRequestUtils.getResponse(getUnBlockUserSyncUrl() + "?userId=" + URLEncoder.encode(userId, "UTF-8"), "application/json", "application/json");
            apiResponse = (ApiResponse) GsonUtils.getObjectFromJson(response, ApiResponse.class);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return apiResponse;
}
Also used : ApiResponse(com.applozic.mobicomkit.feed.ApiResponse) SyncBlockUserApiResponse(com.applozic.mobicomkit.feed.SyncBlockUserApiResponse) JSONException(org.json.JSONException) ApplozicException(com.applozic.mobicomkit.exception.ApplozicException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 38 with ApiResponse

use of com.applozic.mobicomkit.feed.ApiResponse in project Applozic-Android-SDK by AppLozic.

the class UserClientService method logout.

// Cleanup: private
// Cleanup: fromLogin is always false
/**
 * Internal. This methods has a un-necessary parameter.
 *
 * @param fromLogin pass false
 * @return logout backend api response, use {@link ApiResponse#isSuccess()} to check for success
 */
public ApiResponse logout(boolean fromLogin) {
    Utils.printLog(context, TAG, "Al Logout call !!");
    ApiResponse apiResponse = userLogoutResponse();
    MobiComUserPreference mobiComUserPreference = MobiComUserPreference.getInstance(context);
    final String deviceKeyString = mobiComUserPreference.getDeviceKeyString();
    final String userKeyString = mobiComUserPreference.getSuUserKeyString();
    String url = mobiComUserPreference.getUrl();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        Applozic.Store.setCustomNotificationSound(context, null);
        new NotificationChannels(context).deleteAllChannels();
    }
    NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.cancelAll();
    mobiComUserPreference.clearAll();
    ALSpecificSettings.getInstance(context).clearAll();
    MessageDatabaseService.recentlyAddedMessage.clear();
    MobiComDatabaseHelper.getInstance(context).delDatabase();
    mobiComUserPreference.setUrl(url);
    if (!fromLogin) {
        ApplozicMqttWorker.enqueueWorkDisconnectPublish(context, deviceKeyString, userKeyString, false);
    }
    return apiResponse;
}
Also used : NotificationChannels(com.applozic.mobicomkit.api.notification.NotificationChannels) NotificationManager(android.app.NotificationManager) ApiResponse(com.applozic.mobicomkit.feed.ApiResponse) SyncBlockUserApiResponse(com.applozic.mobicomkit.feed.SyncBlockUserApiResponse)

Example 39 with ApiResponse

use of com.applozic.mobicomkit.feed.ApiResponse 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 40 with ApiResponse

use of com.applozic.mobicomkit.feed.ApiResponse in project Applozic-Android-SDK by AppLozic.

the class UserService method updateUserDisplayName.

/**
 * Internal. Do not use.
 *
 * Updates the display name for the given userId (remote and local).
 *
 * <p>Note: This method has database and network operation. Run it asynchronously.</p>
 *
 * @param userId the user id of the user
 * @param userDisplayName the new display name
 * @return api response from the server
 */
public ApiResponse updateUserDisplayName(String userId, String userDisplayName) {
    ApiResponse response = userClientService.updateUserDisplayName(userId, userDisplayName);
    if (response != null && response.isSuccess()) {
        baseContactService.updateMetadataKeyValueForUserId(userId, Contact.AL_DISPLAY_NAME_UPDATED, "true");
        Utils.printLog(context, TAG, " Update display name Response :" + response.getStatus());
    }
    return response;
}
Also used : RegisteredUsersApiResponse(com.applozic.mobicomkit.feed.RegisteredUsersApiResponse) ApiResponse(com.applozic.mobicomkit.feed.ApiResponse) SyncBlockUserApiResponse(com.applozic.mobicomkit.feed.SyncBlockUserApiResponse)

Aggregations

ApiResponse (com.applozic.mobicomkit.feed.ApiResponse)54 SyncBlockUserApiResponse (com.applozic.mobicomkit.feed.SyncBlockUserApiResponse)23 ChannelFeedApiResponse (com.applozic.mobicomkit.feed.ChannelFeedApiResponse)22 JSONException (org.json.JSONException)19 ApplozicException (com.applozic.mobicomkit.exception.ApplozicException)16 RegisteredUsersApiResponse (com.applozic.mobicomkit.feed.RegisteredUsersApiResponse)16 Test (org.junit.Test)14 MultipleChannelFeedApiResponse (com.applozic.mobicomkit.MultipleChannelFeedApiResponse)12 MockedConstants.userDetailsApiResponse (com.applozic.mobicomkit.MockedConstants.userDetailsApiResponse)10 UnsupportedEncodingException (java.io.UnsupportedEncodingException)9 Nullable (androidx.annotation.Nullable)8 Contact (com.applozic.mobicommons.people.contact.Contact)8 ChannelUserMapper (com.applozic.mobicommons.people.channel.ChannelUserMapper)3 ArrayList (java.util.ArrayList)3 PatternSyntaxException (java.util.regex.PatternSyntaxException)3 ProgressDialog (android.app.ProgressDialog)2 Toast (android.widget.Toast)2 UserBlockTask (com.applozic.mobicomkit.api.account.user.UserBlockTask)2 MuteNotificationAsync (com.applozic.mobicomkit.api.notification.MuteNotificationAsync)2 MuteNotificationRequest (com.applozic.mobicomkit.api.notification.MuteNotificationRequest)2