From fd286647474ed9a73c66d972f7b4e10779905612 Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Tue, 13 Feb 2018 16:32:42 +0100 Subject: [PATCH] feat(ChatRoom): update chat room time on events insertion --- src/chat/chat-message/chat-message.cpp | 4 +- src/chat/chat-room/abstract-chat-room-p.h | 2 + src/chat/chat-room/chat-room-p.h | 2 + src/chat/chat-room/chat-room.cpp | 7 ++++ src/chat/chat-room/client-group-chat-room.cpp | 41 +++++++++++-------- src/chat/chat-room/proxy-chat-room-p.h | 5 +++ 6 files changed, 42 insertions(+), 19 deletions(-) diff --git a/src/chat/chat-message/chat-message.cpp b/src/chat/chat-message/chat-message.cpp index 13045da1f..7b5b569bd 100644 --- a/src/chat/chat-message/chat-message.cpp +++ b/src/chat/chat-message/chat-message.cpp @@ -665,7 +665,7 @@ void ChatMessagePrivate::send () { } else { msgOp->send_message(ContentType::PlainText.asString().c_str(), internalContent.getBodyAsUtf8String().c_str()); } - + // Restore FileContents and remove FileTransferContents list::iterator it = contents.begin(); while (it != contents.end()) { @@ -712,7 +712,7 @@ void ChatMessagePrivate::storeInDb () { updateInDb(); } else { shared_ptr eventLog = make_shared(time, q->getSharedFromThis()); - q->getChatRoom()->getCore()->getPrivate()->mainDb->addEvent(eventLog); + q->getChatRoom()->getPrivate()->addEvent(eventLog); if (direction == ChatMessage::Direction::Incoming) { if (hasFileTransferContent()) { diff --git a/src/chat/chat-room/abstract-chat-room-p.h b/src/chat/chat-room/abstract-chat-room-p.h index 5577122ec..bd2ea703e 100644 --- a/src/chat/chat-room/abstract-chat-room-p.h +++ b/src/chat/chat-room/abstract-chat-room-p.h @@ -42,6 +42,8 @@ public: virtual void sendChatMessage (const std::shared_ptr &chatMessage) = 0; + virtual void addEvent (const std::shared_ptr &eventLog) = 0; + virtual void addTransientEvent (const std::shared_ptr &eventLog) = 0; virtual void removeTransientEvent (const std::shared_ptr &eventLog) = 0; diff --git a/src/chat/chat-room/chat-room-p.h b/src/chat/chat-room/chat-room-p.h index dcb22bb92..5492f9bdc 100644 --- a/src/chat/chat-room/chat-room-p.h +++ b/src/chat/chat-room/chat-room-p.h @@ -46,6 +46,8 @@ public: void sendChatMessage (const std::shared_ptr &chatMessage) override; void sendIsComposingNotification (); + void addEvent (const std::shared_ptr &eventLog) override; + void addTransientEvent (const std::shared_ptr &eventLog) override; void removeTransientEvent (const std::shared_ptr &eventLog) override; diff --git a/src/chat/chat-room/chat-room.cpp b/src/chat/chat-room/chat-room.cpp index cd7314757..257892be1 100644 --- a/src/chat/chat-room/chat-room.cpp +++ b/src/chat/chat-room/chat-room.cpp @@ -90,6 +90,13 @@ void ChatRoomPrivate::sendIsComposingNotification () { // ----------------------------------------------------------------------------- +void ChatRoomPrivate::addEvent (const shared_ptr &eventLog) { + L_Q(); + + q->getCore()->getPrivate()->mainDb->addEvent(eventLog); + setLastUpdateTime(eventLog->getCreationTime()); +} + void ChatRoomPrivate::addTransientEvent (const shared_ptr &eventLog) { auto it = find(transientEvents.begin(), transientEvents.end(), eventLog); if (it == transientEvents.end()) diff --git a/src/chat/chat-room/client-group-chat-room.cpp b/src/chat/chat-room/client-group-chat-room.cpp index a3e2847b4..7ff1e7979 100644 --- a/src/chat/chat-room/client-group-chat-room.cpp +++ b/src/chat/chat-room/client-group-chat-room.cpp @@ -20,16 +20,14 @@ #include "linphone/utils/utils.h" #include "address/address-p.h" -#include "c-wrapper/c-wrapper.h" -#include "basic-chat-room.h" #include "basic-to-client-group-chat-room.h" +#include "c-wrapper/c-wrapper.h" #include "client-group-chat-room-p.h" #include "conference/handlers/remote-conference-event-handler.h" #include "conference/participant-p.h" #include "conference/remote-conference-p.h" #include "conference/session/call-session-p.h" #include "core/core-p.h" -#include "event-log/events.h" #include "logger/logger.h" #include "sal/refer-op.h" @@ -65,12 +63,11 @@ shared_ptr ClientGroupChatRoomPrivate::createSession () { if (capabilities & ClientGroupChatRoom::Capabilities::OneToOne) csp.addCustomHeader("One-To-One-Chat-Room", "true"); - shared_ptr focus = qConference->getPrivate()->focus; - shared_ptr session = focus->getPrivate()->createSession(*q, &csp, false, callSessionListener); - const Address &myAddress = q->getMe()->getAddress(); - Address myCleanedAddress(myAddress); - myCleanedAddress.removeUriParam("gr"); // Remove gr parameter for INVITE - session->configure(LinphoneCallOutgoing, nullptr, nullptr, myCleanedAddress, focus->getPrivate()->getDevices().front()->getAddress()); + ParticipantPrivate *dFocus = qConference->getPrivate()->focus->getPrivate(); + shared_ptr session = dFocus->createSession(*q, &csp, false, callSessionListener); + Address myCleanedAddress(q->getMe()->getAddress()); + myCleanedAddress.removeUriParam("gr"); // Remove gr parameter for INVITE. + session->configure(LinphoneCallOutgoing, nullptr, nullptr, myCleanedAddress, dFocus->getDevices().front()->getAddress()); session->initiateOutgoing(); session->getPrivate()->createOp(); return session; @@ -442,7 +439,7 @@ void ClientGroupChatRoom::onConferenceTerminated (const IdentityAddress &addr) { L_D_T(RemoteConference, dConference); dConference->eventHandler->resetLastNotify(); d->setState(ChatRoom::State::Terminated); - getCore()->getPrivate()->mainDb->addEvent(make_shared( + d->addEvent(make_shared( EventLog::Type::ConferenceTerminated, time(nullptr), d->chatRoomId @@ -471,7 +468,7 @@ void ClientGroupChatRoom::onFirstNotifyReceived (const IdentityAddress &addr) { // TODO: Bug. Event is inserted many times. // Avoid this in the future. Deal with signals/slots system. #if 0 - getCore()->getPrivate()->mainDb->addEvent(make_shared( + d->addEvent(make_shared( EventLog::Type::ConferenceCreated, time(nullptr), d->chatRoomId @@ -481,6 +478,7 @@ void ClientGroupChatRoom::onFirstNotifyReceived (const IdentityAddress &addr) { } void ClientGroupChatRoom::onParticipantAdded (const shared_ptr &event, bool isFullState) { + L_D(); L_D_T(RemoteConference, dConference); const IdentityAddress &addr = event->getParticipantAddress(); @@ -499,7 +497,7 @@ void ClientGroupChatRoom::onParticipantAdded (const shared_ptrgetPrivate()->mainDb->addEvent(event); + d->addEvent(event); LinphoneChatRoom *cr = L_GET_C_BACK_PTR(this); LinphoneChatRoomCbs *cbs = linphone_chat_room_get_callbacks(cr); @@ -511,6 +509,7 @@ void ClientGroupChatRoom::onParticipantAdded (const shared_ptr &event, bool isFullState) { (void)isFullState; + L_D(); L_D_T(RemoteConference, dConference); const IdentityAddress &addr = event->getParticipantAddress(); @@ -521,7 +520,7 @@ void ClientGroupChatRoom::onParticipantRemoved (const shared_ptrparticipants.remove(participant); - getCore()->getPrivate()->mainDb->addEvent(event); + d->addEvent(event); LinphoneChatRoom *cr = L_GET_C_BACK_PTR(this); LinphoneChatRoomCbs *cbs = linphone_chat_room_get_callbacks(cr); @@ -531,6 +530,8 @@ void ClientGroupChatRoom::onParticipantRemoved (const shared_ptr &event, bool isFullState) { + L_D(); + const IdentityAddress &addr = event->getParticipantAddress(); shared_ptr participant; if (isMe(addr)) @@ -550,7 +551,7 @@ void ClientGroupChatRoom::onParticipantSetAdmin (const shared_ptrgetPrivate()->mainDb->addEvent(event); + d->addEvent(event); LinphoneChatRoom *cr = L_GET_C_BACK_PTR(this); LinphoneChatRoomCbs *cbs = linphone_chat_room_get_callbacks(cr); @@ -560,6 +561,8 @@ void ClientGroupChatRoom::onParticipantSetAdmin (const shared_ptr &event, bool isFullState) { + L_D(); + if (getSubject() == event->getSubject()) return; // No change in the local subject, do not notify RemoteConference::setSubject(event->getSubject()); @@ -567,7 +570,7 @@ void ClientGroupChatRoom::onSubjectChanged (const shared_ptrgetPrivate()->mainDb->addEvent(event); + d->addEvent(event); LinphoneChatRoom *cr = L_GET_C_BACK_PTR(this); LinphoneChatRoomCbs *cbs = linphone_chat_room_get_callbacks(cr); @@ -577,6 +580,8 @@ void ClientGroupChatRoom::onSubjectChanged (const shared_ptr &event, bool isFullState) { + L_D(); + const IdentityAddress &addr = event->getParticipantAddress(); shared_ptr participant; if (isMe(addr)) @@ -592,7 +597,7 @@ void ClientGroupChatRoom::onParticipantDeviceAdded (const shared_ptrgetPrivate()->mainDb->addEvent(event); + d->addEvent(event); LinphoneChatRoom *cr = L_GET_C_BACK_PTR(this); LinphoneChatRoomCbs *cbs = linphone_chat_room_get_callbacks(cr); @@ -602,6 +607,8 @@ void ClientGroupChatRoom::onParticipantDeviceAdded (const shared_ptr &event, bool isFullState) { + L_D(); + (void)isFullState; const IdentityAddress &addr = event->getParticipantAddress(); @@ -615,7 +622,7 @@ void ClientGroupChatRoom::onParticipantDeviceRemoved (const shared_ptrgetPrivate()->removeDevice(event->getDeviceAddress()); - getCore()->getPrivate()->mainDb->addEvent(event); + d->addEvent(event); LinphoneChatRoom *cr = L_GET_C_BACK_PTR(this); LinphoneChatRoomCbs *cbs = linphone_chat_room_get_callbacks(cr); diff --git a/src/chat/chat-room/proxy-chat-room-p.h b/src/chat/chat-room/proxy-chat-room-p.h index 9559c31c4..89fb81e21 100644 --- a/src/chat/chat-room/proxy-chat-room-p.h +++ b/src/chat/chat-room/proxy-chat-room-p.h @@ -21,6 +21,7 @@ #define _L_PROXY_CHAT_ROOM_P_H_ #include "abstract-chat-room-p.h" +#include "proxy-chat-room.h" // ============================================================================= @@ -44,6 +45,10 @@ public: chatRoom->getPrivate()->sendChatMessage(chatMessage); } + inline void addEvent (const std::shared_ptr &eventLog) override { + chatRoom->getPrivate()->addEvent(eventLog); + } + inline void addTransientEvent (const std::shared_ptr &eventLog) override { chatRoom->getPrivate()->addTransientEvent(eventLog); }