Search in sources :

Example 11 with XmppAddress

use of org.awesomeapp.messenger.plugin.xmpp.XmppAddress in project Zom-Android by zom.

the class GroupDisplayActivity method inviteContacts.

public void inviteContacts(ArrayList<String> invitees) {
    if (mConn == null)
        return;
    try {
        IChatSessionManager manager = mConn.getChatSessionManager();
        IChatSession session = manager.getChatSession(mAddress);
        for (String invitee : invitees) {
            session.inviteContact(invitee);
            GroupMemberDisplay member = new GroupMemberDisplay();
            XmppAddress address = new XmppAddress(invitee);
            member.username = address.getBareAddress();
            member.nickname = address.getUser();
            try {
                member.avatar = DatabaseUtils.getAvatarFromAddress(getContentResolver(), member.username, ImApp.SMALL_AVATAR_WIDTH, ImApp.SMALL_AVATAR_HEIGHT);
            } catch (DecoderException e) {
                e.printStackTrace();
            }
            mMembers.add(member);
        }
        mRecyclerView.getAdapter().notifyDataSetChanged();
    } catch (Exception e) {
        Log.e(ImApp.LOG_TAG, "error inviting contacts to group", e);
    }
}
Also used : IChatSessionManager(org.awesomeapp.messenger.service.IChatSessionManager) DecoderException(org.apache.commons.codec.DecoderException) XmppAddress(org.awesomeapp.messenger.plugin.xmpp.XmppAddress) IChatSession(org.awesomeapp.messenger.service.IChatSession) DecoderException(org.apache.commons.codec.DecoderException) RemoteException(android.os.RemoteException)

Example 12 with XmppAddress

use of org.awesomeapp.messenger.plugin.xmpp.XmppAddress in project Zom-Android by zom.

the class GroupDisplayActivity method updateMembers.

private synchronized void updateMembers() {
    if (mThreadUpdate != null) {
        mThreadUpdate.interrupt();
        mThreadUpdate = null;
    }
    mThreadUpdate = new Thread(new Runnable() {

        @Override
        public void run() {
            final HashMap<String, GroupMemberDisplay> members = new HashMap<>();
            IContactListManager contactManager = null;
            try {
                if (mConn != null) {
                    contactManager = mConn.getContactListManager();
                }
            } catch (RemoteException re) {
            }
            String[] projection = { Imps.GroupMembers.USERNAME, Imps.GroupMembers.NICKNAME, Imps.GroupMembers.ROLE, Imps.GroupMembers.AFFILIATION };
            Uri memberUri = ContentUris.withAppendedId(Imps.GroupMembers.CONTENT_URI, mLastChatId);
            ContentResolver cr = getContentResolver();
            Cursor c = cr.query(memberUri, projection, null, null, null);
            if (c != null) {
                int colUsername = c.getColumnIndex(Imps.GroupMembers.USERNAME);
                int colNickname = c.getColumnIndex(Imps.GroupMembers.NICKNAME);
                int colRole = c.getColumnIndex(Imps.GroupMembers.ROLE);
                int colAffiliation = c.getColumnIndex(Imps.GroupMembers.AFFILIATION);
                while (c.moveToNext()) {
                    GroupMemberDisplay member = new GroupMemberDisplay();
                    member.username = new XmppAddress(c.getString(colUsername)).getBareAddress();
                    member.nickname = c.getString(colNickname);
                    member.role = c.getString(colRole);
                    member.affiliation = c.getString(colAffiliation);
                    try {
                        member.avatar = DatabaseUtils.getAvatarFromAddress(cr, member.username, ImApp.SMALL_AVATAR_WIDTH, ImApp.SMALL_AVATAR_HEIGHT);
                    } catch (DecoderException e) {
                        e.printStackTrace();
                    }
                    if (member.affiliation != null) {
                        if (member.affiliation.contentEquals("owner") || member.affiliation.contentEquals("admin")) {
                            if (member.username.equals(mLocalAddress))
                                mIsOwner = true;
                        }
                    }
                    members.put(member.username, member);
                }
                c.close();
            }
            if (!Thread.currentThread().isInterrupted()) {
                final ArrayList<GroupMemberDisplay> listMembers = new ArrayList<>(members.values());
                // Sort members by name, but keep owners at the top
                Collections.sort(listMembers, new Comparator<GroupMemberDisplay>() {

                    @Override
                    public int compare(GroupMemberDisplay member1, GroupMemberDisplay member2) {
                        if (member1.affiliation == null || member2.affiliation == null)
                            return 1;
                        boolean member1isImportant = (member1.affiliation.contentEquals("owner") || member1.affiliation.contentEquals("admin"));
                        boolean member2isImportant = (member2.affiliation.contentEquals("owner") || member2.affiliation.contentEquals("admin"));
                        if (member1isImportant != member2isImportant) {
                            if (member1isImportant) {
                                return -1;
                            } else {
                                return 1;
                            }
                        }
                        return member1.nickname.compareTo(member2.nickname);
                    }
                });
                runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        mMembers = listMembers;
                        if (mRecyclerView != null && mRecyclerView.getAdapter() != null)
                            mRecyclerView.getAdapter().notifyDataSetChanged();
                    }
                });
            }
        }
    });
    mThreadUpdate.start();
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor) Uri(android.net.Uri) ContentResolver(android.content.ContentResolver) DecoderException(org.apache.commons.codec.DecoderException) XmppAddress(org.awesomeapp.messenger.plugin.xmpp.XmppAddress) IContactListManager(org.awesomeapp.messenger.service.IContactListManager) RemoteException(android.os.RemoteException)

