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