Improved isInLinphoneFriendList method in LinphoneContact

This commit is contained in:
Sylvain Berfini 2016-10-13 12:11:56 +02:00
parent a1dc06be96
commit 3ab5835059
3 changed files with 37 additions and 2 deletions

View file

@ -213,6 +213,32 @@ public class ContactsManager extends ContentObserver {
return null;
}
public LinphoneContact findContactFromPhoneNumber(String phoneNumber) {
LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
LinphoneProxyConfig lpc = null;
if (lc != null) {
lpc = lc.getDefaultProxyConfig();
}
for (LinphoneContact c: getContacts()) {
for (LinphoneNumberOrAddress noa: c.getNumbersOrAddresses()) {
if (noa.isSIPAddress()) {
continue;
}
String normalized = null;
if (lpc != null) {
normalized = lpc.normalizePhoneNumber(noa.getValue());
}
if (noa.getValue().equals(phoneNumber) || (normalized != null && normalized.equals(phoneNumber))) {
return c;
}
}
}
return null;
}
public synchronized void setContacts(List<LinphoneContact> c) {
contacts = c;
sipContacts = new ArrayList<LinphoneContact>();

View file

@ -33,6 +33,7 @@ import org.linphone.core.LinphoneCoreFactory;
import org.linphone.core.LinphoneFriend;
import org.linphone.core.LinphoneFriend.SubscribePolicy;
import org.linphone.core.PresenceBasicStatus;
import org.linphone.core.PresenceModel;
import org.linphone.mediastream.Log;
import android.content.ContentProviderOperation;
@ -632,7 +633,14 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
}
public boolean isInLinphoneFriendList() {
return (friend != null && friend.getPresenceModel() != null && friend.getPresenceModel().getBasicStatus().equals(PresenceBasicStatus.Open));
if (friend == null) return false;
for (LinphoneNumberOrAddress noa : addresses) {
PresenceModel pm = friend.getPresenceModelForUri(noa.getValue());
if (pm != null && pm.getBasicStatus().equals(PresenceBasicStatus.Open)) {
return true;
}
}
return false;
}
public String getPresenceModelForUri(String uri) {

View file

@ -470,6 +470,7 @@ public class LinphoneManager implements LinphoneCoreListener, LinphoneChatMessag
// listenerDispatcher.tryingNewOutgoingCallButAlreadyInCall();
// return;
// }
LinphoneAddress lAddress;
try {
lAddress = mLc.interpretUrl(to);