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