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