diff --git a/coreapi/friendlist.c b/coreapi/friendlist.c index 7aa1ff71a..28a85a2ff 100644 --- a/coreapi/friendlist.c +++ b/coreapi/friendlist.c @@ -448,6 +448,10 @@ LinphoneFriendListStatus linphone_friend_list_remove_friend(LinphoneFriendList * return LinphoneFriendListOK; } +const MSList * linphone_friend_list_get_friends(const LinphoneFriendList *list) { + return list->friends; +} + void linphone_friend_list_update_dirty_friends(LinphoneFriendList *list) { LinphoneCardDavContext *cdc = linphone_carddav_context_new(list); MSList *dirty_friends = list->dirty_friends_to_update; diff --git a/coreapi/friendlist.h b/coreapi/friendlist.h index e33ff1a4e..7d907ac61 100644 --- a/coreapi/friendlist.h +++ b/coreapi/friendlist.h @@ -169,6 +169,13 @@ LINPHONE_PUBLIC LinphoneFriendListStatus linphone_friend_list_add_local_friend(L **/ LINPHONE_PUBLIC LinphoneFriendListStatus linphone_friend_list_remove_friend(LinphoneFriendList *list, LinphoneFriend *afriend); +/** + * Retrieves the list of LinphoneFriend from this LinphoneFriendList. + * @param[in] list LinphoneFriendList object + * @return \mslist{LinphoneFriend} a list of LinphoneFriend + */ +LINPHONE_PUBLIC const MSList * linphone_friend_list_get_friends(const LinphoneFriendList *list); + /** * Find a friend in the friend list using a LinphoneAddress. * @param[in] list LinphoneFriendList object. diff --git a/coreapi/linphonecore_jni.cc b/coreapi/linphonecore_jni.cc index 51f3d2132..a7b8a3c52 100644 --- a/coreapi/linphonecore_jni.cc +++ b/coreapi/linphonecore_jni.cc @@ -2089,6 +2089,27 @@ extern "C" jobjectArray Java_org_linphone_core_LinphoneCoreImpl_getFriendList(JN return jFriends; } + +extern "C" jobjectArray Java_org_linphone_core_LinphoneCoreImpl_getFriendLists(JNIEnv* env + ,jobject thiz + ,jlong lc) { + const MSList* friends = linphone_core_get_friends_lists((LinphoneCore*)lc); + int friendsSize = ms_list_size(friends); + LinphoneJavaBindings *ljb = (LinphoneJavaBindings *)linphone_core_get_user_data((LinphoneCore *)lc); + jobjectArray jFriends = env->NewObjectArray(friendsSize,ljb->friendListClass,NULL); + + for (int i = 0; i < friendsSize; i++) { + LinphoneFriendList* lfriend = (LinphoneFriendList*)friends->data; + jobject jfriend = getFriendList(env,lfriend); + if(jfriend != NULL){ + env->SetObjectArrayElement(jFriends, i, jfriend); + } + friends = friends->next; + } + + return jFriends; +} + extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setPresenceInfo(JNIEnv* env ,jobject thiz ,jlong lc @@ -3339,6 +3360,25 @@ extern "C" void Java_org_linphone_core_LinphoneFriendListImpl_addLocalFriend(JNI linphone_friend_list_add_local_friend((LinphoneFriendList*)friendListptr, (LinphoneFriend*)friendPtr); } +extern "C" jobjectArray Java_org_linphone_core_LinphoneFriendListImpl_getFriendList(JNIEnv* env, jobject thiz, jlong list) { + const MSList* friends = linphone_friend_list_get_friends((LinphoneFriendList *)list); + int friendsSize = ms_list_size(friends); + LinphoneCore *lc = linphone_friend_list_get_core((LinphoneFriendList *)list); + LinphoneJavaBindings *ljb = (LinphoneJavaBindings *)linphone_core_get_user_data(lc); + jobjectArray jFriends = env->NewObjectArray(friendsSize,ljb->friendClass,NULL); + + for (int i = 0; i < friendsSize; i++) { + LinphoneFriend* lfriend = (LinphoneFriend*)friends->data; + jobject jfriend = getFriend(env,lfriend); + if(jfriend != NULL){ + env->SetObjectArrayElement(jFriends, i, jfriend); + } + friends = friends->next; + } + + return jFriends; +} + extern "C" void Java_org_linphone_core_LinphoneFriendListImpl_updateSubscriptions(JNIEnv* env ,jobject thiz ,jlong friendListptr diff --git a/java/common/org/linphone/core/LinphoneCore.java b/java/common/org/linphone/core/LinphoneCore.java index 6afcb11b9..d21d316c9 100644 --- a/java/common/org/linphone/core/LinphoneCore.java +++ b/java/common/org/linphone/core/LinphoneCore.java @@ -1020,6 +1020,12 @@ public interface LinphoneCore { */ LinphoneFriend[] getFriendList(); + /** + * Get list of LinphoneFriendList + * @return LinphoneFriendList list + */ + LinphoneFriendList[] getFriendLists(); + /** * @brief Set my presence status * @param minutes_away how long in away diff --git a/java/common/org/linphone/core/LinphoneFriendList.java b/java/common/org/linphone/core/LinphoneFriendList.java index 0e5a46c45..a65f84b48 100644 --- a/java/common/org/linphone/core/LinphoneFriendList.java +++ b/java/common/org/linphone/core/LinphoneFriendList.java @@ -22,6 +22,7 @@ public interface LinphoneFriendList { public void setRLSUri(String uri); public void addFriend(LinphoneFriend friend); public void addLocalFriend(LinphoneFriend friend); + public LinphoneFriend[] getFriendList(); public void updateSubscriptions(LinphoneProxyConfig proxyConfig,boolean onlyWhenRegistered); public LinphoneFriend findFriendByUri(String uri); public void setUri(String uri); diff --git a/java/impl/org/linphone/core/LinphoneCoreImpl.java b/java/impl/org/linphone/core/LinphoneCoreImpl.java index feb0716a6..20c36d164 100644 --- a/java/impl/org/linphone/core/LinphoneCoreImpl.java +++ b/java/impl/org/linphone/core/LinphoneCoreImpl.java @@ -471,6 +471,11 @@ class LinphoneCoreImpl implements LinphoneCore { public synchronized LinphoneFriend[] getFriendList() { return getFriendList(nativePtr); } + + private native LinphoneFriendList[] getFriendLists(long nativePtr); + public synchronized LinphoneFriendList[] getFriendLists() { + return getFriendLists(nativePtr); + } @SuppressWarnings("deprecation") public synchronized void setPresenceInfo(int minutes_away, String alternative_contact, OnlineStatus status) { diff --git a/java/impl/org/linphone/core/LinphoneFriendListImpl.java b/java/impl/org/linphone/core/LinphoneFriendListImpl.java index 4afd20756..abcb7ebb8 100644 --- a/java/impl/org/linphone/core/LinphoneFriendListImpl.java +++ b/java/impl/org/linphone/core/LinphoneFriendListImpl.java @@ -28,6 +28,7 @@ class LinphoneFriendListImpl implements LinphoneFriendList, Serializable { private native void setRLSUri(long nativePtr, String uri); private native void addFriend(long nativePtr, long friendPtr); private native void addLocalFriend(long nativePtr, long friendPtr); + private native LinphoneFriend[] getFriendList(long nativePtr); private native void updateSubscriptions(long nativePtr, long proxyConfigPtr, boolean onlyWhenRegistered); private native Object getCore(long ptr); private native LinphoneFriend findFriendByUri(long nativePtr, String uri); @@ -58,6 +59,13 @@ class LinphoneFriendListImpl implements LinphoneFriendList, Serializable { } } + @Override + public LinphoneFriend[] getFriendList() { + synchronized(getSyncObject()){ + return getFriendList(nativePtr); + } + } + @Override public void updateSubscriptions(LinphoneProxyConfig proxyConfig,boolean onlyWhenRegistered) { synchronized(getSyncObject()){