diff --git a/src/chat/chat-message/chat-message.cpp b/src/chat/chat-message/chat-message.cpp index ed813723d..e80b6a0d6 100644 --- a/src/chat/chat-message/chat-message.cpp +++ b/src/chat/chat-message/chat-message.cpp @@ -1327,6 +1327,14 @@ void ChatMessage::setToAddress(Address to) { d->to = to; } +const Address &ChatMessage::getLocalAddress () const { + return getDirection() == Direction::Incoming ? getToAddress() : getFromAddress(); +} + +const Address &ChatMessage::getRemoteAddress () const { + return getDirection() != Direction::Incoming ? getToAddress() : getFromAddress(); +} + const string& ChatMessage::getFileTransferFilepath() const { L_D(); return d->fileTransferFilePath; diff --git a/src/chat/chat-message/chat-message.h b/src/chat/chat-message/chat-message.h index d4be49592..c45253e7f 100644 --- a/src/chat/chat-message/chat-message.h +++ b/src/chat/chat-message/chat-message.h @@ -85,6 +85,8 @@ public: const Address &getFromAddress () const; const Address &getToAddress () const; + const Address &getLocalAddress () const; + const Address &getRemoteAddress () const; const LinphoneErrorInfo *getErrorInfo () const; diff --git a/src/chat/chat-room/basic-chat-room.h b/src/chat/chat-room/basic-chat-room.h index 9e8bf1f72..b1bf7523b 100644 --- a/src/chat/chat-room/basic-chat-room.h +++ b/src/chat/chat-room/basic-chat-room.h @@ -33,7 +33,7 @@ public: BasicChatRoom (LinphoneCore *core, const Address &peerAddress); virtual ~BasicChatRoom () = default; - int getCapabilities () const override; + CapabilitiesMask getCapabilities () const override; /* ConferenceInterface. */ void addParticipant (const Address &addr, const CallSessionParams *params, bool hasMedia) override; diff --git a/src/chat/chat-room/chat-room.h b/src/chat/chat-room/chat-room.h index d09203199..562387c65 100644 --- a/src/chat/chat-room/chat-room.h +++ b/src/chat/chat-room/chat-room.h @@ -39,10 +39,12 @@ public: L_DECLARE_ENUM(Capabilities, L_ENUM_VALUES_CHAT_ROOM_CAPABILITIES); L_DECLARE_ENUM(State, L_ENUM_VALUES_CHAT_ROOM_STATE); + typedef int CapabilitiesMask; + ChatRoom (LinphoneCore *core); virtual ~ChatRoom () = default; - virtual int getCapabilities () const = 0; + virtual CapabilitiesMask getCapabilities () const = 0; void compose (); std::shared_ptr createFileTransferMessage (const LinphoneContent *initialContent); diff --git a/src/chat/chat-room/client-group-chat-room.h b/src/chat/chat-room/client-group-chat-room.h index 52f176d00..dc44e18fe 100644 --- a/src/chat/chat-room/client-group-chat-room.h +++ b/src/chat/chat-room/client-group-chat-room.h @@ -34,7 +34,7 @@ public: ClientGroupChatRoom (LinphoneCore *core, const Address &me, const std::string &uri, const std::string &subject); virtual ~ClientGroupChatRoom () = default; - int getCapabilities () const override; + CapabilitiesMask getCapabilities () const override; /* ConferenceInterface */ void addParticipant (const Address &addr, const CallSessionParams *params, bool hasMedia) override; diff --git a/src/chat/chat-room/real-time-text-chat-room.h b/src/chat/chat-room/real-time-text-chat-room.h index 01a84035d..430fcfafe 100644 --- a/src/chat/chat-room/real-time-text-chat-room.h +++ b/src/chat/chat-room/real-time-text-chat-room.h @@ -33,7 +33,7 @@ public: RealTimeTextChatRoom (LinphoneCore *core, const Address &peerAddress); virtual ~RealTimeTextChatRoom () = default; - int getCapabilities () const override; + CapabilitiesMask getCapabilities () const override; uint32_t getChar () const; LinphoneCall *getCall () const; diff --git a/src/db/main-db.cpp b/src/db/main-db.cpp index 5678d63aa..d5badd7ea 100644 --- a/src/db/main-db.cpp +++ b/src/db/main-db.cpp @@ -247,8 +247,37 @@ MainDb::MainDb () : AbstractDb(*new MainDbPrivate) {} } long MainDbPrivate::insertMessageEvent (const EventLog &eventLog) { - // TODO. - return 0; + shared_ptr chatMessage = static_cast(eventLog).getChatMessage(); + shared_ptr chatRoom = chatMessage->getChatRoom(); + if (!chatRoom) { + lError() << "Unable to get a valid chat room. It was removed from database."; + return -1; + } + + tm eventTime = Utils::getLongAsTm(static_cast(eventLog.getTime())); + + struct MessageEventReferences references; + references.eventId = insertEvent(EventLog::Type::ChatMessage, eventTime); + references.localSipAddressId = insertSipAddress(chatMessage->getLocalAddress().asString()); + references.remoteSipAddressId = insertSipAddress(chatMessage->getRemoteAddress().asString()); + references.chatRoomId = insertChatRoom( + references.remoteSipAddressId, + chatRoom->getCapabilities(), + eventTime + ); + + insertChatRoomParticipant(references.chatRoomId, references.remoteSipAddressId, false); + + long eventId = insertMessageEvent ( + references, + static_cast(chatMessage->getState()), + static_cast(chatMessage->getDirection()), + chatMessage->getImdnMessageId(), + chatMessage->isSecured(), + chatMessage->getContents() + ); + + return eventId; } long MainDbPrivate::insertConferenceEvent (const EventLog &eventLog) { @@ -260,6 +289,7 @@ MainDb::MainDb () : AbstractDb(*new MainDbPrivate) {} soci::session *session = dbSession.getBackendSession(); *session << "INSERT INTO conference_event (event_id, chat_room_id)" " VALUES (:eventId, :chatRoomId)", soci::use(eventId), soci::use(chatRoomId); + return eventId; } @@ -271,6 +301,7 @@ MainDb::MainDb () : AbstractDb(*new MainDbPrivate) {} " VALUES (:eventId, :notifyId)", soci::use(eventId), soci::use( static_cast(eventLog).getNotifyId() ); + return eventId; } @@ -283,6 +314,7 @@ MainDb::MainDb () : AbstractDb(*new MainDbPrivate) {} soci::session *session = dbSession.getBackendSession(); *session << "INSERT INTO conference_participant_event (event_id, participant_address_id)" " VALUES (:eventId, :participantAddressId)", soci::use(eventId), soci::use(participantAddressId); + return eventId; } @@ -295,6 +327,7 @@ MainDb::MainDb () : AbstractDb(*new MainDbPrivate) {} soci::session *session = dbSession.getBackendSession(); *session << "INSERT INTO conference_participant_device_event (event_id, gruu_address_id)" " VALUES (:eventId, :gruuAddressId)", soci::use(eventId), soci::use(gruuAddressId); + return eventId; } @@ -306,6 +339,7 @@ MainDb::MainDb () : AbstractDb(*new MainDbPrivate) {} " VALUES (:eventId, :subject)", soci::use(eventId), soci::use( static_cast(eventLog).getSubject() ); + return eventId; }