Search in sources :

Example 26 with MobiComUserPreference

use of com.applozic.mobicomkit.api.account.user.MobiComUserPreference in project Applozic-Android-SDK by AppLozic.

the class MessageDatabaseService method getMessages.

public List<Message> getMessages(Long startTime, Long endTime, Contact contact, Channel channel, Integer conversationId) {
    String structuredNameWhere = "";
    List<String> structuredNameParamsList = new ArrayList<String>();
    if (channel != null && channel.getKey() != null) {
        structuredNameWhere += "channelKey = ? AND ";
        structuredNameParamsList.add(String.valueOf(channel.getKey()));
    } else {
        structuredNameWhere += "channelKey = ? AND ";
        structuredNameParamsList.add("0");
    }
    if (contact != null && !TextUtils.isEmpty(contact.getContactIds())) {
        structuredNameWhere += "contactNumbers = ? AND ";
        structuredNameParamsList.add(contact.getContactIds());
    }
    if (startTime != null) {
        structuredNameWhere += "createdAt >= ? AND ";
        structuredNameParamsList.add(String.valueOf(startTime));
    }
    if (endTime != null) {
        structuredNameWhere += "createdAt < ? AND ";
        structuredNameParamsList.add(String.valueOf(endTime));
    }
    if (BroadcastService.isContextBasedChatEnabled() && conversationId != null && conversationId != 0) {
        structuredNameWhere += "conversationId = ? AND ";
        structuredNameParamsList.add(String.valueOf(conversationId));
    }
    structuredNameWhere += "messageContentType not in ( ?,? ) AND ";
    structuredNameParamsList.add(String.valueOf(Message.ContentType.HIDDEN.getValue()));
    structuredNameParamsList.add(String.valueOf(Message.ContentType.VIDEO_CALL_NOTIFICATION_MSG.getValue()));
    structuredNameWhere += "deleted = ? AND ";
    structuredNameParamsList.add("0");
    structuredNameWhere += "hidden = ? AND ";
    structuredNameParamsList.add("0");
    structuredNameWhere += "replyMessage != ? AND ";
    structuredNameParamsList.add(String.valueOf(Message.ReplyMessage.HIDE_MESSAGE.getValue()));
    MobiComUserPreference userPreferences = MobiComUserPreference.getInstance(context);
    if (!userPreferences.isDisplayCallRecordEnable()) {
        structuredNameWhere += "type != ? AND type != ? AND ";
        structuredNameParamsList.add(String.valueOf(Message.MessageType.CALL_INCOMING.getValue()));
        structuredNameParamsList.add(String.valueOf(Message.MessageType.CALL_OUTGOING.getValue()));
    }
    if (!TextUtils.isEmpty(structuredNameWhere)) {
        structuredNameWhere = structuredNameWhere.substring(0, structuredNameWhere.length() - 5);
    }
    SQLiteDatabase db = dbHelper.getWritableDatabase();
    Cursor cursor = db.query("sms", null, structuredNameWhere, structuredNameParamsList.toArray(new String[structuredNameParamsList.size()]), null, null, "createdAt asc");
    List<Message> messageList = MessageDatabaseService.getMessageList(cursor);
    dbHelper.close();
    return messageList;
}
Also used : Message(com.applozic.mobicomkit.api.conversation.Message) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) MobiComUserPreference(com.applozic.mobicomkit.api.account.user.MobiComUserPreference) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor)

Example 27 with MobiComUserPreference

use of com.applozic.mobicomkit.api.account.user.MobiComUserPreference in project Applozic-Android-SDK by AppLozic.

the class RegisterUserClientService method createAccount.

