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

20 21
#include "linphone/utils/utils.h"

22
#include "address/address-p.h"
23
#include "basic-to-client-group-chat-room.h"
24
#include "c-wrapper/c-wrapper.h"
25
#include "client-group-chat-room-p.h"
26
#include "conference/handlers/remote-conference-event-handler.h"
27
#include "conference/participant-p.h"
28 29
#include "conference/remote-conference-p.h"
#include "conference/session/call-session-p.h"
30
#include "core/core-p.h"
31
#include "logger/logger.h"
32
#include "sal/refer-op.h"
33

Ronan's avatar
Ronan committed
34
// =============================================================================
35

36 37 38 39
using namespace std;

LINPHONE_BEGIN_NAMESPACE

40 41
// -----------------------------------------------------------------------------

42
list<IdentityAddress> ClientGroupChatRoomPrivate::cleanAddressesList (const list<IdentityAddress> &addresses) const {
43
	L_Q();
44
	list<IdentityAddress> cleanedList(addresses);
45 46 47
	cleanedList.sort();
	cleanedList.unique();
	for (auto it = cleanedList.begin(); it != cleanedList.end();) {
48
		if (q->findParticipant(*it) || (q->getMe()->getAddress() == *it))
49 50 51 52 53 54 55
			it = cleanedList.erase(it);
		else
			it++;
	}
	return cleanedList;
}

56 57
shared_ptr<CallSession> ClientGroupChatRoomPrivate::createSession () {
	L_Q();
58
	L_Q_T(RemoteConference, qConference);
59

60 61
	CallSessionParams csp;
	csp.addCustomHeader("Require", "recipient-list-invite");
62
	csp.addCustomContactParameter("text");
63 64
	if (capabilities & ClientGroupChatRoom::Capabilities::OneToOne)
		csp.addCustomHeader("One-To-One-Chat-Room", "true");
65

66 67 68 69 70
	ParticipantPrivate *dFocus = qConference->getPrivate()->focus->getPrivate();
	shared_ptr<CallSession> 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());
71
	session->initiateOutgoing();
Ghislain MARY's avatar
Ghislain MARY committed
72
	session->getPrivate()->createOp();
73 74 75
	return session;
}

Ghislain MARY's avatar
Ghislain MARY committed
76
void ClientGroupChatRoomPrivate::notifyReceived (const string &body) {
77 78
	L_Q_T(RemoteConference, qConference);
	qConference->getPrivate()->eventHandler->notifyReceived(body);
79 80
}

81 82 83 84 85
void ClientGroupChatRoomPrivate::multipartNotifyReceived (const string &body) {
	L_Q_T(RemoteConference, qConference);
	qConference->getPrivate()->eventHandler->multipartNotifyReceived(body);
}

86 87
// -----------------------------------------------------------------------------

88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
void ClientGroupChatRoomPrivate::setCallSessionListener (CallSessionListener *listener) {
	L_Q();
	L_Q_T(RemoteConference, qConference);
	callSessionListener = listener;
	shared_ptr<CallSession> session = qConference->getPrivate()->focus->getPrivate()->getSession();
	if (session)
		session->getPrivate()->setCallSessionListener(listener);
	for (const auto &participant : q->getParticipants()) {
		session = participant->getPrivate()->getSession();
		if (session)
			session->getPrivate()->setCallSessionListener(listener);
	}
}

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

104 105 106 107 108 109 110 111 112 113
void ClientGroupChatRoomPrivate::onChatRoomInsertRequested (const shared_ptr<AbstractChatRoom> &chatRoom) {
	L_Q();
	q->getCore()->getPrivate()->insertChatRoom(chatRoom);
}

void ClientGroupChatRoomPrivate::onChatRoomInsertInDatabaseRequested (const shared_ptr<AbstractChatRoom> &chatRoom) {
	L_Q();
	q->getCore()->getPrivate()->insertChatRoomWithDb(chatRoom);
}

