Search in sources :

Example 1 with ArchiveMode

use of com.xabber.android.data.account.ArchiveMode in project xabber-android by redsolution.

the class MessageArchiveManager method onTimeReceived.

@Override
public void onTimeReceived(final ConnectionItem connection) {
    if (!(connection instanceof AccountItem)) {
        onModifiedAvailable(connection);
        return;
    }
    String account = ((AccountItem) connection).getAccount();
    ModificationStorage modificationStorage = modificationStorages.get(account);
    if (modificationStorage == null) {
        modificationStorage = new ModificationStorage();
        modificationStorages.put(account, modificationStorage);
    }
    modificationStorage.onConnected();
    removeNotReceived(account);
    ArchiveMode archiveMode = AccountManager.getInstance().getArchiveMode(account);
    if (ServerInfoManager.getInstance().isProtocolSupported(account, FEATURE_ARCH) || ServerInfoManager.getInstance().isProtocolSupported(account, FEATURE_PREF) || ServerInfoManager.getInstance().isProtocolSupported(account, FEATURE_MANAGE)) {
        if (archiveMode == ArchiveMode.available) {
            availableArchiveRequestProvider.add(new AvailableArchiveRequest(account), null);
        }
    }
    if (archiveMode != ArchiveMode.server) {
        onModifiedAvailable(account);
        return;
    }
    if (ServerInfoManager.getInstance().isProtocolSupported(account, FEATURE_PREF)) {
        requestPreferences(account);
        return;
    }
    onPreferenceAvailable(account);
}
Also used : ArchiveMode(com.xabber.android.data.account.ArchiveMode) AccountItem(com.xabber.android.data.account.AccountItem)

Example 2 with ArchiveMode

use of com.xabber.android.data.account.ArchiveMode in project xabber-android by redsolution.

the class AccountTable method migrate.

