Fixed issue when using two or more accounts and have 2 basic chat rooms with the same person, can't go to one of the two no matter which one is clicked

This commit is contained in:
Sylvain Berfini 2018-10-25 16:07:35 +02:00
parent 6a2a652957
commit 4c4ad79fd6
10 changed files with 56 additions and 35 deletions

View file

@ -1079,16 +1079,16 @@ public class LinphoneManager implements CoreListener, SensorEventListener, Accou
if (!mServiceContext.getResources().getBoolean(R.bool.disable_chat_message_notification) && !message.isOutgoing()) {
if (cr.hasCapability(ChatRoomCapabilities.OneToOne.toInt())) {
if (contact != null) {
LinphoneService.instance().displayMessageNotification(cr.getPeerAddress().asStringUriOnly(), contact.getFullName(), contact.getThumbnailUri(), textMessage);
LinphoneService.instance().displayMessageNotification(cr.getPeerAddress().asStringUriOnly(), contact.getFullName(), contact.getThumbnailUri(), textMessage, cr.getLocalAddress().asString());
} else {
LinphoneService.instance().displayMessageNotification(cr.getPeerAddress().asStringUriOnly(), from.getUsername(), null, textMessage);
LinphoneService.instance().displayMessageNotification(cr.getPeerAddress().asStringUriOnly(), from.getUsername(), null, textMessage, cr.getLocalAddress().asString());
}
} else {
String subject = cr.getSubject();
if (contact != null) {
LinphoneService.instance().displayGroupChatMessageNotification(subject, cr.getPeerAddress().asStringUriOnly(), contact.getFullName(), contact.getThumbnailUri(), textMessage);
LinphoneService.instance().displayGroupChatMessageNotification(subject, cr.getPeerAddress().asStringUriOnly(), contact.getFullName(), contact.getThumbnailUri(), textMessage, cr.getLocalAddress().asString());
} else {
LinphoneService.instance().displayGroupChatMessageNotification(subject, cr.getPeerAddress().asStringUriOnly(), from.getUsername(), null, textMessage);
LinphoneService.instance().displayGroupChatMessageNotification(subject, cr.getPeerAddress().asStringUriOnly(), from.getUsername(), null, textMessage, cr.getLocalAddress().asString());
}
}
}

View file

