client-group-to-basic-chat-room.cpp 4.56 KB
Newer Older
1 2
/*
 * client-group-to-basic-chat-room.cpp
Ronan's avatar
Ronan committed
3
 * Copyright (C) 2010-2018 Belledonne Communications SARL
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
 *
 * 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 2
 * 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, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

20
#include "client-group-chat-room-p.h"
21 22
#include "client-group-to-basic-chat-room.h"
#include "proxy-chat-room-p.h"
23
#include "c-wrapper/c-wrapper.h"
24
#include "conference/session/call-session.h"
25
#include "core/core-p.h"
26 27 28 29 30 31 32 33 34 35 36

// =============================================================================

using namespace std;

LINPHONE_BEGIN_NAMESPACE

// -----------------------------------------------------------------------------

class ClientGroupToBasicChatRoomPrivate : public ProxyChatRoomPrivate {
public:
37 38 39 40
	void onChatRoomInsertRequested (const shared_ptr<AbstractChatRoom> &chatRoom) override {
		L_Q();
		// Insert the proxy chat room instead of the real one
		q->getCore()->getPrivate()->insertChatRoom(q->getSharedFromThis());
41 42
	}

43 44 45 46
	void onChatRoomInsertInDatabaseRequested (const shared_ptr<AbstractChatRoom> &chatRoom) override {
		L_Q();
		// Insert the proxy chat room instead of the real one
		q->getCore()->getPrivate()->insertChatRoomWithDb(q->getSharedFromThis());
47
	}
48

49 50 51 52 53 54
	void onChatRoomDeleteRequested (const shared_ptr<AbstractChatRoom> &chatRoom) override {
		L_Q();
		q->getCore()->deleteChatRoom(q->getSharedFromThis());
		setState(AbstractChatRoom::State::Deleted);
	}

55
	void onCallSessionSetReleased (const std::shared_ptr<const CallSession> &session) override {
56
		if (!(chatRoom->getCapabilities() & ChatRoom::Capabilities::Conference))
57 58 59 60 61 62
			return;
		static_pointer_cast<ClientGroupChatRoom>(chatRoom)->getPrivate()->onCallSessionSetReleased(session);
	}

	void onCallSessionStateChanged (
		const shared_ptr<const CallSession> &session,
63
		CallSession::State newState,
64 65 66 67 68 69
		const string &message
	) override {
		L_Q();
		shared_ptr<ClientGroupChatRoom> cgcr = dynamic_pointer_cast<ClientGroupChatRoom>(chatRoom);
		if (!cgcr)
			return;
70
		if ((newState == CallSession::State::Error) && (cgcr->getState() == ChatRoom::State::CreationPending)
71
			&& (session->getReason() == LinphoneReasonNotAcceptable) && (invitedAddresses.size() == 1)) {
72
			teardownCallbacks();
73 74 75
			cgcr->getPrivate()->onCallSessionStateChanged(session, newState, message);
			cgcr->getPrivate()->setCallSessionListener(nullptr);
			cgcr->getPrivate()->setChatRoomListener(nullptr);
76
			Core::deleteChatRoom(q->getSharedFromThis());
77
			setupCallbacks();
78
			LinphoneChatRoom *lcr = L_GET_C_BACK_PTR(q);
79 80 81 82
			shared_ptr<AbstractChatRoom> bcr = cgcr->getCore()->onlyGetOrCreateBasicChatRoom(invitedAddresses.front());
			L_SET_CPP_PTR_FROM_C_OBJECT(lcr, bcr);
			bcr->getPrivate()->setState(ChatRoom::State::Instantiated);
			cgcr->getCore()->getPrivate()->insertChatRoom(bcr);
83
			bcr->getPrivate()->setState(ChatRoom::State::Created);
84
			cgcr->getCore()->getPrivate()->insertChatRoomWithDb(bcr);
85 86 87 88 89 90 91 92 93
			return;
		}
		cgcr->getPrivate()->onCallSessionStateChanged(session, newState, message);
	}

private:
	list<IdentityAddress> invitedAddresses;

	L_DECLARE_PUBLIC(ClientGroupToBasicChatRoom);
94 95 96 97 98 99 100
};

// =============================================================================

ClientGroupToBasicChatRoom::ClientGroupToBasicChatRoom (const shared_ptr<ChatRoom> &chatRoom) :
	ProxyChatRoom(*new ClientGroupToBasicChatRoomPrivate, chatRoom) {}

101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
void ClientGroupToBasicChatRoom::addParticipant (
	const IdentityAddress &participantAddress,
	const CallSessionParams *params,
	bool hasMedia
) {
	L_D();
	if (getState() == ChatRoom::State::Instantiated) {
		d->invitedAddresses.clear();
		d->invitedAddresses.push_back(participantAddress);
	}
	ProxyChatRoom::addParticipant(participantAddress, params, hasMedia);
}
void ClientGroupToBasicChatRoom::addParticipants (
	const std::list<IdentityAddress> &addresses,
	const CallSessionParams *params,
	bool hasMedia
) {
	L_D();
	if ((getState() == ChatRoom::State::Instantiated) && (addresses.size() == 1))
		d->invitedAddresses = addresses;
	ProxyChatRoom::addParticipants(addresses, params, hasMedia);
}

124
LINPHONE_END_NAMESPACE