@Override
public void migrate(SQLiteDatabase db, int toVersion) {
    super.migrate(db, toVersion);
    String sql;
    switch(toVersion) {
        case 3:
            DatabaseManager.renameTable(db, "accounts", "accounts_");
            sql = "CREATE TABLE accounts (" + "_id INTEGER PRIMARY KEY," + "host TEXT," + "port INTEGER," + "server_name TEXT," + "user_name TEXT," + "password TEXT," + "resource TEXT," + "color_index INTEGER," + "priority INTEGER," + "status_mode INTEGER," + "status_text TEXT);";
            DatabaseManager.execSQL(db, sql);
            sql = "INSERT INTO accounts SELECT " + "_id, host, port, server_name, user_name, password, resource, " + "_id, 0, " + StatusMode.available.ordinal() + ", '' FROM accounts_;";
            DatabaseManager.execSQL(db, sql);
            DatabaseManager.dropTable(db, "accounts_");
            break;
        case 9:
            sql = "ALTER TABLE accounts ADD COLUMN enabled INTEGER;";
            DatabaseManager.execSQL(db, sql);
            sql = "UPDATE accounts SET enabled = 1;";
            DatabaseManager.execSQL(db, sql);
            break;
        case 21:
            sql = "ALTER TABLE accounts ADD COLUMN required_tls INTEGER;";
            DatabaseManager.execSQL(db, sql);
            sql = "UPDATE accounts SET required_tls = 0;";
            DatabaseManager.execSQL(db, sql);
            break;
        case 22:
            sql = "ALTER TABLE accounts ADD COLUMN compression INTEGER;";
            DatabaseManager.execSQL(db, sql);
            sql = "UPDATE accounts SET compression = 0;";
            DatabaseManager.execSQL(db, sql);
            break;
        case 30:
            sql = "ALTER TABLE accounts ADD COLUMN share_location INTEGER;";
            DatabaseManager.execSQL(db, sql);
            sql = "ALTER TABLE accounts ADD COLUMN accept_location INTEGER;";
            DatabaseManager.execSQL(db, sql);
            sql = "UPDATE accounts SET share_location = 0, accept_location = 1;";
            DatabaseManager.execSQL(db, sql);
            break;
        case 31:
            sql = "UPDATE accounts SET accept_location = 0;";
            DatabaseManager.execSQL(db, sql);
            break;
        case 34:
            long count = db.compileStatement("SELECT COUNT(*) FROM accounts;").simpleQueryForLong();
            Editor editor = PreferenceManager.getDefaultSharedPreferences(Application.getInstance().getBaseContext()).edit();
            if (count < 2) {
                editor.putBoolean(Application.getInstance().getString(R.string.contacts_show_accounts_key), false);
            } else {
                editor.putBoolean(Application.getInstance().getString(R.string.contacts_enable_show_accounts_key), false);
            }
            editor.commit();
            break;
        case 36:
            sql = "ALTER TABLE accounts ADD COLUMN custom INTEGER;";
            DatabaseManager.execSQL(db, sql);
            sql = "UPDATE accounts SET custom = 1;";
            DatabaseManager.execSQL(db, sql);
            break;
        case 37:
            sql = "ALTER TABLE accounts ADD COLUMN sasl_enabled INTEGER;";
            DatabaseManager.execSQL(db, sql);
            sql = "UPDATE accounts SET sasl_enabled = 1;";
            DatabaseManager.execSQL(db, sql);
            break;
        case 43:
            DatabaseManager.renameTable(db, "accounts", "accounts_");
            sql = "CREATE TABLE accounts (" + "_id INTEGER PRIMARY KEY," + "custom INTEGER," + "host TEXT," + "port INTEGER," + "server_name TEXT," + "user_name TEXT," + "password TEXT," + "resource TEXT," + "color_index INTEGER," + "priority INTEGER," + "status_mode INTEGER," + "status_text TEXT," + "enabled INTEGER," + "sasl_enabled INTEGER," + "required_tls INTEGER," + "compression INTEGER);";
            DatabaseManager.execSQL(db, sql);
            String fields = "custom, host, port, server_name, user_name, password, " + "resource, color_index, priority, status_mode, status_text, " + "enabled, sasl_enabled, required_tls, compression";
            sql = "INSERT INTO accounts (" + fields + ") " + "SELECT " + fields + " FROM accounts_;";
            DatabaseManager.execSQL(db, sql);
            DatabaseManager.dropTable(db, "accounts_");
            break;
        case 46:
            sql = "ALTER TABLE accounts ADD COLUMN protocol TEXT;";
            DatabaseManager.execSQL(db, sql);
            sql = "UPDATE accounts SET protocol = 'xmpp';";
            DatabaseManager.execSQL(db, sql);
            break;
        case 48:
            sql = "ALTER TABLE accounts ADD COLUMN syncable INTEGER;";
            DatabaseManager.execSQL(db, sql);
            sql = "UPDATE accounts SET syncable = 0;";
            DatabaseManager.execSQL(db, sql);
            break;
        case 50:
            sql = "ALTER TABLE accounts ADD COLUMN store_password INTEGER;";
            DatabaseManager.execSQL(db, sql);
            sql = "UPDATE accounts SET store_password = 1;";
            DatabaseManager.execSQL(db, sql);
            break;
        case 53:
            sql = "UPDATE accounts SET protocol = 'gtalk' WHERE host = 'talk.google.com';";
            DatabaseManager.execSQL(db, sql);
            break;
        case 55:
            sql = "ALTER TABLE accounts ADD COLUMN public_key BLOB;";
            DatabaseManager.execSQL(db, sql);
            sql = "ALTER TABLE accounts ADD COLUMN private_key BLOB;";
            DatabaseManager.execSQL(db, sql);
            break;
        case 59:
            sql = "ALTER TABLE accounts ADD COLUMN last_sync INTEGER;";
            DatabaseManager.execSQL(db, sql);
            break;
        case 61:
            sql = "ALTER TABLE accounts ADD COLUMN archive_mode INTEGER;";
            DatabaseManager.execSQL(db, sql);
            ArchiveMode archiveMode;
            String value = PreferenceManager.getDefaultSharedPreferences(Application.getInstance().getBaseContext()).getString("chats_history", "all");
            switch(value) {
                case "all":
                    archiveMode = ArchiveMode.available;
                    break;
                case "unread":
                    archiveMode = ArchiveMode.unreadOnly;
                    break;
                default:
                    archiveMode = ArchiveMode.dontStore;
                    break;
            }
            sql = "UPDATE accounts SET archive_mode = " + archiveMode.ordinal() + ";";
            DatabaseManager.execSQL(db, sql);
            break;
        case 66:
            sql = "ALTER TABLE accounts ADD COLUMN proxy_type INTEGER;";
            DatabaseManager.execSQL(db, sql);
            sql = "ALTER TABLE accounts ADD COLUMN proxy_host TEXT;";
            DatabaseManager.execSQL(db, sql);
            sql = "ALTER TABLE accounts ADD COLUMN proxy_port INTEGER;";
            DatabaseManager.execSQL(db, sql);
            sql = "ALTER TABLE accounts ADD COLUMN proxy_user TEXT;";
            DatabaseManager.execSQL(db, sql);
            sql = "ALTER TABLE accounts ADD COLUMN proxy_password TEXT;";
            DatabaseManager.execSQL(db, sql);
            sql = "UPDATE accounts SET proxy_type = " + ProxyType.none.ordinal() + ", " + "proxy_host = \"localhost\", " + "proxy_port = 8080, " + "proxy_user = \"\", " + "proxy_password = \"\" " + "WHERE proxy_type IS NULL;";
            DatabaseManager.execSQL(db, sql);
            break;
        default:
            break;
    }
}
Also used : ArchiveMode(com.xabber.android.data.account.ArchiveMode) Editor(android.content.SharedPreferences.Editor)

Example 3 with ArchiveMode

use of com.xabber.android.data.account.ArchiveMode in project xabber-android by redsolution.

the class AbstractChat method newMessage.

