Now can add, remove and change admin status of group chat room participants

This commit is contained in:
Sylvain Berfini 2017-11-10 14:17:09 +01:00
parent 24b81aa8b7
commit b4754f0cae
6 changed files with 100 additions and 36 deletions

View file

@ -714,13 +714,15 @@ public class LinphoneActivity extends LinphoneGenericActivity implements OnClick
}
}
public void goToChatCreator(ArrayList<ContactAddress> selectedContacts, boolean isGoBack) {
public void goToChatCreator(String address, ArrayList<ContactAddress> selectedContacts, String subject, boolean isGoBack) {
if (currentFragment == FragmentsAvailable.INFO_GROUP_CHAT && isGoBack) {
getFragmentManager().popBackStackImmediate();
getFragmentManager().popBackStackImmediate();
}
Bundle extras = new Bundle();
extras.putSerializable("selectedContacts", selectedContacts);
extras.putString("subject", subject);
extras.putString("groupChatRoomAddress", address);
changeCurrentFragment(FragmentsAvailable.CREATE_CHAT, extras);
}
@ -730,7 +732,11 @@ public class LinphoneActivity extends LinphoneGenericActivity implements OnClick
changeCurrentFragment(FragmentsAvailable.GROUP_CHAT, extras);
}
public void goToChatGroupInfos(String address, ArrayList<ContactAddress> contacts, String subject, boolean isEditionEnabled) {
public void goToChatGroupInfos(String address, ArrayList<ContactAddress> contacts, String subject, boolean isEditionEnabled, boolean isGoBack) {
if (currentFragment == FragmentsAvailable.CREATE_CHAT && isGoBack) {
getFragmentManager().popBackStackImmediate();
getFragmentManager().popBackStackImmediate();
}
Bundle extras = new Bundle();
extras.putString("groupChatRoomAddress", address);
extras.putBoolean("isEditionEnabled", isEditionEnabled);

View file

@ -66,16 +66,22 @@ public class ChatCreationFragment extends Fragment implements View.OnClickListen
private ProgressBar contactsFetchInProgress;
private SearchContactsListAdapter searchAdapter;
private ImageView back, next;
private String mChatRoomSubject, mChatRoomAddress;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
mInflater = inflater;
View view = inflater.inflate(R.layout.chat_create, container, false);
if (getArguments() != null && getArguments().getSerializable("selectedContacts") != null) {
contactsSelected = (ArrayList<ContactAddress>) getArguments().getSerializable("selectedContacts");
} else {
contactsSelected = new ArrayList<>();
contactsSelected = new ArrayList<>();
mChatRoomSubject = null;
mChatRoomAddress = null;
if (getArguments() != null) {
if (getArguments().getSerializable("selectedContacts") != null) {
contactsSelected = (ArrayList<ContactAddress>) getArguments().getSerializable("selectedContacts");
}
mChatRoomSubject = getArguments().getString("subject");
mChatRoomAddress = getArguments().getString("groupChatRoomAddress");
}
waitLayout = view.findViewById(R.id.waitScreen);
@ -283,34 +289,38 @@ public class ChatCreationFragment extends Fragment implements View.OnClickListen
contactsSelectedLayout.removeAllViews();
LinphoneActivity.instance().popBackStack();
} else if (id == R.id.next) {
if (contactsSelected.size() == 1) {
contactsSelectedLayout.removeAllViews();
waitLayout.setVisibility(View.VISIBLE);
//LinphoneActivity.instance().displayChat(contactsSelected.get(0).getAddress(), "", "");
//TODO create group chat room with only two participants ?
//TODO what subject to set ?
ChatRoom chatRoom = LinphoneManager.getLc().createClientGroupChatRoom(getString(R.string.dummy_group_chat_subject));
chatRoom.setListener(new ChatRoomListenerStub() {
@Override
public void onStateChanged(ChatRoom cr, ChatRoom.State newState) {
if (newState == ChatRoom.State.Created) {
waitLayout.setVisibility(View.GONE);
LinphoneActivity.instance().goToChat(cr.getConferenceAddress().asStringUriOnly());
} else if (newState == ChatRoom.State.CreationFailed) {
waitLayout.setVisibility(View.GONE);
//TODO display error
Log.e("Group chat room for address " + cr.getConferenceAddress() + " has failed !");
if (mChatRoomAddress == null && mChatRoomSubject == null) {
if (contactsSelected.size() == 1) {
contactsSelectedLayout.removeAllViews();
waitLayout.setVisibility(View.VISIBLE);
//LinphoneActivity.instance().displayChat(contactsSelected.get(0).getAddress(), "", "");
//TODO create group chat room with only two participants ?
//TODO what subject to set ?
ChatRoom chatRoom = LinphoneManager.getLc().createClientGroupChatRoom(getString(R.string.dummy_group_chat_subject));
chatRoom.setListener(new ChatRoomListenerStub() {
@Override
public void onStateChanged(ChatRoom cr, ChatRoom.State newState) {
if (newState == ChatRoom.State.Created) {
waitLayout.setVisibility(View.GONE);
LinphoneActivity.instance().goToChat(cr.getConferenceAddress().asStringUriOnly());
} else if (newState == ChatRoom.State.CreationFailed) {
waitLayout.setVisibility(View.GONE);
//TODO display error
Log.e("Group chat room for address " + cr.getConferenceAddress() + " has failed !");
}
}
}
});
});
Address addresses[] = new Address[1];
String addr = contactsSelected.get(0).getAddress();
addresses[0] = LinphoneManager.getLc().interpretUrl(addr);
chatRoom.addParticipants(addresses);
Address addresses[] = new Address[1];
String addr = contactsSelected.get(0).getAddress();
addresses[0] = LinphoneManager.getLc().interpretUrl(addr);
chatRoom.addParticipants(addresses);
} else {
contactsSelectedLayout.removeAllViews();
LinphoneActivity.instance().goToChatGroupInfos(null, contactsSelected, null, true, false);
}
} else {
contactsSelectedLayout.removeAllViews();
LinphoneActivity.instance().goToChatGroupInfos(null, contactsSelected, null, true);
LinphoneActivity.instance().goToChatGroupInfos(mChatRoomAddress, contactsSelected, mChatRoomSubject, true, true);
}
} else if (id == R.id.clearSearchField) {
searchField.setText("");

View file

@ -92,7 +92,7 @@ public class ChatListFragment extends Fragment implements OnItemClickListener, C
mNewDiscussionButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
LinphoneActivity.instance().goToChatCreator(null, false);
LinphoneActivity.instance().goToChatCreator(null, null, null, false);
}
});

View file

@ -149,10 +149,10 @@ public class GroupChatFragment extends Fragment implements ChatRoomListener, Con
String displayName = LinphoneUtils.getAddressDisplayName(a);
c.setFullName(displayName);
}
ContactAddress ca = new ContactAddress(c, a.asString(), c.isFriend());
ContactAddress ca = new ContactAddress(c, a.asString(), c.isFriend(), p.isAdmin());
participants.add(ca);
}
LinphoneActivity.instance().goToChatGroupInfos(mRemoteSipAddress.asString(), participants, mChatRoom.getSubject(), mChatRoom.getMe() != null ? mChatRoom.getMe().isAdmin() : false);
LinphoneActivity.instance().goToChatGroupInfos(mRemoteSipAddress.asString(), participants, mChatRoom.getSubject(), mChatRoom.getMe() != null ? mChatRoom.getMe().isAdmin() : false, false);
}
});