114 115 116 117 118 119
void ClientGroupChatRoomPrivate::onChatRoomDeleteRequested (const shared_ptr<AbstractChatRoom> &chatRoom) {
	L_Q();
	q->getCore()->deleteChatRoom(q->getSharedFromThis());
	setState(ClientGroupChatRoom::State::Deleted);
}

120 121
// -----------------------------------------------------------------------------

122
void ClientGroupChatRoomPrivate::onCallSessionSetReleased (const shared_ptr<CallSession> &session) {
123 124 125 126 127 128 129 130
	L_Q_T(RemoteConference, qConference);

	ParticipantPrivate *participantPrivate = qConference->getPrivate()->focus->getPrivate();
	if (session == participantPrivate->getSession())
		participantPrivate->removeSession();
}

void ClientGroupChatRoomPrivate::onCallSessionStateChanged (
131
	const shared_ptr<CallSession> &session,
132
	CallSession::State newState,
133 134 135 136 137
	const string &message
) {
	L_Q();
	L_Q_T(RemoteConference, qConference);

138
	if (newState == CallSession::State::Connected) {
139
		if (q->getState() == ChatRoom::State::CreationPending) {
140 141 142 143
			IdentityAddress addr(session->getRemoteContactAddress()->asStringUriOnly());
			q->onConferenceCreated(addr);
			if (session->getRemoteContactAddress()->hasParam("isfocus"))
				qConference->getPrivate()->eventHandler->subscribe(q->getChatRoomId());
144
		} else if (q->getState() == ChatRoom::State::TerminationPending)
145
			qConference->getPrivate()->focus->getPrivate()->getSession()->terminate();
146
	} else if ((newState == CallSession::State::Released) && (q->getState() == ChatRoom::State::TerminationPending)) {
147
		q->onConferenceTerminated(q->getConferenceAddress());
148 149 150 151 152 153 154 155
	} else if (newState == CallSession::State::Error) {
		if (q->getState() == ChatRoom::State::CreationPending)
			setState(ChatRoom::State::CreationFailed);
		else if (q->getState() == ChatRoom::State::TerminationPending) {
			// Go to state TerminationFailed and then back to Created since it has not been terminated
			setState(ChatRoom::State::TerminationFailed);
			setState(ChatRoom::State::Created);
		}
156 157 158
	}
}

159 160
// =============================================================================

161
ClientGroupChatRoom::ClientGroupChatRoom (
162
	const shared_ptr<Core> &core,
163
	const string &uri,
164
	const IdentityAddress &me,
165
	const string &subject
166
) : ChatRoom(*new ClientGroupChatRoomPrivate, core, ChatRoomId(IdentityAddress(), me)),
167
RemoteConference(core, me, nullptr) {
168
	L_D();
169
	L_D_T(RemoteConference, dConference);
170 171 172

	d->bgTask.setName("Client group chat room refer received");

173 174 175
	IdentityAddress focusAddr(uri);
	dConference->focus = make_shared<Participant>(focusAddr);
	dConference->focus->getPrivate()->addDevice(focusAddr);
176
	RemoteConference::setSubject(subject);
177 178
}

179 180
ClientGroupChatRoom::ClientGroupChatRoom (
	const shared_ptr<Core> &core,
Benjamin REIS's avatar
Benjamin REIS committed
181
	const ChatRoomId &chatRoomId,
Ronan's avatar
Ronan committed
182
	shared_ptr<Participant> &me,
183
	AbstractChatRoom::CapabilitiesMask capabilities,
184
	const string &subject,
185
	list<shared_ptr<Participant>> &&participants,
186
	unsigned int lastNotifyId
Benjamin REIS's avatar
Benjamin REIS committed
187
) : ChatRoom(*new ClientGroupChatRoomPrivate, core, chatRoomId),
Ronan's avatar
Ronan committed
188
RemoteConference(core, me->getAddress(), nullptr) {
189
	L_D();
190
	L_D_T(RemoteConference, dConference);
191

192
	d->capabilities |= capabilities & ClientGroupChatRoom::Capabilities::OneToOne;
Benjamin REIS's avatar
Benjamin REIS committed
193
	const IdentityAddress &peerAddress = chatRoomId.getPeerAddress();
194
	dConference->focus = make_shared<Participant>(peerAddress);
195
	dConference->focus->getPrivate()->addDevice(peerAddress);
196 197
	dConference->conferenceAddress = peerAddress;
	dConference->subject = subject;
198
	dConference->participants = move(participants);
199

Ronan's avatar
Ronan committed
200
	getMe()->getPrivate()->setAdmin(me->isAdmin());
201

202
	dConference->eventHandler->setLastNotify(lastNotifyId);
203
	dConference->eventHandler->subscribe(getChatRoomId());
204 205
}

