Search in sources :

Example 21 with AbstractChat

use of com.xabber.android.data.message.AbstractChat in project xabber-android by redsolution.

the class OTRManager method sessionStatusChanged.

@Override
public void sessionStatusChanged(SessionID sessionID) {
    removeSMRequest(sessionID.getAccountID(), sessionID.getUserID());
    removeSMProgress(sessionID.getAccountID(), sessionID.getUserID());
    Session session = sessions.get(sessionID.getAccountID(), sessionID.getUserID());
    SessionStatus sStatus = session.getSessionStatus();
    LogManager.i(this, "session status changed " + sessionID.getUserID() + " status: " + sStatus);
    if (sStatus == SessionStatus.ENCRYPTED) {
        finished.remove(sessionID.getAccountID(), sessionID.getUserID());
        PublicKey remotePublicKey = session.getRemotePublicKey();
        String value;
        try {
            OtrCryptoEngine otrCryptoEngine = new OtrCryptoEngineImpl();
            value = otrCryptoEngine.getFingerprint(remotePublicKey);
        } catch (OtrCryptoException e) {
            LogManager.exception(this, e);
            value = null;
        }
        if (value != null) {
            actives.put(sessionID.getAccountID(), sessionID.getUserID(), value);
            if (fingerprints.get(sessionID.getAccountID(), sessionID.getUserID(), value) == null) {
                fingerprints.put(sessionID.getAccountID(), sessionID.getUserID(), value, false);
                requestToWrite(sessionID.getAccountID(), sessionID.getUserID(), value, false);
            }
        }
        newAction(sessionID.getAccountID(), sessionID.getUserID(), null, isVerified(sessionID.getAccountID(), sessionID.getUserID()) ? ChatAction.otr_verified : ChatAction.otr_encryption);
        AbstractChat chat = getChat(sessionID.getAccountID(), sessionID.getUserID());
        if (chat != null) {
            chat.sendMessages();
        }
    } else if (sStatus == SessionStatus.PLAINTEXT) {
        actives.remove(sessionID.getAccountID(), sessionID.getUserID());
        sessions.remove(sessionID.getAccountID(), sessionID.getUserID());
        finished.remove(sessionID.getAccountID(), sessionID.getUserID());
        try {
            session.endSession();
        } catch (OtrException e) {
            LogManager.exception(this, e);
        }
        newAction(sessionID.getAccountID(), sessionID.getUserID(), null, ChatAction.otr_plain);
    } else if (sStatus == SessionStatus.FINISHED) {
        actives.remove(sessionID.getAccountID(), sessionID.getUserID());
        sessions.remove(sessionID.getAccountID(), sessionID.getUserID());
        finished.put(sessionID.getAccountID(), sessionID.getUserID(), true);
        newAction(sessionID.getAccountID(), sessionID.getUserID(), null, ChatAction.otr_finish);
        // if session was finished then clear OTR-resource for this chat
        RegularChat chat = (RegularChat) getChat(sessionID.getAccountID(), sessionID.getUserID());
        if (chat != null) {
            chat.setOTRresource(null);
        }
    } else {
        throw new IllegalStateException();
    }
    onContactChanged(sessionID);
}
Also used : OtrCryptoEngine(net.java.otr4j.crypto.OtrCryptoEngine) OtrCryptoException(net.java.otr4j.crypto.OtrCryptoException) PublicKey(java.security.PublicKey) AbstractChat(com.xabber.android.data.message.AbstractChat) SessionStatus(net.java.otr4j.session.SessionStatus) OtrCryptoEngineImpl(net.java.otr4j.crypto.OtrCryptoEngineImpl) OtrException(net.java.otr4j.OtrException) RegularChat(com.xabber.android.data.message.RegularChat) Session(net.java.otr4j.session.Session)

Example 22 with AbstractChat

use of com.xabber.android.data.message.AbstractChat in project xabber-android by redsolution.

the class ChatContactSettingsFragment method getValues.

