diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt
index a2b7662f5..40d842bf5 100644
--- a/include/CMakeLists.txt
+++ b/include/CMakeLists.txt
@@ -86,6 +86,7 @@ set(C_API_HEADER_FILES
)
set(ENUMS_HEADER_FILES
+ chat-room-enums.h
event-log-enums.h
)
diff --git a/include/linphone/api/c-callbacks.h b/include/linphone/api/c-callbacks.h
index 7402dda84..a1edf51ee 100644
--- a/include/linphone/api/c-callbacks.h
+++ b/include/linphone/api/c-callbacks.h
@@ -21,6 +21,7 @@
// TODO: Remove me in the future.
#include "linphone/callbacks.h"
+#include "linphone/api/c-types.h"
// =============================================================================
@@ -47,6 +48,13 @@ typedef void (*LinphoneChatRoomCbsIsComposingReceivedCb) (LinphoneChatRoom *cr,
*/
typedef void (*LinphoneChatRoomCbsMessageReceivedCb) (LinphoneChatRoom *cr, LinphoneChatMessage *msg);
+/**
+ * Callback used to notify a chat room state has changed.
+ * @param[in] cr #LinphoneChatRoom object
+ * @param[in] newState The new state of the chat room
+ */
+typedef void (*LinphoneChatRoomCbsStateChangedCb) (LinphoneChatRoom *cr, LinphoneChatRoomState newState);
+
/**
* Callback used to notify a chat room that a message has been received but we were unable to decrypt it
* @param cr #LinphoneChatRoom involved in this conversation
diff --git a/include/linphone/api/c-chat-room-cbs.h b/include/linphone/api/c-chat-room-cbs.h
index 2b26c2a3f..0c895cecc 100644
--- a/include/linphone/api/c-chat-room-cbs.h
+++ b/include/linphone/api/c-chat-room-cbs.h
@@ -88,6 +88,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 state changed callback.
+ * @param[in] cbs LinphoneChatRoomCbs object.
+ * @return The current state changed callback.
+ */
+LINPHONE_PUBLIC LinphoneChatRoomCbsStateChangedCb linphone_chat_room_cbs_get_state_changed (const LinphoneChatRoomCbs *cbs);
+
+/**
+ * Set the state changed callback.
+ * @param[in] cbs LinphoneChatRoomCbs object.
+ * @param[in] cb The state changed callback to be used.
+ */
+LINPHONE_PUBLIC void linphone_chat_room_cbs_set_state_changed (LinphoneChatRoomCbs *cbs, LinphoneChatRoomCbsStateChangedCb cb);
+
/**
* Get the undecryptable message received callback.
* @param[in] cbs LinphoneChatRoomCbs object.
diff --git a/include/linphone/api/c-types.h b/include/linphone/api/c-types.h
index 72d74fb9d..de41cda49 100644
--- a/include/linphone/api/c-types.h
+++ b/include/linphone/api/c-types.h
@@ -23,6 +23,7 @@
#include "linphone/types.h"
#include "linphone/utils/enum-generator.h"
+#include "linphone/enums/chat-room-enums.h"
#include "linphone/enums/event-log-enums.h"
// =============================================================================
@@ -109,6 +110,7 @@ typedef struct _LinphoneMessageEvent LinphoneMessageEvent;
// C Enums.
// =============================================================================
+L_DECLARE_C_ENUM(ChatRoomState, L_ENUM_VALUES_CHAT_ROOM_STATE);
L_DECLARE_C_ENUM(EventLogType, L_ENUM_VALUES_EVENT_LOG_TYPE);
#ifdef __cplusplus
diff --git a/include/linphone/enums/chat-room-enums.h b/include/linphone/enums/chat-room-enums.h
new file mode 100644
index 000000000..7d67728cb
--- /dev/null
+++ b/include/linphone/enums/chat-room-enums.h
@@ -0,0 +1,32 @@
+/*
+ * chat-room-enums.h
+ * Copyright (C) 2017 Belledonne Communications SARL
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#ifndef _CHAT_ROOM_ENUMS_H_
+#define _CHAT_ROOM_ENUMS_H_
+
+// =============================================================================
+
+#define L_ENUM_VALUES_CHAT_ROOM_STATE(F) \
+ F(None) \
+ F(Instantiated) \
+ F(CreationPending) \
+ F(Created) \
+ F(Terminated) \
+ F(CreationFailed)
+
+#endif // ifndef _CHAT_ROOM_ENUMS_H_
diff --git a/include/linphone/utils/enum-generator.h b/include/linphone/utils/enum-generator.h
index 030fd94b5..333ff6d98 100644
--- a/include/linphone/utils/enum-generator.h
+++ b/include/linphone/utils/enum-generator.h
@@ -55,7 +55,8 @@ LINPHONE_BEGIN_NAMESPACE
#define L_DECLARE_C_ENUM(NAME, VALUES) \
enum L_CONCAT(L_C_ENUM_PREFIX, NAME) { \
L_APPLY(L_CONCAT, L_CONCAT(L_C_ENUM_PREFIX, NAME), L_GET_HEAP(VALUES(L_DECLARE_ENUM_VALUE))) \
- };
+ }; \
+ typedef enum L_CONCAT(L_C_ENUM_PREFIX, NAME) L_CONCAT(L_C_ENUM_PREFIX, NAME);
LINPHONE_END_NAMESPACE
diff --git a/src/c-wrapper/api/c-chat-room-cbs.cpp b/src/c-wrapper/api/c-chat-room-cbs.cpp
index 094bd9a15..2e1dd09e2 100644
--- a/src/c-wrapper/api/c-chat-room-cbs.cpp
+++ b/src/c-wrapper/api/c-chat-room-cbs.cpp
@@ -26,6 +26,7 @@ struct _LinphoneChatRoomCbs {
void *userData;
LinphoneChatRoomCbsIsComposingReceivedCb isComposingReceivedCb;
LinphoneChatRoomCbsMessageReceivedCb messageReceivedCb;
+ LinphoneChatRoomCbsStateChangedCb stateChangedCb;
LinphoneChatRoomCbsUndecryptableMessageReceivedCb undecryptableMessageReceivedCb;
};
@@ -77,6 +78,14 @@ void linphone_chat_room_cbs_set_message_received (LinphoneChatRoomCbs *cbs, Linp
cbs->messageReceivedCb = cb;
}
+LinphoneChatRoomCbsStateChangedCb linphone_chat_room_cbs_get_state_changed (const LinphoneChatRoomCbs *cbs) {
+ return cbs->stateChangedCb;
+}
+
+void linphone_chat_room_cbs_set_state_changed (LinphoneChatRoomCbs *cbs, LinphoneChatRoomCbsStateChangedCb cb) {
+ cbs->stateChangedCb = cb;
+}
+
LinphoneChatRoomCbsUndecryptableMessageReceivedCb linphone_chat_room_cbs_get_undecryptable_message_received (const LinphoneChatRoomCbs *cbs) {
return cbs->undecryptableMessageReceivedCb;
}
diff --git a/src/c-wrapper/api/c-chat-room.cpp b/src/c-wrapper/api/c-chat-room.cpp
index c53b3c41f..ffe36c6cc 100644
--- a/src/c-wrapper/api/c-chat-room.cpp
+++ b/src/c-wrapper/api/c-chat-room.cpp
@@ -267,6 +267,8 @@ LinphoneChatRoom * linphone_chat_room_new(LinphoneCore *core, const LinphoneAddr
else
L_SET_CPP_PTR_FROM_C_STRUCT(cr, std::make_shared(core, *L_GET_CPP_PTR_FROM_C_STRUCT(addr, Address, Address)));
linphone_core_notify_chat_room_instantiated(core, cr);
+ L_GET_PRIVATE_FROM_C_STRUCT(cr, ChatRoom, ChatRoom)->setState(LinphonePrivate::ChatRoom::State::Instantiated);
+ L_GET_PRIVATE_FROM_C_STRUCT(cr, ChatRoom, ChatRoom)->setState(LinphonePrivate::ChatRoom::State::Created);
return cr;
}
@@ -287,6 +289,8 @@ LinphoneChatRoom * linphone_client_group_chat_room_new(LinphoneCore *core, const
LinphoneChatRoom *cr = _linphone_chat_room_init();
L_SET_CPP_PTR_FROM_C_STRUCT(cr, make_shared(core, me, l));
linphone_core_notify_chat_room_instantiated(core, cr);
+ L_GET_PRIVATE_FROM_C_STRUCT(cr, ChatRoom, ChatRoom)->setState(LinphonePrivate::ChatRoom::State::Instantiated);
+ L_GET_PRIVATE_FROM_C_STRUCT(cr, ChatRoom, ChatRoom)->setState(LinphonePrivate::ChatRoom::State::CreationPending);
return cr;
}
diff --git a/src/chat/chat-room-p.h b/src/chat/chat-room-p.h
index d7dd25fe0..1f082da49 100644
--- a/src/chat/chat-room-p.h
+++ b/src/chat/chat-room-p.h
@@ -22,6 +22,9 @@
// From coreapi.
#include "private.h"
+#include "linphone/enums/chat-room-enums.h"
+#include "linphone/utils/enum-generator.h"
+
#include "chat-room.h"
#include "is-composing.h"
#include "is-composing-listener.h"
@@ -46,7 +49,6 @@ public:
std::list getTransientMessages () const {
return transientMessages;
}
-
void moveTransientMessageToWeakMessages (LinphoneChatMessage *msg);
void removeTransientMessage (LinphoneChatMessage *msg);
@@ -54,6 +56,7 @@ public:
void sendImdn (const std::string &content, LinphoneReason reason);
int getMessagesCount (bool unreadOnly);
+ void setState (ChatRoom::State newState);
protected:
void sendIsComposingNotification ();
@@ -78,6 +81,7 @@ protected:
private:
void notifyChatMessageReceived (LinphoneChatMessage *msg);
+ void notifyStateChanged ();
void notifyUndecryptableMessageReceived (LinphoneChatMessage *msg);
private:
@@ -89,6 +93,7 @@ private:
public:
LinphoneCore *core = nullptr;
LinphoneCall *call = nullptr;
+ ChatRoom::State state = ChatRoom::State::None;
Address peerAddress;
int unreadCount = -1;
bool isComposing = false;
diff --git a/src/chat/chat-room.cpp b/src/chat/chat-room.cpp
index 50550a0e7..776c9bd86 100644
--- a/src/chat/chat-room.cpp
+++ b/src/chat/chat-room.cpp
@@ -182,6 +182,13 @@ int ChatRoomPrivate::getMessagesCount (bool unreadOnly) {
return numrows;
}
+void ChatRoomPrivate::setState (ChatRoom::State newState) {
+ if (newState != state) {
+ state = newState;
+ notifyStateChanged();
+ }
+}
+
// -----------------------------------------------------------------------------
void ChatRoomPrivate::sendIsComposingNotification () {
@@ -528,6 +535,15 @@ void ChatRoomPrivate::notifyChatMessageReceived (LinphoneChatMessage *msg) {
linphone_core_notify_message_received(core, cr, msg);
}
+void ChatRoomPrivate::notifyStateChanged () {
+ L_Q(ChatRoom);
+ LinphoneChatRoom *cr = GET_BACK_PTR(q);
+ LinphoneChatRoomCbs *cbs = linphone_chat_room_get_callbacks(cr);
+ LinphoneChatRoomCbsStateChangedCb cb = linphone_chat_room_cbs_get_state_changed(cbs);
+ if (cb)
+ cb(cr, (LinphoneChatRoomState)state);
+}
+
void ChatRoomPrivate::notifyUndecryptableMessageReceived (LinphoneChatMessage *msg) {
L_Q(ChatRoom);
LinphoneChatRoom *cr = GET_BACK_PTR(q);
@@ -924,4 +940,9 @@ const Address& ChatRoom::getPeerAddress () const {
return d->peerAddress;
}
+ChatRoom::State ChatRoom::getState () const {
+ L_D(const ChatRoom);
+ return d->state;
+}
+
LINPHONE_END_NAMESPACE
diff --git a/src/chat/chat-room.h b/src/chat/chat-room.h
index e2c34047f..c71fc7880 100644
--- a/src/chat/chat-room.h
+++ b/src/chat/chat-room.h
@@ -38,6 +38,8 @@ class ChatRoomPrivate;
class ChatRoom : public Object, public ConferenceInterface {
public:
+ L_DECLARE_ENUM(State, L_ENUM_VALUES_CHAT_ROOM_STATE);
+
ChatRoom (LinphoneCore *core);
virtual ~ChatRoom () = default;
@@ -59,6 +61,7 @@ public:
LinphoneCore *getCore () const;
const Address& getPeerAddress () const;
+ State getState () const;
protected:
explicit ChatRoom (ChatRoomPrivate &p);