206 207 208 209
shared_ptr<Core> ClientGroupChatRoom::getCore () const {
	return ChatRoom::getCore();
}

Sylvain Berfini's avatar
Sylvain Berfini committed
210
void ClientGroupChatRoom::allowCpim (bool value) {
211

Sylvain Berfini's avatar
Sylvain Berfini committed
212 213 214
}

void ClientGroupChatRoom::allowMultipart (bool value) {
215

Sylvain Berfini's avatar
Sylvain Berfini committed
216 217
}

218 219 220 221 222 223 224 225
bool ClientGroupChatRoom::canHandleCpim () const {
	return true;
}

bool ClientGroupChatRoom::canHandleMultipart () const {
	return true;
}

226
ClientGroupChatRoom::CapabilitiesMask ClientGroupChatRoom::getCapabilities () const {
227 228
	L_D();
	return d->capabilities;
229 230
}

231
bool ClientGroupChatRoom::hasBeenLeft () const {
232
	return getState() != State::Created;
233 234
}

235 236 237 238
bool ClientGroupChatRoom::canHandleParticipants () const {
	return RemoteConference::canHandleParticipants();
}

239
const IdentityAddress &ClientGroupChatRoom::getConferenceAddress () const {
240
	return RemoteConference::getConferenceAddress();
241
}
242

243 244 245 246 247 248 249 250 251 252
void ClientGroupChatRoom::deleteFromDb () {
	L_D();
	if (!hasBeenLeft()) {
		d->deletionOnTerminationEnabled = true;
		leave();
		return;
	}
	d->chatRoomListener->onChatRoomDeleteRequested(getSharedFromThis());
}

253 254
void ClientGroupChatRoom::addParticipant (const IdentityAddress &addr, const CallSessionParams *params, bool hasMedia) {
	list<IdentityAddress> addresses;
255 256
	addresses.push_back(addr);
	addParticipants(addresses, params, hasMedia);
257 258
}

259
void ClientGroupChatRoom::addParticipants (
260
	const list<IdentityAddress> &addresses,
261 262 263
	const CallSessionParams *params,
	bool hasMedia
) {
264
	L_D();
265
	L_D_T(RemoteConference, dConference);
266

267
	list<IdentityAddress> addressesList = d->cleanAddressesList(addresses);
268
	if (addressesList.empty())
269
		return;
270

271
	if ((getState() != ChatRoom::State::Instantiated) && (getState() != ChatRoom::State::Created)) {
272 273 274
		lError() << "Cannot add participants to the ClientGroupChatRoom in a state other than Instantiated or Created";
		return;
	}
275

276 277 278 279 280 281 282 283 284 285 286 287 288
	if ((getState() == ChatRoom::State::Created) && (d->capabilities & ClientGroupChatRoom::Capabilities::OneToOne)) {
		lError() << "Cannot add more participants to a OneToOne ClientGroupChatRoom";
		return;
	}

	if ((getState() == ChatRoom::State::Instantiated)
		&& (addressesList.size() == 1)
		&& (linphone_config_get_bool(linphone_core_get_config(L_GET_C_BACK_PTR(getCore())),
			"misc", "one_to_one_chat_room_enabled", TRUE))
	) {
		d->capabilities |= ClientGroupChatRoom::Capabilities::OneToOne;
	}

289
	Content content;
290
	content.setBody(getResourceLists(addressesList));
291 292
	content.setContentType("application/resource-lists+xml");
	content.setContentDisposition("recipient-list");
293

294
	shared_ptr<CallSession> session = dConference->focus->getPrivate()->getSession();
295
	if (session)
296
		session->update(nullptr, getSubject(), &content);
297 298
	else {
		session = d->createSession();
299
		session->startInvite(nullptr, getSubject(), &content);
300
		if (getState() == ChatRoom::State::Instantiated)
301
			d->setState(ChatRoom::State::CreationPending);
302
	}
303 304
}

