use of com.xabber.android.data.entity.UserJid in project xabber-android by redsolution.
the class ChatMarkerManager method processCarbonsMessage.
public void processCarbonsMessage(AccountJid account, final Message message, CarbonExtension.Direction direction) {
if (direction == CarbonExtension.Direction.sent) {
ChatMarkersElements.DisplayedExtension extension = ChatMarkersElements.DisplayedExtension.from(message);
if (extension != null) {
UserJid companion;
try {
companion = UserJid.from(message.getTo()).getBareUserJid();
} catch (UserJid.UserJidCreateException e) {
return;
}
AbstractChat chat = MessageManager.getInstance().getOrCreateChat(account, companion);
if (chat != null) {
chat.markAsRead(extension.getId(), false);
MessageNotificationManager.getInstance().removeChatWithTimer(account, companion);
// start grace period
AccountManager.getInstance().startGracePeriod(account);
}
}
}
}
use of com.xabber.android.data.entity.UserJid in project xabber-android by redsolution.
the class AttentionManager method onStanza.
@Override
public void onStanza(ConnectionItem connection, Stanza stanza) {
if (!(stanza instanceof Message)) {
return;
}
if (!SettingsManager.chatsAttention()) {
return;
}
final AccountJid account = connection.getAccount();
UserJid from;
try {
from = UserJid.from(stanza.getFrom());
} catch (UserJid.UserJidCreateException e) {
e.printStackTrace();
return;
}
for (ExtensionElement packetExtension : stanza.getExtensions()) {
if (packetExtension instanceof AttentionExtension) {
boolean fromMUC = ((Message) stanza).getType().equals(Message.Type.groupchat);
MessageManager.getInstance().openChat(account, from);
MessageManager.getInstance().getOrCreateChat(account, from).newAction(null, null, ChatAction.attention_requested, fromMUC);
attentionRequestProvider.add(new AttentionRequest(account, from.getBareUserJid()), true);
}
}
}
use of com.xabber.android.data.entity.UserJid in project xabber-android by redsolution.
the class AttentionManager method sendAttention.
public void sendAttention(AccountJid account, UserJid user) throws NetworkException {
AbstractChat chat = MessageManager.getInstance().getOrCreateChat(account, user);
if (!(chat instanceof RegularChat)) {
throw new NetworkException(R.string.ENTRY_IS_NOT_FOUND);
}
Jid to = chat.getTo();
if (to.getResourceOrNull() == null || to.getResourceOrNull().equals(Resourcepart.EMPTY)) {
final Presence presence = RosterManager.getInstance().getPresence(account, user);
if (presence == null) {
to = null;
} else {
to = presence.getFrom();
}
}
if (to == null) {
throw new NetworkException(R.string.ENTRY_IS_NOT_AVAILABLE);
}
if (!CapabilitiesManager.getInstance().isFeatureSupported(to, AttentionExtension.NAMESPACE)) {
throw new NetworkException(R.string.ATTENTION_IS_NOT_SUPPORTED);
}
Message message = new Message();
message.setTo(to);
message.setType(Message.Type.headline);
message.addExtension(new AttentionExtension());
StanzaSender.sendStanza(account, message);
chat.newAction(null, null, ChatAction.attention_called, false);
}
use of com.xabber.android.data.entity.UserJid in project xabber-android by redsolution.
the class MUCManager method onStanza.
@Override
public void onStanza(ConnectionItem connection, Stanza stanza) {
if (!(connection instanceof AccountItem)) {
return;
}
AccountJid account = ((AccountItem) connection).getAccount();
Jid from = stanza.getFrom();
if (from == null || !(stanza instanceof Message)) {
return;
}
Message message = (Message) stanza;
if (message.getType() != Message.Type.normal && message.getType() != Message.Type.chat) {
return;
}
MUCUser mucUser = MUCUser.from(stanza);
if (mucUser == null || mucUser.getInvite() == null) {
return;
}
RoomChat roomChat = getRoomChat(account, from.asEntityBareJidIfPossible());
if (roomChat == null || !roomChat.getState().inUse()) {
UserJid inviter = null;
try {
inviter = UserJid.from(mucUser.getInvite().getFrom());
} catch (UserJid.UserJidCreateException e) {
LogManager.exception(this, e);
}
if (inviter == null) {
try {
inviter = UserJid.from(from);
} catch (UserJid.UserJidCreateException e) {
LogManager.exception(this, e);
}
}
try {
inviteProvider.add(new RoomInvite(account, UserJid.from(from), inviter, mucUser.getInvite().getReason(), mucUser.getPassword()), true);
} catch (UserJid.UserJidCreateException e) {
LogManager.exception(this, e);
}
}
}
use of com.xabber.android.data.entity.UserJid in project xabber-android by redsolution.
the class OTRManager method askForSecret.
@Override
public void askForSecret(SessionID sessionID, InstanceTag receiverTag, String question) {
try {
AccountJid accountJid = AccountJid.from(sessionID.getAccountID());
UserJid userJid = UserJid.from(sessionID.getUserID());
// set notify intent to chat
setNotifyIntentToChat(QuestionActivity.createIntent(Application.getInstance(), accountJid, userJid, question != null, true, question), accountJid, userJid);
// show android notification
SMRequest request = new SMRequest(AccountJid.from(sessionID.getAccountID()), UserJid.from(sessionID.getUserID()), question);
smRequestProvider.add(request, true);
// send event of adding auth request to fragment
EventBus.getDefault().post(new AuthAskEvent(accountJid, userJid));
} catch (UserJid.UserJidCreateException | XmppStringprepException e) {
LogManager.exception(this, e);
}
}
Aggregations