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
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
......
......@@ -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
......
......@@ -70,9 +70,9 @@ MainDb::MainDb (Core *core) : AbstractDb(*new MainDbPrivate) {
}
static constexpr EnumToSql<MainDb::Filter> 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<soci::session>();
*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();
}
......@@ -408,7 +408,7 @@ MainDb::MainDb (Core *core) : AbstractDb(*new MainDbPrivate) {
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 remoteSipAddressId = insertSipAddress(chatMessage->getRemoteAddress().asString());
......@@ -842,14 +842,47 @@ MainDb::MainDb (Core *core) : AbstractDb(*new MainDbPrivate) {
return count;
}
list<shared_ptr<EventLog>> MainDb::getHistorySinceNotifyId (
list<shared_ptr<EventLog>> MainDb::getConferenceNotifiedEvents (
const string &peerAddress,
unsigned int notifyId
unsigned int lastNotifyId
) {
// TODO.
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<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 {
L_D();
......@@ -969,17 +1002,15 @@ MainDb::MainDb (Core *core) : AbstractDb(*new MainDbPrivate) {
soci::transaction tr(*session);
soci::rowset<soci::row> rows = (session->prepare << query, soci::use(peerAddress));
for (const auto &row : rows) {
tm date = row.get<tm>(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<long long>(row.get<int>(0)) : row.get<long long>(0),
static_cast<EventLog::Type>(row.get<int>(1)),
mktime(&date),
Utils::getTmAsTimeT(row.get<tm>(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<shared_ptr<ChatRoom>>();
}
list<shared_ptr<ChatRoom>> 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<long>(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<soci::session>();
......@@ -1154,7 +1201,7 @@ MainDb::MainDb (Core *core) : AbstractDb(*new MainDbPrivate) {
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;
const string url = getValueFromLegacyMessage<string>(message, LEGACY_MESSAGE_COL_URL, isNull);
......@@ -1259,7 +1306,7 @@ MainDb::MainDb (Core *core) : AbstractDb(*new MainDbPrivate) {
return 0;
}
list<shared_ptr<EventLog>> MainDb::getHistorySinceNotifyId (
list<shared_ptr<EventLog>> MainDb::getConferenceNotifiedEvents (
const string &peerAddress,
unsigned int notifyId
) {
......
......@@ -55,9 +55,9 @@ public:
int getEventsCount (FilterMask mask = NoFilter) const;
// Messages, calls and conferences.
std::list<std::shared_ptr<EventLog>> getHistorySinceNotifyId (
std::list<std::shared_ptr<EventLog>> getConferenceNotifiedEvents (
const std::string &peerAddress,
unsigned int notifyId
unsigned int lastNotifyId
);
int getMessagesCount (const std::string &peerAddress = "") const;
......
......@@ -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_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));
}
......
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