Example 13 with XmppAddress

use of org.awesomeapp.messenger.plugin.xmpp.XmppAddress in project Zom-Android by zom.

the class MainActivity method startChat.

public void startChat(long providerId, long accountId, String username, final boolean openChat) {
    if (username != null)
        new ChatSessionInitTask(((ImApp) getApplication()), providerId, accountId, Imps.Contacts.TYPE_NORMAL, true) {

            @Override
            protected void onPostExecute(Long chatId) {
                if (chatId != -1 && openChat) {
                    Intent intent = new Intent(MainActivity.this, ConversationDetailActivity.class);
                    intent.putExtra("id", chatId);
                    startActivity(intent);
                }
                super.onPostExecute(chatId);
            }
        }.executeOnExecutor(ImApp.sThreadPoolExecutor, new Contact(new XmppAddress(username)));
}
Also used : ChatSessionInitTask(org.awesomeapp.messenger.tasks.ChatSessionInitTask) XmppAddress(org.awesomeapp.messenger.plugin.xmpp.XmppAddress) Intent(android.content.Intent) Contact(org.awesomeapp.messenger.model.Contact)

Example 14 with XmppAddress

use of org.awesomeapp.messenger.plugin.xmpp.XmppAddress in project Zom-Android by zom.

the class ChatSessionAdapter method inviteContact.

public void inviteContact(String contact) {
    if (!mIsGroupChat) {
        return;
    }
    ContactListManagerAdapter listManager = (ContactListManagerAdapter) mConnection.getContactListManager();
    Contact invitee = new Contact(new XmppAddress(contact), contact, Imps.Contacts.TYPE_NORMAL);
    getGroupManager().inviteUserAsync((ChatGroup) mChatSession.getParticipant(), invitee);
}
Also used : XmppAddress(org.awesomeapp.messenger.plugin.xmpp.XmppAddress) Contact(org.awesomeapp.messenger.model.Contact)

Example 15 with XmppAddress

use of org.awesomeapp.messenger.plugin.xmpp.XmppAddress in project Zom-Android by zom.

the class ChatSessionManagerAdapter method createChatSession.

public IChatSession createChatSession(String contactAddress, boolean isNewSession) {
    ContactListManagerAdapter listManager = (ContactListManagerAdapter) mConnection.getContactListManager();
    Contact contact = listManager.getContactByAddress(Address.stripResource(contactAddress));
    if (contact == null) {
        try {
            contact = new Contact(new XmppAddress(contactAddress), contactAddress, Imps.Contacts.TYPE_NORMAL);
        // long contactId = listManager.queryOrInsertContact(contact);
        // String[] address = {Address.stripResource(contactAddress)};
        // contact = listManager.createTemporaryContacts(address)[0];
        } catch (IllegalArgumentException e) {
            mSessionListenerAdapter.notifyChatSessionCreateFailed(contactAddress, new ImErrorInfo(ImErrorInfo.ILLEGAL_CONTACT_ADDRESS, "Invalid contact address:" + contactAddress));
            return null;
        }
    }
    if (contact != null) {
        ChatSession session = getChatSessionManager().createChatSession(contact, isNewSession);
        return getChatSessionAdapter(session, isNewSession);
    } else
        return null;
}
Also used : XmppAddress(org.awesomeapp.messenger.plugin.xmpp.XmppAddress) IChatSession(org.awesomeapp.messenger.service.IChatSession) ChatSession(org.awesomeapp.messenger.model.ChatSession) Contact(org.awesomeapp.messenger.model.Contact) ImErrorInfo(org.awesomeapp.messenger.model.ImErrorInfo)

Aggregations

XmppAddress (org.awesomeapp.messenger.plugin.xmpp.XmppAddress)17 Contact (org.awesomeapp.messenger.model.Contact)10 RemoteException (android.os.RemoteException)8 IContactListManager (org.awesomeapp.messenger.service.IContactListManager)5 Intent (android.content.Intent)4 IChatSession (org.awesomeapp.messenger.service.IChatSession)4 ChatSessionInitTask (org.awesomeapp.messenger.tasks.ChatSessionInitTask)4 ImApp (org.awesomeapp.messenger.ImApp)3 Activity (android.app.Activity)2 DecoderException (org.apache.commons.codec.DecoderException)2 Address (org.awesomeapp.messenger.model.Address)2 ChatSession (org.awesomeapp.messenger.model.ChatSession)2 IChatSessionManager (org.awesomeapp.messenger.service.IChatSessionManager)2 IImConnection (org.awesomeapp.messenger.service.IImConnection)2 ContentResolver (android.content.ContentResolver)1 Cursor (android.database.Cursor)1 Uri (android.net.Uri)1 View (android.view.View)1 TextView (android.widget.TextView)1 IOException (java.io.IOException)1