305
void ClientGroupChatRoom::removeParticipant (const shared_ptr<const Participant> &participant) {
306
	LinphoneCore *cCore = getCore()->getCCore();
307 308

	SalReferOp *referOp = new SalReferOp(cCore->sal);
309
	LinphoneAddress *lAddr = linphone_address_new(getConferenceAddress().asString().c_str());
310
	linphone_configure_op(cCore, referOp, lAddr, nullptr, false);
311 312 313 314 315 316
	linphone_address_unref(lAddr);
	Address referToAddr = participant->getAddress();
	referToAddr.setParam("text");
	referToAddr.setUriParam("method", "BYE");
	referOp->send_refer(referToAddr.getPrivate()->getInternalAddress());
	referOp->unref();
317 318
}

319
void ClientGroupChatRoom::removeParticipants (const list<shared_ptr<Participant>> &participants) {
320
	RemoteConference::removeParticipants(participants);
321
}
322

323
shared_ptr<Participant> ClientGroupChatRoom::findParticipant (const IdentityAddress &addr) const {
324 325 326 327 328 329 330
	return RemoteConference::findParticipant(addr);
}

shared_ptr<Participant> ClientGroupChatRoom::getMe () const {
	return RemoteConference::getMe();
}

331 332
int ClientGroupChatRoom::getParticipantCount () const {
	return RemoteConference::getParticipantCount();
333 334
}

Ghislain MARY's avatar
Ghislain MARY committed
335
const list<shared_ptr<Participant>> &ClientGroupChatRoom::getParticipants () const {
336 337 338
	return RemoteConference::getParticipants();
}

339
void ClientGroupChatRoom::setParticipantAdminStatus (const shared_ptr<Participant> &participant, bool isAdmin) {
340 341
	if (isAdmin == participant->isAdmin())
		return;
342 343

	if (!getMe()->isAdmin()) {
344 345 346
		lError() << "Cannot change the participant admin status because I am not admin";
		return;
	}
347

348
	LinphoneCore *cCore = getCore()->getCCore();
349 350

	SalReferOp *referOp = new SalReferOp(cCore->sal);
351
	LinphoneAddress *lAddr = linphone_address_new(getConferenceAddress().asString().c_str());
352
	linphone_configure_op(cCore, referOp, lAddr, nullptr, false);
353 354 355 356 357 358 359 360
	linphone_address_unref(lAddr);
	Address referToAddr = participant->getAddress();
	referToAddr.setParam("text");
	referToAddr.setParam("admin", Utils::toString(isAdmin));
	referOp->send_refer(referToAddr.getPrivate()->getInternalAddress());
	referOp->unref();
}

361 362 363 364
const string &ClientGroupChatRoom::getSubject () const {
	return RemoteConference::getSubject();
}

365 366
void ClientGroupChatRoom::setSubject (const string &subject) {
	L_D();
367
	L_D_T(RemoteConference, dConference);
368

369
	if (getState() != ChatRoom::State::Created) {
370 371 372
		lError() << "Cannot change the ClientGroupChatRoom subject in a state other than Created";
		return;
	}
373 374

	if (!getMe()->isAdmin()) {
375 376 377
		lError() << "Cannot change the ClientGroupChatRoom subject because I am not admin";
		return;
	}
378

379
	shared_ptr<CallSession> session = dConference->focus->getPrivate()->getSession();
380 381 382 383 384 385
	if (session)
		session->update(nullptr, subject);
	else {
		session = d->createSession();
		session->startInvite(nullptr, subject, nullptr);
	}
386 387
}

