Commit 403053f1 authored by Sylvain Berfini's avatar Sylvain Berfini 🎩

Handle in liblinphone the friend lists subscription setting and automatically...

Handle in liblinphone the friend lists subscription setting and automatically start/stop them depending on background/foreground state
parent 969db615
......@@ -5701,6 +5701,20 @@ LINPHONE_PUBLIC LinphoneFriendList * linphone_core_get_default_friend_list(const
*/
LINPHONE_PUBLIC LinphoneFriendList* linphone_core_get_friend_list_by_name(const LinphoneCore *lc, const char *name);
/**
* Sets whether or not to start friend lists subscription when in foreground
* @param[in] lc The #LinphoneCore
* @param[in] enable whether or not to enable the feature
**/
LINPHONE_PUBLIC void linphone_core_enable_friend_list_subscription(LinphoneCore *lc, bool_t enable);
/**
* Returns whether or not friend lists subscription are enabled
* @param[in] lc The #LinphoneCore
* @return whether or not the feature is enabled
**/
LINPHONE_PUBLIC bool_t linphone_core_is_friend_list_subscription_enabled(LinphoneCore *lc);
/**
* Retrieves a list of #LinphoneAddress sort and filter
* @param[in] lc #LinphoneCore object
......
......@@ -109,3 +109,11 @@ void linphone_core_remove_linphone_spec (LinphoneCore *lc, const char *spec) {
const bctbx_list_t *linphone_core_get_linphone_specs_list (LinphoneCore *lc) {
return L_GET_C_LIST_FROM_CPP_LIST(L_GET_CPP_PTR_FROM_C_OBJECT(lc)->getSpecsList());
}
void linphone_core_enable_friend_list_subscription(LinphoneCore *lc, bool_t enable) {
L_GET_CPP_PTR_FROM_C_OBJECT(lc)->enableFriendListSubscription(enable == TRUE ? true : false);
}
bool_t linphone_core_is_friend_list_subscription_enabled(LinphoneCore *lc) {
return L_GET_CPP_PTR_FROM_C_OBJECT(lc)->isFriendListSubscriptionEnabled() ? TRUE : FALSE;
}
......@@ -48,6 +48,8 @@ public:
void notifyEnteringBackground ();
void notifyEnteringForeground ();
void enableFriendListsSubscription (bool enable);
int addCall (const std::shared_ptr<Call> &call);
bool canWeAddCall () const;
bool hasCalls () const { return !calls.empty(); }
......@@ -87,6 +89,7 @@ public:
private:
bool isInBackground = false;
bool isFriendListSubscriptionEnabled = false;
std::list<CoreListener *> listeners;
......
......@@ -74,7 +74,9 @@ void CorePrivate::init () {
lFatal() << "Unable to open linphone database with uri " << uri << " and backend " << backend;
loadChatRooms();
}else lWarning() << "Database explicitely not requested, this Core is built with no database support.";
} else lWarning() << "Database explicitely not requested, this Core is built with no database support.";
isFriendListSubscriptionEnabled = !!lp_config_get_int(linphone_core_get_config(L_GET_C_BACK_PTR(q)), "net", "friendlist_subscription_enabled", 1);
}
void CorePrivate::registerListener (CoreListener *listener) {
......@@ -131,6 +133,9 @@ void CorePrivate::notifyEnteringBackground () {
auto listenersCopy = listeners; // Allow removable of a listener in its own call
for (const auto &listener : listenersCopy)
listener->onEnteringBackground();
if (isFriendListSubscriptionEnabled)
enableFriendListsSubscription(false);
}
void CorePrivate::notifyEnteringForeground () {
......@@ -141,6 +146,9 @@ void CorePrivate::notifyEnteringForeground () {
auto listenersCopy = listeners; // Allow removable of a listener in its own call
for (const auto &listener : listenersCopy)
listener->onEnteringForeground();
if (isFriendListSubscriptionEnabled)
enableFriendListsSubscription(true);
}
belle_sip_main_loop_t *CorePrivate::getMainLoop(){
......@@ -152,6 +160,17 @@ void CorePrivate::doLater(const std::function<void ()> &something){
belle_sip_main_loop_cpp_do_later(getMainLoop(), something);
}
void CorePrivate::enableFriendListsSubscription(bool enable) {
L_Q();
LinphoneCore *lc = L_GET_C_BACK_PTR(q);
bctbx_list_t *elem;
for (elem = lc->friends_lists; elem != NULL; elem = bctbx_list_next(elem)) {
LinphoneFriendList *list = (LinphoneFriendList *)elem->data;
linphone_friend_list_enable_subscriptions(list, enable);
}
}
// =============================================================================
Core::Core () : Object(*new CorePrivate) {
......@@ -340,6 +359,24 @@ std::string Core::getSpecs() const {
return Utils::join(Utils::toVector(d->specs), ",");
}
// ---------------------------------------------------------------------------
// Friends.
// ---------------------------------------------------------------------------
void Core::enableFriendListSubscription (bool enable) {
L_D();
if (d->isFriendListSubscriptionEnabled != enable) {
d->isFriendListSubscriptionEnabled = enable;
lp_config_set_int(linphone_core_get_config(getCCore()), "net", "friendlist_subscription_enabled", enable ? 1 : 0);
}
d->enableFriendListsSubscription(enable);
}
bool Core::isFriendListSubscriptionEnabled () const {
L_D();
return d->isFriendListSubscriptionEnabled;
}
// -----------------------------------------------------------------------------
// Misc.
// -----------------------------------------------------------------------------
......
......@@ -157,6 +157,13 @@ public:
void setSpecs (const std::string &specs);
std::string getSpecs() const;
// ---------------------------------------------------------------------------
// Friends.
// ---------------------------------------------------------------------------
void enableFriendListSubscription (bool enable);
bool isFriendListSubscriptionEnabled () const;
// ---------------------------------------------------------------------------
// Misc.
// ---------------------------------------------------------------------------
......
......@@ -949,7 +949,7 @@ static void long_term_presence_list(void) {
}else ms_warning("Test skipped, no vcard support");
}
static void long_term_presence_with_e164_phone_without_sip(void) {
static void long_term_presence_with_e164_phone_without_sip_base(bool_t background_foreground_changes) {
if (linphone_core_vcard_supported()){
LinphoneCoreManager *marie = linphone_core_manager_new3("marie_rc", TRUE, random_phone_number());
linphone_core_set_user_agent(marie->lc, "bypass", NULL);
......@@ -966,8 +966,9 @@ static void long_term_presence_with_e164_phone_without_sip(void) {
linphone_friend_add_phone_number(friend2, marie->phone_alias);
linphone_core_add_friend(pauline->lc,friend2);
linphone_friend_list_set_rls_uri(linphone_core_get_default_friend_list(pauline->lc), "sip:rls@sip.example.org");
linphone_friend_list_enable_subscriptions(linphone_core_get_default_friend_list(pauline->lc), TRUE);
LinphoneFriendList *pauline_default_friend_list = linphone_core_get_default_friend_list(pauline->lc);
linphone_friend_list_set_rls_uri(pauline_default_friend_list, "sip:rls@sip.example.org");
linphone_friend_list_enable_subscriptions(pauline_default_friend_list, TRUE);
linphone_core_refresh_registers(pauline->lc);
BC_ASSERT_TRUE(wait_for(pauline->lc,NULL,&pauline->stat.number_of_LinphonePresenceActivityAway,1));
......@@ -980,6 +981,16 @@ static void long_term_presence_with_e164_phone_without_sip(void) {
ms_free(presence_contact);
}
}
if (background_foreground_changes) {
BC_ASSERT_TRUE(linphone_friend_list_subscriptions_enabled(pauline_default_friend_list));
linphone_core_enter_background(pauline->lc);
BC_ASSERT_FALSE(linphone_friend_list_subscriptions_enabled(pauline_default_friend_list));
linphone_core_enter_foreground(pauline->lc);
BC_ASSERT_TRUE(linphone_friend_list_subscriptions_enabled(pauline_default_friend_list));
BC_ASSERT_TRUE(wait_for(pauline->lc,NULL,&pauline->stat.number_of_LinphonePresenceActivityAway,2));
BC_ASSERT_EQUAL(pauline->stat.number_of_LinphonePresenceActivityAway, 2, int, "%d");
}
linphone_friend_unref(friend2);
linphone_core_manager_destroy(pauline);
......@@ -990,6 +1001,14 @@ static void long_term_presence_with_e164_phone_without_sip(void) {
}else ms_warning("Test skipped, no vcard support");
}
static void long_term_presence_with_e164_phone_without_sip(void) {
long_term_presence_with_e164_phone_without_sip_base(FALSE);
}
static void long_term_presence_with_e164_phone_without_sip_background_foreground(void) {
long_term_presence_with_e164_phone_without_sip_base(TRUE);
}
static void long_term_presence_with_phone_without_sip(void) {
if (linphone_core_vcard_supported()){
const LinphoneDialPlan *dialPlan;
......@@ -2376,6 +2395,7 @@ test_t presence_server_tests[] = {
TEST_ONE_TAG("Long term presence phone alias 2",long_term_presence_phone_alias2, "longterm"),
TEST_ONE_TAG("Long term presence list",long_term_presence_list, "longterm"),
TEST_ONE_TAG("Long term presence with +164 phone, without sip",long_term_presence_with_e164_phone_without_sip, "longterm"),
TEST_ONE_TAG("Long term presence with +164 phone, without sip and background/foreground changes", long_term_presence_with_e164_phone_without_sip_background_foreground, "longterm"),
TEST_ONE_TAG("Long term presence with phone, without sip",long_term_presence_with_phone_without_sip, "longterm"),
TEST_ONE_TAG("Long term presence with cross references", long_term_presence_with_crossed_references,"longterm"),
TEST_ONE_TAG("Long term presence with large number of subs", long_term_presence_large_number_of_subs,"longterm"),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment