Commit f702e9a8 authored by Sylvain Berfini's avatar Sylvain Berfini 🎩
Browse files

Added new callback for message received on chat room with chat event log

parent c927f68a
......@@ -156,6 +156,13 @@ typedef void (*LinphoneChatRoomCbsIsComposingReceivedCb) (LinphoneChatRoom *cr,
*/
typedef void (*LinphoneChatRoomCbsMessageReceivedCb) (LinphoneChatRoom *cr, LinphoneChatMessage *msg);
/**
* Callback used to notify a chat room that a chat message has been received.
* @param[in] cr #LinphoneChatRoom object
* @param[in] event_log The #LinphoneChatMessage event log that has been received
*/
typedef void (*LinphoneChatRoomCbsChatMessageReceivedCb) (LinphoneChatRoom *cr, const LinphoneEventLog *event_log);
/**
* Callback used to notify a chat room that a participant has been added.
* @param[in] cr #LinphoneChatRoom object
......
......@@ -89,6 +89,20 @@ LINPHONE_PUBLIC LinphoneChatRoomCbsMessageReceivedCb linphone_chat_room_cbs_get_
*/
LINPHONE_PUBLIC void linphone_chat_room_cbs_set_message_received (LinphoneChatRoomCbs *cbs, LinphoneChatRoomCbsMessageReceivedCb cb);
/**
* Get the chat message received callback.
* @param[in] cbs LinphoneChatRoomCbs object.
* @return The current chat message received callback.
*/
LINPHONE_PUBLIC LinphoneChatRoomCbsChatMessageReceivedCb linphone_chat_room_cbs_get_chat_message_received (const LinphoneChatRoomCbs *cbs);
/**
* Set the chat message received callback.
* @param[in] cbs LinphoneChatRoomCbs object.
* @param[in] cb The chat message received callback to be used.
*/
LINPHONE_PUBLIC void linphone_chat_room_cbs_set_chat_message_received (LinphoneChatRoomCbs *cbs, LinphoneChatRoomCbsChatMessageReceivedCb cb);
/**
* Get the participant added callback.
* @param[in] cbs LinphoneChatRoomCbs object.
......
......@@ -36,6 +36,7 @@ struct _LinphoneChatRoomCbs {
LinphoneChatRoomCbsStateChangedCb stateChangedCb;
LinphoneChatRoomCbsSubjectChangedCb subjectChangedCb;
LinphoneChatRoomCbsUndecryptableMessageReceivedCb undecryptableMessageReceivedCb;
LinphoneChatRoomCbsChatMessageReceivedCb chatMessageReceivedCb;
};
BELLE_SIP_DECLARE_VPTR_NO_EXPORT(LinphoneChatRoomCbs);
......@@ -88,6 +89,14 @@ void linphone_chat_room_cbs_set_message_received (LinphoneChatRoomCbs *cbs, Linp
cbs->messageReceivedCb = cb;
}
LinphoneChatRoomCbsChatMessageReceivedCb linphone_chat_room_cbs_get_chat_message_received (const LinphoneChatRoomCbs *cbs) {
return cbs->chatMessageReceivedCb;
}
void linphone_chat_room_cbs_set_chat_message_received (LinphoneChatRoomCbs *cbs, LinphoneChatRoomCbsChatMessageReceivedCb cb) {
cbs->chatMessageReceivedCb = cb;
}
LinphoneChatRoomCbsParticipantAddedCb linphone_chat_room_cbs_get_participant_added (const LinphoneChatRoomCbs *cbs) {
return cbs->participantAddedCb;
}
......
......@@ -40,6 +40,10 @@ BasicChatRoom::BasicChatRoom (LinphoneCore *core, const Address &peerAddress) :
// -----------------------------------------------------------------------------
void BasicChatRoom::onChatMessageReceived (const shared_ptr<ChatMessage> &msg) {
}
int BasicChatRoom::getCapabilities () const {
return static_cast<int>(Capabilities::Basic);
}
......
......@@ -35,6 +35,7 @@ public:
CapabilitiesMask getCapabilities () const override;
void onChatMessageReceived (const std::shared_ptr<ChatMessage> &msg) override;
/* ConferenceInterface. */
void addParticipant (const Address &addr, const CallSessionParams *params, bool hasMedia) override;
void addParticipants (const std::list<Address> &addresses, const CallSessionParams *params, bool hasMedia) override;
......
......@@ -20,6 +20,7 @@
#include <algorithm>
#include "c-wrapper/c-wrapper.h"
#include "event-log/conference/conference-chat-message-event.h"
#include "chat/chat-message/chat-message-p.h"
#include "chat/chat-room/chat-room-p.h"
#include "chat/notification/imdn.h"
......@@ -435,8 +436,21 @@ end:
// -----------------------------------------------------------------------------
void ChatRoomPrivate::chatMessageReceived (const shared_ptr<ChatMessage> &msg) {
L_Q();
if ((msg->getPrivate()->getContentType() != ContentType::Imdn) && (msg->getPrivate()->getContentType() != ContentType::ImIsComposing)) {
q->onChatMessageReceived(msg);
LinphoneChatRoom *cr = L_GET_C_BACK_PTR(q);
LinphoneChatRoomCbs *cbs = linphone_chat_room_get_callbacks(cr);
LinphoneChatRoomCbsParticipantAddedCb cb = linphone_chat_room_cbs_get_chat_message_received(cbs);
shared_ptr<ConferenceChatMessageEvent> event = make_shared<ConferenceChatMessageEvent>(msg->getTime(), msg);
if (cb) {
cb(cr, L_GET_C_BACK_PTR(event));
}
// Legacy
notifyChatMessageReceived(msg);
remoteIsComposing.erase(msg->getFromAddress().asStringUriOnly());
isComposingHandler.stopRemoteRefreshTimer(msg->getFromAddress().asStringUriOnly());
notifyIsComposingReceived(msg->getFromAddress(), false);
......
......@@ -69,6 +69,7 @@ public:
State getState () const;
protected:
virtual void onChatMessageReceived (const std::shared_ptr<ChatMessage> &msg) = 0;
explicit ChatRoom (ChatRoomPrivate &p);
private:
......
......@@ -245,6 +245,10 @@ void ClientGroupChatRoom::setSubject (const string &subject) {
// -----------------------------------------------------------------------------
void ClientGroupChatRoom::onChatMessageReceived (const shared_ptr<ChatMessage> &msg) {
}
void ClientGroupChatRoom::onConferenceCreated (const Address &addr) {
L_D();
L_D_T(RemoteConference, dConference);
......
......@@ -52,6 +52,9 @@ public:
void setParticipantAdminStatus (std::shared_ptr<Participant> &participant, bool isAdmin) override;
void setSubject (const std::string &subject) override;
private:
void onChatMessageReceived (const std::shared_ptr<ChatMessage> &msg) override;
private:
/* ConferenceListener */
void onConferenceCreated (const Address &addr) override;
......
......@@ -135,6 +135,8 @@ LinphoneCall *RealTimeTextChatRoom::getCall () const {
// -----------------------------------------------------------------------------
void RealTimeTextChatRoom::onChatMessageReceived(const shared_ptr<ChatMessage> &msg) {}
void RealTimeTextChatRoom::addParticipant (const Address &addr, const CallSessionParams *params, bool hasMedia) {
lError() << "addParticipant() is not allowed on a RealTimeTextChatRoom";
}
......
......@@ -38,6 +38,7 @@ public:
uint32_t getChar () const;
LinphoneCall *getCall () const;
void onChatMessageReceived (const std::shared_ptr<ChatMessage> &msg) override;
/* ConferenceInterface */
void addParticipant (const Address &addr, const CallSessionParams *params, bool hasMedia) override;
void addParticipants (const std::list<Address> &addresses, const CallSessionParams *params, bool hasMedia) override;
......
......@@ -82,6 +82,8 @@ int ServerGroupChatRoom::getCapabilities () const {
// -----------------------------------------------------------------------------
void ServerGroupChatRoom::onChatMessageReceived(const shared_ptr<ChatMessage> &msg) {}
void ServerGroupChatRoom::addParticipant (const Address &, const CallSessionParams *, bool) {}
void ServerGroupChatRoom::addParticipants (const list<Address> &, const CallSessionParams *, bool) {}
......
......@@ -59,6 +59,7 @@ public:
void setSubject (const std::string &subject) override;
private:
void onChatMessageReceived (const std::shared_ptr<ChatMessage> &msg) override;
/* CallSessionListener */
void onCallSessionStateChanged (const std::shared_ptr<const CallSession> &session, LinphoneCallState state, const std::string &message) override;
......
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