diff --git a/coreapi/linphonecore.c b/coreapi/linphonecore.c index 92b84d072..156df2ba2 100644 --- a/coreapi/linphonecore.c +++ b/coreapi/linphonecore.c @@ -2284,10 +2284,6 @@ static void _linphone_core_set_platform_helpers(LinphoneCore *lc, LinphonePrivat static void _linphone_core_set_system_context(LinphoneCore *lc, void *system_context){ _linphone_core_set_platform_helpers(lc, LinphonePrivate::createAndroidPlatformHelpers(lc, system_context)); -} -#else -static void _linphone_core_set_system_context(LinphoneCore *lc, void *system_context){ - } #endif diff --git a/include/linphone/utils/utils.h b/include/linphone/utils/utils.h index f8e8a0929..6fea7d5c2 100644 --- a/include/linphone/utils/utils.h +++ b/include/linphone/utils/utils.h @@ -105,8 +105,8 @@ namespace Utils { return object; } - LINPHONE_PUBLIC std::tm getLongAsTm (long time); - LINPHONE_PUBLIC long getTmAsLong (const std::tm &time); + LINPHONE_PUBLIC std::tm getTimeTAsTm (std::time_t time); + LINPHONE_PUBLIC std::time_t getTmAsTimeT (const std::tm &time); } LINPHONE_END_NAMESPACE diff --git a/src/db/main-db.cpp b/src/db/main-db.cpp index 94473a522..895e89dd4 100644 --- a/src/db/main-db.cpp +++ b/src/db/main-db.cpp @@ -70,9 +70,9 @@ MainDb::MainDb (Core *core) : AbstractDb(*new MainDbPrivate) { } static constexpr EnumToSql eventFilterToSql[] = { - { MainDb::ConferenceCallFilter, "1, 2" }, + { MainDb::ConferenceCallFilter, "3, 4" }, { MainDb::ConferenceChatMessageFilter, "5" }, - { MainDb::ConferenceInfoFilter, "3, 4, 6, 7, 8, 9, 10, 11, 12" } + { MainDb::ConferenceInfoFilter, "1, 2, 6, 7, 8, 9, 10, 11, 12" } }; static constexpr const char *mapEventFilterToSql (MainDb::Filter filter) { @@ -375,7 +375,7 @@ MainDb::MainDb (Core *core) : AbstractDb(*new MainDbPrivate) { soci::session *session = dbSession.getBackendSession(); *session << "INSERT INTO event (type, date) VALUES (:type, :date)", - soci::use(static_cast(eventLog->getType())), soci::use(Utils::getLongAsTm(eventLog->getTime())); + soci::use(static_cast(eventLog->getType())), soci::use(Utils::getTimeTAsTm(eventLog->getTime())); return q->getLastInsertId(); } @@ -408,7 +408,7 @@ MainDb::MainDb (Core *core) : AbstractDb(*new MainDbPrivate) { return -1; } - tm eventTime = Utils::getLongAsTm(static_cast(eventLog->getTime())); + tm eventTime = Utils::getTimeTAsTm(eventLog->getTime()); long long localSipAddressId = insertSipAddress(chatMessage->getLocalAddress().asString()); long long remoteSipAddressId = insertSipAddress(chatMessage->getRemoteAddress().asString()); @@ -842,12 +842,45 @@ MainDb::MainDb (Core *core) : AbstractDb(*new MainDbPrivate) { return count; } - list> MainDb::getHistorySinceNotifyId ( + list> MainDb::getConferenceNotifiedEvents ( const string &peerAddress, - unsigned int notifyId + unsigned int lastNotifyId ) { - // TODO. - return list>(); + static const string query = "SELECT id, type, date FROM event" + " WHERE id IN (" + " SELECT event_id FROM conference_notified_event WHERE event_id IN (" + " SELECT event_id FROM conference_event WHERE chat_room_id = (" + " SELECT id FROM sip_address WHERE value = :peerAddress" + " )" + " ) AND notify_id > :lastNotifyId" + " )"; + + L_D(); + + if (!isConnected()) { + lWarning() << "Unable to get conference notified events. Not connected."; + return list>(); + } + + list> events; + + L_BEGIN_LOG_EXCEPTION + + soci::session *session = d->dbSession.getBackendSession(); + soci::transaction tr(*session); + + soci::rowset rows = (session->prepare << query, soci::use(peerAddress), soci::use(lastNotifyId)); + for (const auto &row : rows) + events.push_back(d->selectGenericConferenceEvent( + getBackend() == Sqlite3 ? static_cast(row.get(0)) : row.get(0), + static_cast(row.get(1)), + Utils::getTmAsTimeT(row.get(2)), + peerAddress + )); + + L_END_LOG_EXCEPTION + + return events; } int MainDb::getMessagesCount (const string &peerAddress) const { @@ -969,17 +1002,15 @@ MainDb::MainDb (Core *core) : AbstractDb(*new MainDbPrivate) { soci::transaction tr(*session); soci::rowset rows = (session->prepare << query, soci::use(peerAddress)); - for (const auto &row : rows) { - tm date = row.get(2); + for (const auto &row : rows) events.push_back(d->selectGenericConferenceEvent( // See: http://soci.sourceforge.net/doc/master/backends/ // `row id` is not supported by soci on Sqlite3. It's necessary to cast id to int... getBackend() == Sqlite3 ? static_cast(row.get(0)) : row.get(0), static_cast(row.get(1)), - mktime(&date), + Utils::getTmAsTimeT(row.get(2)), peerAddress )); - } L_END_LOG_EXCEPTION @@ -1022,6 +1053,11 @@ MainDb::MainDb (Core *core) : AbstractDb(*new MainDbPrivate) { L_D(); + if (!isConnected()) { + lWarning() << "Unable to get chat rooms. Not connected."; + return list>(); + } + list> chatRooms; L_BEGIN_LOG_EXCEPTION @@ -1066,16 +1102,27 @@ MainDb::MainDb (Core *core) : AbstractDb(*new MainDbPrivate) { void MainDb::insertChatRoom (const string &peerAddress, int capabilities) { L_D(); + + if (!isConnected()) { + lWarning() << "Unable to insert chat room. Not connected."; + return; + } + d->insertChatRoom( d->insertSipAddress(peerAddress), capabilities, - Utils::getLongAsTm(static_cast(time(0))) + Utils::getTimeTAsTm(time(0)) ); } void MainDb::deleteChatRoom (const string &peerAddress) { L_D(); + if (!isConnected()) { + lWarning() << "Unable to delete chat room. Not connected."; + return; + } + L_BEGIN_LOG_EXCEPTION soci::session *session = d->dbSession.getBackendSession(); @@ -1154,7 +1201,7 @@ MainDb::MainDb (Core *core) : AbstractDb(*new MainDbPrivate) { continue; } - const tm date = Utils::getLongAsTm(message.get(LEGACY_MESSAGE_COL_DATE, 0)); + const tm date = Utils::getTimeTAsTm(message.get(LEGACY_MESSAGE_COL_DATE, 0)); bool isNull; const string url = getValueFromLegacyMessage(message, LEGACY_MESSAGE_COL_URL, isNull); @@ -1259,7 +1306,7 @@ MainDb::MainDb (Core *core) : AbstractDb(*new MainDbPrivate) { return 0; } - list> MainDb::getHistorySinceNotifyId ( + list> MainDb::getConferenceNotifiedEvents ( const string &peerAddress, unsigned int notifyId ) { diff --git a/src/db/main-db.h b/src/db/main-db.h index 71889472b..200d70999 100644 --- a/src/db/main-db.h +++ b/src/db/main-db.h @@ -55,9 +55,9 @@ public: int getEventsCount (FilterMask mask = NoFilter) const; // Messages, calls and conferences. - std::list> getHistorySinceNotifyId ( + std::list> getConferenceNotifiedEvents ( const std::string &peerAddress, - unsigned int notifyId + unsigned int lastNotifyId ); int getMessagesCount (const std::string &peerAddress = "") const; diff --git a/src/utils/utils.cpp b/src/utils/utils.cpp index cfde5c7ac..0013cb2f5 100644 --- a/src/utils/utils.cpp +++ b/src/utils/utils.cpp @@ -173,12 +173,12 @@ char *Utils::utf8ToChar (uint32_t ic) { // ----------------------------------------------------------------------------- -tm Utils::getLongAsTm (long time) { +tm Utils::getTimeTAsTm (time_t time) { tm result; - return *gmtime_r(&static_cast(time), &result); + return *gmtime_r(&time, &result); } -long Utils::getTmAsLong (const tm &time) { +long Utils::getTmAsTimeT (const tm &time) { return timegm(&const_cast(time)); }