388 389 390 391 392
void ClientGroupChatRoom::join () {
	L_D();
	L_D_T(RemoteConference, dConference);

	shared_ptr<CallSession> session = dConference->focus->getPrivate()->getSession();
393
	if (!session && ((getState() == ChatRoom::State::Instantiated) || (getState() == ChatRoom::State::Terminated))) {
394
		d->bgTask.start();
395
		session = d->createSession();
396 397 398 399
	}
	if (session) {
		if (getState() != ChatRoom::State::TerminationPending)
			session->startInvite(nullptr, "", nullptr);
400 401 402 403 404 405 406 407
		d->setState(ChatRoom::State::CreationPending);
	}
}

void ClientGroupChatRoom::leave () {
	L_D();
	L_D_T(RemoteConference, dConference);

408
	d->bgTask.start();
409
	dConference->eventHandler->unsubscribe();
410

411 412 413 414 415 416 417
	shared_ptr<CallSession> session = dConference->focus->getPrivate()->getSession();
	if (session)
		session->terminate();
	else {
		session = d->createSession();
		session->startInvite(nullptr, "", nullptr);
	}
418

419
	d->setState(ChatRoom::State::TerminationPending);
420 421
}

422 423
// -----------------------------------------------------------------------------

424
void ClientGroupChatRoom::onConferenceCreated (const IdentityAddress &addr) {
425
	L_D();
426 427
	L_D_T(RemoteConference, dConference);
	dConference->conferenceAddress = addr;
428
	dConference->focus->getPrivate()->setAddress(addr);
429 430
	dConference->focus->getPrivate()->clearDevices();
	dConference->focus->getPrivate()->addDevice(addr);
431
	d->chatRoomId = ChatRoomId(addr, d->chatRoomId.getLocalAddress());
432
	d->chatRoomListener->onChatRoomInsertRequested(getSharedFromThis());
433 434
}

435 436 437 438 439
void ClientGroupChatRoom::onConferenceKeywordsChanged (const vector<string> &keywords) {
	L_D();
	d->capabilities |= ClientGroupChatRoom::Capabilities::OneToOne;
}

440
void ClientGroupChatRoom::onConferenceTerminated (const IdentityAddress &addr) {
441
	L_D();
442 443
	L_D_T(RemoteConference, dConference);
	dConference->eventHandler->resetLastNotify();
444
	d->setState(ChatRoom::State::Terminated);
445
	d->addEvent(make_shared<ConferenceEvent>(
446 447 448 449
		EventLog::Type::ConferenceTerminated,
		time(nullptr),
		d->chatRoomId
	));
450 451 452 453
	if (d->deletionOnTerminationEnabled) {
		d->deletionOnTerminationEnabled = false;
		d->chatRoomListener->onChatRoomDeleteRequested(getSharedFromThis());
	}
454 455
}

456
void ClientGroupChatRoom::onFirstNotifyReceived (const IdentityAddress &addr) {
457 458
	L_D();
	d->setState(ChatRoom::State::Created);
459

460 461 462 463 464 465 466 467 468
	if (getParticipantCount() == 1) {
		ChatRoomId id(getParticipants().front()->getAddress(), getMe()->getAddress());
		shared_ptr<AbstractChatRoom> chatRoom = getCore()->findChatRoom(id);
		if (chatRoom && (chatRoom->getCapabilities() & ChatRoom::Capabilities::Basic)) {
			BasicToClientGroupChatRoom::migrate(getSharedFromThis(), chatRoom);
			return;
		}
	}

469
	d->chatRoomListener->onChatRoomInsertInDatabaseRequested(getSharedFromThis());
470 471 472 473

	// TODO: Bug. Event is inserted many times.
	// Avoid this in the future. Deal with signals/slots system.
	#if 0
474
	d->addEvent(make_shared<ConferenceEvent>(
475 476 477 478
		EventLog::Type::ConferenceCreated,
		time(nullptr),
		d->chatRoomId
	));
479
	#endif
480
	d->bgTask.stop();
481 482
}