// final RegistrationResponse registrationResponse = createAccount(user);
// Intent intent = new Intent(context, ApplozicMqttIntentService.class);
// intent.putExtra(ApplozicMqttIntentService.CONNECTED_PUBLISH,true);
// ApplozicMqttIntentService.enqueueWork(context, intent);
// return registrationResponse;
public RegistrationResponse createAccount(User user) throws Exception {
    user.setDeviceType(Short.valueOf("1"));
    user.setPrefContactAPI(Short.valueOf("2"));
    user.setTimezone(TimeZone.getDefault().getID());
    user.setEnableEncryption(user.isEnableEncryption());
    MobiComUserPreference mobiComUserPreference = MobiComUserPreference.getInstance(context);
    Gson gson = new Gson();
    user.setAppVersionCode(MOBICOMKIT_VERSION_CODE);
    user.setApplicationId(getApplicationKey(context));
    user.setRegistrationId(mobiComUserPreference.getDeviceRegistrationId());
    if (getAppModuleName(context) != null) {
        user.setAppModuleName(getAppModuleName(context));
    }
    Utils.printLog(context, TAG, "Net status" + Utils.isInternetAvailable(context.getApplicationContext()));
    if (!Utils.isInternetAvailable(context.getApplicationContext())) {
        throw new ConnectException("No Internet Connection");
    }
    // Log.i(TAG, "App Id is: " + getApplicationKey(context));
    Utils.printLog(context, TAG, "Registration json " + gson.toJson(user));
    String response = httpRequestUtils.postJsonToServer(getCreateAccountUrl(), gson.toJson(user));
    Utils.printLog(context, TAG, "Registration response is: " + response);
    if (TextUtils.isEmpty(response) || response.contains("<html")) {
        throw new Exception("503 Service Unavailable");
    // return null;
    }
    if (response.contains(INVALID_APP_ID)) {
        throw new InvalidApplicationException("Invalid Application Id");
    }
    final RegistrationResponse registrationResponse = gson.fromJson(response, RegistrationResponse.class);
    if (registrationResponse.isPasswordInvalid()) {
        throw new UnAuthoriseException("Invalid uername/password");
    }
    Utils.printLog(context, "Registration response ", "is " + registrationResponse);
    if (registrationResponse.getNotificationResponse() != null) {
        Utils.printLog(context, "Registration response ", "" + registrationResponse.getNotificationResponse());
    }
    mobiComUserPreference.setEncryptionKey(registrationResponse.getEncryptionKey());
    mobiComUserPreference.enableEncryption(user.isEnableEncryption());
    mobiComUserPreference.setCountryCode(user.getCountryCode());
    mobiComUserPreference.setUserId(user.getUserId());
    mobiComUserPreference.setContactNumber(user.getContactNumber());
    mobiComUserPreference.setEmailVerified(user.isEmailVerified());
    mobiComUserPreference.setDisplayName(user.getDisplayName());
    mobiComUserPreference.setMqttBrokerUrl(registrationResponse.getBrokerUrl());
    mobiComUserPreference.setDeviceKeyString(registrationResponse.getDeviceKey());
    mobiComUserPreference.setEmailIdValue(user.getEmail());
    mobiComUserPreference.setImageLink(user.getImageLink());
    mobiComUserPreference.setSuUserKeyString(registrationResponse.getUserKey());
    mobiComUserPreference.setLastSyncTimeForMetadataUpdate(String.valueOf(registrationResponse.getCurrentTimeStamp()));
    mobiComUserPreference.setLastSyncTime(String.valueOf(registrationResponse.getCurrentTimeStamp()));
    mobiComUserPreference.setLastSeenAtSyncTime(String.valueOf(registrationResponse.getCurrentTimeStamp()));
    mobiComUserPreference.setChannelSyncTime(String.valueOf(registrationResponse.getCurrentTimeStamp()));
    mobiComUserPreference.setUserBlockSyncTime("10000");
    mobiComUserPreference.setPassword(user.getPassword());
    mobiComUserPreference.setPricingPackage(registrationResponse.getPricingPackage());
    mobiComUserPreference.setAuthenticationType(String.valueOf(user.getAuthenticationTypeId()));
    mobiComUserPreference.setUserRoleType(user.getRoleType());
    if (user.getUserTypeId() != null) {
        mobiComUserPreference.setUserTypeId(String.valueOf(user.getUserTypeId()));
    }
    if (!TextUtils.isEmpty(user.getNotificationSoundFilePath())) {
        mobiComUserPreference.setNotificationSoundFilePath(user.getNotificationSoundFilePath());
    }
    Contact contact = new Contact();
    contact.setUserId(user.getUserId());
    contact.setFullName(registrationResponse.getDisplayName());
    contact.setImageURL(registrationResponse.getImageLink());
    contact.setContactNumber(registrationResponse.getContactNumber());
    if (user.getUserTypeId() != null) {
        contact.setUserTypeId(user.getUserTypeId());
    }
    contact.setRoleType(user.getRoleType());
    contact.setMetadata(user.getMetadata());
    contact.setStatus(registrationResponse.getStatusMessage());
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        createNotificationChannel(context);
    }
    contact.processContactNumbers(context);
    new AppContactService(context).upsert(contact);
    Intent conversationIntentService = new Intent(context, ConversationIntentService.class);
    conversationIntentService.putExtra(ConversationIntentService.SYNC, false);
    ConversationIntentService.enqueueWork(context, conversationIntentService);
    Intent mutedUserListService = new Intent(context, ConversationIntentService.class);
    mutedUserListService.putExtra(ConversationIntentService.MUTED_USER_LIST_SYNC, true);
    ConversationIntentService.enqueueWork(context, mutedUserListService);
    Intent intent = new Intent(context, ApplozicMqttIntentService.class);
    intent.putExtra(ApplozicMqttIntentService.CONNECTED_PUBLISH, true);
    ApplozicMqttIntentService.enqueueWork(context, intent);
    return registrationResponse;
}
Also used : AppContactService(com.applozic.mobicomkit.contact.AppContactService) MobiComUserPreference(com.applozic.mobicomkit.api.account.user.MobiComUserPreference) Gson(com.google.gson.Gson) InvalidApplicationException(com.applozic.mobicomkit.exception.InvalidApplicationException) UnAuthoriseException(com.applozic.mobicomkit.exception.UnAuthoriseException) Intent(android.content.Intent) UnAuthoriseException(com.applozic.mobicomkit.exception.UnAuthoriseException) ConnectException(java.net.ConnectException) InvalidApplicationException(com.applozic.mobicomkit.exception.InvalidApplicationException) ConnectException(java.net.ConnectException) Contact(com.applozic.mobicommons.people.contact.Contact)

