Commit 54e0f253 authored by Ronan's avatar Ronan

feat(MainDb): add getConferenceNotifiedEvents impl

parent a100df85
...@@ -2284,10 +2284,6 @@ static void _linphone_core_set_platform_helpers(LinphoneCore *lc, LinphonePrivat ...@@ -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){ static void _linphone_core_set_system_context(LinphoneCore *lc, void *system_context){
_linphone_core_set_platform_helpers(lc, LinphonePrivate::createAndroidPlatformHelpers(lc, 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 #endif
......
...@@ -105,8 +105,8 @@ namespace Utils { ...@@ -105,8 +105,8 @@ namespace Utils {
return object; return object;
} }
LINPHONE_PUBLIC std::tm getLongAsTm (long time); LINPHONE_PUBLIC std::tm getTimeTAsTm (std::time_t time);
LINPHONE_PUBLIC long getTmAsLong (const std::tm &time); LINPHONE_PUBLIC std::time_t getTmAsTimeT (const std::tm &time);
} }
LINPHONE_END_NAMESPACE LINPHONE_END_NAMESPACE
......
...@@ -70,9 +70,9 @@ MainDb::MainDb (Core *core) : AbstractDb(*new MainDbPrivate) { ...@@ -70,9 +70,9 @@ MainDb::MainDb (Core *core) : AbstractDb(*new MainDbPrivate) {
} }
static constexpr EnumToSql<MainDb::Filter> eventFilterToSql[] = { static constexpr EnumToSql<MainDb::Filter> eventFilterToSql[] = {
{ MainDb::ConferenceCallFilter, "1, 2" }, { MainDb::ConferenceCallFilter, "3, 4" },
{ MainDb::ConferenceChatMessageFilter, "5" }, { 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) { static constexpr const char *mapEventFilterToSql (MainDb::Filter filter) {
...@@ -375,7 +375,7 @@ MainDb::MainDb (Core *core) : AbstractDb(*new MainDbPrivate) { ...@@ -375,7 +375,7 @@ MainDb::MainDb (Core *core) : AbstractDb(*new MainDbPrivate) {
soci::session *session = dbSession.getBackendSession<soci::session>(); soci::session *session = dbSession.getBackendSession<soci::session>();
*session << "INSERT INTO event (type, date) VALUES (:type, :date)", *session << "INSERT INTO event (type, date) VALUES (:type, :date)",
soci::use(static_cast<int>(eventLog->getType())), soci::use(Utils::getLongAsTm(eventLog->getTime())); soci::use(static_cast<int>(eventLog->getType())), soci::use(Utils::getTimeTAsTm(eventLog->getTime()));
return q->getLastInsertId(); return q->getLastInsertId();
} }
...@@ -408,7 +408,7 @@ MainDb::MainDb (Core *core) : AbstractDb(*new MainDbPrivate) { ...@@ -408,7 +408,7 @@ MainDb::MainDb (Core *core) : AbstractDb(*new MainDbPrivate) {
return -1; return -1;
} }
tm eventTime = Utils::getLongAsTm(static_cast<long>(eventLog->getTime())); tm eventTime = Utils::getTimeTAsTm(eventLog->getTime());
long long localSipAddressId = insertSipAddress(chatMessage->getLocalAddress().asString()); long long localSipAddressId = insertSipAddress(chatMessage->getLocalAddress().asString());
long long remoteSipAddressId = insertSipAddress(chatMessage->getRemoteAddress().asString()); long long remoteSipAddressId = insertSipAddress(chatMessage->getRemoteAddress().asString());
...@@ -842,12 +842,45 @@ MainDb::MainDb (Core *core) : AbstractDb(*new MainDbPrivate) { ...@@ -842,12 +842,45 @@ MainDb::MainDb (Core *core) : AbstractDb(*new MainDbPrivate) {
return count; return count;
} }
list<shared_ptr<EventLog>> MainDb::getHistorySinceNotifyId ( list<shared_ptr<EventLog>> MainDb::getConferenceNotifiedEvents (
const string &peerAddress, const string &peerAddress,
unsigned int notifyId unsigned int lastNotifyId
) { ) {
// TODO. static const string query = "SELECT id, type, date FROM event"
return list<shared_ptr<EventLog>>(); " 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<shared_ptr<EventLog>>();
}
list<shared_ptr<EventLog>> events;
L_BEGIN_LOG_EXCEPTION
soci::session *session = d->dbSession.getBackendSession<soci::session>();
soci::transaction tr(*session);
soci::rowset<soci::row> rows = (session->prepare << query, soci::use(peerAddress), soci::use(lastNotifyId));
for (const auto &row : rows)
events.push_back(d->selectGenericConferenceEvent(
getBackend() == Sqlite3 ? static_cast<long long>(row.get<int>(0)) : row.get<long long>(0),
static_cast<EventLog::Type>(row.get<int>(1)),
Utils::getTmAsTimeT(row.get<tm>(2)),
peerAddress
));
L_END_LOG_EXCEPTION
return events;
} }
int MainDb::getMessagesCount (const string &peerAddress) const { int MainDb::getMessagesCount (const string &peerAddress) const {
...@@ -969,17 +1002,15 @@ MainDb::MainDb (Core *core) : AbstractDb(*new MainDbPrivate) { ...@@ -969,17 +1002,15 @@ MainDb::MainDb (Core *core) : AbstractDb(*new MainDbPrivate) {
soci::transaction tr(*session); soci::transaction tr(*session);
soci::rowset<soci::row> rows = (session->prepare << query, soci::use(peerAddress)); soci::rowset<soci::row> rows = (session->prepare << query, soci::use(peerAddress));
for (const auto &row : rows) { for (const auto &row : rows)
tm date = row.get<tm>(2);
events.push_back(d->selectGenericConferenceEvent( events.push_back(d->selectGenericConferenceEvent(
// See: http://soci.sourceforge.net/doc/master/backends/ // 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... // `row id` is not supported by soci on Sqlite3. It's necessary to cast id to int...
getBackend() == Sqlite3 ? static_cast<long long>(row.get<int>(0)) : row.get<long long>(0), getBackend() == Sqlite3 ? static_cast<long long>(row.get<int>(0)) : row.get<long long>(0),
static_cast<EventLog::Type>(row.get<int>(1)), static_cast<EventLog::Type>(row.get<int>(1)),
mktime(&date), Utils::getTmAsTimeT(row.get<tm>(2)),
peerAddress peerAddress
)); ));
}
L_END_LOG_EXCEPTION L_END_LOG_EXCEPTION
...@@ -1022,6 +1053,11 @@ MainDb::MainDb (Core *core) : AbstractDb(*new MainDbPrivate) { ...@@ -1022,6 +1053,11 @@ MainDb::MainDb (Core *core) : AbstractDb(*new MainDbPrivate) {
L_D(); L_D();
if (!isConnected()) {
lWarning() << "Unable to get chat rooms. Not connected.";
return list<shared_ptr<ChatRoom>>();
}
list<shared_ptr<ChatRoom>> chatRooms; list<shared_ptr<ChatRoom>> chatRooms;
L_BEGIN_LOG_EXCEPTION L_BEGIN_LOG_EXCEPTION
...@@ -1066,16 +1102,27 @@ MainDb::MainDb (Core *core) : AbstractDb(*new MainDbPrivate) { ...@@ -1066,16 +1102,27 @@ MainDb::MainDb (Core *core) : AbstractDb(*new MainDbPrivate) {
void MainDb::insertChatRoom (const string &peerAddress, int capabilities) { void MainDb::insertChatRoom (const string &peerAddress, int capabilities) {
L_D(); L_D();
if (!isConnected()) {
lWarning() << "Unable to insert chat room. Not connected.";
return;
}
d->insertChatRoom( d->insertChatRoom(
d->insertSipAddress(peerAddress), d->insertSipAddress(peerAddress),
capabilities, capabilities,
Utils::getLongAsTm(static_cast<long>(time(0))) Utils::getTimeTAsTm(time(0))
); );
} }
void MainDb::deleteChatRoom (const string &peerAddress) { void MainDb::deleteChatRoom (const string &peerAddress) {
L_D(); L_D();
if (!isConnected()) {
lWarning() << "Unable to delete chat room. Not connected.";
return;
}
L_BEGIN_LOG_EXCEPTION L_BEGIN_LOG_EXCEPTION
soci::session *session = d->dbSession.getBackendSession<soci::session>(); soci::session *session = d->dbSession.getBackendSession<soci::session>();
...@@ -1154,7 +1201,7 @@ MainDb::MainDb (Core *core) : AbstractDb(*new MainDbPrivate) { ...@@ -1154,7 +1201,7 @@ MainDb::MainDb (Core *core) : AbstractDb(*new MainDbPrivate) {
continue; continue;
} }
const tm date = Utils::getLongAsTm(message.get<int>(LEGACY_MESSAGE_COL_DATE, 0)); const tm date = Utils::getTimeTAsTm(message.get<int>(LEGACY_MESSAGE_COL_DATE, 0));
bool isNull; bool isNull;
const string url = getValueFromLegacyMessage<string>(message, LEGACY_MESSAGE_COL_URL, isNull); const string url = getValueFromLegacyMessage<string>(message, LEGACY_MESSAGE_COL_URL, isNull);
...@@ -1259,7 +1306,7 @@ MainDb::MainDb (Core *core) : AbstractDb(*new MainDbPrivate) { ...@@ -1259,7 +1306,7 @@ MainDb::MainDb (Core *core) : AbstractDb(*new MainDbPrivate) {
return 0; return 0;
} }
list<shared_ptr<EventLog>> MainDb::getHistorySinceNotifyId ( list<shared_ptr<EventLog>> MainDb::getConferenceNotifiedEvents (
const string &peerAddress, const string &peerAddress,
unsigned int notifyId unsigned int notifyId
) { ) {
......
...@@ -55,9 +55,9 @@ public: ...@@ -55,9 +55,9 @@ public:
int getEventsCount (FilterMask mask = NoFilter) const; int getEventsCount (FilterMask mask = NoFilter) const;
// Messages, calls and conferences. // Messages, calls and conferences.
std::list<std::shared_ptr<EventLog>> getHistorySinceNotifyId ( std::list<std::shared_ptr<EventLog>> getConferenceNotifiedEvents (
const std::string &peerAddress, const std::string &peerAddress,
unsigned int notifyId unsigned int lastNotifyId
); );
int getMessagesCount (const std::string &peerAddress = "") const; int getMessagesCount (const std::string &peerAddress = "") const;
......
...@@ -173,12 +173,12 @@ char *Utils::utf8ToChar (uint32_t ic) { ...@@ -173,12 +173,12 @@ char *Utils::utf8ToChar (uint32_t ic) {
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
tm Utils::getLongAsTm (long time) { tm Utils::getTimeTAsTm (time_t time) {
tm result; tm result;
return *gmtime_r(&static_cast<time_t &>(time), &result); return *gmtime_r(&time, &result);
} }
long Utils::getTmAsLong (const tm &time) { long Utils::getTmAsTimeT (const tm &time) {
return timegm(&const_cast<tm &>(time)); return timegm(&const_cast<tm &>(time));
} }
......
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