View file

@ -36,9 +36,11 @@ import org.linphone.LinphoneManager;
import org.linphone.R;
import org.linphone.activities.LinphoneActivity;
import org.linphone.contacts.ContactAddress;
import org.linphone.contacts.LinphoneContact;
import org.linphone.core.Address;
import org.linphone.core.ChatRoom;
import org.linphone.core.ChatRoomListenerStub;
import org.linphone.core.Participant;
import org.linphone.mediastream.Log;
import java.util.ArrayList;
@ -109,7 +111,7 @@ public class GroupInfoFragment extends Fragment {
if (mIsAlreadyCreatedGroup) {
getFragmentManager().popBackStack();
} else {
LinphoneActivity.instance().goToChatCreator(mParticipants, true);
LinphoneActivity.instance().goToChatCreator(null, mParticipants, null, true);
}
}
});
@ -134,7 +136,7 @@ public class GroupInfoFragment extends Fragment {
mAddParticipantsButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
LinphoneActivity.instance().goToChatCreator(mParticipants, !mIsAlreadyCreatedGroup);
LinphoneActivity.instance().goToChatCreator(mGroupChatRoomAddress.asString(), mParticipants, mSubject, !mIsAlreadyCreatedGroup);
}
});
@ -185,10 +187,49 @@ public class GroupInfoFragment extends Fragment {
}
chatRoom.addParticipants(addresses);
} else {
// Subject
String newSubject = mSubjectField.getText().toString();
if (!newSubject.equals(mSubject)) {
mChatRoom.setSubject(newSubject);
}
// Participants removed
for (Participant p : mChatRoom.getParticipants()) {
boolean found = false;
for (ContactAddress c : mParticipants) {
if (c.getAddress().equals(p.getAddress().asStringUriOnly())) {
found = true;
break;
}
}
if (!found) {
mChatRoom.removeParticipant(p);
}
}
// Participants added
for (ContactAddress c : mParticipants) {
boolean found = false;
for (Participant p : mChatRoom.getParticipants()) {
if (p.getAddress().asStringUriOnly().equals(c.getAddress())) {
// Admin rights
if (c.isAdmin() != p.isAdmin()) {
mChatRoom.setParticipantAdminStatus(p, c.isAdmin());
}
found = true;
break;
}
}
if (!found) {
Address addr = LinphoneManager.getLc().createAddress(c.getAddress());
if (addr != null) {
mChatRoom.addParticipant(addr);
} else {
//TODO error
}
}
}
LinphoneActivity.instance().goToChat(mGroupChatRoomAddress.asString());
}
}

View file

@ -73,6 +73,13 @@ public class ContactAddress implements Serializable {
this.isLinphoneContact = isLC;
}
public ContactAddress(LinphoneContact c, String a, boolean isLC, boolean isAdmin){
this.contact = c;
this.address = a;
this.isLinphoneContact = isLC;
this.isAdmin = isAdmin;
}
@Override
public boolean equals(Object other){
if (other == null) return false;