From c1611c94dc28b14cd67dc132d34f0517a2383154 Mon Sep 17 00:00:00 2001 From: Sylvain Berfini <sylvain.berfini@belledonne-communications.com> Date: Tue, 10 Oct 2023 10:46:53 +0200 Subject: [PATCH] Added a method to only get the conferences info for a given address --- include/linphone/api/c-account.h | 8 +++++++ src/account/account.cpp | 12 ++++++++++ src/account/account.h | 2 ++ src/c-wrapper/api/c-account.cpp | 14 +++++++++++ src/db/main-db.cpp | 41 ++++++++++++++++++++++++++++++++ src/db/main-db.h | 2 ++ 6 files changed, 79 insertions(+) diff --git a/include/linphone/api/c-account.h b/include/linphone/api/c-account.h index 3f9f57b75b..74a9ab5467 100644 --- a/include/linphone/api/c-account.h +++ b/include/linphone/api/c-account.h @@ -301,6 +301,14 @@ LINPHONE_PUBLIC bctbx_list_t *linphone_account_get_call_logs_for_address(const L **/ LINPHONE_PUBLIC void linphone_account_clear_call_logs(const LinphoneAccount *account); +/** + * Returns the list of conference information for a given account. + * This list must be freed after use. + * @param account The #LinphoneAccount object. @notnil + * @return The list of call logs \bctbx_list{LinphoneConferenceInfo}. @tobefreed @maybenil + **/ +LINPHONE_PUBLIC bctbx_list_t *linphone_account_get_conference_information_list(const LinphoneAccount *account); + /** * Detect if the given input is a phone number or not. * @param account The #LinphoneAccount object, unused yet but may contain useful data. Can be NULL. @maybenil diff --git a/src/account/account.cpp b/src/account/account.cpp index 126e0feed0..25769f680d 100644 --- a/src/account/account.cpp +++ b/src/account/account.cpp @@ -890,6 +890,18 @@ void Account::deleteCallLogs() const { mainDb->deleteCallHistoryForLocalAddress(localAddress); } +list<shared_ptr<ConferenceInfo>> Account::getConferenceInfos() const { + if (!mParams) { + lWarning() << "getConferenceInfos is called but no AccountParams is set on Account [" << this->toC() << "]"; + list<shared_ptr<ConferenceInfo>> conferences; + return conferences; + } + + auto localAddress = mParams->mIdentityAddress; + unique_ptr<MainDb> &mainDb = getCore()->getPrivate()->mainDb; + return mainDb->getConferenceInfosForLocalAddress(localAddress); +} + void Account::writeToConfigFile(int index) { if (!mParams) { lWarning() << "writeToConfigFile is called but no AccountParams is set on Account [" << this->toC() << "]"; diff --git a/src/account/account.h b/src/account/account.h index b50971cbe4..4f3218b9c0 100644 --- a/src/account/account.h +++ b/src/account/account.h @@ -27,6 +27,7 @@ #include "c-wrapper/c-wrapper.h" #include "c-wrapper/internal/c-sal.h" #include "call/call-log.h" +#include "conference/conference-info.h" #include "linphone/api/c-types.h" #include "sal/register-op.h" @@ -101,6 +102,7 @@ public: int getMissedCallsCount() const; std::list<std::shared_ptr<CallLog>> getCallLogs() const; std::list<std::shared_ptr<CallLog>> getCallLogsForAddress(const std::shared_ptr<Address>) const; + std::list<std::shared_ptr<ConferenceInfo>> getConferenceInfos() const; // Other void resetMissedCallsCount(); diff --git a/src/c-wrapper/api/c-account.cpp b/src/c-wrapper/api/c-account.cpp index e81000209f..e1facbcc24 100644 --- a/src/c-wrapper/api/c-account.cpp +++ b/src/c-wrapper/api/c-account.cpp @@ -220,6 +220,20 @@ void linphone_account_clear_call_logs(const LinphoneAccount *account) { Account::toCpp(account)->deleteCallLogs(); } +bctbx_list_t *linphone_account_get_conference_information_list(const LinphoneAccount *account) { + AccountLogContextualizer logContextualizer(account); + + bctbx_list_t *results = NULL; + std::list list = Account::toCpp(account)->getConferenceInfos(); + if (!list.empty()) { + for (auto &confInfo : list) { + results = bctbx_list_append(results, linphone_conference_info_ref(confInfo->toC())); + } + } + + return results; +} + void linphone_account_add_callbacks(LinphoneAccount *account, LinphoneAccountCbs *cbs) { Account::toCpp(account)->addCallbacks(AccountCbs::toCpp(cbs)->getSharedFromThis()); } diff --git a/src/db/main-db.cpp b/src/db/main-db.cpp index e96cb9f844..44aac9ee19 100644 --- a/src/db/main-db.cpp +++ b/src/db/main-db.cpp @@ -5448,6 +5448,47 @@ std::list<std::shared_ptr<ConferenceInfo>> MainDb::getConferenceInfos(time_t aft #endif } +std::list<std::shared_ptr<ConferenceInfo>> +MainDb::getConferenceInfosForLocalAddress(const std::shared_ptr<Address> &localAddress) const { +#ifdef HAVE_DB_STORAGE + string query = "SELECT conference_info.id, organizer_sip_address.value, uri_sip_address.value," + " start_time, duration, subject, description, state, ics_sequence, ics_uid, security_level" + " FROM conference_info, sip_address AS organizer_sip_address, sip_address AS uri_sip_address" + " WHERE conference_info.organizer_sip_address_id = organizer_sip_address.id" + " AND conference_info.uri_sip_address_id = uri_sip_address.id" + " AND (conference_info.organizer_sip_address_id = :sipAddressId" + " OR :sipAddressId IN (" + " SELECT participant_sip_address_id FROM conference_info_participant WHERE" + " conference_info_id = conference_info.id" + " ))"; + query += " ORDER BY start_time"; + + DurationLogger durationLogger("Get conference infos for account."); + + return L_DB_TRANSACTION { + L_D(); + + list<shared_ptr<ConferenceInfo>> conferenceInfos; + + const long long &sipAddressId = d->selectSipAddressId(localAddress->toStringUriOnlyOrdered()); + + soci::session *session = d->dbSession.getBackendSession(); + soci::rowset<soci::row> rows = (session->prepare << query, soci::use(sipAddressId)); + + for (const auto &row : rows) { + auto confInfo = d->selectConferenceInfo(row); + conferenceInfos.push_back(confInfo); + } + + tr.commit(); + + return conferenceInfos; + }; +#else + return list<shared_ptr<ConferenceInfo>>(); +#endif +} + std::shared_ptr<ConferenceInfo> MainDb::getConferenceInfo(long long conferenceInfoId) const { #ifdef HAVE_DB_STORAGE static const string query = diff --git a/src/db/main-db.h b/src/db/main-db.h index d7e68835dd..da0ac5d4f4 100644 --- a/src/db/main-db.h +++ b/src/db/main-db.h @@ -209,6 +209,8 @@ public: // --------------------------------------------------------------------------- std::list<std::shared_ptr<ConferenceInfo>> getConferenceInfos(time_t afterThisTime = -1) const; + std::list<std::shared_ptr<ConferenceInfo>> + getConferenceInfosForLocalAddress(const std::shared_ptr<Address> &localAddress) const; std::shared_ptr<ConferenceInfo> getConferenceInfo(long long conferenceInfoId) const; std::shared_ptr<ConferenceInfo> getConferenceInfoFromURI(const std::shared_ptr<Address> &uri) const; long long insertConferenceInfo(const std::shared_ptr<ConferenceInfo> &conferenceInfo); -- GitLab