private void init(ChatGroup group, boolean isNewSession) { mIsGroupChat = true; mContactId = insertOrUpdateGroupContactInDb(group); group.addMemberListener(mListenerAdapter); try { mChatSessionManager .getChatGroupManager() .joinChatGroupAsync(group.getAddress(), group.getName()); mMessageURI = Imps.Messages.getContentUriByThreadId(mContactId); mChatURI = ContentUris.withAppendedId(Imps.Chats.CONTENT_URI, mContactId); if (isNewSession) insertOrUpdateChat(""); for (Contact c : group.getMembers()) { mContactStatusMap.put(c.getName(), c.getPresence().getStatus()); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }
public void onMemberJoined(ChatGroup group, Contact contact) { if (mChatSession.getParticipant().equals(contact)) { onConvertToGroupChatSuccess(group); } mContactStatusMap.put(contact.getName(), contact.getPresence().getStatus()); }
private void init(Contact contact, boolean isNewSession) { mIsGroupChat = false; ContactListManagerAdapter listManager = (ContactListManagerAdapter) mConnection.getContactListManager(); mContactId = listManager.queryOrInsertContact(contact); mChatURI = ContentUris.withAppendedId(Imps.Chats.CONTENT_URI, mContactId); if (isNewSession) insertOrUpdateChat(null); mMessageURI = Imps.Messages.getContentUriByThreadId(mContactId); mContactStatusMap.put(contact.getName(), contact.getPresence().getStatus()); }
void insertGroupMemberInDb(Contact member) { if (mChatURI != null) { ContentValues values1 = new ContentValues(2); values1.put(Imps.GroupMembers.USERNAME, member.getAddress().getAddress()); values1.put(Imps.GroupMembers.NICKNAME, member.getName()); ContentValues values = values1; long groupId = ContentUris.parseId(mChatURI); Uri uri = ContentUris.withAppendedId(Imps.GroupMembers.CONTENT_URI, groupId); mContentResolver.insert(uri, values); // insertMessageInDb(member.getName(), null, System.currentTimeMillis(), // Imps.MessageType.PRESENCE_AVAILABLE); } }
private long insertOrUpdateGroupContactInDb(ChatGroup group) { // Insert a record in contacts table ContentValues values = new ContentValues(4); values.put(Imps.Contacts.USERNAME, group.getAddress().getAddress()); values.put(Imps.Contacts.NICKNAME, group.getName()); values.put(Imps.Contacts.CONTACTLIST, ContactListManagerAdapter.LOCAL_GROUP_LIST_ID); values.put(Imps.Contacts.TYPE, Imps.Contacts.TYPE_GROUP); Uri contactUri = ContentUris.withAppendedId( ContentUris.withAppendedId(Imps.Contacts.CONTENT_URI, mConnection.mProviderId), mConnection.mAccountId); ContactListManagerAdapter listManager = (ContactListManagerAdapter) mConnection.getContactListManager(); long id = listManager.queryGroup(group); if (id == -1) { id = ContentUris.parseId(mContentResolver.insert(contactUri, values)); ArrayList<ContentValues> memberValues = new ArrayList<ContentValues>(); Contact self = mConnection.getLoginUser(); for (Contact member : group.getMembers()) { if (!member.equals(self)) { // avoid to insert the user himself ContentValues memberValue = new ContentValues(2); memberValue.put(Imps.GroupMembers.USERNAME, member.getAddress().getAddress()); memberValue.put(Imps.GroupMembers.NICKNAME, member.getName()); memberValues.add(memberValue); } } if (!memberValues.isEmpty()) { ContentValues[] result = new ContentValues[memberValues.size()]; memberValues.toArray(result); Uri memberUri = ContentUris.withAppendedId(Imps.GroupMembers.CONTENT_URI, id); mContentResolver.bulkInsert(memberUri, result); } } return id; }
public void onMemberLeft(ChatGroup group, Contact contact) { mContactStatusMap.remove(contact.getName()); }