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) { if (currentFragment == FragmentsAvailable.INFO_GROUP_CHAT && isGoBack) {
getFragmentManager().popBackStackImmediate(); getFragmentManager().popBackStackImmediate();
getFragmentManager().popBackStackImmediate(); getFragmentManager().popBackStackImmediate();
} }
Bundle extras = new Bundle(); Bundle extras = new Bundle();
extras.putSerializable("selectedContacts", selectedContacts); extras.putSerializable("selectedContacts", selectedContacts);
extras.putString("subject", subject);
extras.putString("groupChatRoomAddress", address);
changeCurrentFragment(FragmentsAvailable.CREATE_CHAT, extras); changeCurrentFragment(FragmentsAvailable.CREATE_CHAT, extras);
} }
@ -730,7 +732,11 @@ public class LinphoneActivity extends LinphoneGenericActivity implements OnClick
changeCurrentFragment(FragmentsAvailable.GROUP_CHAT, extras); 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(); Bundle extras = new Bundle();
extras.putString("groupChatRoomAddress", address); extras.putString("groupChatRoomAddress", address);
extras.putBoolean("isEditionEnabled", isEditionEnabled); extras.putBoolean("isEditionEnabled", isEditionEnabled);

View file

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

View file

@ -92,7 +92,7 @@ public class ChatListFragment extends Fragment implements OnItemClickListener, C
mNewDiscussionButton.setOnClickListener(new View.OnClickListener() { mNewDiscussionButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { 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); String displayName = LinphoneUtils.getAddressDisplayName(a);
c.setFullName(displayName); 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); 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.R;
import org.linphone.activities.LinphoneActivity; import org.linphone.activities.LinphoneActivity;
import org.linphone.contacts.ContactAddress; import org.linphone.contacts.ContactAddress;
import org.linphone.contacts.LinphoneContact;
import org.linphone.core.Address; import org.linphone.core.Address;
import org.linphone.core.ChatRoom; import org.linphone.core.ChatRoom;
import org.linphone.core.ChatRoomListenerStub; import org.linphone.core.ChatRoomListenerStub;
import org.linphone.core.Participant;
import org.linphone.mediastream.Log; import org.linphone.mediastream.Log;
import java.util.ArrayList; import java.util.ArrayList;
@ -109,7 +111,7 @@ public class GroupInfoFragment extends Fragment {
if (mIsAlreadyCreatedGroup) { if (mIsAlreadyCreatedGroup) {
getFragmentManager().popBackStack(); getFragmentManager().popBackStack();
} else { } 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() { mAddParticipantsButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { 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); chatRoom.addParticipants(addresses);
} else { } else {
// Subject
String newSubject = mSubjectField.getText().toString(); String newSubject = mSubjectField.getText().toString();
if (!newSubject.equals(mSubject)) { if (!newSubject.equals(mSubject)) {
mChatRoom.setSubject(newSubject); 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()); LinphoneActivity.instance().goToChat(mGroupChatRoomAddress.asString());
} }
} }

View file

@ -73,6 +73,13 @@ public class ContactAddress implements Serializable {
this.isLinphoneContact = isLC; 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 @Override
public boolean equals(Object other){ public boolean equals(Object other){
if (other == null) return false; if (other == null) return false;