Commit 1b60a6fc authored by Ghislain MARY's avatar Ghislain MARY
Browse files

Handle the chat room state.

parent ffc4abad
......@@ -86,6 +86,7 @@ set(C_API_HEADER_FILES
)
set(ENUMS_HEADER_FILES
chat-room-enums.h
event-log-enums.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
......
......@@ -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.
......
......@@ -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
......
/*
* 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 <http://www.gnu.org/licenses/>.
*/
#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_
......@@ -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
......
......@@ -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;
}
......
......@@ -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<LinphonePrivate::BasicChatRoom>(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<LinphonePrivate::ClientGroupChatRoom>(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;
}
......
......@@ -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<LinphoneChatMessage *> 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;
......
......@@ -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
......@@ -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);
......
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