Example 28 with MobiComUserPreference

use of com.applozic.mobicomkit.api.account.user.MobiComUserPreference in project Applozic-Android-SDK by AppLozic.

the class RegisterUserClientService method updateRegisteredAccount.

public RegistrationResponse updateRegisteredAccount(User user) throws Exception {
    RegistrationResponse registrationResponse = null;
    user.setDeviceType(Short.valueOf("1"));
    user.setPrefContactAPI(Short.valueOf("2"));
    user.setTimezone(TimeZone.getDefault().getID());
    MobiComUserPreference mobiComUserPreference = MobiComUserPreference.getInstance(context);
    Gson gson = new Gson();
    user.setEnableEncryption(mobiComUserPreference.isEncryptionEnabled());
    user.setAppVersionCode(MOBICOMKIT_VERSION_CODE);
    user.setApplicationId(getApplicationKey(context));
    user.setAuthenticationTypeId(Short.valueOf(mobiComUserPreference.getAuthenticationType()));
    if (!TextUtils.isEmpty(mobiComUserPreference.getUserTypeId())) {
        user.setUserTypeId(Short.valueOf(mobiComUserPreference.getUserTypeId()));
    }
    if (getAppModuleName(context) != null) {
        user.setAppModuleName(getAppModuleName(context));
    }
    if (!TextUtils.isEmpty(mobiComUserPreference.getDeviceRegistrationId())) {
        user.setRegistrationId(mobiComUserPreference.getDeviceRegistrationId());
    }
    Utils.printLog(context, TAG, "Registration update json " + gson.toJson(user));
    String response = httpRequestUtils.postJsonToServer(getUpdateAccountUrl(), gson.toJson(user));
    if (TextUtils.isEmpty(response) || response.contains("<html")) {
        throw null;
    }
    if (response.contains(INVALID_APP_ID)) {
        throw new InvalidApplicationException("Invalid Application Id");
    }
    registrationResponse = gson.fromJson(response, RegistrationResponse.class);
    if (registrationResponse.isPasswordInvalid()) {
        throw new UnAuthoriseException("Invalid uername/password");
    }
    Utils.printLog(context, TAG, "Registration update response: " + registrationResponse);
    mobiComUserPreference.setPricingPackage(registrationResponse.getPricingPackage());
    if (registrationResponse.getNotificationResponse() != null) {
        Utils.printLog(context, TAG, "Notification response: " + registrationResponse.getNotificationResponse());
    }
    return registrationResponse;
}
Also used : MobiComUserPreference(com.applozic.mobicomkit.api.account.user.MobiComUserPreference) Gson(com.google.gson.Gson) InvalidApplicationException(com.applozic.mobicomkit.exception.InvalidApplicationException) UnAuthoriseException(com.applozic.mobicomkit.exception.UnAuthoriseException)

