/
recipient.cpp
781 lines (657 loc) · 21 KB
/
recipient.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
/******************************************************************************
**
** This file is part of libcommhistory.
**
** Copyright (C) 2014 Jolla Ltd.
** Contact: John Brooks <john.brooks@jolla.com>
**
** This library is free software; you can redistribute it and/or modify it
** under the terms of the GNU Lesser General Public License version 2.1 as
** published by the Free Software Foundation.
**
** This library 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 Lesser General Public
** License for more details.
**
** You should have received a copy of the GNU Lesser General Public License
** along with this library; if not, write to the Free Software Foundation, Inc.,
** 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
**
******************************************************************************/
#include "recipient.h"
#include "commonutils.h"
#include <QSet>
#include <QHash>
#include <QDebug>
#include <phonenumbers/phonenumberutil.h>
namespace {
bool initializeTypes()
{
qRegisterMetaType<CommHistory::Recipient>();
qRegisterMetaType<CommHistory::RecipientList>();
return true;
}
QString minimizeRemoteUid(const QString &remoteUid, bool isPhoneNumber)
{
// For non-standard localUid values, we still need a comparable value.
// For non-phone-number remoteUid values (e.g. non-replyable SMS senders), we still need a comparable value.
// In that case, even if isPhoneNumber is true (e.g. is from a SIM modem)
// the minimized form of the number might be empty (due to invalid phone number format).
const QString minimized = isPhoneNumber ? CommHistory::minimizePhoneNumber(remoteUid).toLower() : QString();
return minimized.isEmpty() ? remoteUid.toLower() : minimized;
}
quint32 addressFlagValues(quint64 statusFlags)
{
return statusFlags & (QContactStatusFlags::HasPhoneNumber | QContactStatusFlags::HasEmailAddress | QContactStatusFlags::HasOnlineAccount);
}
QPair<QString, QString> makeUidPair(const QString &localUid, const QString &remoteUid)
{
// If localUid is for phone number, use prefix alone to find the RecipientPrivate
// this avoids problems with different SIMs etc.
const bool usesPhoneNumberComparison = CommHistory::localUidComparesPhoneNumbers(localUid);
return qMakePair(usesPhoneNumberComparison ? CommHistory::RING_ACCOUNT : localUid,
::minimizeRemoteUid(remoteUid, usesPhoneNumberComparison));
}
}
bool recipient_initialized = initializeTypes();
namespace CommHistory {
class RecipientPrivate
{
public:
QString localUid;
QString remoteUid;
SeasideCache::CacheItem* item;
bool isResolved;
bool isPhoneNumber;
QString minimizedRemoteUid;
quint32 localUidHash;
quint32 remoteUidHash;
quint32 contactNameHash;
quint32 addressFlags;
RecipientPrivate(const QString &localUid, const QString &remoteUid);
~RecipientPrivate();
static QSharedPointer<RecipientPrivate> get(const QString &localUid, const QString &remoteUid);
};
}
using namespace CommHistory;
typedef QHash<QPair<QString,QString>,WeakRecipient> RecipientUidMap;
typedef QMultiHash<int,WeakRecipient> RecipientContactMap;
Q_GLOBAL_STATIC(RecipientUidMap, recipientInstances);
Q_GLOBAL_STATIC(RecipientContactMap, recipientContactMap);
Q_GLOBAL_STATIC_WITH_ARGS(QSharedPointer<RecipientPrivate>, sharedNullRecipient, (new RecipientPrivate(QString(), QString())));
Recipient::Recipient()
{
d = *sharedNullRecipient;
}
Recipient::Recipient(const QString &localUid, const QString &remoteUid)
: d(RecipientPrivate::get(localUid, remoteUid))
{
}
Recipient::Recipient(const Recipient &o)
: d(o.d)
{
}
Recipient::Recipient(const WeakRecipient &weak)
: d(weak)
{
if (!d)
d = *sharedNullRecipient;
}
Recipient &Recipient::operator=(const Recipient &o)
{
d = o.d;
return *this;
}
Recipient::~Recipient()
{
}
RecipientPrivate::RecipientPrivate(const QString &local, const QString &remote)
: localUid(local)
, remoteUid(remote)
, item(0)
, isResolved(false)
, isPhoneNumber(localUidComparesPhoneNumbers(localUid))
// The following members could be initialized on-demand, but that appears to be slower overall
, minimizedRemoteUid(::minimizeRemoteUid(remoteUid, isPhoneNumber))
, localUidHash(qHash(localUid))
, remoteUidHash(qHash(minimizedRemoteUid))
, contactNameHash(0)
, addressFlags(0)
{
}
RecipientPrivate::~RecipientPrivate()
{
if (!recipientInstances.isDestroyed()) {
recipientInstances->remove(makeUidPair(localUid, remoteUid));
}
}
QSharedPointer<RecipientPrivate> RecipientPrivate::get(const QString &localUid, const QString &remoteUid)
{
if (localUid.isEmpty() && remoteUid.isEmpty()) {
return *sharedNullRecipient;
}
const QPair<QString, QString> uids = makeUidPair(localUid, remoteUid);
QSharedPointer<RecipientPrivate> instance = recipientInstances->value(uids);
if (!instance) {
instance = QSharedPointer<RecipientPrivate>(new RecipientPrivate(localUid, remoteUid));
recipientInstances->insert(uids, instance);
}
return instance;
}
bool Recipient::isNull() const
{
return d->localUid.isEmpty() && d->remoteUid.isEmpty();
}
QString Recipient::displayName() const
{
return d->item ? d->item->displayLabel : d->remoteUid;
}
QString Recipient::localUid() const
{
return d->localUid;
}
QString Recipient::remoteUid() const
{
return d->remoteUid;
}
bool Recipient::isPhoneNumber() const
{
return d->isPhoneNumber;
}
QString Recipient::minimizedPhoneNumber() const
{
return d->isPhoneNumber ? CommHistory::minimizePhoneNumber(d->remoteUid) : QString();
}
QString Recipient::minimizedRemoteUid() const
{
return d->minimizedRemoteUid;
}
// Because all equal instances share a dptr, this is a very fast comparison
bool Recipient::operator==(const Recipient &o) const
{
return d == o.d;
}
bool Recipient::matches(const Recipient &o) const
{
if (d == o.d)
return true;
if (d->isPhoneNumber != o.d->isPhoneNumber)
return false;
// For phone numbers, we ignore localUid comparison - may have to change in future?
if (!d->isPhoneNumber && d->localUidHash != o.d->localUidHash)
return false;
if (d->remoteUidHash != o.d->remoteUidHash)
return false;
if (!d->isPhoneNumber && d->localUid != o.d->localUid)
return false;
// Phone numbers are a special case
if (d->isPhoneNumber)
return matchesPhoneNumber(o.toPhoneNumberMatchDetails());
// For non-phonenumbers, matching the minimized remote uid is sufficient
if (!d->minimizedRemoteUid.isEmpty() || !o.d->minimizedRemoteUid.isEmpty())
return d->minimizedRemoteUid == o.d->minimizedRemoteUid;
return d->remoteUid == o.d->remoteUid;
}
bool Recipient::isSameContact(const Recipient &o) const
{
if (d == o.d)
return true;
if (d->isResolved && o.d->isResolved && (d->item || o.d->item))
return d->item == o.d->item;
return matches(o);
}
bool Recipient::matchesRemoteUid(const QString &o) const
{
// Phone numbers are a special case
if (d->isPhoneNumber)
return matchesPhoneNumber(Recipient::phoneNumberMatchDetails(o));
const QString minimizedMatch(::minimizeRemoteUid(o, d->isPhoneNumber));
if (!minimizedMatch.isEmpty())
return d->minimizedRemoteUid == minimizedMatch;
return d->remoteUid == o;
}
bool Recipient::matchesPhoneNumber(const PhoneNumberMatchDetails &phoneNumber) const
{
if (!d->isPhoneNumber)
return false;
// Matching the minimized phone number is necessary, but insufficient
if (d->remoteUidHash != 0 && phoneNumber.minimizedNumberHash != 0 && d->remoteUidHash != phoneNumber.minimizedNumberHash)
return false;
if (!phoneNumber.minimizedNumber.isEmpty() && !d->minimizedRemoteUid.isEmpty() && d->minimizedRemoteUid != phoneNumber.minimizedNumber)
return false;
// Full match of the full phone number is always sufficient
if (d->remoteUid == phoneNumber.number)
return true;
// TODO: consider plumbing the region code here for potentially more accurate matching
::i18n::phonenumbers::PhoneNumberUtil *util = ::i18n::phonenumbers::PhoneNumberUtil::GetInstance();
::i18n::phonenumbers::PhoneNumberUtil::MatchType match = util->IsNumberMatchWithTwoStrings(d->remoteUid.toStdString(), phoneNumber.number.toStdString());
return match == ::i18n::phonenumbers::PhoneNumberUtil::EXACT_MATCH || match == ::i18n::phonenumbers::PhoneNumberUtil::NSN_MATCH;
}
bool Recipient::matchesAddressFlags(quint64 flags) const
{
if (!d->item)
return false;
if (addressFlagValues(flags) == 0)
return true;
return d->item->statusFlags & flags;
}
int Recipient::contactId() const
{
return d->item ? d->item->iid : 0;
}
QString Recipient::contactName() const
{
return d->item ? d->item->displayLabel : QString();
}
QUrl Recipient::contactAvatarUrl() const
{
return d->item ? SeasideCache::filteredAvatarUrl(d->item->contact) : QUrl();
}
bool Recipient::isContactResolved() const
{
return d->isResolved;
}
bool Recipient::setResolved(SeasideCache::CacheItem *item) const
{
if (d->isResolved && item == d->item)
return false;
if (d->isResolved && d->item)
recipientContactMap->remove(d->item->iid, d);
recipientContactMap->insert(item ? item->iid : 0, d.toWeakRef());
d->isResolved = true;
d->item = item;
d->contactNameHash = item ? qHash(item->displayLabel) : 0;
d->addressFlags = item ? addressFlagValues(item->statusFlags) : 0;
return true;
}
void Recipient::setUnresolved() const
{
if (!d->isResolved)
return;
if (d->item)
recipientContactMap->remove(d->item->iid, d);
d->isResolved = false;
d->item = 0;
d->contactNameHash = 0;
d->addressFlags = 0;
}
bool Recipient::contactUpdateIsSignificant() const
{
if (d->item) {
// The contact display label may have been updated
const quint32 hash(qHash(d->item->displayLabel));
const quint32 addressFlags(addressFlagValues(d->item->statusFlags));
if (hash != d->contactNameHash || addressFlags != d->addressFlags) {
d->contactNameHash = hash;
d->addressFlags = addressFlags;
return true;
}
}
return false;
}
QList<Recipient> Recipient::recipientsForContact(int contactId)
{
QList<Recipient> re;
RecipientContactMap::iterator it = recipientContactMap->find(contactId);
for (; it != recipientContactMap->end() && it.key() == contactId; ) {
if (!*it) {
it = recipientContactMap->erase(it);
continue;
}
re.append(Recipient(*it));
it++;
}
return re;
}
Recipient::PhoneNumberMatchDetails Recipient::phoneNumberMatchDetails(const QString &s)
{
PhoneNumberMatchDetails rv;
rv.number = s;
rv.minimizedNumber = minimizeRemoteUid(s, true);
rv.minimizedNumberHash = qHash(rv.minimizedNumber);
return rv;
}
Recipient::PhoneNumberMatchDetails Recipient::toPhoneNumberMatchDetails() const
{
Q_ASSERT(d->isPhoneNumber);
if (d->minimizedRemoteUid.isEmpty() || d->remoteUidHash == 0) {
return phoneNumberMatchDetails(d->remoteUid);
}
PhoneNumberMatchDetails det;
det.number = d->remoteUid;
det.minimizedNumber = d->minimizedRemoteUid;
det.minimizedNumberHash = d->remoteUidHash;
return det;
}
RecipientList::RecipientList()
{
}
RecipientList::RecipientList(const Recipient &recipient)
{
m_recipients << recipient;
}
RecipientList::RecipientList(const QList<Recipient> &r)
: m_recipients(r)
{
}
RecipientList RecipientList::fromUids(const QString &localUid, const QStringList &remoteUids)
{
RecipientList re;
foreach (const QString &remoteUid, remoteUids)
re << Recipient(localUid, remoteUid);
return re;
}
RecipientList RecipientList::fromContact(int contactId)
{
return fromCacheItem(SeasideCache::itemById(contactId, false));
}
RecipientList RecipientList::fromContact(const QContactId &contactId)
{
return fromCacheItem(SeasideCache::itemById(contactId, false));
}
RecipientList RecipientList::fromCacheItem(const SeasideCache::CacheItem *item)
{
RecipientList re;
if (item && item->contactState == SeasideCache::ContactComplete) {
foreach (const QContactOnlineAccount &account, item->contact.details<QContactOnlineAccount>()) {
re << Recipient(account.value<QString>(QContactOnlineAccount__FieldAccountPath), account.accountUri());
}
foreach (const QContactPhoneNumber &phoneNumber, item->contact.details<QContactPhoneNumber>()) {
// Match with recipients calling from any SIM
re << Recipient(RING_ACCOUNT, phoneNumber.number());
}
}
return re;
}
bool RecipientList::isEmpty() const
{
return m_recipients.isEmpty();
}
int RecipientList::size() const
{
return m_recipients.size();
}
QList<Recipient> RecipientList::recipients() const
{
return m_recipients;
}
QStringList RecipientList::displayNames() const
{
QStringList re;
re.reserve(m_recipients.size());
foreach (const Recipient &r, m_recipients)
re.append(r.displayName());
return re;
}
// XXX flawed, shouldn't be around
QList<int> RecipientList::contactIds() const
{
QSet<int> re;
re.reserve(m_recipients.size());
foreach (const Recipient &r, m_recipients) {
if (r.contactId() > 0)
re.insert(r.contactId());
}
return re.values();
}
QStringList RecipientList::remoteUids() const
{
QStringList re;
re.reserve(m_recipients.size());
foreach (const Recipient &r, m_recipients)
re.append(r.remoteUid());
return re;
}
bool RecipientList::operator==(const RecipientList &o) const
{
if (o.m_recipients.size() != m_recipients.size())
return false;
QList<Recipient> match = o.m_recipients;
foreach (const Recipient &r, m_recipients) {
int i = match.indexOf(r);
if (i < 0)
return false;
match.removeAt(i);
}
return true;
}
namespace {
QList<Recipient> removeMatches(const RecipientList &list, bool (Recipient::*mf)(const Recipient &) const)
{
QList<Recipient> rv;
rv.reserve(list.size());
foreach (const Recipient &r, list) {
QList<Recipient>::const_iterator it = rv.constBegin(), end = rv.constEnd();
for ( ; it != end; ++it) {
if ((r.*mf)(*it)) {
break;
}
}
if (it == end) {
// No previous instances that match this recipient
rv.append(r);
}
}
return rv;
}
QList<Recipient> removeMatches(const RecipientList &list)
{
return removeMatches(list, &Recipient::matches);
}
QList<Recipient> removeSameContacts(const RecipientList &list)
{
return removeMatches(list, &Recipient::isSameContact);
}
}
bool RecipientList::matches(const RecipientList &o) const
{
if (m_recipients.size() == 1 && o.m_recipients.size() == 1)
return m_recipients.first().matches(o.m_recipients.first());
QList<Recipient> myRecipients(removeMatches(m_recipients));
QList<Recipient> otherRecipients(removeMatches(o.m_recipients));
if (myRecipients.size() != otherRecipients.size())
return false;
foreach (const Recipient &r, myRecipients) {
QList<Recipient>::iterator it = otherRecipients.begin(), end = otherRecipients.end();
for ( ; it != end; ++it) {
if (r.matches(*it)) {
otherRecipients.erase(it);
break;
}
}
if (it == end)
return false;
}
return true;
}
bool RecipientList::hasSameContacts(const RecipientList &o) const
{
if (m_recipients.size() == 1 && o.m_recipients.size() == 1)
return m_recipients.first().isSameContact(o.m_recipients.first());
QList<Recipient> myRecipients(removeSameContacts(m_recipients));
QList<Recipient> otherRecipients(removeSameContacts(o.m_recipients));
if (myRecipients.size() != otherRecipients.size())
return false;
foreach (const Recipient &r, myRecipients) {
QList<Recipient>::iterator it = otherRecipients.begin(), end = otherRecipients.end();
for ( ; it != end; ++it) {
if (r.isSameContact(*it)) {
otherRecipients.erase(it);
break;
}
}
if (it == end)
return false;
}
return true;
}
bool RecipientList::allContactsResolved() const
{
foreach (const Recipient &r, m_recipients) {
if (!r.isContactResolved())
return false;
}
return true;
}
QString RecipientList::debugString() const
{
QString output = QStringLiteral("(");
foreach (const Recipient &r, m_recipients) {
if (output.size() > 1)
output.append(QStringLiteral(", "));
output.append(QStringLiteral("[%1:%2]").arg(r.localUid()).arg(r.remoteUid()));
if (r.contactId() > 0)
output.append(QStringLiteral(" -> %1 '%2'").arg(r.contactId()).arg(r.contactName()));
}
output.append(QLatin1Char(')'));
return output;
}
RecipientList::iterator RecipientList::begin()
{
return m_recipients.begin();
}
RecipientList::iterator RecipientList::end()
{
return m_recipients.end();
}
RecipientList::iterator RecipientList::find(const Recipient &r)
{
iterator it = begin(), end = this->end();
for ( ; it != end; ++it) {
if (it->isSameContact(r)) {
break;
}
}
return it;
}
RecipientList::iterator RecipientList::findMatch(const Recipient &r)
{
iterator it = begin(), end = this->end();
for ( ; it != end; ++it) {
if (it->matches(r)) {
break;
}
}
return it;
}
RecipientList::const_iterator RecipientList::constBegin() const
{
return m_recipients.constBegin();
}
RecipientList::const_iterator RecipientList::constEnd() const
{
return m_recipients.constEnd();
}
RecipientList::const_iterator RecipientList::constFind(const Recipient &r) const
{
const_iterator it = constBegin(), end = constEnd();
for ( ; it != end; ++it) {
if (it->isSameContact(r)) {
break;
}
}
return it;
}
RecipientList::const_iterator RecipientList::constFindMatch(const Recipient &r) const
{
const_iterator it = constBegin(), end = constEnd();
for ( ; it != end; ++it) {
if (it->matches(r)) {
break;
}
}
return it;
}
bool RecipientList::contains(const Recipient &r) const
{
return (constFind(r) != constEnd());
}
bool RecipientList::containsMatch(const Recipient &r) const
{
return (constFindMatch(r) != constEnd());
}
Recipient RecipientList::value(int index) const
{
return m_recipients.value(index);
}
const Recipient &RecipientList::at(int index) const
{
return m_recipients.at(index);
}
void RecipientList::append(const Recipient &r)
{
m_recipients.append(r);
}
void RecipientList::append(const QList<Recipient> &o)
{
m_recipients.append(o);
}
RecipientList &RecipientList::unite(const RecipientList &other)
{
foreach (const Recipient &r, other.m_recipients) {
if (constFind(r) == constEnd()) {
append(r);
}
}
return *this;
}
RecipientList &RecipientList::operator<<(const Recipient &recipient)
{
if (!m_recipients.contains(recipient))
m_recipients.append(recipient);
return *this;
}
QDebug &operator<<(QDebug &debug, const CommHistory::Recipient &r)
{
debug.nospace() << "Recipient(" << r.localUid() << " " << r.remoteUid()
<< " | " << r.contactId() << " " << r.contactName() << ")";
return debug.space();
}
QDebug &operator<<(QDebug &debug, const CommHistory::RecipientList &list)
{
debug.nospace() << "RecipientList(";
for (CommHistory::RecipientList::const_iterator begin = list.begin(), it = begin, end = list.end(); it != end; ++it) {
if (it != begin) {
debug << ", ";
}
debug << *it;
}
debug << ")";
return debug.space();
}
QDBusArgument &operator<<(QDBusArgument &argument, const CommHistory::Recipient &recipient)
{
argument.beginStructure();
argument << recipient.localUid() << recipient.remoteUid();
argument.endStructure();
return argument;
}
const QDBusArgument &operator>>(const QDBusArgument &argument, CommHistory::Recipient &recipient)
{
QString localUid, remoteUid;
argument.beginStructure();
argument >> localUid >> remoteUid;
argument.endStructure();
recipient = Recipient(localUid, remoteUid);
return argument;
}
QDBusArgument &operator<<(QDBusArgument &argument, const CommHistory::RecipientList &recipients)
{
argument.beginArray(qMetaTypeId<Recipient>());
foreach (const Recipient &r, recipients.recipients())
argument << r;
argument.endArray();
return argument;
}
const QDBusArgument &operator>>(const QDBusArgument &argument, CommHistory::RecipientList &recipients)
{
argument.beginArray();
while (!argument.atEnd()) {
Recipient r;
argument >> r;
recipients << r;
}
argument.endArray();
return argument;
}