@Override
protected Map<String, Object> getValues() {
    Map<String, Object> map = new HashMap<>();
    AccountJid account = mListener.getAccount();
    UserJid user = mListener.getUser();
    boolean isMUC = false;
    if (MUCManager.getInstance().hasRoom(account, user.getJid().asEntityBareJidIfPossible())) {
        isMUC = true;
    }
    // custom notification
    AbstractChat chat = MessageManager.getInstance().getChat(account, user);
    if (chat != null) {
        putValue(map, R.string.chat_notification_settings_key, chat.notifyAboutMessage());
    }
    putValue(map, R.string.chat_save_history_key, ChatManager.getInstance().isSaveMessages(account, user));
    putValue(map, R.string.chat_events_visible_chat_key, ChatManager.getInstance().isNotifyVisible(account, user));
    putValue(map, R.string.chat_events_show_text_key, ChatManager.getInstance().getShowText(account, user).ordinal());
    putValue(map, R.string.chat_events_vibro_key, ChatManager.getInstance().isMakeVibro(account, user));
    putValue(map, R.string.chat_events_sound_key, ChatManager.getInstance().getSound(account, user, isMUC));
    putValue(map, R.string.chat_events_suppress_100_key, ChatManager.getInstance().isSuppress100(account, user));
    return map;
}
Also used : HashMap(java.util.HashMap) AbstractChat(com.xabber.android.data.message.AbstractChat) AccountJid(com.xabber.android.data.entity.AccountJid) UserJid(com.xabber.android.data.entity.UserJid)

Example 23 with AbstractChat

use of com.xabber.android.data.message.AbstractChat in project xabber-android by redsolution.

the class ChatContactSettingsFragment method setValues.

@Override
protected boolean setValues(Map<String, Object> source, Map<String, Object> result) {
    AccountJid account = mListener.getAccount();
    UserJid user = mListener.getUser();
    // custom notification
    if (hasChanges(source, result, R.string.chat_notification_settings_key)) {
        AbstractChat chat = MessageManager.getInstance().getChat(account, user);
        if (chat != null) {
            boolean newValue = getBoolean(result, R.string.chat_notification_settings_key);
            if (chat.getNotificationState().getMode().equals(NotificationState.NotificationMode.bydefault)) {
                NotificationState.NotificationMode mode = newValue ? NotificationState.NotificationMode.enabled : NotificationState.NotificationMode.disabled;
                chat.setNotificationState(new NotificationState(mode, 0), true);
            } else {
                boolean defValue;
                if (MUCManager.getInstance().hasRoom(account, user.getJid().asEntityBareJidIfPossible()))
                    defValue = SettingsManager.eventsOnMuc();
                else
                    defValue = SettingsManager.eventsOnChat();
                if (!defValue && chat.getNotificationState().getMode().equals(NotificationState.NotificationMode.disabled)) {
                    chat.setNotificationState(new NotificationState(NotificationState.NotificationMode.enabled, 0), true);
                } else if (defValue && chat.getNotificationState().getMode().equals(NotificationState.NotificationMode.enabled)) {
                    chat.setNotificationState(new NotificationState(NotificationState.NotificationMode.disabled, 0), true);
                } else
                    chat.setNotificationState(new NotificationState(NotificationState.NotificationMode.bydefault, 0), true);
            }
        }
    }
    if (hasChanges(source, result, R.string.chat_save_history_key))
        ChatManager.getInstance().setSaveMessages(account, user, getBoolean(result, R.string.chat_save_history_key));
    if (hasChanges(source, result, R.string.chat_events_visible_chat_key))
        ChatManager.getInstance().setNotifyVisible(account, user, getBoolean(result, R.string.chat_events_visible_chat_key));
    if (hasChanges(source, result, R.string.chat_events_show_text_key)) {
        ChatManager.getInstance().setShowText(account, user, ShowMessageTextInNotification.fromInteger(getInt(result, R.string.chat_events_show_text_key)));
    }
    if (hasChanges(source, result, R.string.chat_events_vibro_key))
        ChatManager.getInstance().setMakeVibro(account, user, getBoolean(result, R.string.chat_events_vibro_key));
    if (hasChanges(source, result, R.string.chat_events_sound_key))
        ChatManager.getInstance().setSound(account, user, getUri(result, R.string.chat_events_sound_key));
    if (hasChanges(source, result, R.string.chat_events_suppress_100_key))
        ChatManager.getInstance().setSuppress100(account, user, getBoolean(result, R.string.chat_events_suppress_100_key));
    return true;
}
Also used : AbstractChat(com.xabber.android.data.message.AbstractChat) AccountJid(com.xabber.android.data.entity.AccountJid) UserJid(com.xabber.android.data.entity.UserJid) NotificationState(com.xabber.android.data.message.NotificationState)