483
void ClientGroupChatRoom::onParticipantAdded (const shared_ptr<ConferenceParticipantEvent> &event, bool isFullState) {
484
	L_D();
485 486
	L_D_T(RemoteConference, dConference);

487
	const IdentityAddress &addr = event->getParticipantAddress();
488 489
	if (isMe(addr))
		return;
490

491 492 493 494 495
	shared_ptr<Participant> participant = findParticipant(addr);
	if (participant) {
		lWarning() << "Participant " << participant << " added but already in the list of participants!";
		return;
	}
496

Ronan's avatar
Ronan committed
497
	participant = make_shared<Participant>(addr);
498
	dConference->participants.push_back(participant);
499 500 501 502

	if (isFullState)
		return;

503
	d->addEvent(event);
Benjamin REIS's avatar
Benjamin REIS committed
504

505
	LinphoneChatRoom *cr = L_GET_C_BACK_PTR(this);
506 507 508
	LinphoneChatRoomCbs *cbs = linphone_chat_room_get_callbacks(cr);
	LinphoneChatRoomCbsParticipantAddedCb cb = linphone_chat_room_cbs_get_participant_added(cbs);
	if (cb)
Ronan's avatar
Ronan committed
509
		cb(cr, L_GET_C_BACK_PTR(event));
510 511
}

512
void ClientGroupChatRoom::onParticipantRemoved (const shared_ptr<ConferenceParticipantEvent> &event, bool isFullState) {
513
	(void)isFullState;
514

515
	L_D();
516 517
	L_D_T(RemoteConference, dConference);

518
	const IdentityAddress &addr = event->getParticipantAddress();
519 520
	shared_ptr<Participant> participant = findParticipant(addr);
	if (!participant) {
521
		lWarning() << "Participant " << addr.asString() << " removed but not in the list of participants!";
522 523
		return;
	}
524

525
	dConference->participants.remove(participant);
526
	d->addEvent(event);
527

528
	LinphoneChatRoom *cr = L_GET_C_BACK_PTR(this);
529 530 531
	LinphoneChatRoomCbs *cbs = linphone_chat_room_get_callbacks(cr);
	LinphoneChatRoomCbsParticipantRemovedCb cb = linphone_chat_room_cbs_get_participant_removed(cbs);
	if (cb)
Ronan's avatar
Ronan committed
532
		cb(cr, L_GET_C_BACK_PTR(event));
533 534
}

535
void ClientGroupChatRoom::onParticipantSetAdmin (const shared_ptr<ConferenceParticipantEvent> &event, bool isFullState) {
536 537
	L_D();

538
	const IdentityAddress &addr = event->getParticipantAddress();
539
	shared_ptr<Participant> participant;
540
	if (isMe(addr))
541
		participant = getMe();
542 543
	else
		participant = findParticipant(addr);
544
	if (!participant) {
545
		lWarning() << "Participant " << addr.asString() << " admin status has been changed but is not in the list of participants!";
546 547
		return;
	}
548

549 550 551 552 553
	bool isAdmin = event->getType() == EventLog::Type::ConferenceParticipantSetAdmin;
	if (participant->isAdmin() == isAdmin)
		return; // No change in the local admin status, do not notify
	participant->getPrivate()->setAdmin(isAdmin);

554 555 556
	if (isFullState)
		return;

557
	d->addEvent(event);
Benjamin REIS's avatar
Benjamin REIS committed
558

559
	LinphoneChatRoom *cr = L_GET_C_BACK_PTR(this);
560 561 562
	LinphoneChatRoomCbs *cbs = linphone_chat_room_get_callbacks(cr);
	LinphoneChatRoomCbsParticipantAdminStatusChangedCb cb = linphone_chat_room_cbs_get_participant_admin_status_changed(cbs);
	if (cb)
Ronan's avatar
Ronan committed
563
		cb(cr, L_GET_C_BACK_PTR(event));
564 565
}

