client-group-chat-room.cpp 20.8 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 396 397 398 399 400 401 402 403 404
		session = d->createSession();
		session->startInvite(nullptr, "", nullptr);
		d->setState(ChatRoom::State::CreationPending);
	}
}

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

405
	d->bgTask.start();
406
	dConference->eventHandler->unsubscribe();
407

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

416
	d->setState(ChatRoom::State::TerminationPending);
417 418
}

419 420
// -----------------------------------------------------------------------------

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

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

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

453
void ClientGroupChatRoom::onFirstNotifyReceived (const IdentityAddress &addr) {
454 455
	L_D();
	d->setState(ChatRoom::State::Created);
456

457 458 459 460 461 462 463 464 465
	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;
		}
	}

466
	d->chatRoomListener->onChatRoomInsertInDatabaseRequested(getSharedFromThis());
467 468 469 470

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

480
void ClientGroupChatRoom::onParticipantAdded (const shared_ptr<ConferenceParticipantEvent> &event, bool isFullState) {
481
	L_D();
482 483
	L_D_T(RemoteConference, dConference);

484
	const IdentityAddress &addr = event->getParticipantAddress();
485 486
	if (isMe(addr))
		return;
487

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

Ronan's avatar
Ronan committed
494
	participant = make_shared<Participant>(addr);
495
	dConference->participants.push_back(participant);
496 497 498 499

	if (isFullState)
		return;

500
	d->addEvent(event);
Benjamin REIS's avatar
Benjamin REIS committed
501

502
	LinphoneChatRoom *cr = L_GET_C_BACK_PTR(this);
503 504 505
	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
506
		cb(cr, L_GET_C_BACK_PTR(event));
507 508
}

509
void ClientGroupChatRoom::onParticipantRemoved (const shared_ptr<ConferenceParticipantEvent> &event, bool isFullState) {
510
	(void)isFullState;
511

512
	L_D();
513 514
	L_D_T(RemoteConference, dConference);

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

522
	dConference->participants.remove(participant);
523
	d->addEvent(event);
524

525
	LinphoneChatRoom *cr = L_GET_C_BACK_PTR(this);
526 527 528
	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
529
		cb(cr, L_GET_C_BACK_PTR(event));
530 531
}

532
void ClientGroupChatRoom::onParticipantSetAdmin (const shared_ptr<ConferenceParticipantEvent> &event, bool isFullState) {
533 534
	L_D();

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

546 547 548 549 550
	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);

551 552 553
	if (isFullState)
		return;

554
	d->addEvent(event);
Benjamin REIS's avatar
Benjamin REIS committed
555

556
	LinphoneChatRoom *cr = L_GET_C_BACK_PTR(this);
557 558 559
	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
560
		cb(cr, L_GET_C_BACK_PTR(event));
561 562
}

563
void ClientGroupChatRoom::onSubjectChanged (const shared_ptr<ConferenceSubjectEvent> &event, bool isFullState) {
564 565
	L_D();

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

570 571 572
	if (isFullState)
		return;

573
	d->addEvent(event);
Benjamin REIS's avatar
Benjamin REIS committed
574

575 576 577 578
	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
579
		cb(cr, L_GET_C_BACK_PTR(event));
580 581
}

582
void ClientGroupChatRoom::onParticipantDeviceAdded (const shared_ptr<ConferenceParticipantDeviceEvent> &event, bool isFullState) {
583 584
	L_D();

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

	if (isFullState)
		return;

600
	d->addEvent(event);
Benjamin REIS's avatar
Benjamin REIS committed
601

Benjamin REIS's avatar
Benjamin REIS committed
602 603 604 605
	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
606
		cb(cr, L_GET_C_BACK_PTR(event));
607 608
}

609
void ClientGroupChatRoom::onParticipantDeviceRemoved (const shared_ptr<ConferenceParticipantDeviceEvent> &event, bool isFullState) {
610 611
	L_D();

612
	(void)isFullState;
613

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

Benjamin REIS's avatar
Benjamin REIS committed
627 628 629 630
	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
631
		cb(cr, L_GET_C_BACK_PTR(event));
632 633
}

634
LINPHONE_END_NAMESPACE