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
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
|
/*
* Copyright (C) 2008-2021 The QXmpp developers
*
* Authors:
* Manjeet Dahiya
* Jeremy Lainé
* Linus Jahn
*
* Source:
* https://github.com/qxmpp-project/qxmpp
*
* This file is a part of QXmpp library.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* 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.
*
*/
#include "QXmppMessage.h"
#include "QXmppBitsOfBinaryDataList.h"
#include "QXmppConstants_p.h"
#include "QXmppMixInvitation.h"
#include "QXmppOmemoElement.h"
#include "QXmppTrustMessageElement.h"
#include "QXmppUtils.h"
#include <optional>
#include <QDateTime>
#include <QDomElement>
#include <QTextStream>
#include <QXmlStreamWriter>
static const QStringList CHAT_STATES = {
QString(),
QStringLiteral("active"),
QStringLiteral("inactive"),
QStringLiteral("gone"),
QStringLiteral("composing"),
QStringLiteral("paused")
};
static const QStringList MESSAGE_TYPES = {
QStringLiteral("error"),
QStringLiteral("normal"),
QStringLiteral("chat"),
QStringLiteral("groupchat"),
QStringLiteral("headline")
};
static const QStringList MARKER_TYPES = {
QString(),
QStringLiteral("received"),
QStringLiteral("displayed"),
QStringLiteral("acknowledged")
};
static const QStringList ENCRYPTION_NAMESPACES = {
QString(),
QString(),
ns_otr,
ns_legacy_openpgp,
ns_ox,
ns_omemo
};
static const QStringList HINT_TYPES = {
QStringLiteral("no-permanent-store"),
QStringLiteral("no-store"),
QStringLiteral("no-copy"),
QStringLiteral("store")
};
static const QStringList ENCRYPTION_NAMES = {
QString(),
QString(),
QStringLiteral("OTR"),
QStringLiteral("Legacy OpenPGP"),
QStringLiteral("OpenPGP for XMPP (OX)"),
QStringLiteral("OMEMO")
};
static bool checkElement(const QDomElement &element, const QString &tagName, const QString &xmlns)
{
return element.tagName() == tagName && element.namespaceURI() == xmlns;
}
enum StampType {
LegacyDelayedDelivery, // XEP-0091: Legacy Delayed Delivery
DelayedDelivery // XEP-0203: Delayed Delivery
};
class QXmppMessagePrivate : public QSharedData
{
public:
QXmppMessagePrivate();
QString body;
QString subject;
QString thread;
QString parentThread;
QXmppMessage::Type type;
// XEP-0066: Out of Band Data
QString outOfBandUrl;
// XEP-0071: XHTML-IM
QString xhtml;
// XEP-0085: Chat State Notifications
QXmppMessage::State state;
// XEP-0091: Legacy Delayed Delivery | XEP-0203: Delayed Delivery
QDateTime stamp;
StampType stampType;
// XEP-0184: Message Delivery Receipts
QString receiptId;
bool receiptRequested;
// XEP-0224: Attention
bool attentionRequested;
// XEP-0231: Bits of Binary
QXmppBitsOfBinaryDataList bitsOfBinaryData;
// XEP-0249: Direct MUC Invitations
QString mucInvitationJid;
QString mucInvitationPassword;
QString mucInvitationReason;
// XEP-0280: Message Carbons
bool privatemsg;
// XEP-0308: Last Message Correction
QString replaceId;
// XEP-0333: Chat Markers
bool markable;
QXmppMessage::Marker marker;
QString markedId;
QString markedThread;
// XEP-0334: Message Processing Hints
quint8 hints;
// XEP-0359: Unique and Stable Stanza IDs
QString stanzaId;
QString stanzaIdBy;
QString originId;
// XEP-0367: Message Attaching
QString attachId;
// XEP-0369: Mediated Information eXchange (MIX)
QString mixUserJid;
QString mixUserNick;
// XEP-0380: Explicit Message Encryption
QString encryptionMethod;
QString encryptionName;
// XEP-0382: Spoiler messages
bool isSpoiler;
QString spoilerHint;
// XEP-0384: OMEMO Encryption
std::optional<QXmppOmemoElement> omemoElement;
// XEP-0407: Mediated Information eXchange (MIX): Miscellaneous Capabilities
std::optional<QXmppMixInvitation> mixInvitation;
// XEP-0428: Fallback Indication
bool isFallback;
// XEP-0434: Trust Messages (TM)
std::optional<QXmppTrustMessageElement> trustMessageElement;
};
QXmppMessagePrivate::QXmppMessagePrivate()
: type(QXmppMessage::Normal),
state(QXmppMessage::None),
stampType(DelayedDelivery),
receiptRequested(false),
attentionRequested(false),
privatemsg(false),
markable(false),
marker(QXmppMessage::NoMarker),
hints(0),
isSpoiler(false),
isFallback(false)
{
}
/// Constructs a QXmppMessage.
///
/// \param from
/// \param to
/// \param body
/// \param thread
QXmppMessage::QXmppMessage(const QString &from, const QString &to, const QString &body, const QString &thread)
: QXmppStanza(from, to), d(new QXmppMessagePrivate)
{
d->type = Chat;
d->body = body;
d->thread = thread;
}
/// Constructs a copy of \a other.
QXmppMessage::QXmppMessage(const QXmppMessage &other) = default;
QXmppMessage::~QXmppMessage() = default;
/// Assigns \a other to this message.
QXmppMessage &QXmppMessage::operator=(const QXmppMessage &other) = default;
///
/// Indicates if the QXmppStanza is a stanza in the XMPP sense (i. e. a message,
/// iq or presence)
///
/// \since QXmpp 1.0
///
bool QXmppMessage::isXmppStanza() const
{
return true;
}
/// Returns the message's body.
QString QXmppMessage::body() const
{
return d->body;
}
/// Sets the message's body.
///
/// \param body
void QXmppMessage::setBody(const QString &body)
{
d->body = body;
}
/// Returns the message's type.
QXmppMessage::Type QXmppMessage::type() const
{
return d->type;
}
/// Sets the message's type.
///
/// \param type
void QXmppMessage::setType(QXmppMessage::Type type)
{
d->type = type;
}
/// Returns the message's subject.
QString QXmppMessage::subject() const
{
return d->subject;
}
/// Sets the message's subject.
///
/// \param subject
void QXmppMessage::setSubject(const QString &subject)
{
d->subject = subject;
}
/// Returns the message's thread.
QString QXmppMessage::thread() const
{
return d->thread;
}
/// Sets the message's thread.
///
/// \param thread
void QXmppMessage::setThread(const QString &thread)
{
d->thread = thread;
}
///
/// Returns the optional parent thread of this message.
///
/// The possibility to create child threads was added in RFC6121.
///
/// \since QXmpp 1.3
///
QString QXmppMessage::parentThread() const
{
return d->parentThread;
}
///
/// Sets the optional parent thread of this message.
///
/// The possibility to create child threads was added in RFC6121.
///
/// \since QXmpp 1.3
///
void QXmppMessage::setParentThread(const QString &parent)
{
d->parentThread = parent;
}
///
/// Returns a possibly attached URL from \xep{0066}: Out of Band Data
///
/// \since QXmpp 1.0
///
QString QXmppMessage::outOfBandUrl() const
{
return d->outOfBandUrl;
}
///
/// Sets the attached URL for \xep{0066}: Out of Band Data
///
/// \since QXmpp 1.0
///
void QXmppMessage::setOutOfBandUrl(const QString &url)
{
d->outOfBandUrl = url;
}
///
/// Returns the message's XHTML body as defined by \xep{0071}: XHTML-IM.
///
/// \since QXmpp 0.6.2
///
QString QXmppMessage::xhtml() const
{
return d->xhtml;
}
///
/// Sets the message's XHTML body as defined by \xep{0071}: XHTML-IM.
///
/// \since QXmpp 0.6.2
///
void QXmppMessage::setXhtml(const QString &xhtml)
{
d->xhtml = xhtml;
}
///
/// Returns the the chat state notification according to \xep{0085}: Chat State
/// Notifications.
///
/// \since QXmpp 0.2
///
QXmppMessage::State QXmppMessage::state() const
{
return d->state;
}
///
/// Sets the the chat state notification according to \xep{0085}: Chat State
/// Notifications.
///
/// \since QXmpp 0.2
///
void QXmppMessage::setState(QXmppMessage::State state)
{
d->state = state;
}
///
/// Returns the optional timestamp of the message specified using \xep{0093}:
/// Legacy Delayed Delivery or using \xep{0203}: Delayed Delivery (preferred).
///
/// \since QXmpp 0.2
///
QDateTime QXmppMessage::stamp() const
{
return d->stamp;
}
///
/// Sets the message's timestamp without modifying the type of the stamp
/// (\xep{0093}: Legacy Delayed Delivery or \xep{0203}: Delayed Delivery).
///
/// By default messages are constructed with the new delayed delivery XEP, but
/// parsed messages keep their type.
///
/// \since QXmpp 0.2
///
void QXmppMessage::setStamp(const QDateTime &stamp)
{
d->stamp = stamp;
}
///
/// Returns true if a delivery receipt is requested, as defined by \xep{0184}:
/// Message Delivery Receipts.
///
/// \since QXmpp 0.4
///
bool QXmppMessage::isReceiptRequested() const
{
return d->receiptRequested;
}
///
/// Sets whether a delivery receipt is requested, as defined by \xep{0184}:
/// Message Delivery Receipts.
///
/// \since QXmpp 0.4
///
void QXmppMessage::setReceiptRequested(bool requested)
{
d->receiptRequested = requested;
if (requested && id().isEmpty())
generateAndSetNextId();
}
///
/// If this message is a delivery receipt, returns the ID of the original
/// message.
///
/// \since QXmpp 0.4
///
QString QXmppMessage::receiptId() const
{
return d->receiptId;
}
///
/// Make this message a delivery receipt for the message with the given \a id.
///
/// \since QXmpp 0.4
///
void QXmppMessage::setReceiptId(const QString &id)
{
d->receiptId = id;
}
///
/// Returns true if the user's attention is requested, as defined by \xep{0224}:
/// Attention.
///
/// \since QXmpp 0.4
///
bool QXmppMessage::isAttentionRequested() const
{
return d->attentionRequested;
}
///
/// Sets whether the user's attention is requested, as defined by \xep{0224}:
/// Attention.
///
/// \param requested Whether to request attention (true) or not (false)
///
/// \since QXmpp 0.4
///
void QXmppMessage::setAttentionRequested(bool requested)
{
d->attentionRequested = requested;
}
///
/// Returns a list of data packages attached using \xep{0231}: Bits of Binary.
///
/// This could be used to resolve \c cid: URIs found in the X-HTML body.
///
/// \since QXmpp 1.2
///
QXmppBitsOfBinaryDataList QXmppMessage::bitsOfBinaryData() const
{
return d->bitsOfBinaryData;
}
///
/// Returns a list of data attached using \xep{0231}: Bits of Binary.
///
/// This could be used to resolve \c cid: URIs found in the X-HTML body.
///
/// \since QXmpp 1.2
///
QXmppBitsOfBinaryDataList &QXmppMessage::bitsOfBinaryData()
{
return d->bitsOfBinaryData;
}
///
/// Sets a list of \xep{0231}: Bits of Binary attachments to be included.
///
/// \since QXmpp 1.2
///
void QXmppMessage::setBitsOfBinaryData(const QXmppBitsOfBinaryDataList &bitsOfBinaryData)
{
d->bitsOfBinaryData = bitsOfBinaryData;
}
///
/// Returns whether the given text is a '/me command' as defined in \xep{0245}:
/// The /me Command.
///
/// \since QXmpp 1.3
///
bool QXmppMessage::isSlashMeCommand(const QString &body)
{
return body.startsWith(QStringLiteral("/me "));
}
///
/// Returns whether the body of the message is a '/me command' as defined in
/// \xep{0245}: The /me Command.
///
/// \note If you want to check a custom string for the /me command, you can use
/// the static version of this method. This can be helpful when checking user
/// input before a message was sent.
///
/// \since QXmpp 1.3
///
bool QXmppMessage::isSlashMeCommand() const
{
return isSlashMeCommand(d->body);
}
///
/// Returns the part of the body after the /me command.
///
/// This cuts off '/me ' (with the space) from the body, in case the body
/// starts with that. In case the body does not contain a /me command as
/// defined in \xep{0245}: The /me Command, a null string is returned.
///
/// This is useful when displaying the /me command correctly to the user.
///
/// \since QXmpp 1.3
///
QString QXmppMessage::slashMeCommandText(const QString &body)
{
if (isSlashMeCommand(body))
return body.mid(4);
return {};
}
///
/// Returns the part of the body after the /me command.
///
/// This cuts off '/me ' (with the space) from the body, in case the body
/// starts with that. In case the body does not contain a /me command as
/// defined in \xep{0245}: The /me Command, a null string is returned.
///
/// This is useful when displaying the /me command correctly to the user.
///
/// \since QXmpp 1.3
///
QString QXmppMessage::slashMeCommandText() const
{
return slashMeCommandText(d->body);
}
///
/// Returns the JID for a multi-user chat direct invitation as defined by
/// \xep{0249}: Direct MUC Invitations.
///
/// \since QXmpp 0.7.4
///
QString QXmppMessage::mucInvitationJid() const
{
return d->mucInvitationJid;
}
///
/// Sets the JID for a multi-user chat direct invitation as defined by
/// \xep{0249}: Direct MUC Invitations.
///
/// \since QXmpp 0.7.4
///
void QXmppMessage::setMucInvitationJid(const QString &jid)
{
d->mucInvitationJid = jid;
}
///
/// Returns the password for a multi-user chat direct invitation as defined by
/// \xep{0249}: Direct MUC Invitations.
///
/// \since QXmpp 0.7.4
///
QString QXmppMessage::mucInvitationPassword() const
{
return d->mucInvitationPassword;
}
///
/// Sets the \a password for a multi-user chat direct invitation as defined by
/// \xep{0249}: Direct MUC Invitations.
///
/// \since QXmpp 0.7.4
///
void QXmppMessage::setMucInvitationPassword(const QString &password)
{
d->mucInvitationPassword = password;
}
///
/// Returns the reason for a multi-user chat direct invitation as defined by
/// \xep{0249}: Direct MUC Invitations.
///
/// \since QXmpp 0.7.4
///
QString QXmppMessage::mucInvitationReason() const
{
return d->mucInvitationReason;
}
///
/// Sets the \a reason for a multi-user chat direct invitation as defined by
/// \xep{0249}: Direct MUC Invitations.
///
/// \since QXmpp 0.7.4
///
void QXmppMessage::setMucInvitationReason(const QString &reason)
{
d->mucInvitationReason = reason;
}
///
/// Returns if the message is marked with a <private/> tag, in which case
/// it will not be forwarded to other resources according to \xep{0280}: Message
/// Carbons.
///
/// \since QXmpp 1.0
///
bool QXmppMessage::isPrivate() const
{
return d->privatemsg;
}
///
/// If true is passed, the message is marked with a <private/> tag, in
/// which case it will not be forwarded to other resources according to
/// \xep{0280}: Message Carbons.
///
/// \since QXmpp 1.0
///
void QXmppMessage::setPrivate(const bool priv)
{
d->privatemsg = priv;
}
///
/// Returns the message id to replace with this message as used in \xep{0308}:
/// Last Message Correction. If the returned string is empty, this message is
/// not replacing another.
///
/// \since QXmpp 1.0
///
QString QXmppMessage::replaceId() const
{
return d->replaceId;
}
///
/// Sets the message id to replace with this message as in \xep{0308}: Last
/// Message Correction.
///
/// \since QXmpp 1.0
///
void QXmppMessage::setReplaceId(const QString &replaceId)
{
d->replaceId = replaceId;
}
///
/// Returns true if a message is markable, as defined by \xep{0333}: Chat
/// Markers.
///
/// \since QXmpp 0.8.1
///
bool QXmppMessage::isMarkable() const
{
return d->markable;
}
///
/// Sets if the message is markable, as defined by \xep{0333}: Chat Markers.
///
/// \since QXmpp 0.8.1
///
void QXmppMessage::setMarkable(const bool markable)
{
d->markable = markable;
}
///
/// Returns the message's marker id, as defined by \xep{0333}: Chat Markers.
///
/// \since QXmpp 0.8.1
///
QString QXmppMessage::markedId() const
{
return d->markedId;
}
///
/// Sets the message's marker id, as defined by \xep{0333}: Chat Markers.
///
/// \since QXmpp 0.8.1
///
void QXmppMessage::setMarkerId(const QString &markerId)
{
d->markedId = markerId;
}
///
/// Returns the message's marker thread, as defined by \xep{0333}: Chat Markers.
///
/// \since QXmpp 0.8.1
///
QString QXmppMessage::markedThread() const
{
return d->markedThread;
}
///
/// Sets the message's marked thread, as defined by \xep{0333}: Chat Markers.
///
/// \since QXmpp 0.8.1
///
void QXmppMessage::setMarkedThread(const QString &markedThread)
{
d->markedThread = markedThread;
}
///
/// Returns the message's marker, as defined by \xep{0333}: Chat Markers.
///
/// \since QXmpp 0.8.1
///
QXmppMessage::Marker QXmppMessage::marker() const
{
return d->marker;
}
///
/// Sets the message's marker, as defined by \xep{0333}: Chat Markers
///
/// \since QXmpp 0.8.1
///
void QXmppMessage::setMarker(const Marker marker)
{
d->marker = marker;
}
///
/// Returns true if the message contains the hint passed, as defined in
/// \xep{0334}: Message Processing Hints
///
/// \since QXmpp 1.1
///
bool QXmppMessage::hasHint(const Hint hint) const
{
return d->hints & hint;
}
///
/// Adds a hint to the message, as defined in \xep{0334}: Message Processing
/// Hints
///
/// \since QXmpp 1.1
///
void QXmppMessage::addHint(const Hint hint)
{
d->hints |= hint;
}
///
/// Removes a hint from the message, as defined in \xep{0334}: Message
/// Processing Hints
///
/// \since QXmpp 1.1
///
void QXmppMessage::removeHint(const Hint hint)
{
d->hints &= ~hint;
}
///
/// Removes all hints from the message, as defined in \xep{0334}: Message
/// Processing Hints
///
/// \since QXmpp 1.1
///
void QXmppMessage::removeAllHints()
{
d->hints = 0;
}
///
/// Returns the stanza ID of the message according to \xep{0359}: Unique and
/// Stable Stanza IDs.
///
/// \since QXmpp 1.3
///
QString QXmppMessage::stanzaId() const
{
return d->stanzaId;
}
///
/// Sets the stanza ID of the message according to \xep{0359}: Unique and
/// Stable Stanza IDs.
///
/// \since QXmpp 1.3
///
void QXmppMessage::setStanzaId(const QString &id)
{
d->stanzaId = id;
}
///
/// Returns the creator of the stanza ID according to \xep{0359}: Unique and
/// Stable Stanza IDs.
///
/// \since QXmpp 1.3
///
QString QXmppMessage::stanzaIdBy() const
{
return d->stanzaIdBy;
}
///
/// Sets the creator of the stanza ID according to \xep{0359}: Unique and
/// Stable Stanza IDs.
///
/// \since QXmpp 1.3
///
void QXmppMessage::setStanzaIdBy(const QString &by)
{
d->stanzaIdBy = by;
}
///
/// Returns the origin ID of the message according to \xep{0359}: Unique and
/// Stable Stanza IDs.
///
/// \since QXmpp 1.3
///
QString QXmppMessage::originId() const
{
return d->originId;
}
///
/// Sets the origin ID of the message according to \xep{0359}: Unique and
/// Stable Stanza IDs.
///
/// \since QXmpp 1.3
///
void QXmppMessage::setOriginId(const QString &id)
{
d->originId = id;
}
///
/// Returns the message id this message is linked/attached to. See \xep{0367}:
/// Message Attaching for details.
///
/// \since QXmpp 1.1
///
QString QXmppMessage::attachId() const
{
return d->attachId;
}
///
/// Sets the id of the attached message as in \xep{0367}: Message Attaching.
/// This can be used for a "reply to" or "reaction" function.
///
/// The used message id depends on the message context, see the Business rules
/// section of the XEP for details about when to use which id.
///
/// \since QXmpp 1.1
///
void QXmppMessage::setAttachId(const QString &attachId)
{
d->attachId = attachId;
}
///
/// Returns the actual JID of a MIX channel participant.
///
/// \since QXmpp 1.1
///
QString QXmppMessage::mixUserJid() const
{
return d->mixUserJid;
}
///
/// Sets the actual JID of a MIX channel participant.
///
/// \since QXmpp 1.1
///
void QXmppMessage::setMixUserJid(const QString &mixUserJid)
{
d->mixUserJid = mixUserJid;
}
///
/// Returns the MIX participant's nickname.
///
/// \since QXmpp 1.1
///
QString QXmppMessage::mixUserNick() const
{
return d->mixUserNick;
}
///
/// Sets the MIX participant's nickname.
///
/// \since QXmpp 1.1
///
void QXmppMessage::setMixUserNick(const QString &mixUserNick)
{
d->mixUserNick = mixUserNick;
}
///
/// Returns the encryption method this message is advertised to be encrypted
/// with.
///
/// \note QXmppMessage::NoEncryption does not necesserily mean that the message
/// is not encrypted; it may also be that the author of the message does not
/// support \xep{0380}: Explicit Message Encryption.
///
/// \note If this returns QXmppMessage::UnknownEncryption, you can still get
/// the namespace of the encryption with \c encryptionMethodNs() and possibly
/// also a name with \c encryptionName().
///
/// \since QXmpp 1.1
///
QXmppMessage::EncryptionMethod QXmppMessage::encryptionMethod() const
{
if (d->encryptionMethod.isEmpty())
return QXmppMessage::NoEncryption;
int index = ENCRYPTION_NAMESPACES.indexOf(d->encryptionMethod);
if (index < 0)
return QXmppMessage::UnknownEncryption;
return static_cast<QXmppMessage::EncryptionMethod>(index);
}
///
/// Advertises that this message is encrypted with the given encryption method.
/// See \xep{0380}: Explicit Message Encryption for details.
///
/// \since QXmpp 1.1
///
void QXmppMessage::setEncryptionMethod(QXmppMessage::EncryptionMethod method)
{
d->encryptionMethod = ENCRYPTION_NAMESPACES.at(int(method));
}
///
/// Returns the namespace of the advertised encryption method via. \xep{0380}:
/// Explicit Message Encryption.
///
/// \since QXmpp 1.1
///
QString QXmppMessage::encryptionMethodNs() const
{
return d->encryptionMethod;
}
///
/// Sets the namespace of the encryption method this message advertises to be
/// encrypted with. See \xep{0380}: Explicit Message Encryption for details.
///
/// \since QXmpp 1.1
///
void QXmppMessage::setEncryptionMethodNs(const QString &encryptionMethod)
{
d->encryptionMethod = encryptionMethod;
}
///
/// Returns the associated name of the encryption method this message
/// advertises to be encrypted with. See \xep{0380}: Explicit Message Encryption
/// for details.
///
/// \since QXmpp 1.1
///
QString QXmppMessage::encryptionName() const
{
if (!d->encryptionName.isEmpty())
return d->encryptionName;
return ENCRYPTION_NAMES.at(int(encryptionMethod()));
}
///
/// Sets the name of the encryption method for \xep{0380}: Explicit Message
/// Encryption.
///
/// \note This should only be used, if the encryption method is custom and is
/// not one of the methods listed in the XEP.
///
/// \since QXmpp 1.1
///
void QXmppMessage::setEncryptionName(const QString &encryptionName)
{
d->encryptionName = encryptionName;
}
///
/// Returns true, if this is a spoiler message according to \xep{0382}: Spoiler
/// messages. The spoiler hint however can still be empty.
///
/// A spoiler message's content should not be visible to the user by default.
///
/// \since QXmpp 1.1
///
bool QXmppMessage::isSpoiler() const
{
return d->isSpoiler;
}
///
/// Sets whether this is a spoiler message as specified in \xep{0382}: Spoiler
/// messages.
///
/// The content of spoiler messages will not be displayed by default to the
/// user. However, clients not supporting spoiler messages will still display
/// the content as usual.
///
/// \since QXmpp 1.1
///
void QXmppMessage::setIsSpoiler(bool isSpoiler)
{
d->isSpoiler = isSpoiler;
}
///
/// Returns the spoiler hint as specified in \xep{0382}: Spoiler messages.
///
/// The hint may be empty, even if isSpoiler is true.
///
/// \since QXmpp 1.1
///
QString QXmppMessage::spoilerHint() const
{
return d->spoilerHint;
}
///
/// Sets a spoiler hint for \xep{0382}: Spoiler messages. If the spoiler hint
/// is not empty, isSpoiler will be set to true.
///
/// A spoiler hint is optional for spoiler messages.
///
/// Keep in mind that the spoiler hint is not displayed at all by clients not
/// supporting spoiler messages.
///
/// \since QXmpp 1.1
///
void QXmppMessage::setSpoilerHint(const QString &spoilerHint)
{
d->spoilerHint = spoilerHint;
if (!spoilerHint.isEmpty())
d->isSpoiler = true;
}
///
/// Returns an included OMEMO element as defined by \xep{0384, OMEMO Encryption}.
///
/// \since QXmpp 1.5
///
std::optional<QXmppOmemoElement> QXmppMessage::omemoElement() const
{
return d->omemoElement;
}
///
/// Sets an OMEMO element as defined by \xep{0384, OMEMO Encryption}.
///
/// \since QXmpp 1.5
///
void QXmppMessage::setOmemoElement(const std::optional<QXmppOmemoElement> &omemoElement)
{
d->omemoElement = omemoElement;
}
///
/// Returns an included \xep{0369}: Mediated Information eXchange (MIX)
/// invitation as defined by \xep{0407}: Mediated Information eXchange (MIX):
/// Miscellaneous Capabilities.
///
/// \since QXmpp 1.4
///
std::optional<QXmppMixInvitation> QXmppMessage::mixInvitation() const
{
return d->mixInvitation;
}
///
/// Sets a \xep{0369}: Mediated Information eXchange (MIX) invitation as defined
/// by \xep{0407}: Mediated Information eXchange (MIX): Miscellaneous
/// Capabilities.
///
/// \since QXmpp 1.4
///
void QXmppMessage::setMixInvitation(const std::optional<QXmppMixInvitation> &mixInvitation)
{
d->mixInvitation = mixInvitation;
}
///
/// Sets whether this message is only a fallback according to \xep{0428}:
/// Fallback Indication.
///
/// This is useful for clients not supporting end-to-end encryption to indicate
/// that the message body does not contain the intended text of the author.
///
/// \since QXmpp 1.3
///
bool QXmppMessage::isFallback() const
{
return d->isFallback;
}
///
/// Sets whether this message is only a fallback according to \xep{0428}:
/// Fallback Indication.
///
/// This is useful for clients not supporting end-to-end encryption to indicate
/// that the message body does not contain the intended text of the author.
///
/// \since QXmpp 1.3
///
void QXmppMessage::setIsFallback(bool isFallback)
{
d->isFallback = isFallback;
}
///
/// Returns an included trust message element as defined by
/// \xep{0434, Trust Messages (TM)}.
///
/// \since QXmpp 1.5
///
std::optional<QXmppTrustMessageElement> QXmppMessage::trustMessageElement() const
{
return d->trustMessageElement;
}
///
/// Sets a trust message element as defined by \xep{0434, Trust Messages (TM)}.
///
/// \since QXmpp 1.5
///
void QXmppMessage::setTrustMessageElement(const std::optional<QXmppTrustMessageElement> &trustMessageElement)
{
d->trustMessageElement = trustMessageElement;
}
/// \cond
void QXmppMessage::parse(const QDomElement &element)
{
QXmppStanza::parse(element);
// message type
int messageType = MESSAGE_TYPES.indexOf(element.attribute(QStringLiteral("type")));
if (messageType != -1)
d->type = static_cast<Type>(messageType);
else
d->type = QXmppMessage::Normal;
QXmppElementList extensions;
QDomElement childElement = element.firstChildElement();
while (!childElement.isNull()) {
if (childElement.tagName() == QStringLiteral("body")) {
d->body = childElement.text();
} else if (childElement.tagName() == QStringLiteral("subject")) {
d->subject = childElement.text();
} else if (childElement.tagName() == QStringLiteral("thread")) {
d->thread = childElement.text();
d->parentThread = childElement.attribute(QStringLiteral("parent"));
// parse message extensions
// XEP-0033: Extended Stanza Addressing and errors are parsed by QXmppStanza
} else if (!checkElement(childElement, QStringLiteral("addresses"), ns_extended_addressing) &&
childElement.tagName() != QStringLiteral("error")) {
// add to unknown extensions, if element couldn't be parsed
if (!parseExtension(childElement)) {
// other extensions
extensions << QXmppElement(childElement);
}
}
childElement = childElement.nextSiblingElement();
}
setExtensions(extensions);
}
void QXmppMessage::toXml(QXmlStreamWriter *xmlWriter) const
{
xmlWriter->writeStartElement(QStringLiteral("message"));
helperToXmlAddAttribute(xmlWriter, QStringLiteral("xml:lang"), lang());
helperToXmlAddAttribute(xmlWriter, QStringLiteral("id"), id());
helperToXmlAddAttribute(xmlWriter, QStringLiteral("to"), to());
helperToXmlAddAttribute(xmlWriter, QStringLiteral("from"), from());
helperToXmlAddAttribute(xmlWriter, QStringLiteral("type"), MESSAGE_TYPES.at(d->type));
if (!d->subject.isEmpty())
helperToXmlAddTextElement(xmlWriter, QStringLiteral("subject"), d->subject);
if (!d->body.isEmpty())
helperToXmlAddTextElement(xmlWriter, QStringLiteral("body"), d->body);
if (!d->thread.isEmpty()) {
xmlWriter->writeStartElement(QStringLiteral("thread"));
helperToXmlAddAttribute(xmlWriter, QStringLiteral("parent"), d->parentThread);
xmlWriter->writeCharacters(d->thread);
xmlWriter->writeEndElement();
}
error().toXml(xmlWriter);
// extensions
serializeExtensions(xmlWriter);
// other, unknown extensions
QXmppStanza::extensionsToXml(xmlWriter);
xmlWriter->writeEndElement();
}
/// \endcond
///
/// Parses a child element of the message stanza.
///
/// Allows inherited classes to parse additional extension elements. This
/// function may be executed multiple times with different elements.
///
/// \param element child element of the message to be parsed
///
/// \return True, if the element was successfully parsed.
///
/// \since QXmpp 1.5
///
bool QXmppMessage::parseExtension(const QDomElement &element)
{
if (element.tagName() == QStringLiteral("x")) {
if (element.namespaceURI() == ns_legacy_delayed_delivery) {
// if XEP-0203 exists, XEP-0091 has no need to parse because XEP-0091
// is no more standard protocol)
if (d->stamp.isNull()) {
// XEP-0091: Legacy Delayed Delivery
d->stamp = QDateTime::fromString(
element.attribute(QStringLiteral("stamp")),
QStringLiteral("yyyyMMddThh:mm:ss"));
d->stamp.setTimeSpec(Qt::UTC);
d->stampType = LegacyDelayedDelivery;
}
} else if (element.namespaceURI() == ns_conference) {
// XEP-0249: Direct MUC Invitations
d->mucInvitationJid = element.attribute(QStringLiteral("jid"));
d->mucInvitationPassword = element.attribute(QStringLiteral("password"));
d->mucInvitationReason = element.attribute(QStringLiteral("reason"));
} else if (element.namespaceURI() == ns_oob) {
// XEP-0066: Out of Band Data
d->outOfBandUrl = element.firstChildElement(QStringLiteral("url")).text();
} else {
return false;
}
} else if (checkElement(element, QStringLiteral("html"), ns_xhtml_im)) {
// XEP-0071: XHTML-IM
QDomElement bodyElement = element.firstChildElement(QStringLiteral("body"));
if (!bodyElement.isNull() && bodyElement.namespaceURI() == ns_xhtml) {
QTextStream stream(&d->xhtml, QIODevice::WriteOnly);
bodyElement.save(stream, 0);
d->xhtml = d->xhtml.mid(d->xhtml.indexOf('>') + 1);
d->xhtml.replace(
QStringLiteral(" xmlns=\"http://www.w3.org/1999/xhtml\""),
QString());
d->xhtml.replace(QStringLiteral("</body>"), QString());
d->xhtml = d->xhtml.trimmed();
}
} else if (element.namespaceURI() == ns_chat_states) {
// XEP-0085: Chat State Notifications
int i = CHAT_STATES.indexOf(element.tagName());
if (i > 0)
d->state = static_cast<QXmppMessage::State>(i);
} else if (checkElement(element, QStringLiteral("received"), ns_message_receipts)) {
// XEP-0184: Message Delivery Receipts
d->receiptId = element.attribute(QStringLiteral("id"));
// compatibility with old-style XEP
if (d->receiptId.isEmpty())
d->receiptId = id();
} else if (checkElement(element, QStringLiteral("request"), ns_message_receipts)) {
d->receiptRequested = true;
} else if (checkElement(element, QStringLiteral("delay"), ns_delayed_delivery)) {
// XEP-0203: Delayed Delivery
d->stamp = QXmppUtils::datetimeFromString(
element.attribute(QStringLiteral("stamp")));
d->stampType = DelayedDelivery;
} else if (checkElement(element, QStringLiteral("attention"), ns_attention)) {
// XEP-0224: Attention
d->attentionRequested = true;
} else if (QXmppBitsOfBinaryData::isBitsOfBinaryData(element)) {
// XEP-0231: Bits of Binary
QXmppBitsOfBinaryData data;
data.parseElementFromChild(element);
d->bitsOfBinaryData << data;
} else if (checkElement(element, QStringLiteral("private"), ns_carbons)) {
// XEP-0280: Message Carbons
d->privatemsg = true;
} else if (checkElement(element, QStringLiteral("replace"), ns_message_correct)) {
// XEP-0308: Last Message Correction
d->replaceId = element.attribute(QStringLiteral("id"));
} else if (element.namespaceURI() == ns_chat_markers) {
// XEP-0333: Chat Markers
if (element.tagName() == QStringLiteral("markable")) {
d->markable = true;
} else {
int marker = MARKER_TYPES.indexOf(element.tagName());
if (marker != -1) {
d->marker = static_cast<QXmppMessage::Marker>(marker);
d->markedId = element.attribute(QStringLiteral("id"));
d->markedThread = element.attribute(QStringLiteral("thread"));
}
}
} else if (element.namespaceURI() == ns_message_processing_hints &&
HINT_TYPES.contains(element.tagName())) {
// XEP-0334: Message Processing Hints
addHint(Hint(1 << HINT_TYPES.indexOf(element.tagName())));
} else if (checkElement(element, QStringLiteral("stanza-id"), ns_sid)) {
// XEP-0359: Unique and Stable Stanza IDs
d->stanzaId = element.attribute(QStringLiteral("id"));
d->stanzaIdBy = element.attribute(QStringLiteral("by"));
} else if (checkElement(element, QStringLiteral("origin-id"), ns_sid)) {
d->originId = element.attribute(QStringLiteral("id"));
} else if (checkElement(element, QStringLiteral("attach-to"), ns_message_attaching)) {
// XEP-0367: Message Attaching
d->attachId = element.attribute(QStringLiteral("id"));
} else if (checkElement(element, QStringLiteral("mix"), ns_mix)) {
// XEP-0369: Mediated Information eXchange (MIX)
d->mixUserJid = element.firstChildElement(QStringLiteral("jid")).text();
d->mixUserNick = element.firstChildElement(QStringLiteral("nick")).text();
} else if (checkElement(element, QStringLiteral("encryption"), ns_eme)) {
// XEP-0380: Explicit Message Encryption
d->encryptionMethod = element.attribute(QStringLiteral("namespace"));
d->encryptionName = element.attribute(QStringLiteral("name"));
} else if (checkElement(element, QStringLiteral("spoiler"), ns_spoiler)) {
// XEP-0382: Spoiler messages
d->isSpoiler = true;
d->spoilerHint = element.text();
} else if (QXmppOmemoElement::isOmemoElement(element)) {
// XEP-0384: OMEMO Encryption
QXmppOmemoElement omemoElement;
omemoElement.parse(element);
d->omemoElement = omemoElement;
} else if (checkElement(element, QStringLiteral("invitation"), ns_mix_misc)) {
// XEP-0407: Mediated Information eXchange (MIX): Miscellaneous Capabilities
QXmppMixInvitation mixInvitation;
mixInvitation.parse(element);
d->mixInvitation = mixInvitation;
} else if (checkElement(element, QStringLiteral("fallback"), ns_fallback_indication)) {
// XEP-0428: Fallback Indication
d->isFallback = true;
} else if (QXmppTrustMessageElement::isTrustMessageElement(element)) {
// XEP-0434: Trust Messages (TM)
QXmppTrustMessageElement trustMessageElement;
trustMessageElement.parse(element);
d->trustMessageElement = trustMessageElement;
} else {
return false;
}
return true;
}
///
/// Serializes all additional child elements.
///
/// \since QXmpp 1.5
///
void QXmppMessage::serializeExtensions(QXmlStreamWriter *xmlWriter) const
{
// XEP-0066: Out of Band Data
if (!d->outOfBandUrl.isEmpty()) {
xmlWriter->writeStartElement(QStringLiteral("x"));
xmlWriter->writeDefaultNamespace(ns_oob);
xmlWriter->writeTextElement(QStringLiteral("url"), d->outOfBandUrl);
xmlWriter->writeEndElement();
}
// XEP-0071: XHTML-IM
if (!d->xhtml.isEmpty()) {
xmlWriter->writeStartElement(QStringLiteral("html"));
xmlWriter->writeDefaultNamespace(ns_xhtml_im);
xmlWriter->writeStartElement(QStringLiteral("body"));
xmlWriter->writeDefaultNamespace(ns_xhtml);
xmlWriter->writeCharacters(QStringLiteral(""));
xmlWriter->device()->write(d->xhtml.toUtf8());
xmlWriter->writeEndElement();
xmlWriter->writeEndElement();
}
// XEP-0085: Chat State Notifications
if (d->state > None && d->state <= Paused) {
xmlWriter->writeStartElement(CHAT_STATES.at(d->state));
xmlWriter->writeDefaultNamespace(ns_chat_states);
xmlWriter->writeEndElement();
}
// XEP-0091: Legacy Delayed Delivery | XEP-0203: Delayed Delivery
if (d->stamp.isValid()) {
QDateTime utcStamp = d->stamp.toUTC();
if (d->stampType == DelayedDelivery) {
// XEP-0203: Delayed Delivery
xmlWriter->writeStartElement(QStringLiteral("delay"));
xmlWriter->writeDefaultNamespace(ns_delayed_delivery);
helperToXmlAddAttribute(xmlWriter, QStringLiteral("stamp"), QXmppUtils::datetimeToString(utcStamp));
xmlWriter->writeEndElement();
} else {
// XEP-0091: Legacy Delayed Delivery
xmlWriter->writeStartElement(QStringLiteral("x"));
xmlWriter->writeDefaultNamespace(ns_legacy_delayed_delivery);
helperToXmlAddAttribute(xmlWriter, QStringLiteral("stamp"), utcStamp.toString(QStringLiteral("yyyyMMddThh:mm:ss")));
xmlWriter->writeEndElement();
}
}
// XEP-0184: Message Delivery Receipts
if (!d->receiptId.isEmpty()) {
xmlWriter->writeStartElement(QStringLiteral("received"));
xmlWriter->writeDefaultNamespace(ns_message_receipts);
xmlWriter->writeAttribute(QStringLiteral("id"), d->receiptId);
xmlWriter->writeEndElement();
}
if (d->receiptRequested) {
xmlWriter->writeStartElement(QStringLiteral("request"));
xmlWriter->writeDefaultNamespace(ns_message_receipts);
xmlWriter->writeEndElement();
}
// XEP-0224: Attention
if (d->attentionRequested) {
xmlWriter->writeStartElement(QStringLiteral("attention"));
xmlWriter->writeDefaultNamespace(ns_attention);
xmlWriter->writeEndElement();
}
// XEP-0249: Direct MUC Invitations
if (!d->mucInvitationJid.isEmpty()) {
xmlWriter->writeStartElement(QStringLiteral("x"));
xmlWriter->writeDefaultNamespace(ns_conference);
xmlWriter->writeAttribute(QStringLiteral("jid"), d->mucInvitationJid);
if (!d->mucInvitationPassword.isEmpty())
xmlWriter->writeAttribute(QStringLiteral("password"), d->mucInvitationPassword);
if (!d->mucInvitationReason.isEmpty())
xmlWriter->writeAttribute(QStringLiteral("reason"), d->mucInvitationReason);
xmlWriter->writeEndElement();
}
// XEP-0231: Bits of Binary
for (const auto &data : std::as_const(d->bitsOfBinaryData))
data.toXmlElementFromChild(xmlWriter);
// XEP-0280: Message Carbons
if (d->privatemsg) {
xmlWriter->writeStartElement(QStringLiteral("private"));
xmlWriter->writeDefaultNamespace(ns_carbons);
xmlWriter->writeEndElement();
}
// XEP-0308: Last Message Correction
if (!d->replaceId.isEmpty()) {
xmlWriter->writeStartElement(QStringLiteral("replace"));
xmlWriter->writeDefaultNamespace(ns_message_correct);
xmlWriter->writeAttribute(QStringLiteral("id"), d->replaceId);
xmlWriter->writeEndElement();
}
// XEP-0333: Chat Markers
if (d->markable) {
xmlWriter->writeStartElement(QStringLiteral("markable"));
xmlWriter->writeDefaultNamespace(ns_chat_markers);
xmlWriter->writeEndElement();
}
if (d->marker != NoMarker) {
xmlWriter->writeStartElement(MARKER_TYPES.at(d->marker));
xmlWriter->writeDefaultNamespace(ns_chat_markers);
xmlWriter->writeAttribute(QStringLiteral("id"), d->markedId);
if (!d->markedThread.isNull() && !d->markedThread.isEmpty()) {
xmlWriter->writeAttribute(QStringLiteral("thread"), d->markedThread);
}
xmlWriter->writeEndElement();
}
// XEP-0334: Message Processing Hints
for (quint8 i = 0; i < HINT_TYPES.size(); i++) {
if (hasHint(Hint(1 << i))) {
xmlWriter->writeStartElement(HINT_TYPES.at(i));
xmlWriter->writeDefaultNamespace(ns_message_processing_hints);
xmlWriter->writeEndElement();
}
}
// XEP-0359: Unique and Stable Stanza IDs
if (!d->stanzaId.isNull()) {
xmlWriter->writeStartElement(QStringLiteral("stanza-id"));
xmlWriter->writeDefaultNamespace(ns_sid);
xmlWriter->writeAttribute(QStringLiteral("id"), d->stanzaId);
if (!d->stanzaIdBy.isNull())
xmlWriter->writeAttribute(QStringLiteral("by"), d->stanzaIdBy);
xmlWriter->writeEndElement();
}
if (!d->originId.isNull()) {
xmlWriter->writeStartElement(QStringLiteral("origin-id"));
xmlWriter->writeDefaultNamespace(ns_sid);
xmlWriter->writeAttribute(QStringLiteral("id"), d->originId);
xmlWriter->writeEndElement();
}
// XEP-0367: Message Attaching
if (!d->attachId.isEmpty()) {
xmlWriter->writeStartElement(QStringLiteral("attach-to"));
xmlWriter->writeDefaultNamespace(ns_message_attaching);
xmlWriter->writeAttribute(QStringLiteral("id"), d->attachId);
xmlWriter->writeEndElement();
}
// XEP-0369: Mediated Information eXchange (MIX)
if (!d->mixUserJid.isEmpty() || !d->mixUserNick.isEmpty()) {
xmlWriter->writeStartElement(QStringLiteral("mix"));
xmlWriter->writeDefaultNamespace(ns_mix);
helperToXmlAddTextElement(xmlWriter, QStringLiteral("jid"), d->mixUserJid);
helperToXmlAddTextElement(xmlWriter, QStringLiteral("nick"), d->mixUserNick);
xmlWriter->writeEndElement();
}
// XEP-0380: Explicit Message Encryption
if (!d->encryptionMethod.isEmpty()) {
xmlWriter->writeStartElement(QStringLiteral("encryption"));
xmlWriter->writeDefaultNamespace(ns_eme);
xmlWriter->writeAttribute(QStringLiteral("namespace"), d->encryptionMethod);
helperToXmlAddAttribute(xmlWriter, QStringLiteral("name"), d->encryptionName);
xmlWriter->writeEndElement();
}
// XEP-0382: Spoiler messages
if (d->isSpoiler) {
xmlWriter->writeStartElement(QStringLiteral("spoiler"));
xmlWriter->writeDefaultNamespace(ns_spoiler);
xmlWriter->writeCharacters(d->spoilerHint);
xmlWriter->writeEndElement();
}
// XEP-0384: OMEMO Encryption
if (d->omemoElement) {
d->omemoElement->toXml(xmlWriter);
}
// XEP-0407: Mediated Information eXchange (MIX): Miscellaneous Capabilities
if (d->mixInvitation) {
d->mixInvitation->toXml(xmlWriter);
}
// XEP-0428: Fallback Indication
if (d->isFallback) {
xmlWriter->writeStartElement(QStringLiteral("fallback"));
xmlWriter->writeDefaultNamespace(ns_fallback_indication);
xmlWriter->writeEndElement();
}
// XEP-0434: Trust Messages (TM)
if (d->trustMessageElement) {
d->trustMessageElement->toXml(xmlWriter);
}
}
|