Example 29 with MobiComUserPreference

use of com.applozic.mobicomkit.api.account.user.MobiComUserPreference in project Applozic-Android-SDK by AppLozic.

the class ApplozicMqttService method typingStarted.

public void typingStarted(Contact contact, Channel channel) {
    String currentId;
    if (channel != null) {
        currentId = String.valueOf(channel.getKey());
    } else {
        currentId = contact.getUserId();
    }
    MobiComUserPreference mobiComUserPreference = MobiComUserPreference.getInstance(context);
    publishTopic(getApplicationKey(context), "1", mobiComUserPreference.getUserId(), currentId);
}
Also used : MobiComUserPreference(com.applozic.mobicomkit.api.account.user.MobiComUserPreference)

Example 30 with MobiComUserPreference

use of com.applozic.mobicomkit.api.account.user.MobiComUserPreference in project Applozic-Android-SDK by AppLozic.

the class ApplozicMqttService method unSubscribeToTypingTopic.

public synchronized void unSubscribeToTypingTopic(Channel channel) {
    try {
        String currentId = null;
        if (channel != null) {
            currentId = String.valueOf(channel.getKey());
        } else {
            MobiComUserPreference mobiComUserPreference = MobiComUserPreference.getInstance(context);
            currentId = mobiComUserPreference.getUserId();
        }
        final MqttClient client = connect();
        if (client == null || !client.isConnected()) {
            return;
        }
        client.unsubscribe("typing-" + getApplicationKey(context) + "-" + currentId);
        Utils.printLog(context, TAG, "UnSubscribed to topic: " + "typing-" + getApplicationKey(context) + "-" + currentId);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : MqttClient(org.eclipse.paho.client.mqttv3.MqttClient) MobiComUserPreference(com.applozic.mobicomkit.api.account.user.MobiComUserPreference) MqttException(org.eclipse.paho.client.mqttv3.MqttException)

Aggregations

MobiComUserPreference (com.applozic.mobicomkit.api.account.user.MobiComUserPreference)33 Message (com.applozic.mobicomkit.api.conversation.Message)8 ArrayList (java.util.ArrayList)6 Intent (android.content.Intent)5 Gson (com.google.gson.Gson)5 Contact (com.applozic.mobicommons.people.contact.Contact)4 PersonalizedMessage (com.applozic.mobicommons.personalization.PersonalizedMessage)4 User (com.applozic.mobicomkit.api.account.user.User)3 Channel (com.applozic.mobicommons.people.channel.Channel)3 Cursor (android.database.Cursor)2 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)2 NonNull (android.support.annotation.NonNull)2 FileClientService (com.applozic.mobicomkit.api.attachment.FileClientService)2 MobiComConversationService (com.applozic.mobicomkit.api.conversation.MobiComConversationService)2 InvalidApplicationException (com.applozic.mobicomkit.exception.InvalidApplicationException)2 UnAuthoriseException (com.applozic.mobicomkit.exception.UnAuthoriseException)2 MessageResponse (com.applozic.mobicomkit.feed.MessageResponse)2 SyncMessageFeed (com.applozic.mobicomkit.sync.SyncMessageFeed)2 JsonParser (com.google.gson.JsonParser)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2