/**
     * Creates new message.
     * <p/>
     * Any parameter can be <code>null</code> (except boolean values).
     *
     * @param resource       Contact's resource or nick in conference.
     * @param text           message.
     * @param action         Informational message.
     * @param delayTimestamp Time when incoming message was sent or outgoing was created.
     * @param incoming       Incoming message.
     * @param notify         Notify user about this message when appropriated.
     * @param unencrypted    Whether not encrypted message in OTR chat was received.
     * @param offline        Whether message was received from server side offline storage.
     * @param record         Whether record server side is enabled.
     * @return
     */
protected MessageItem newMessage(String resource, String text, ChatAction action, Date delayTimestamp, boolean incoming, boolean notify, boolean unencrypted, boolean offline, boolean record) {
    boolean save;
    boolean visible = MessageManager.getInstance().isVisibleChat(this);
    boolean read = incoming ? visible : true;
    boolean send = incoming;
    if (action == null && text == null)
        throw new IllegalArgumentException();
    if (resource == null)
        resource = "";
    if (text == null)
        text = "";
    if (action != null) {
        read = true;
        send = true;
        save = false;
    } else {
        ArchiveMode archiveMode = AccountManager.getInstance().getArchiveMode(account);
        if (archiveMode == ArchiveMode.dontStore)
            save = false;
        else
            save = archiveMode.saveLocally() || !send || (!read && archiveMode == ArchiveMode.unreadOnly);
        if (save)
            save = ChatManager.getInstance().isSaveMessages(account, user);
    }
    if (save && (unencrypted || (!SettingsManager.securityOtrHistory() && OTRManager.getInstance().getSecurityLevel(account, user) != SecurityLevel.plain)))
        save = false;
    Date timestamp = new Date();
    if (text.trim().isEmpty()) {
        notify = false;
    }
    if (notify || !incoming)
        openChat();
    if (!incoming)
        notify = false;
    if (isPrivateMucChat) {
        if (!isPrivateMucChatAccepted || PrivateMucChatBlockingManager.getInstance().getBlockedContacts(account).contains(user)) {
            notify = false;
        }
    }
    MessageItem messageItem = new MessageItem(this, record ? null : NO_RECORD_TAG, resource, text, action, timestamp, delayTimestamp, incoming, read, send, false, incoming, unencrypted, offline);
    FileManager.processFileMessage(messageItem, true);
    messages.add(messageItem);
    updateSendQuery(messageItem);
    sort();
    if (save && !isPrivateMucChat)
        requestToWriteMessage(messageItem, resource, text, action, timestamp, delayTimestamp, incoming, read, send);
    if (notify && notifyAboutMessage()) {
        if (visible) {
            if (ChatManager.getInstance().isNotifyVisible(account, user)) {
                NotificationManager.getInstance().onCurrentChatMessageNotification(messageItem);
            }
        } else {
            NotificationManager.getInstance().onMessageNotification(messageItem);
        }
    }
    MessageManager.getInstance().onChatChanged(account, user, incoming);
    return messageItem;
}
Also used : ArchiveMode(com.xabber.android.data.account.ArchiveMode) Date(java.util.Date)

Example 4 with ArchiveMode

use of com.xabber.android.data.account.ArchiveMode in project xabber-android by redsolution.

the class MessageManager method onAccountArchiveModeChanged.

@Override
public void onAccountArchiveModeChanged(AccountItem accountItem) {
    final ArchiveMode archiveMode = AccountManager.getInstance().getArchiveMode(accountItem.getAccount());
    if (archiveMode.saveLocally()) {
        return;
    }
    final String account = accountItem.getAccount();
    final ArrayList<MessageItem> removeMessageItems = new ArrayList<MessageItem>();
    for (AbstractChat chat : chats.getNested(account).values()) {
        for (MessageItem messageItem : chat.getMessages()) {
            if (archiveMode == ArchiveMode.dontStore || ((messageItem.isRead() || archiveMode != ArchiveMode.unreadOnly) && messageItem.isSent())) {
                removeMessageItems.add(messageItem);
            }
        }
    }
    Application.getInstance().runInBackground(new Runnable() {

        @Override
        public void run() {
            // If message was read or received after removeMessageItems
            // was created then it's ID will be not null. DB actions with
            // such message will have no effect as if it was removed.
            // History ids becomes invalid and will be cleared on next
            // history load.
            MessageTable.getInstance().removeMessages(getMessageIds(removeMessageItems, true));
            if (archiveMode == ArchiveMode.dontStore) {
                MessageTable.getInstance().removeAccount(account);
            } else if (archiveMode == ArchiveMode.unreadOnly) {
                MessageTable.getInstance().removeReadAndSent(account);
            } else {
                MessageTable.getInstance().removeSent(account);
            }
        }
    });
    AccountManager.getInstance().onAccountChanged(accountItem.getAccount());
}
Also used : ArchiveMode(com.xabber.android.data.account.ArchiveMode) ArrayList(java.util.ArrayList)

Aggregations

ArchiveMode (com.xabber.android.data.account.ArchiveMode)4 Editor (android.content.SharedPreferences.Editor)1 AccountItem (com.xabber.android.data.account.AccountItem)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1