Example 24 with AbstractChat

use of com.xabber.android.data.message.AbstractChat in project xabber-android by redsolution.

the class ComparatorByChat method compare.

@Override
public int compare(AbstractContact contact1, AbstractContact contact2) {
    final MessageManager messageManager = MessageManager.getInstance();
    final AbstractChat abstractChat1 = messageManager.getChat(contact1.getAccount(), contact1.getUser());
    final AbstractChat abstractChat2 = messageManager.getChat(contact2.getAccount(), contact2.getUser());
    final boolean hasActiveChat1 = abstractChat1 != null && abstractChat1.isActive();
    final boolean hasActiveChat2 = abstractChat2 != null && abstractChat2.isActive();
    if (hasActiveChat1 && !hasActiveChat2) {
        return -1;
    }
    if (!hasActiveChat1 && hasActiveChat2) {
        return 1;
    }
    if (hasActiveChat1) {
        int result;
        result = ChatComparator.CHAT_COMPARATOR.compare(abstractChat1, abstractChat2);
        if (result != 0) {
            return result;
        }
    }
    return super.compare(contact1, contact2);
}
Also used : MessageManager(com.xabber.android.data.message.MessageManager) AbstractChat(com.xabber.android.data.message.AbstractChat)

Example 25 with AbstractChat

use of com.xabber.android.data.message.AbstractChat in project xabber-android by redsolution.

the class ChatFragment method onResume.

@Override
public void onResume() {
    super.onResume();
    LogManager.i(this, "onResume");
    updateContact();
    restoreInputState();
    restoreScrollState();
    showHideNotifyIfNeed();
    AbstractChat chat = getChat();
    if (chat != null)
        chat.resetUnreadMessageCount();
    showJoinButtonIfNeed();
}
Also used : AbstractChat(com.xabber.android.data.message.AbstractChat)

Aggregations

AbstractChat (com.xabber.android.data.message.AbstractChat)55 UserJid (com.xabber.android.data.entity.UserJid)10 RoomChat (com.xabber.android.data.extension.muc.RoomChat)10 NetworkException (com.xabber.android.data.NetworkException)9 RegularChat (com.xabber.android.data.message.RegularChat)9 ArrayList (java.util.ArrayList)8 AccountJid (com.xabber.android.data.entity.AccountJid)7 RoomContact (com.xabber.android.data.extension.muc.RoomContact)6 ChatContact (com.xabber.android.data.message.ChatContact)6 AbstractContact (com.xabber.android.data.roster.AbstractContact)6 RosterContact (com.xabber.android.data.roster.RosterContact)6 NotificationState (com.xabber.android.data.message.NotificationState)5 Message (org.jivesoftware.smack.packet.Message)5 GroupConfiguration (com.xabber.android.ui.adapter.contactlist.GroupConfiguration)4 View (android.view.View)3 MessageManager (com.xabber.android.data.message.MessageManager)3 Map (java.util.Map)3 Intent (android.content.Intent)2 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)2 RecyclerView (android.support.v7.widget.RecyclerView)2