Commit 38528459 authored by Ronan's avatar Ronan

feat(ChatRoom): provide a get creation/last update time accessor

parent d41e2d5d
......@@ -94,8 +94,14 @@ public:
// TODO: Use CoreAccessor on IsComposing. And avoid pointer if possible.
std::unique_ptr<IsComposing> isComposingHandler;
// TODO: Check all fields before this point.
public:
ChatRoomId chatRoomId;
time_t creationTime = -1;
time_t lastUpdateTime = -1;
private:
L_DECLARE_PUBLIC(ChatRoom);
};
......
......@@ -139,6 +139,18 @@ const IdentityAddress &ChatRoom::getLocalAddress () const {
// -----------------------------------------------------------------------------
time_t ChatRoom::getCreationTime () const {
L_D();
return d->creationTime;
}
time_t ChatRoom::getLastUpdateTime () const {
L_D();
return d->lastUpdateTime;
}
// -----------------------------------------------------------------------------
/**
* DB layout:
*
......
......@@ -31,11 +31,12 @@ LINPHONE_BEGIN_NAMESPACE
class ChatRoomPrivate;
class LINPHONE_PUBLIC ChatRoom : public Object, public CoreAccessor, public ConferenceInterface {
friend class Core;
friend class CorePrivate;
friend class ChatMessage;
friend class ChatMessagePrivate;
friend class Core;
friend class CorePrivate;
friend class FileTransferChatMessageModifier;
friend class MainDb;
public:
L_OVERRIDE_SHARED_FROM_THIS(ChatRoom);
......@@ -52,6 +53,9 @@ public:
const IdentityAddress &getPeerAddress () const;
const IdentityAddress &getLocalAddress () const;
time_t getCreationTime () const;
time_t getLastUpdateTime () const;
virtual CapabilitiesMask getCapabilities () const = 0;
// TODO: Remove useless functions.
......
......@@ -28,6 +28,7 @@
#include "chat/chat-message/chat-message-p.h"
#include "chat/chat-room/client-group-chat-room.h"
#include "chat/chat-room/chat-room-p.h"
#include "conference/participant.h"
#include "content/content-type.h"
#include "content/content.h"
......@@ -205,13 +206,13 @@ MainDb::MainDb (const shared_ptr<Core> &core) : AbstractDb(*new MainDbPrivate),
soci::session *session = dbSession.getBackendSession<soci::session>();
soci::statement statement = (
session->prepare << "UPDATE chat_room_participant SET is_admin = :isAdmin"
" WHERE chat_room_id = :chatRoomId AND participant_address_id = :sipAddressId",
" WHERE chat_room_id = :chatRoomId AND participant_sip_address_id = :sipAddressId",
soci::use(static_cast<int>(isAdmin)), soci::use(chatRoomId), soci::use(sipAddressId)
);
statement.execute(true);
if (statement.get_affected_rows() == 0) {
lInfo() << "Insert new chat room participant in database: `" << sipAddressId << "` (isAdmin=" << isAdmin << ").";
*session << "INSERT INTO chat_room_participant (chat_room_id, participant_address_id, is_admin)"
*session << "INSERT INTO chat_room_participant (chat_room_id, participant_sip_address_id, is_admin)"
" VALUES (:chatRoomId, :sipAddressId, :isAdmin)",
soci::use(chatRoomId), soci::use(sipAddressId), soci::use(static_cast<int>(isAdmin));
}
......@@ -221,12 +222,12 @@ MainDb::MainDb (const shared_ptr<Core> &core) : AbstractDb(*new MainDbPrivate),
soci::session *session = dbSession.getBackendSession<soci::session>();
soci::statement statement = (
session->prepare << "UPDATE chat_message_participant SET state = :state"
" WHERE event_id = :eventId AND participant_address_id = :sipAddressId",
" WHERE event_id = :eventId AND participant_sip_address_id = :sipAddressId",
soci::use(state), soci::use(eventId), soci::use(sipAddressId)
);
statement.execute(true);
if (statement.get_affected_rows() == 0 && state != static_cast<int>(ChatMessage::State::Displayed))
*session << "INSERT INTO chat_message_participant (event_id, participant_address_id, state)"
*session << "INSERT INTO chat_message_participant (event_id, participant_sip_address_id, state)"
" VALUES (:eventId, :sipAddressId, :state)",
soci::use(eventId), soci::use(sipAddressId), soci::use(state);
}
......@@ -432,7 +433,7 @@ MainDb::MainDb (const shared_ptr<Core> &core) : AbstractDb(*new MainDbPrivate),
" FROM conference_notified_event, conference_participant_event, sip_address as participant_address"
" WHERE conference_participant_event.event_id = :eventId"
" AND conference_notified_event.event_id = conference_participant_event.event_id"
" AND participant_address.id = participant_address_id",
" AND participant_address.id = participant_sip_address_id",
soci::into(notifyId), soci::into(participantAddress), soci::use(eventId);
return make_shared<ConferenceParticipantEvent>(
......@@ -461,8 +462,8 @@ MainDb::MainDb (const shared_ptr<Core> &core) : AbstractDb(*new MainDbPrivate),
" WHERE conference_participant_device_event.event_id = :eventId"
" AND conference_participant_event.event_id = conference_participant_device_event.event_id"
" AND conference_notified_event.event_id = conference_participant_event.event_id"
" AND participant_address.id = participant_address_id"
" AND device_address.id = device_address_id",
" AND participant_address.id = participant_sip_address_id"
" AND device_address.id = device_sip_address_id",
soci::into(notifyId), soci::into(participantAddress), soci::into(deviceAddress), soci::use(eventId);
return make_shared<ConferenceParticipantDeviceEvent>(
......@@ -608,7 +609,7 @@ MainDb::MainDb (const shared_ptr<Core> &core) : AbstractDb(*new MainDbPrivate),
);
soci::session *session = dbSession.getBackendSession<soci::session>();
*session << "INSERT INTO conference_participant_event (event_id, participant_address_id)"
*session << "INSERT INTO conference_participant_event (event_id, participant_sip_address_id)"
" VALUES (:eventId, :participantAddressId)", soci::use(eventId), soci::use(participantAddressId);
return eventId;
......@@ -624,7 +625,7 @@ MainDb::MainDb (const shared_ptr<Core> &core) : AbstractDb(*new MainDbPrivate),
);
soci::session *session = dbSession.getBackendSession<soci::session>();
*session << "INSERT INTO conference_participant_device_event (event_id, device_address_id)"
*session << "INSERT INTO conference_participant_device_event (event_id, device_sip_address_id)"
" VALUES (:eventId, :deviceAddressId)", soci::use(eventId), soci::use(deviceAddressId);
return eventId;
......@@ -741,16 +742,16 @@ MainDb::MainDb (const shared_ptr<Core> &core) : AbstractDb(*new MainDbPrivate),
*session <<
"CREATE TABLE IF NOT EXISTS chat_room_participant ("
" chat_room_id" + primaryKeyRefStr("BIGINT UNSIGNED") + ","
" participant_address_id" + primaryKeyRefStr("BIGINT UNSIGNED") + ","
" participant_sip_address_id" + primaryKeyRefStr("BIGINT UNSIGNED") + ","
" is_admin BOOLEAN NOT NULL,"
" PRIMARY KEY (chat_room_id, participant_address_id),"
" PRIMARY KEY (chat_room_id, participant_sip_address_id),"
" FOREIGN KEY (chat_room_id)"
" REFERENCES chat_room(id)"
" ON DELETE CASCADE,"
" FOREIGN KEY (participant_address_id)"
" FOREIGN KEY (participant_sip_address_id)"
" REFERENCES sip_address(id)"
" ON DELETE CASCADE"
") " + charset;
......@@ -784,12 +785,12 @@ MainDb::MainDb (const shared_ptr<Core> &core) : AbstractDb(*new MainDbPrivate),
"CREATE TABLE IF NOT EXISTS conference_participant_event ("
" event_id" + primaryKeyStr("BIGINT UNSIGNED") + ","
" participant_address_id" + primaryKeyRefStr("BIGINT UNSIGNED") + " NOT NULL,"
" participant_sip_address_id" + primaryKeyRefStr("BIGINT UNSIGNED") + " NOT NULL,"
" FOREIGN KEY (event_id)"
" REFERENCES conference_notified_event(event_id)"
" ON DELETE CASCADE,"
" FOREIGN KEY (participant_address_id)"
" FOREIGN KEY (participant_sip_address_id)"
" REFERENCES sip_address(id)"
" ON DELETE CASCADE"
") " + charset;
......@@ -798,12 +799,12 @@ MainDb::MainDb (const shared_ptr<Core> &core) : AbstractDb(*new MainDbPrivate),
"CREATE TABLE IF NOT EXISTS conference_participant_device_event ("
" event_id" + primaryKeyStr("BIGINT UNSIGNED") + ","
" device_address_id" + primaryKeyRefStr("BIGINT UNSIGNED") + " NOT NULL,"
" device_sip_address_id" + primaryKeyRefStr("BIGINT UNSIGNED") + " NOT NULL,"
" FOREIGN KEY (event_id)"
" REFERENCES conference_participant_event(event_id)"
" ON DELETE CASCADE,"
" FOREIGN KEY (device_address_id)"
" FOREIGN KEY (device_sip_address_id)"
" REFERENCES sip_address(id)"
" ON DELETE CASCADE"
") " + charset;
......@@ -846,14 +847,16 @@ MainDb::MainDb (const shared_ptr<Core> &core) : AbstractDb(*new MainDbPrivate),
*session <<
"CREATE TABLE IF NOT EXISTS chat_message_participant ("
" event_id" + primaryKeyStr("BIGINT UNSIGNED") + ","
" participant_address_id" + primaryKeyRefStr("BIGINT UNSIGNED") + ","
" event_id" + primaryKeyRefStr("BIGINT UNSIGNED") + ","
" participant_sip_address_id" + primaryKeyRefStr("BIGINT UNSIGNED") + ","
" state TINYINT UNSIGNED NOT NULL,"
" PRIMARY KEY (event_id, participant_sip_address_id),"
" FOREIGN KEY (event_id)"
" REFERENCES conference_chat_message_event(event_id)"
" ON DELETE CASCADE,"
" FOREIGN KEY (participant_address_id)"
" FOREIGN KEY (participant_sip_address_id)"
" REFERENCES sip_address(id)"
" ON DELETE CASCADE"
") " + charset;
......@@ -866,6 +869,8 @@ MainDb::MainDb (const shared_ptr<Core> &core) : AbstractDb(*new MainDbPrivate),
" content_type_id" + primaryKeyRefStr("SMALLINT UNSIGNED") + " NOT NULL,"
" body TEXT NOT NULL,"
" UNIQUE (id, event_id),"
" FOREIGN KEY (event_id)"
" REFERENCES conference_chat_message_event(event_id)"
" ON DELETE CASCADE,"
......@@ -1385,8 +1390,6 @@ MainDb::MainDb (const shared_ptr<Core> &core) : AbstractDb(*new MainDbPrivate),
unsigned int lastNotifyId = static_cast<unsigned int>(row.get<int>(6, 0));
// TODO: Use me.
(void)creationDate;
(void)lastUpdateDate;
(void)lastNotifyId;
if (capabilities & static_cast<int>(ChatRoom::Capabilities::Basic)) {
......@@ -1394,6 +1397,11 @@ MainDb::MainDb (const shared_ptr<Core> &core) : AbstractDb(*new MainDbPrivate),
chatRoomId,
capabilities & static_cast<int>(ChatRoom::Capabilities::RealTimeText)
);
chatRoom->setSubject(subject);
ChatRoomPrivate *dChatRoom = chatRoom->getPrivate();
dChatRoom->creationTime = Utils::getTmAsTimeT(creationDate);
dChatRoom->lastUpdateTime = Utils::getTmAsTimeT(lastUpdateDate);
} else if (capabilities & static_cast<int>(ChatRoom::Capabilities::Conference)) {
// TODO: Fetch!
// chatRoom = make_shared<ClientGroupChatRoom>(
......
......@@ -73,11 +73,11 @@ static void open_database () {
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(), 5175, 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");
BC_ASSERT_EQUAL(mainDb.getEventsCount(MainDb::NoFilter), 5175, int, "%d");
}
static void get_messages_count () {
......@@ -86,9 +86,9 @@ static void get_messages_count () {
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"))
ChatRoomId(IdentityAddress("sip:test-3@sip.linphone.org"), IdentityAddress("sip:test-1@sip.linphone.org"))
),
3, int, "%d"
861, int, "%d"
);
}
......@@ -98,7 +98,7 @@ static void get_unread_messages_count () {
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"))
ChatRoomId(IdentityAddress("sip:test-3@sip.linphone.org"), IdentityAddress("sip:test-1@sip.linphone.org"))
),
0, int, "%d"
);
......@@ -109,10 +109,10 @@ static void get_history () {
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")),
ChatRoomId(IdentityAddress("sip:test-4@sip.linphone.org"), IdentityAddress("sip:test-1@sip.linphone.org")),
0, -1, MainDb::Filter::ConferenceChatMessageFilter
).size(),
3,
54,
int,
"%d"
);
......@@ -177,7 +177,7 @@ static void get_conference_notified_events () {
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");
BC_ASSERT_TRUE(deviceEvent->getDeviceAddress().asString() == "sip:device-address-1@sip.linphone.org");
}
event = *++it;
......@@ -189,7 +189,7 @@ static void get_conference_notified_events () {
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");
BC_ASSERT_TRUE(deviceEvent->getDeviceAddress().asString() == "sip:device-address-1@sip.linphone.org");
}
}
......
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