Search in sources :

Example 6 with UserJid

use of com.xabber.android.data.entity.UserJid in project xabber-android by redsolution.

the class HttpFileUploadManager method uploadFile.

public void uploadFile(final AccountJid account, final UserJid user, final List<String> filePaths, final List<Uri> fileUris, String existMessageId, Context context) {
    if (isUploading) {
        progressSubscribe.onNext(new ProgressData(0, 0, "Uploading already started", false, null));
        return;
    }
    isUploading = true;
    final Jid uploadServerUrl = uploadServers.get(account.getFullJid().asBareJid());
    if (uploadServerUrl == null) {
        progressSubscribe.onNext(new ProgressData(0, 0, "Upload server not found", false, null));
        isUploading = false;
        return;
    }
    Intent intent = new Intent(context, UploadService.class);
    intent.putExtra(UploadService.KEY_RECEIVER, new UploadReceiver(new Handler()));
    intent.putExtra(UploadService.KEY_ACCOUNT_JID, (Parcelable) account);
    intent.putExtra(UploadService.KEY_USER_JID, user);
    intent.putStringArrayListExtra(UploadService.KEY_FILE_PATHS, (ArrayList<String>) filePaths);
    intent.putParcelableArrayListExtra(UploadService.KEY_FILE_URIS, (ArrayList<Uri>) fileUris);
    intent.putExtra(UploadService.KEY_UPLOAD_SERVER_URL, (CharSequence) uploadServerUrl);
    intent.putExtra(UploadService.KEY_MESSAGE_ID, existMessageId);
    context.startService(intent);
}
Also used : UserJid(com.xabber.android.data.entity.UserJid) AccountJid(com.xabber.android.data.entity.AccountJid) DomainBareJid(org.jxmpp.jid.DomainBareJid) Jid(org.jxmpp.jid.Jid) BareJid(org.jxmpp.jid.BareJid) Handler(android.os.Handler) Intent(android.content.Intent) Uri(android.net.Uri)

Example 7 with UserJid

use of com.xabber.android.data.entity.UserJid in project xabber-android by redsolution.

the class ChatStateManager method onStanza.

@Override
public void onStanza(ConnectionItem connection, Stanza stanza) {
    if (stanza.getFrom() == null) {
        return;
    }
    final Resourcepart resource = stanza.getFrom().getResourceOrNull();
    if (resource == null) {
        return;
    }
    final AccountJid account = ((AccountItem) connection).getAccount();
    final UserJid bareUserJid;
    try {
        bareUserJid = UserJid.from(stanza.getFrom()).getBareUserJid();
    } catch (UserJid.UserJidCreateException e) {
        return;
    }
    if (stanza instanceof Presence) {
        Presence presence = (Presence) stanza;
        if (presence.getType() != Type.unavailable) {
            return;
        }
        chatStates.remove(account.toString(), bareUserJid.toString(), resource);
        removeCallback(account, bareUserJid.getBareJid(), resource);
        supports.remove(account.toString(), bareUserJid.toString(), resource);
    } else if (stanza instanceof Message) {
        boolean support = false;
        for (ExtensionElement extension : stanza.getExtensions()) if (extension instanceof ChatStateExtension) {
            removeCallback(account, bareUserJid.getBareJid(), resource);
            ChatState chatState = ((ChatStateExtension) extension).getChatState();
            chatStates.put(account.toString(), bareUserJid.toString(), resource, chatState);
            if (chatState != ChatState.active) {
                Runnable runnable = new Runnable() {

                    @Override
                    public void run() {
                        if (this != stateCleaners.get(account.toString(), bareUserJid.toString(), resource)) {
                            return;
                        }
                        chatStates.remove(account.toString(), bareUserJid.toString(), resource);
                        removeCallback(account, bareUserJid.getBareJid(), resource);
                        RosterManager.onChatStateChanged(account, bareUserJid);
                    }
                };
                handler.postDelayed(runnable, REMOVE_STATE_DELAY);
                stateCleaners.put(account.toString(), bareUserJid.toString(), resource, runnable);
            }
            RosterManager.onChatStateChanged(account, bareUserJid);
            support = true;
            break;
        }
        Message message = (Message) stanza;
        if (message.getType() != Message.Type.chat && message.getType() != Message.Type.groupchat) {
            return;
        }
        if (support) {
            supports.put(account.toString(), bareUserJid.toString(), resource, true);
        } else if (supports.get(account.toString(), bareUserJid.toString(), resource) == null) {
            // Disable only if there no information about support.
            supports.put(account.toString(), bareUserJid.toString(), resource, false);
        }
    }
}
Also used : ChatState(org.jivesoftware.smackx.chatstates.ChatState) Message(org.jivesoftware.smack.packet.Message) ChatStateExtension(org.jivesoftware.smackx.chatstates.packet.ChatStateExtension) AccountItem(com.xabber.android.data.account.AccountItem) AccountJid(com.xabber.android.data.entity.AccountJid) ExtensionElement(org.jivesoftware.smack.packet.ExtensionElement) UserJid(com.xabber.android.data.entity.UserJid) Presence(org.jivesoftware.smack.packet.Presence) Resourcepart(org.jxmpp.jid.parts.Resourcepart)