566
void ClientGroupChatRoom::onSubjectChanged (const shared_ptr<ConferenceSubjectEvent> &event, bool isFullState) {
567 568
	L_D();

569 570
	if (getSubject() == event->getSubject())
		return; // No change in the local subject, do not notify
571
	RemoteConference::setSubject(event->getSubject());
572

573 574 575
	if (isFullState)
		return;

576
	d->addEvent(event);
Benjamin REIS's avatar
Benjamin REIS committed
577

578 579 580 581
	LinphoneChatRoom *cr = L_GET_C_BACK_PTR(this);
	LinphoneChatRoomCbs *cbs = linphone_chat_room_get_callbacks(cr);
	LinphoneChatRoomCbsSubjectChangedCb cb = linphone_chat_room_cbs_get_subject_changed(cbs);
	if (cb)
Ronan's avatar
Ronan committed
582
		cb(cr, L_GET_C_BACK_PTR(event));
583 584
}

585
void ClientGroupChatRoom::onParticipantDeviceAdded (const shared_ptr<ConferenceParticipantDeviceEvent> &event, bool isFullState) {
586 587
	L_D();

588
	const IdentityAddress &addr = event->getParticipantAddress();
589
	shared_ptr<Participant> participant;
590
	if (isMe(addr))
591
		participant = getMe();
592 593 594
	else
		participant = findParticipant(addr);
	if (!participant) {
595
		lWarning() << "Participant " << addr.asString() << " added a device but is not in the list of participants!";
596 597
		return;
	}
598
	participant->getPrivate()->addDevice(event->getDeviceAddress());
599 600 601 602

	if (isFullState)
		return;

603
	d->addEvent(event);
Benjamin REIS's avatar
Benjamin REIS committed
604

Benjamin REIS's avatar
Benjamin REIS committed
605 606 607 608
	LinphoneChatRoom *cr = L_GET_C_BACK_PTR(this);
	LinphoneChatRoomCbs *cbs = linphone_chat_room_get_callbacks(cr);
	LinphoneChatRoomCbsParticipantDeviceAddedCb cb = linphone_chat_room_cbs_get_participant_device_added(cbs);
	if (cb)
Ronan's avatar
Ronan committed
609
		cb(cr, L_GET_C_BACK_PTR(event));
610 611
}

612
void ClientGroupChatRoom::onParticipantDeviceRemoved (const shared_ptr<ConferenceParticipantDeviceEvent> &event, bool isFullState) {
613 614
	L_D();

615
	(void)isFullState;
616

617
	const IdentityAddress &addr = event->getParticipantAddress();
618
	shared_ptr<Participant> participant;
619
	if (isMe(addr))
620
		participant = getMe();
621 622 623
	else
		participant = findParticipant(addr);
	if (!participant) {
624
		lWarning() << "Participant " << addr.asString() << " removed a device but is not in the list of participants!";
625 626
		return;
	}
627
	participant->getPrivate()->removeDevice(event->getDeviceAddress());
628
	d->addEvent(event);
Benjamin REIS's avatar
Benjamin REIS committed
629

Benjamin REIS's avatar
Benjamin REIS committed
630 631 632 633
	LinphoneChatRoom *cr = L_GET_C_BACK_PTR(this);
	LinphoneChatRoomCbs *cbs = linphone_chat_room_get_callbacks(cr);
	LinphoneChatRoomCbsParticipantDeviceRemovedCb cb = linphone_chat_room_cbs_get_participant_device_removed(cbs);
	if (cb)
Ronan's avatar
Ronan committed
634
		cb(cr, L_GET_C_BACK_PTR(event));
635 636
}

637
LINPHONE_END_NAMESPACE