Search in sources :

Example 1 with ApplozicMqttService

use of com.applozic.mobicomkit.api.ApplozicMqttService in project Applozic-Android-SDK by AppLozic.

the class ApplozicMqttWorker method doWork.

@NonNull
@Override
public Result doWork() {
    Data data = getInputData();
    boolean useEncryptedTopic = data.getBoolean(USE_ENCRYPTED_TOPIC, false);
    boolean subscribe = data.getBoolean(SUBSCRIBE, false);
    Contact contact = null;
    Channel channel = null;
    try {
        contact = (Contact) GsonUtils.getObjectFromJson(data.getString(CONTACT), Contact.class);
        channel = (Channel) GsonUtils.getObjectFromJson(data.getString(CHANNEL), Channel.class);
    } catch (Exception exception) {
        exception.printStackTrace();
    }
    boolean subscribeToTyping = data.getBoolean(SUBSCRIBE_TO_TYPING, false);
    boolean unSubscribeToTyping = data.getBoolean(UN_SUBSCRIBE_TO_TYPING, false);
    boolean subscribeToSupportGroupTopic = data.getBoolean(CONNECT_TO_SUPPORT_GROUP_TOPIC, false);
    boolean unSubscribeToSupportGroupTopic = data.getBoolean(DISCONNECT_FROM_SUPPORT_GROUP_TOPIC, false);
    String userKeyString = data.getString(USER_KEY_STRING);
    String deviceKeyString = data.getString(DEVICE_KEY_STRING);
    boolean connectedStatus = data.getBoolean(CONNECTED_PUBLISH, false);
    boolean stop = data.getBoolean(STOP_TYPING, false);
    boolean typing = data.getBoolean(TYPING, false);
    if (subscribe) {
        if (isAppInBackground()) {
            Log.d(TAG, "App is in background, MQTT method call not required...");
            return Result.success();
        }
        ApplozicMqttService applozicMqttService = ApplozicMqttService.getInstance(getApplicationContext());
        applozicMqttService.connectClient(true);
        applozicMqttService.subscribe(useEncryptedTopic);
        applozicMqttService.publishClientStatus(MobiComUserPreference.getInstance(getApplicationContext()).getSuUserKeyString(), MobiComUserPreference.getInstance(getApplicationContext()).getDeviceKeyString(), "1");
    }
    if (subscribeToTyping) {
        ApplozicMqttService.getInstance(getApplicationContext()).subscribeToTypingTopic(channel);
        if (channel != null && Channel.GroupType.OPEN.getValue().equals(channel.getType())) {
            ApplozicMqttService.getInstance(getApplicationContext()).subscribeToOpenGroupTopic(channel);
        }
        return Result.success();
    }
    if (unSubscribeToTyping) {
        ApplozicMqttService.getInstance(getApplicationContext()).unSubscribeToTypingTopic(channel);
        if (channel != null && Channel.GroupType.OPEN.getValue().equals(channel.getType())) {
            ApplozicMqttService.getInstance(getApplicationContext()).unSubscribeToOpenGroupTopic(channel);
        }
        return Result.success();
    }
    if (subscribeToSupportGroupTopic) {
        ApplozicMqttService.getInstance(getApplicationContext()).subscribeToSupportGroup(useEncryptedTopic);
        return Result.success();
    }
    if (unSubscribeToSupportGroupTopic) {
        ApplozicMqttService.getInstance(getApplicationContext()).unSubscribeToSupportGroup(useEncryptedTopic);
        return Result.success();
    }
    if (!TextUtils.isEmpty(userKeyString) && !TextUtils.isEmpty(deviceKeyString)) {
        ApplozicMqttService.getInstance(getApplicationContext()).publishOfflineStatusUnsubscribeAndDisconnect(userKeyString, deviceKeyString, useEncryptedTopic);
    }
    if (connectedStatus) {
        ApplozicMqttService applozicMqttService = ApplozicMqttService.getInstance(getApplicationContext());
        applozicMqttService.connectClient(true);
        applozicMqttService.publishClientStatus(MobiComUserPreference.getInstance(getApplicationContext()).getSuUserKeyString(), MobiComUserPreference.getInstance(getApplicationContext()).getDeviceKeyString(), "1");
    }
    if (contact != null && stop) {
        ApplozicMqttService.getInstance(getApplicationContext()).typingStopped(contact, null);
    }
    if (contact != null && (contact.isBlocked() || contact.isBlockedBy())) {
        return Result.success();
    }
    if (contact != null || channel != null) {
        if (typing) {
            ApplozicMqttService.getInstance(getApplicationContext()).typingStarted(contact, channel);
        } else {
            ApplozicMqttService.getInstance(getApplicationContext()).typingStopped(contact, channel);
        }
    }
    return Result.success();
}
Also used : ApplozicMqttService(com.applozic.mobicomkit.api.ApplozicMqttService) Channel(com.applozic.mobicommons.people.channel.Channel) Data(androidx.work.Data) Contact(com.applozic.mobicommons.people.contact.Contact) NonNull(androidx.annotation.NonNull)

Example 2 with ApplozicMqttService

use of com.applozic.mobicomkit.api.ApplozicMqttService in project Applozic-Android-SDK by AppLozic.

the class ApplozicConversation method isMessageStatusPublished.

// internal methods >>>
/**
 * Internal method. Do not use.
 */
public static boolean isMessageStatusPublished(Context context, String pairedMessageKey, Short status) {
    ApplozicMqttService applozicMqttService = ApplozicMqttService.getInstance(context);
    if (!TextUtils.isEmpty(pairedMessageKey) && applozicMqttService.isConnected()) {
        final String MESSAGE_STATUS_TOPIC = "message-status";
        applozicMqttService.connectAndPublishMessageStatus(MESSAGE_STATUS_TOPIC, MobiComUserPreference.getInstance(context).getUserId() + "," + pairedMessageKey + "," + status);
        return true;
    }
    return false;
}
Also used : ApplozicMqttService(com.applozic.mobicomkit.api.ApplozicMqttService)

Aggregations

ApplozicMqttService (com.applozic.mobicomkit.api.ApplozicMqttService)2 NonNull (androidx.annotation.NonNull)1 Data (androidx.work.Data)1 Channel (com.applozic.mobicommons.people.channel.Channel)1 Contact (com.applozic.mobicommons.people.contact.Contact)1