Example 8 with UserJid

use of com.xabber.android.data.entity.UserJid in project xabber-android by redsolution.

the class ChatMarkerManager method isClientSupportChatMarkers.

private boolean isClientSupportChatMarkers(AccountJid account, UserJid user) {
    AccountItem accountItem = AccountManager.getInstance().getAccount(account);
    if (accountItem == null)
        return false;
    XMPPConnection connection = accountItem.getConnection();
    final List<Presence> allPresences = RosterManager.getInstance().getPresences(account, user.getJid());
    boolean isChatMarkersSupport = false;
    for (Presence presence : allPresences) {
        Jid fromJid = presence.getFrom();
        DiscoverInfo discoverInfo = null;
        try {
            discoverInfo = ServiceDiscoveryManager.getInstanceFor(connection).discoverInfo(fromJid);
        } catch (SmackException.NoResponseException | XMPPException.XMPPErrorException | SmackException.NotConnectedException | InterruptedException | ClassCastException e) {
            e.printStackTrace();
        }
        isChatMarkersSupport = discoverInfo != null && discoverInfo.containsFeature(ChatMarkersElements.NAMESPACE);
        if (isChatMarkersSupport)
            break;
    }
    return isChatMarkersSupport;
}
Also used : DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo) UserJid(com.xabber.android.data.entity.UserJid) AccountJid(com.xabber.android.data.entity.AccountJid) Jid(org.jxmpp.jid.Jid) AccountItem(com.xabber.android.data.account.AccountItem) XMPPConnection(org.jivesoftware.smack.XMPPConnection) Presence(org.jivesoftware.smack.packet.Presence)

Example 9 with UserJid

use of com.xabber.android.data.entity.UserJid in project xabber-android by redsolution.

the class MessageManager method onLoad.

@Override
public void onLoad() {
    Realm realm = MessageDatabaseManager.getInstance().getNewBackgroundRealm();
    realm.executeTransaction(new Realm.Transaction() {

        @Override
        public void execute(Realm realm) {
            RealmResults<MessageItem> messagesToSend = realm.where(MessageItem.class).equalTo(MessageItem.Fields.SENT, false).findAll();
            for (MessageItem messageItem : messagesToSend) {
                AccountJid account = messageItem.getAccount();
                UserJid user = messageItem.getUser();
                if (account != null && user != null) {
                    if (getChat(account, user) == null) {
                        createChat(account, user);
                    }
                }
            }
        }
    });
    realm.close();
    NotificationManager.getInstance().registerNotificationProvider(mucPrivateChatRequestProvider);
}
Also used : MessageItem(com.xabber.android.data.database.messagerealm.MessageItem) AccountJid(com.xabber.android.data.entity.AccountJid) UserJid(com.xabber.android.data.entity.UserJid) Realm(io.realm.Realm) RealmResults(io.realm.RealmResults)

Example 10 with UserJid

use of com.xabber.android.data.entity.UserJid in project xabber-android by redsolution.

the class MessageNotificationManager method performAction.

public void performAction(FullAction action) {
    AccountJid accountJid = action.getAccountJid();
    UserJid userJid = action.getUserJid();
    switch(action.getActionType()) {
        case read:
            AbstractChat chat = MessageManager.getInstance().getChat(accountJid, userJid);
            if (chat != null) {
                AccountManager.getInstance().stopGracePeriod(chat.getAccount());
                chat.markAsReadAll(true);
                callUiUpdate();
            }
            break;
        case snooze:
            AbstractChat chat1 = MessageManager.getInstance().getChat(accountJid, userJid);
            if (chat1 != null) {
                chat1.setNotificationState(new NotificationState(NotificationState.NotificationMode.snooze2h, (int) (System.currentTimeMillis() / 1000L)), true);
                callUiUpdate();
            }
            break;
        case reply:
            MessageManager.getInstance().sendMessage(accountJid, userJid, action.getReplyText().toString());
    }
}
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)

Aggregations

UserJid (com.xabber.android.data.entity.UserJid)67 AccountJid (com.xabber.android.data.entity.AccountJid)43 AbstractChat (com.xabber.android.data.message.AbstractChat)15 ArrayList (java.util.ArrayList)15 Intent (android.content.Intent)9 Jid (org.jxmpp.jid.Jid)9 Presence (org.jivesoftware.smack.packet.Presence)8 XmppStringprepException (org.jxmpp.stringprep.XmppStringprepException)8 AccountItem (com.xabber.android.data.account.AccountItem)7 AbstractContact (com.xabber.android.data.roster.AbstractContact)6 Message (org.jivesoftware.smack.packet.Message)6 Resourcepart (org.jxmpp.jid.parts.Resourcepart)6 NetworkException (com.xabber.android.data.NetworkException)5 IFlexible (eu.davidea.flexibleadapter.items.IFlexible)5 SmackException (org.jivesoftware.smack.SmackException)5 Uri (android.net.Uri)4 ContactVO (com.xabber.android.presentation.ui.contactlist.viewobjects.ContactVO)4 DomainBareJid (org.jxmpp.jid.DomainBareJid)4 TextView (android.widget.TextView)3 MessageItem (com.xabber.android.data.database.messagerealm.MessageItem)3