@ -624,10 +624,11 @@ public final class LinphoneService extends Service {
notifyWrapper(CUSTOM_NOTIF_ID, mCustomNotif);
}
public void displayGroupChatMessageNotification(String subject, String conferenceAddress, String fromName, Uri fromPictureUri, String message) {
public void displayGroupChatMessageNotification(String subject, String conferenceAddress, String fromName, Uri fromPictureUri, String message, String localIdentity) {
Intent notifIntent = new Intent(this, LinphoneActivity.class);
notifIntent.putExtra("GoToChat", true);
notifIntent.putExtra("ChatContactSipUri", conferenceAddress);
notifIntent.putExtra("LocalIdentity", localIdentity);
PendingIntent notifContentIntent = PendingIntent.getActivity(this, 0, notifIntent, PendingIntent.FLAG_UPDATE_CURRENT);
@ -658,11 +659,11 @@ public final class LinphoneService extends Service {
notifyWrapper(notif.notificationId, notification);
}
public void displayMessageNotification(String fromSipUri, String fromName, Uri fromPictureUri, String message) {
public void displayMessageNotification(String fromSipUri, String fromName, Uri fromPictureUri, String message, String localIdentity) {
Intent notifIntent = new Intent(this, LinphoneActivity.class);
notifIntent.putExtra("GoToChat", true);
notifIntent.putExtra("ChatContactSipUri", fromSipUri);
notifIntent.putExtra("LocalIdentity", localIdentity);
PendingIntent notifContentIntent = PendingIntent.getActivity(this, 0, notifIntent, PendingIntent.FLAG_UPDATE_CURRENT);
if (fromName == null) {

View file

@ -125,7 +125,6 @@ public class LinphoneActivity extends LinphoneGenericActivity implements OnClick
private static final int CALL_ACTIVITY = 19;
private static final int PERMISSIONS_REQUEST_OVERLAY = 206;
private static final int PERMISSIONS_REQUEST_SYNC = 207;
private static final int PERMISSIONS_REQUEST_CONTACTS = 208;
private static final int PERMISSIONS_RECORD_AUDIO_ECHO_CANCELLER = 209;
private static final int PERMISSIONS_READ_EXTERNAL_STORAGE_DEVICE_RINGTONE = 210;
private static final int PERMISSIONS_RECORD_AUDIO_ECHO_TESTER = 211;
@ -699,9 +698,10 @@ public class LinphoneActivity extends LinphoneGenericActivity implements OnClick
changeCurrentFragment(FragmentsAvailable.CREATE_CHAT, extras);
}
public void goToChat(String sipUri, Bundle shareInfos) {
public void goToChat(String sipUri, Bundle shareInfos, String localIdentity) {
Bundle extras = new Bundle();
extras.putString("SipUri", sipUri);
extras.putString("LocalIdentity", localIdentity);
if (shareInfos != null) {
if (shareInfos.getString("fileSharedUri") != null)
@ -1455,11 +1455,12 @@ public class LinphoneActivity extends LinphoneGenericActivity implements OnClick
Bundle extras = intent.getExtras();
if (extras != null && extras.getBoolean("GoToChat", false)) {
String sipUri = extras.getString("ChatContactSipUri");
String localIdentity = extras.getString("LocalIdentity");
intent.putExtra("DoNotGoToCallActivity", true);
if (sipUri == null) {
goToChatList();
} else {
displayChat(sipUri, null, null);
goToChat(sipUri, extras, localIdentity);
}
} else if (extras != null && extras.getBoolean("GoToHistory", false)) {
intent.putExtra("DoNotGoToCallActivity", true);

View file

@ -185,7 +185,7 @@ public class ChatCreationFragment extends Fragment implements View.OnClickListen
public void onStateChanged(ChatRoom cr, ChatRoom.State newState) {
if (newState == ChatRoom.State.Created) {
mWaitLayout.setVisibility(View.GONE);
LinphoneActivity.instance().goToChat(cr.getPeerAddress().asStringUriOnly(), mShareInfos);
LinphoneActivity.instance().goToChat(cr.getPeerAddress().asStringUriOnly(), mShareInfos, cr.getLocalAddress().asString());
} else if (newState == ChatRoom.State.CreationFailed) {
mWaitLayout.setVisibility(View.GONE);
LinphoneActivity.instance().displayChatRoomError();
@ -414,10 +414,10 @@ public class ChatCreationFragment extends Fragment implements View.OnClickListen
mChatRoom.addParticipant(participant);
} else {
chatRoom = lc.getChatRoom(participant);
LinphoneActivity.instance().goToChat(chatRoom.getPeerAddress().asStringUriOnly(), mShareInfos);
LinphoneActivity.instance().goToChat(chatRoom.getPeerAddress().asStringUriOnly(), mShareInfos, participant.asString());
}
} else {
LinphoneActivity.instance().goToChat(chatRoom.getPeerAddress().asStringUriOnly(), mShareInfos);
LinphoneActivity.instance().goToChat(chatRoom.getPeerAddress().asStringUriOnly(), mShareInfos, participant.asString());
}
} else {
mContactsSelectedLayout.removeAllViews();
@ -442,7 +442,7 @@ public class ChatCreationFragment extends Fragment implements View.OnClickListen
ProxyConfig lpc = lc.getDefaultProxyConfig();
if (lpc == null || lpc.getConferenceFactoryUri() == null) {
ChatRoom chatRoom = lc.getChatRoom(ca.getAddress());
LinphoneActivity.instance().goToChat(chatRoom.getPeerAddress().asStringUriOnly(), mShareInfos);
LinphoneActivity.instance().goToChat(chatRoom.getPeerAddress().asStringUriOnly(), mShareInfos, chatRoom.getLocalAddress().asString());
} else {
removeContactFromSelection(ca);
}

View file

@ -43,6 +43,7 @@ import org.linphone.core.Core;
import org.linphone.core.CoreListenerStub;
import org.linphone.core.EventLog;
import org.linphone.fragments.FragmentsAvailable;
import org.linphone.mediastream.Log;
import org.linphone.ui.SelectableHelper;
import java.io.File;
@ -151,7 +152,7 @@ public class ChatListFragment extends Fragment implements ContactsUpdatedListene
mChatRoomsAdapter.toggleSelection(position);
} else {
ChatRoom room = (ChatRoom) mChatRoomsAdapter.getItem(position);
LinphoneActivity.instance().goToChat(room.getPeerAddress().asString(), null);
LinphoneActivity.instance().goToChat(room.getPeerAddress().asString(), null, room.getLocalAddress().asString());
}
}
@ -173,7 +174,7 @@ public class ChatListFragment extends Fragment implements ContactsUpdatedListene
ChatRoomsAdapter adapter = (ChatRoomsAdapter) mChatRoomsList.getAdapter();
if (adapter != null && adapter.getItemCount() > 0) {
ChatRoom room = (ChatRoom) adapter.getItem(0);
LinphoneActivity.instance().goToChat(room.getPeerAddress().asStringUriOnly(), null);
LinphoneActivity.instance().goToChat(room.getPeerAddress().asStringUriOnly(), null, room.getLocalAddress().asString());
} else {
LinphoneActivity.instance().displayEmptyFragment();
}

View file

@ -105,7 +105,7 @@ public class GroupChatFragment extends Fragment implements ChatRoomListener, Con
private Uri mImageToUploadUri;
private ChatEventsAdapter mEventsAdapter;
private String mRemoteSipUri;
private Address mRemoteSipAddress, mRemoteParticipantAddress;
private Address mRemoteSipAddress, mRemoteParticipantAddress, mLocalIdentityAddress;
private ChatRoom mChatRoom;
private ArrayList<LinphoneContact> mParticipants;
private LinearLayoutManager layoutManager;
@ -119,10 +119,16 @@ public class GroupChatFragment extends Fragment implements ChatRoomListener, Con
// Retain the fragment across configuration changes
setRetainInstance(true);
if (getArguments() != null && getArguments().getString("SipUri") != null) {
if (getArguments() != null) {
if (getArguments().getString("SipUri") != null) {
mRemoteSipUri = getArguments().getString("SipUri");
mRemoteSipAddress = LinphoneManager.getLc().createAddress(mRemoteSipUri);
}
if (getArguments().getString("LocalIdentity") != null) {
String localIdentity = getArguments().getString("LocalIdentity");
mLocalIdentityAddress = LinphoneManager.getLc().createAddress(localIdentity);
}
}
mContext = getActivity().getApplicationContext();
mInflater = inflater;
@ -541,13 +547,19 @@ public class GroupChatFragment extends Fragment implements ChatRoomListener, Con
//TODO error
return;
}
Address proxyConfigContact = (core.getDefaultProxyConfig() != null) ? core.getDefaultProxyConfig().getContact() : null;
Address proxyConfigContact = mLocalIdentityAddress;
if (proxyConfigContact == null) {
proxyConfigContact = core.getDefaultProxyConfig() != null ? core.getDefaultProxyConfig().getContact() : null;
}
if (proxyConfigContact != null) {
mChatRoom = core.findOneToOneChatRoom(proxyConfigContact, mRemoteSipAddress);
}
if (mChatRoom == null) {
mChatRoom = core.getChatRoomFromUri(mRemoteSipAddress.asStringUriOnly());
}
mChatRoom.addListener(this);
mChatRoom.markAsRead();
LinphoneManager.getInstance().updateUnreadCountForChatRoom(mChatRoom, 0);
@ -594,10 +606,16 @@ public class GroupChatFragment extends Fragment implements ChatRoomListener, Con
if (mChatRoom.hasBeenLeft()) {
setReadOnly();
}
if (mChatRoom.hasCapability(ChatRoomCapabilities.Basic.toInt())) {
mChatRoomSecurityLevel.setVisibility(View.GONE);
} else {
//TODO
//mChatRoomSecurityLevel.setImageResource();
}
}
private void displayChatRoomHistory() {
if (mChatRoom == null) return;
if (mChatRoom.hasCapability(ChatRoomCapabilities.OneToOne.toInt())) {
mEventsAdapter = new ChatEventsAdapter(this, mSelectionHelper, R.layout.chat_bubble, mChatRoom.getHistoryMessageEvents(MESSAGES_PER_PAGE), mParticipants, this);
@ -820,10 +838,10 @@ public class GroupChatFragment extends Fragment implements ChatRoomListener, Con
if (!getResources().getBoolean(R.bool.disable_chat_message_notification)) {
if (contact != null) {
LinphoneService.instance().displayMessageNotification(from.asStringUriOnly(),
contact.getFullName(), contact.getThumbnailUri(), getString(R.string.message_cant_be_decrypted_notif));
contact.getFullName(), contact.getThumbnailUri(), getString(R.string.message_cant_be_decrypted_notif), cr.getLocalAddress().asString());
} else {
LinphoneService.instance().displayMessageNotification(from.asStringUriOnly(),
from.getUsername(), null, getString(R.string.message_cant_be_decrypted_notif));
from.getUsername(), null, getString(R.string.message_cant_be_decrypted_notif), cr.getLocalAddress().asString());
}
}
} else if (LinphoneManager.getLc().limeEnabled() == LimeState.Mandatory) {

View file

@ -155,7 +155,7 @@ public class GroupInfoFragment extends Fragment implements ChatRoomListener {
public void onClick(View view) {
if (mIsAlreadyCreatedGroup) {
if (LinphoneActivity.instance().isTablet()) {
LinphoneActivity.instance().goToChat(mGroupChatRoomAddress.asStringUriOnly(), mShareInfos);
LinphoneActivity.instance().goToChat(mGroupChatRoomAddress.asStringUriOnly(), mShareInfos, mChatRoom.getLocalAddress().asString());
} else {
getFragmentManager().popBackStack();
}
@ -181,7 +181,7 @@ public class GroupInfoFragment extends Fragment implements ChatRoomListener {
public void onClick(View view) {
if (mChatRoom != null) {
mChatRoom.leave();
LinphoneActivity.instance().goToChat(mGroupChatRoomAddress.asString(), null);
LinphoneActivity.instance().goToChat(mGroupChatRoomAddress.asString(), null, mChatRoom.getLocalAddress().asString());
} else {
Log.e("Can't leave, chatRoom for address " + mGroupChatRoomAddress.asString() + " is null...");
}
@ -244,7 +244,7 @@ public class GroupInfoFragment extends Fragment implements ChatRoomListener {
// This will remove both the creation fragment and the group info fragment from the back stack
getFragmentManager().popBackStack();
getFragmentManager().popBackStack();
LinphoneActivity.instance().goToChat(cr.getPeerAddress().asStringUriOnly(), mShareInfos);
LinphoneActivity.instance().goToChat(cr.getPeerAddress().asStringUriOnly(), mShareInfos, cr.getLocalAddress().asString());
} else if (newState == ChatRoom.State.CreationFailed) {
mWaitLayout.setVisibility(View.GONE);
LinphoneActivity.instance().displayChatRoomError();
@ -320,7 +320,7 @@ public class GroupInfoFragment extends Fragment implements ChatRoomListener {
toAdd.toArray(participantsToAdd);
mChatRoom.addParticipants(participantsToAdd);
LinphoneActivity.instance().goToChat(mGroupChatRoomAddress.asString(), null);
LinphoneActivity.instance().goToChat(mGroupChatRoomAddress.asString(), null, mChatRoom.getLocalAddress().asString());
}
}
});

View file

@ -87,7 +87,7 @@ public class ImdnFragment extends Fragment {
@Override
public void onClick(View view) {
if (LinphoneActivity.instance().isTablet()) {
LinphoneActivity.instance().goToChat(mRoomUri, null);
LinphoneActivity.instance().goToChat(mRoomUri, null, mRoom.getLocalAddress().asString());
} else {
LinphoneActivity.instance().onBackPressed();
}

View file

@ -81,7 +81,7 @@ public class ContactDetailsFragment extends Fragment implements OnClickListener
if (defaultProxyConfig != null) {
ChatRoom room = lc.findOneToOneChatRoom(defaultProxyConfig.getContact(), participant);
if (room != null) {
LinphoneActivity.instance().goToChat(room.getPeerAddress().asStringUriOnly(), null);
LinphoneActivity.instance().goToChat(room.getPeerAddress().asStringUriOnly(), null, room.getLocalAddress().asString());
} else {
if (defaultProxyConfig.getConferenceFactoryUri() != null && !LinphonePreferences.instance().useBasicChatRoomFor1To1()) {
mWaitLayout.setVisibility(View.VISIBLE);
@ -90,7 +90,7 @@ public class ContactDetailsFragment extends Fragment implements OnClickListener
mChatRoom.addParticipant(participant);
} else {
room = lc.getChatRoom(participant);
LinphoneActivity.instance().goToChat(room.getPeerAddress().asStringUriOnly(), null);
LinphoneActivity.instance().goToChat(room.getPeerAddress().asStringUriOnly(), null, room.getLocalAddress().asString());
}
}
}
@ -138,7 +138,7 @@ public class ContactDetailsFragment extends Fragment implements OnClickListener
public void onStateChanged(ChatRoom cr, ChatRoom.State newState) {
if (newState == ChatRoom.State.Created) {
mWaitLayout.setVisibility(View.GONE);
LinphoneActivity.instance().goToChat(cr.getPeerAddress().asStringUriOnly(), null);
LinphoneActivity.instance().goToChat(cr.getPeerAddress().asStringUriOnly(), null, cr.getLocalAddress().asString());
} else if (newState == ChatRoom.State.CreationFailed) {
mWaitLayout.setVisibility(View.GONE);
LinphoneActivity.instance().displayChatRoomError();

View file

@ -109,7 +109,7 @@ public class HistoryDetailFragment extends Fragment implements OnClickListener {
public void onStateChanged(ChatRoom cr, ChatRoom.State newState) {
if (newState == ChatRoom.State.Created) {
mWaitLayout.setVisibility(View.GONE);
LinphoneActivity.instance().goToChat(cr.getPeerAddress().asStringUriOnly(), null);
LinphoneActivity.instance().goToChat(cr.getPeerAddress().asStringUriOnly(), null, cr.getLocalAddress().asString());
} else if (newState == ChatRoom.State.CreationFailed) {
mWaitLayout.setVisibility(View.GONE);
LinphoneActivity.instance().displayChatRoomError();
@ -199,7 +199,7 @@ public class HistoryDetailFragment extends Fragment implements OnClickListener {
Address participant = Factory.instance().createAddress(sipUri);
ChatRoom room = lc.findOneToOneChatRoom(lc.getDefaultProxyConfig().getContact(), participant);
if (room != null) {
LinphoneActivity.instance().goToChat(room.getPeerAddress().asStringUriOnly(), null);
LinphoneActivity.instance().goToChat(room.getPeerAddress().asStringUriOnly(), null, room.getLocalAddress().asString());
} else {
ProxyConfig lpc = lc.getDefaultProxyConfig();
if (lpc != null && lpc.getConferenceFactoryUri() != null && !LinphonePreferences.instance().useBasicChatRoomFor1To1()) {
@ -209,7 +209,7 @@ public class HistoryDetailFragment extends Fragment implements OnClickListener {
mChatRoom.addParticipant(participant);
} else {
room = lc.getChatRoom(participant);
LinphoneActivity.instance().goToChat(room.getPeerAddress().asStringUriOnly(), null);
LinphoneActivity.instance().goToChat(room.getPeerAddress().asStringUriOnly(), null, room.getLocalAddress().asString());
}
}
} else if (id == R.id.add_contact) {