Commit 13f4afe1 authored by Ronan's avatar Ronan
Browse files

feat(MainDb): supports local chat room id

parent d2a7cfaf
......@@ -675,11 +675,11 @@ ChatMessage::ChatMessage (const shared_ptr<ChatRoom> &chatRoom, ChatMessage::Dir
d->chatRoom = chatRoom;
d->chatRoomId = chatRoom->getChatRoomId();
if (direction == Direction::Outgoing) {
d->fromAddress = chatRoom->getLocalAddress();
d->toAddress = chatRoom->getPeerAddress();
d->fromAddress = d->chatRoomId.getLocalAddress();
d->toAddress = d->chatRoomId.getPeerAddress();
} else {
d->fromAddress = chatRoom->getPeerAddress();
d->toAddress = chatRoom->getLocalAddress();
d->fromAddress = d->chatRoomId.getPeerAddress();
d->toAddress = d->chatRoomId.getLocalAddress();
}
d->direction = direction;
}
......@@ -766,16 +766,6 @@ const IdentityAddress &ChatMessage::getToAddress () const {
return d->toAddress;
}
const IdentityAddress &ChatMessage::getLocalAddress () const {
L_D();
return d->chatRoomId.getLocalAddress();
}
const IdentityAddress &ChatMessage::getRemoteAddress () const {
L_D();
return d->direction == Direction::Outgoing ? d->chatRoomId.getPeerAddress() : d->fromAddress;
}
// -----------------------------------------------------------------------------
const LinphoneErrorInfo *ChatMessage::getErrorInfo () const {
......
......@@ -83,9 +83,6 @@ public:
const IdentityAddress &getFromAddress () const;
const IdentityAddress &getToAddress () const;
const IdentityAddress &getLocalAddress () const;
const IdentityAddress &getRemoteAddress () const;
// TODO: Return a cpp reference.
const LinphoneErrorInfo *getErrorInfo () const;
......
......@@ -74,4 +74,9 @@ const IdentityAddress &ChatRoomId::getLocalAddress () const {
return d->localAddress;
}
bool ChatRoomId::isValid () const {
L_D();
return d->peerAddress.isValid() && d->localAddress.isValid();
}
LINPHONE_END_NAMESPACE
......@@ -44,6 +44,8 @@ public:
const IdentityAddress &getPeerAddress () const;
const IdentityAddress &getLocalAddress () const;
bool isValid () const;
private:
L_DECLARE_PRIVATE(ChatRoomId);
};
......
......@@ -42,10 +42,20 @@ private:
long long insertSipAddress (const std::string &sipAddress);
void insertContent (long long messageEventId, const Content &content);
long long insertContentType (const std::string &contentType);
long long insertChatRoom (long long sipAddressId, int capabilities, const tm &date);
long long insertChatRoom (
long long peerSipAddressId,
long long localSipAddressId,
int capabilities,
const tm &date
);
long long insertChatRoom (const ChatRoomId &chatRoomId, int capabilities, const tm &date);
void insertChatRoomParticipant (long long chatRoomId, long long sipAddressId, bool isAdmin);
void insertChatMessageParticipant (long long messageEventId, long long sipAddressId, int state);
long long selectSipAddressId (const std::string &sipAddress) const;
long long selectChatRoomId (long long peerSipAddressId, long long localSipAddressId) const;
long long selectChatRoomId (const ChatRoomId &chatRoomId) const;
// ---------------------------------------------------------------------------
// Events API.
// ---------------------------------------------------------------------------
......@@ -54,56 +64,56 @@ private:
long long eventId,
EventLog::Type type,
time_t date,
const std::string &peerAddress
const ChatRoomId &chatRoomId
) const;
std::shared_ptr<EventLog> selectConferenceEvent (
long long eventId,
EventLog::Type type,
time_t date,
const std::string &peerAddress
const ChatRoomId &chatRoomId
) const;
std::shared_ptr<EventLog> selectConferenceCallEvent (
long long eventId,
EventLog::Type type,
time_t date,
const std::string &peerAddress
const ChatRoomId &chatRoomId
) const;
std::shared_ptr<EventLog> selectConferenceChatMessageEvent (
long long eventId,
EventLog::Type type,
time_t date,
const std::string &peerAddress
const ChatRoomId &chatRoomId
) const;
std::shared_ptr<EventLog> selectConferenceParticipantEvent (
long long eventId,
EventLog::Type type,
time_t date,
const std::string &peerAddress
const ChatRoomId &chatRoomId
) const;
std::shared_ptr<EventLog> selectConferenceParticipantDeviceEvent (
long long eventId,
EventLog::Type type,
time_t date,
const std::string &peerAddress
const ChatRoomId &chatRoomId
) const;
std::shared_ptr<EventLog> selectConferenceSubjectEvent (
long long eventId,
EventLog::Type type,
time_t date,
const std::string &peerAddress
const ChatRoomId &chatRoomId
) const;
long long insertEvent (const std::shared_ptr<EventLog> &eventLog);
long long insertConferenceEvent (const std::shared_ptr<EventLog> &eventLog, long long *chatRoomId = nullptr);
long long insertConferenceCallEvent (const std::shared_ptr<EventLog> &eventLog);
long long insertConferenceChatMessageEvent (const std::shared_ptr<EventLog> &eventLog);
long long insertConferenceNotifiedEvent (const std::shared_ptr<EventLog> &eventLog);
long long insertConferenceNotifiedEvent (const std::shared_ptr<EventLog> &eventLog, long long *chatRoomId = nullptr);
long long insertConferenceParticipantEvent (const std::shared_ptr<EventLog> &eventLog);
long long insertConferenceParticipantDeviceEvent (const std::shared_ptr<EventLog> &eventLog);
long long insertConferenceSubjectEvent (const std::shared_ptr<EventLog> &eventLog);
......@@ -113,7 +123,7 @@ private:
// ---------------------------------------------------------------------------
std::shared_ptr<EventLog> getEventFromCache (long long eventId) const;
void invalidEventsFromQuery (const std::string &query, const std::string &peerAddress);
void invalidConferenceEventsFromQuery (const std::string &query, long long chatRoomId);
L_DECLARE_PUBLIC(MainDb);
};
......
This diff is collapsed.
......@@ -34,149 +34,172 @@ using namespace LinphonePrivate;
// -----------------------------------------------------------------------------
// TODO: DEV GROUP CHAT
// static const string getDatabasePath () {
// static const string path = string(bc_tester_get_resource_dir_prefix()) + "db/linphone.db";
// return path;
// }
//
// // -----------------------------------------------------------------------------
//
// class MainDbProvider {
// public:
// MainDbProvider () {
// mCoreManager = linphone_core_manager_new("marie_rc");
// mMainDb = new MainDb(mCoreManager->lc->cppCore->getSharedFromThis());
// mMainDb->connect(MainDb::Sqlite3, getDatabasePath());
// }
//
// ~MainDbProvider () {
// delete mMainDb;
// linphone_core_manager_destroy(mCoreManager);
// }
//
// const MainDb &getMainDb () {
// return *mMainDb;
// }
//
// private:
// LinphoneCoreManager *mCoreManager;
// MainDb *mMainDb;
// };
//
// // -----------------------------------------------------------------------------
//
// static void open_database () {
// MainDbProvider provider;
// BC_ASSERT_TRUE(provider.getMainDb().isConnected());
// }
//
// static void get_events_count () {
// MainDbProvider provider;
// const MainDb &mainDb = provider.getMainDb();
// BC_ASSERT_EQUAL(mainDb.getEventsCount(), 4994, int, "%d");
// BC_ASSERT_EQUAL(mainDb.getEventsCount(MainDb::ConferenceCallFilter), 0, int, "%d");
// BC_ASSERT_EQUAL(mainDb.getEventsCount(MainDb::ConferenceInfoFilter), 18, int, "%d");
// BC_ASSERT_EQUAL(mainDb.getEventsCount(MainDb::ConferenceChatMessageFilter), 5157, int, "%d");
// BC_ASSERT_EQUAL(mainDb.getEventsCount(MainDb::NoFilter), 4994, int, "%d");
// }
//
// static void get_messages_count () {
// MainDbProvider provider;
// const MainDb &mainDb = provider.getMainDb();
// BC_ASSERT_EQUAL(mainDb.getChatMessagesCount(), 5157, int, "%d");
// BC_ASSERT_EQUAL(mainDb.getChatMessagesCount("sip:test-39@sip.linphone.org"), 3, int, "%d");
// }
//
// static void get_unread_messages_count () {
// MainDbProvider provider;
// const MainDb &mainDb = provider.getMainDb();
// BC_ASSERT_EQUAL(mainDb.getUnreadChatMessagesCount(), 2, int, "%d");
// BC_ASSERT_EQUAL(mainDb.getUnreadChatMessagesCount("sip:test-39@sip.linphone.org"), 0, int, "%d");
// }
//
// static void get_history () {
// MainDbProvider provider;
// const MainDb &mainDb = provider.getMainDb();
// BC_ASSERT_EQUAL(
// mainDb.getHistoryRange("sip:test-39@sip.linphone.org", 0, -1, MainDb::Filter::ConferenceChatMessageFilter).size(),
// 3,
// int,
// "%d"
// );
// BC_ASSERT_EQUAL(
// mainDb.getHistoryRange("sip:test-7@sip.linphone.org", 0, -1, MainDb::Filter::ConferenceCallFilter).size(),
// 0,
// int,
// "%d"
// );
// BC_ASSERT_EQUAL(
// mainDb.getHistoryRange("sip:test-1@sip.linphone.org", 0, -1, MainDb::Filter::ConferenceChatMessageFilter).size(),
// 862,
// int,
// "%d"
// );
// BC_ASSERT_EQUAL(
// mainDb.getHistory("sip:test-1@sip.linphone.org", 100, MainDb::Filter::ConferenceChatMessageFilter).size(),
// 100,
// int,
// "%d"
// );
// }
//
// static void get_conference_notified_events () {
// MainDbProvider provider;
// const MainDb &mainDb = provider.getMainDb();
// list<shared_ptr<EventLog>> events = mainDb.getConferenceNotifiedEvents("sip:fake-group-2@sip.linphone.org", 1);
// BC_ASSERT_EQUAL(events.size(), 3, int, "%d");
// if (events.size() != 3)
// return;
//
// shared_ptr<EventLog> event;
// auto it = events.cbegin();
//
// event = *it;
// if (!BC_ASSERT_TRUE(event->getType() == EventLog::Type::ConferenceParticipantRemoved)) return;
// {
// shared_ptr<ConferenceParticipantEvent> participantEvent = static_pointer_cast<ConferenceParticipantEvent>(event);
// BC_ASSERT_TRUE(participantEvent->getConferenceAddress().asStringUriOnly() == "sip:fake-group-2@sip.linphone.org");
// BC_ASSERT_TRUE(participantEvent->getParticipantAddress().asStringUriOnly() == "sip:test-11@sip.linphone.org");
// BC_ASSERT_TRUE(participantEvent->getNotifyId() == 2);
// }
//
// event = *++it;
// if (!BC_ASSERT_TRUE(event->getType() == EventLog::Type::ConferenceParticipantDeviceAdded)) return;
// {
// shared_ptr<ConferenceParticipantDeviceEvent> deviceEvent = static_pointer_cast<
// ConferenceParticipantDeviceEvent
// >(event);
// BC_ASSERT_TRUE(deviceEvent->getConferenceAddress().asStringUriOnly() == "sip:fake-group-2@sip.linphone.org");
// BC_ASSERT_TRUE(deviceEvent->getParticipantAddress().asStringUriOnly() == "sip:test-11@sip.linphone.org");
// BC_ASSERT_TRUE(deviceEvent->getNotifyId() == 3);
// BC_ASSERT_TRUE(deviceEvent->getGruuAddress().asStringUriOnly() == "sip:gruu-address-1@sip.linphone.org");
// }
//
// event = *++it;
// if (!BC_ASSERT_TRUE(event->getType() == EventLog::Type::ConferenceParticipantDeviceRemoved)) return;
// {
// shared_ptr<ConferenceParticipantDeviceEvent> deviceEvent = static_pointer_cast<
// ConferenceParticipantDeviceEvent
// >(event);
// BC_ASSERT_TRUE(deviceEvent->getConferenceAddress().asStringUriOnly() == "sip:fake-group-2@sip.linphone.org");
// BC_ASSERT_TRUE(deviceEvent->getParticipantAddress().asStringUriOnly() == "sip:test-11@sip.linphone.org");
// BC_ASSERT_TRUE(deviceEvent->getNotifyId() == 4);
// BC_ASSERT_TRUE(deviceEvent->getGruuAddress().asStringUriOnly() == "sip:gruu-address-1@sip.linphone.org");
// }
// }
static const string getDatabasePath () {
static const string path = string(bc_tester_get_resource_dir_prefix()) + "db/linphone.db";
return path;
}
// -----------------------------------------------------------------------------
class MainDbProvider {
public:
MainDbProvider () {
mCoreManager = linphone_core_manager_new("marie_rc");
mMainDb = new MainDb(mCoreManager->lc->cppCore->getSharedFromThis());
mMainDb->connect(MainDb::Sqlite3, getDatabasePath());
}
~MainDbProvider () {
delete mMainDb;
linphone_core_manager_destroy(mCoreManager);
}
const MainDb &getMainDb () {
return *mMainDb;
}
private:
LinphoneCoreManager *mCoreManager;
MainDb *mMainDb;
};
// -----------------------------------------------------------------------------
static void open_database () {
MainDbProvider provider;
BC_ASSERT_TRUE(provider.getMainDb().isConnected());
}
static void get_events_count () {
MainDbProvider provider;
const MainDb &mainDb = provider.getMainDb();
BC_ASSERT_EQUAL(mainDb.getEventsCount(), 4994, int, "%d");
BC_ASSERT_EQUAL(mainDb.getEventsCount(MainDb::ConferenceCallFilter), 0, int, "%d");
BC_ASSERT_EQUAL(mainDb.getEventsCount(MainDb::ConferenceInfoFilter), 18, int, "%d");
BC_ASSERT_EQUAL(mainDb.getEventsCount(MainDb::ConferenceChatMessageFilter), 5157, int, "%d");
BC_ASSERT_EQUAL(mainDb.getEventsCount(MainDb::NoFilter), 4994, int, "%d");
}
static void get_messages_count () {
MainDbProvider provider;
const MainDb &mainDb = provider.getMainDb();
BC_ASSERT_EQUAL(mainDb.getChatMessagesCount(), 5157, int, "%d");
BC_ASSERT_EQUAL(
mainDb.getChatMessagesCount(
ChatRoomId(IdentityAddress("sip:test-39@sip.linphone.org"), IdentityAddress("sip:test-39@sip.linphone.org"))
),
3, int, "%d"
);
}
static void get_unread_messages_count () {
MainDbProvider provider;
const MainDb &mainDb = provider.getMainDb();
BC_ASSERT_EQUAL(mainDb.getUnreadChatMessagesCount(), 2, int, "%d");
BC_ASSERT_EQUAL(
mainDb.getUnreadChatMessagesCount(
ChatRoomId(IdentityAddress("sip:test-39@sip.linphone.org"), IdentityAddress("sip:test-39@sip.linphone.org"))
),
0, int, "%d"
);
}
static void get_history () {
MainDbProvider provider;
const MainDb &mainDb = provider.getMainDb();
BC_ASSERT_EQUAL(
mainDb.getHistoryRange(
ChatRoomId(IdentityAddress("sip:test-39@sip.linphone.org"), IdentityAddress("sip:test-39@sip.linphone.org")),
0, -1, MainDb::Filter::ConferenceChatMessageFilter
).size(),
3,
int,
"%d"
);
BC_ASSERT_EQUAL(
mainDb.getHistoryRange(
ChatRoomId(IdentityAddress("sip:test-7@sip.linphone.org"), IdentityAddress("sip:test-7@sip.linphone.org")),
0, -1, MainDb::Filter::ConferenceCallFilter
).size(),
0,
int,
"%d"
);
BC_ASSERT_EQUAL(
mainDb.getHistoryRange(
ChatRoomId(IdentityAddress("sip:test-1@sip.linphone.org"), IdentityAddress("sip:test-1@sip.linphone.org")),
0, -1, MainDb::Filter::ConferenceChatMessageFilter
).size(),
862,
int,
"%d"
);
BC_ASSERT_EQUAL(
mainDb.getHistory(
ChatRoomId(IdentityAddress("sip:test-1@sip.linphone.org"), IdentityAddress("sip:test-1@sip.linphone.org")),
100, MainDb::Filter::ConferenceChatMessageFilter
).size(),
100,
int,
"%d"
);
}
static void get_conference_notified_events () {
MainDbProvider provider;
const MainDb &mainDb = provider.getMainDb();
list<shared_ptr<EventLog>> events = mainDb.getConferenceNotifiedEvents(
ChatRoomId(IdentityAddress("sip:fake-group-2@sip.linphone.org"), IdentityAddress("sip:fake-group-2@sip.linphone.org")),
1
);
BC_ASSERT_EQUAL(events.size(), 3, int, "%d");
if (events.size() != 3)
return;
shared_ptr<EventLog> event;
auto it = events.cbegin();
event = *it;
if (!BC_ASSERT_TRUE(event->getType() == EventLog::Type::ConferenceParticipantRemoved)) return;
{
shared_ptr<ConferenceParticipantEvent> participantEvent = static_pointer_cast<ConferenceParticipantEvent>(event);
BC_ASSERT_TRUE(participantEvent->getChatRoomId().getPeerAddress().asString() == "sip:fake-group-2@sip.linphone.org");
BC_ASSERT_TRUE(participantEvent->getParticipantAddress().asString() == "sip:test-11@sip.linphone.org");
BC_ASSERT_TRUE(participantEvent->getNotifyId() == 2);
}
event = *++it;
if (!BC_ASSERT_TRUE(event->getType() == EventLog::Type::ConferenceParticipantDeviceAdded)) return;
{
shared_ptr<ConferenceParticipantDeviceEvent> deviceEvent = static_pointer_cast<
ConferenceParticipantDeviceEvent
>(event);
BC_ASSERT_TRUE(deviceEvent->getChatRoomId().getPeerAddress().asString() == "sip:fake-group-2@sip.linphone.org");
BC_ASSERT_TRUE(deviceEvent->getParticipantAddress().asString() == "sip:test-11@sip.linphone.org");
BC_ASSERT_TRUE(deviceEvent->getNotifyId() == 3);
BC_ASSERT_TRUE(deviceEvent->getDeviceAddress().asString() == "sip:gruu-address-1@sip.linphone.org");
}
event = *++it;
if (!BC_ASSERT_TRUE(event->getType() == EventLog::Type::ConferenceParticipantDeviceRemoved)) return;
{
shared_ptr<ConferenceParticipantDeviceEvent> deviceEvent = static_pointer_cast<
ConferenceParticipantDeviceEvent
>(event);
BC_ASSERT_TRUE(deviceEvent->getChatRoomId().getPeerAddress().asString() == "sip:fake-group-2@sip.linphone.org");
BC_ASSERT_TRUE(deviceEvent->getParticipantAddress().asString() == "sip:test-11@sip.linphone.org");
BC_ASSERT_TRUE(deviceEvent->getNotifyId() == 4);
BC_ASSERT_TRUE(deviceEvent->getDeviceAddress().asString() == "sip:gruu-address-1@sip.linphone.org");
}
}
test_t main_db_tests[] = {
// TEST_NO_TAG("Open database", open_database),
// TEST_NO_TAG("Get events count", get_events_count),
// TEST_NO_TAG("Get messages count", get_messages_count),
// TEST_NO_TAG("Get unread messages count", get_unread_messages_count),
// TEST_NO_TAG("Get history", get_history),
// TEST_NO_TAG("Get conference events", get_conference_notified_events)
TEST_NO_TAG("Open database", open_database),
TEST_NO_TAG("Get events count", get_events_count),
TEST_NO_TAG("Get messages count", get_messages_count),
TEST_NO_TAG("Get unread messages count", get_unread_messages_count),
TEST_NO_TAG("Get history", get_history),
TEST_NO_TAG("Get conference events", get_conference_notified_events)
};
test_suite_t main_db_test_suite = {
......
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