/
QXmppMessage.cpp
906 lines (749 loc) · 24.5 KB
/
QXmppMessage.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
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
/*
* Copyright (C) 2008-2019 The QXmpp developers
*
* Authors:
* Manjeet Dahiya
* Jeremy Lainé
*
* 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 <QDomElement>
#include <QTextStream>
#include <QXmlStreamWriter>
#include <QPair>
#include "QXmppConstants_p.h"
#include "QXmppMessage.h"
#include "QXmppUtils.h"
static const char* chat_states[] = {
"",
"active",
"inactive",
"gone",
"composing",
"paused",
};
static const char* message_types[] = {
"error",
"normal",
"chat",
"groupchat",
"headline"
};
static const char* marker_types[] = {
"",
"received",
"displayed",
"acknowledged"
};
static const char *ns_xhtml = "http://www.w3.org/1999/xhtml";
enum StampType
{
LegacyDelayedDelivery, // XEP-0091: Legacy Delayed Delivery
DelayedDelivery // XEP-0203: Delayed Delivery
};
class QXmppMessagePrivate : public QSharedData
{
public:
QXmppMessage::Type type;
QDateTime stamp;
StampType stampType;
QXmppMessage::State state;
bool attentionRequested;
QString body;
QString subject;
QString thread;
// XEP-0071: XHTML-IM
QString xhtml;
// Request message receipt as per XEP-0184.
QString receiptId;
bool receiptRequested;
// XEP-0249: Direct MUC Invitations
QString mucInvitationJid;
QString mucInvitationPassword;
QString mucInvitationReason;
// XEP-0333: Chat Markers
bool markable;
QXmppMessage::Marker marker;
QString markedId;
QString markedThread;
// XEP-0280: Message Carbons
bool privatemsg;
// XEP-0066: Out of Band Data
QString outOfBandUrl;
// XEP-0308: Last Message Correction
QString replaceId;
// XEP-0369: Mediated Information eXchange (MIX)
QString mixUserJid;
QString mixUserNick;
// XEP-0382: Spoiler messages
bool isSpoiler = false;
QString spoilerHint;
};
/// 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->stampType = DelayedDelivery;
d->state = None;
d->attentionRequested = false;
d->body = body;
d->thread = thread;
d->receiptRequested = false;
d->markable = false;
d->marker = NoMarker;
d->privatemsg = false;
}
/// Constructs a copy of \a other.
QXmppMessage::QXmppMessage(const QXmppMessage &other)
: QXmppStanza(other)
, d(other.d)
{
}
QXmppMessage::~QXmppMessage()
{
}
/// Assigns \a other to this message.
QXmppMessage& QXmppMessage::operator=(const QXmppMessage &other)
{
QXmppStanza::operator=(other);
d = other.d;
return *this;
}
/// 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 true if the user's attention is requested, as defined
/// by XEP-0224: Attention.
bool QXmppMessage::isAttentionRequested() const
{
return d->attentionRequested;
}
/// Sets whether the user's attention is requested, as defined
/// by XEP-0224: Attention.
///
/// \a param requested
void QXmppMessage::setAttentionRequested(bool requested)
{
d->attentionRequested = requested;
}
/// Returns true if a delivery receipt is requested, as defined
/// by XEP-0184: Message Delivery Receipts.
bool QXmppMessage::isReceiptRequested() const
{
return d->receiptRequested;
}
/// Sets whether a delivery receipt is requested, as defined
/// by XEP-0184: Message Delivery Receipts.
///
/// \a param requested
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.
QString QXmppMessage::receiptId() const
{
return d->receiptId;
}
/// Make this message a delivery receipt for the message with
/// the given \a id.
void QXmppMessage::setReceiptId(const QString &id)
{
d->receiptId = id;
}
/// Returns the JID for a multi-user chat direct invitation as defined
/// by XEP-0249: Direct MUC Invitations.
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.
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.
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.
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.
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.
void QXmppMessage::setMucInvitationReason(const QString &reason)
{
d->mucInvitationReason = reason;
}
/// 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 timestamp (if any).
QDateTime QXmppMessage::stamp() const
{
return d->stamp;
}
/// Sets the message's timestamp.
///
/// \param stamp
void QXmppMessage::setStamp(const QDateTime &stamp)
{
d->stamp = stamp;
}
/// Returns the message's chat state.
///
QXmppMessage::State QXmppMessage::state() const
{
return d->state;
}
/// Sets the message's chat state.
///
/// \param state
void QXmppMessage::setState(QXmppMessage::State state)
{
d->state = state;
}
/// 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 message's XHTML body as defined by
/// XEP-0071: XHTML-IM.
QString QXmppMessage::xhtml() const
{
return d->xhtml;
}
/// Sets the message's XHTML body as defined by
/// XEP-0071: XHTML-IM.
void QXmppMessage::setXhtml(const QString &xhtml)
{
d->xhtml = xhtml;
}
namespace
{
static QList<QPair<QString, QString> > knownMessageSubelems()
{
QList<QPair<QString, QString> > result;
result << qMakePair(QString("body"), QString())
<< qMakePair(QString("subject"), QString())
<< qMakePair(QString("thread"), QString())
<< qMakePair(QString("html"), QString())
<< qMakePair(QString("received"), QString(ns_message_receipts))
<< qMakePair(QString("replace"), QString(ns_message_correct))
<< qMakePair(QString("request"), QString())
<< qMakePair(QString("delay"), QString())
<< qMakePair(QString("attention"), QString())
<< qMakePair(QString("addresses"), QString())
<< qMakePair(QString("private"), QString(ns_carbons));
for (int i = QXmppMessage::Active; i <= QXmppMessage::Paused; i++)
result << qMakePair(QString(chat_states[i]), QString());
return result;
}
}
/// Returns true if a message is markable, as defined
/// XEP-0333: Chat Markers.
bool QXmppMessage::isMarkable() const
{
return d->markable;
}
/// Sets if the message is markable, as defined
/// XEP-0333: Chat Markers.
void QXmppMessage::setMarkable(const bool markable)
{
d->markable = markable;
}
/// Returns the message's marker id, as defined
/// XEP-0333: Chat Markers.
QString QXmppMessage::markedId() const
{
return d->markedId;
}
/// Sets the message's marker id, as defined
/// XEP-0333: Chat Markers.
void QXmppMessage::setMarkerId(const QString &markerId)
{
d->markedId = markerId;
}
/// Returns the message's marker thread, as defined
/// XEP-0333: Chat Markers.
QString QXmppMessage::markedThread() const
{
return d->markedThread;
}
/// Sets the message's marked thread, as defined
/// XEP-0333: Chat Markers.
void QXmppMessage::setMarkedThread(const QString &markedThread)
{
d->markedThread = markedThread;
}
/// Returns the message's marker, as defined
/// XEP-0333: Chat Markers.
QXmppMessage::Marker QXmppMessage::marker() const
{
return d->marker;
}
/// Sets the message's marker, as defined
/// XEP-0333: Chat Markers
void QXmppMessage::setMarker(const Marker marker)
{
d->marker = marker;
}
/// 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.
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.
void QXmppMessage::setPrivate(const bool priv)
{
d->privatemsg = priv;
}
/// Indicates if the QXmppStanza is a stanza in the XMPP sense (i. e. a message,
/// iq or presence)
bool QXmppMessage::isXmppStanza() const
{
return true;
}
/// Returns a possibly attached URL from XEP-0066: Out of Band Data
QString QXmppMessage::outOfBandUrl() const
{
return d->outOfBandUrl;
}
/// Sets the attached URL for XEP-0066: Out of Band Data
void QXmppMessage::setOutOfBandUrl(const QString &url)
{
d->outOfBandUrl = url;
}
/// 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.
QString QXmppMessage::replaceId() const
{
return d->replaceId;
}
/// Sets the message id to replace with this message as in XEP-0308: Last
/// Message Correction.
void QXmppMessage::setReplaceId(const QString &replaceId)
{
d->replaceId = replaceId;
}
/// Returns the actual JID of a MIX channel participant.
QString QXmppMessage::mixUserJid() const
{
return d->mixUserJid;
}
/// Sets the actual JID of a MIX channel participant.
void QXmppMessage::setMixUserJid(const QString& mixUserJid)
{
d->mixUserJid = mixUserJid;
}
/// Returns the MIX participant's nickname.
QString QXmppMessage::mixUserNick() const
{
return d->mixUserNick;
}
/// Sets the MIX participant's nickname.
void QXmppMessage::setMixUserNick(const QString& mixUserNick)
{
d->mixUserNick = mixUserNick;
}
/// 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.
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.
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.
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.
void QXmppMessage::setSpoilerHint(const QString &spoilerHint)
{
d->spoilerHint = spoilerHint;
if (!spoilerHint.isEmpty())
d->isSpoiler = true;
}
/// \cond
void QXmppMessage::parse(const QDomElement &element)
{
QXmppStanza::parse(element);
const QString type = element.attribute("type");
d->type = Normal;
for (int i = Error; i <= Headline; i++) {
if (type == message_types[i]) {
d->type = static_cast<Type>(i);
break;
}
}
d->body = element.firstChildElement("body").text();
d->subject = element.firstChildElement("subject").text();
d->thread = element.firstChildElement("thread").text();
// chat states
for (int i = Active; i <= Paused; i++)
{
QDomElement stateElement = element.firstChildElement(chat_states[i]);
if (!stateElement.isNull() &&
stateElement.namespaceURI() == ns_chat_states)
{
d->state = static_cast<QXmppMessage::State>(i);
break;
}
}
// XEP-0071: XHTML-IM
QDomElement htmlElement = element.firstChildElement("html");
if (!htmlElement.isNull() && htmlElement.namespaceURI() == ns_xhtml_im) {
QDomElement bodyElement = htmlElement.firstChildElement("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(" xmlns=\"http://www.w3.org/1999/xhtml\"", "");
d->xhtml.replace("</body>", "");
d->xhtml = d->xhtml.trimmed();
}
}
// XEP-0184: Message Delivery Receipts
QDomElement receivedElement = element.firstChildElement("received");
if (!receivedElement.isNull() && receivedElement.namespaceURI() == ns_message_receipts) {
d->receiptId = receivedElement.attribute("id");
// compatibility with old-style XEP
if (d->receiptId.isEmpty())
d->receiptId = id();
} else {
d->receiptId = QString();
}
d->receiptRequested = element.firstChildElement("request").namespaceURI() == ns_message_receipts;
// XEP-0203: Delayed Delivery
QDomElement delayElement = element.firstChildElement("delay");
if (!delayElement.isNull() && delayElement.namespaceURI() == ns_delayed_delivery)
{
const QString str = delayElement.attribute("stamp");
d->stamp = QXmppUtils::datetimeFromString(str);
d->stampType = DelayedDelivery;
}
// XEP-0224: Attention
d->attentionRequested = element.firstChildElement("attention").namespaceURI() == ns_attention;
// XEP-0333: Chat Markers
QDomElement markableElement = element.firstChildElement("markable");
if (!markableElement.isNull())
{
d->markable = true;
}
// check for all the marker types
QDomElement chatStateElement;
QXmppMessage::Marker marker = QXmppMessage::NoMarker;
for (int i = Received; i <= Acknowledged; i++)
{
chatStateElement = element.firstChildElement(marker_types[i]);
if (!chatStateElement.isNull() &&
chatStateElement.namespaceURI() == ns_chat_markers)
{
marker = static_cast<QXmppMessage::Marker>(i);
break;
}
}
// if marker is present, check it's the right ns
if (!chatStateElement.isNull())
{
if (chatStateElement.namespaceURI() == ns_chat_markers)
{
d->marker = marker;
d->markedId = chatStateElement.attribute("id", QString());
d->markedThread = chatStateElement.attribute("thread", QString());
}
}
// XEP-0280: Message Carbons
QDomElement privateElement = element.firstChildElement("private");
if (!privateElement.isNull())
d->privatemsg = true;
// XEP-0308: Last Message Correction
QDomElement replaceElement = element.firstChildElement("replace");
if (!replaceElement.isNull() && replaceElement.namespaceURI() == ns_message_correct)
d->replaceId = replaceElement.attribute("id");
const QList<QPair<QString, QString> > &knownElems = knownMessageSubelems();
QXmppElementList extensions;
QDomElement xElement = element.firstChildElement();
while (!xElement.isNull())
{
if (xElement.tagName() == "x")
{
if (xElement.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
const QString str = xElement.attribute("stamp");
d->stamp = QDateTime::fromString(str, "yyyyMMddThh:mm:ss");
d->stamp.setTimeSpec(Qt::UTC);
d->stampType = LegacyDelayedDelivery;
}
} else if (xElement.namespaceURI() == ns_conference) {
// XEP-0249: Direct MUC Invitations
d->mucInvitationJid = xElement.attribute("jid");
d->mucInvitationPassword = xElement.attribute("password");
d->mucInvitationReason = xElement.attribute("reason");
} else if (xElement.namespaceURI() == ns_oob) {
// XEP-0066: Out of Band Data
d->outOfBandUrl = xElement.firstChildElement("url").text();
}
else {
extensions << QXmppElement(xElement);
}
// XEP-0369: Mediated Information eXchange (MIX)
} else if (xElement.tagName() == "mix" && xElement.namespaceURI() == ns_mix) {
d->mixUserJid = xElement.firstChildElement("jid").text();
d->mixUserNick = xElement.firstChildElement("nick").text();
// XEP-0382: Spoiler messages
} else if (xElement.tagName() == "spoiler" && xElement.namespaceURI() == ns_spoiler) {
d->isSpoiler = true;
d->spoilerHint = xElement.text();
} else if (!knownElems.contains(qMakePair(xElement.tagName(), xElement.namespaceURI())) &&
!knownElems.contains(qMakePair(xElement.tagName(), QString()))) {
// other extensions
extensions << QXmppElement(xElement);
}
xElement = xElement.nextSiblingElement();
}
setExtensions(extensions);
}
void QXmppMessage::toXml(QXmlStreamWriter *xmlWriter) const
{
xmlWriter->writeStartElement("message");
helperToXmlAddAttribute(xmlWriter, "xml:lang", lang());
helperToXmlAddAttribute(xmlWriter, "id", id());
helperToXmlAddAttribute(xmlWriter, "to", to());
helperToXmlAddAttribute(xmlWriter, "from", from());
helperToXmlAddAttribute(xmlWriter, "type", message_types[d->type]);
if (!d->subject.isEmpty())
helperToXmlAddTextElement(xmlWriter, "subject", d->subject);
if (!d->body.isEmpty())
helperToXmlAddTextElement(xmlWriter, "body", d->body);
if (!d->thread.isEmpty())
helperToXmlAddTextElement(xmlWriter, "thread", d->thread);
error().toXml(xmlWriter);
// chat states
if (d->state > None && d->state <= Paused)
{
xmlWriter->writeStartElement(chat_states[d->state]);
xmlWriter->writeAttribute("xmlns", ns_chat_states);
xmlWriter->writeEndElement();
}
// XEP-0071: XHTML-IM
if (!d->xhtml.isEmpty()) {
xmlWriter->writeStartElement("html");
xmlWriter->writeAttribute("xmlns", ns_xhtml_im);
xmlWriter->writeStartElement("body");
xmlWriter->writeAttribute("xmlns", ns_xhtml);
xmlWriter->writeCharacters("");
xmlWriter->device()->write(d->xhtml.toUtf8());
xmlWriter->writeEndElement();
xmlWriter->writeEndElement();
}
// time stamp
if (d->stamp.isValid())
{
QDateTime utcStamp = d->stamp.toUTC();
if (d->stampType == DelayedDelivery)
{
// XEP-0203: Delayed Delivery
xmlWriter->writeStartElement("delay");
xmlWriter->writeAttribute("xmlns", ns_delayed_delivery);
helperToXmlAddAttribute(xmlWriter, "stamp", QXmppUtils::datetimeToString(utcStamp));
xmlWriter->writeEndElement();
} else {
// XEP-0091: Legacy Delayed Delivery
xmlWriter->writeStartElement("x");
xmlWriter->writeAttribute("xmlns", ns_legacy_delayed_delivery);
helperToXmlAddAttribute(xmlWriter, "stamp", utcStamp.toString("yyyyMMddThh:mm:ss"));
xmlWriter->writeEndElement();
}
}
// XEP-0184: Message Delivery Receipts
if (!d->receiptId.isEmpty()) {
xmlWriter->writeStartElement("received");
xmlWriter->writeAttribute("xmlns", ns_message_receipts);
xmlWriter->writeAttribute("id", d->receiptId);
xmlWriter->writeEndElement();
}
if (d->receiptRequested) {
xmlWriter->writeStartElement("request");
xmlWriter->writeAttribute("xmlns", ns_message_receipts);
xmlWriter->writeEndElement();
}
// XEP-0224: Attention
if (d->attentionRequested) {
xmlWriter->writeStartElement("attention");
xmlWriter->writeAttribute("xmlns", ns_attention);
xmlWriter->writeEndElement();
}
// XEP-0249: Direct MUC Invitations
if (!d->mucInvitationJid.isEmpty()) {
xmlWriter->writeStartElement("x");
xmlWriter->writeAttribute("xmlns", ns_conference);
xmlWriter->writeAttribute("jid", d->mucInvitationJid);
if (!d->mucInvitationPassword.isEmpty())
xmlWriter->writeAttribute("password", d->mucInvitationPassword);
if (!d->mucInvitationReason.isEmpty())
xmlWriter->writeAttribute("reason", d->mucInvitationReason);
xmlWriter->writeEndElement();
}
// XEP-0333: Chat Markers
if (d->markable) {
xmlWriter->writeStartElement("markable");
xmlWriter->writeAttribute("xmlns", ns_chat_markers);
xmlWriter->writeEndElement();
}
if (d->marker != NoMarker) {
xmlWriter->writeStartElement(marker_types[d->marker]);
xmlWriter->writeAttribute("xmlns", ns_chat_markers);
xmlWriter->writeAttribute("id", d->markedId);
if (!d->markedThread.isNull() && !d->markedThread.isEmpty()) {
xmlWriter->writeAttribute("thread", d->markedThread);
}
xmlWriter->writeEndElement();
}
// XEP-0280: Message Carbons
if (d->privatemsg) {
xmlWriter->writeStartElement("private");
xmlWriter->writeAttribute("xmlns", ns_carbons);
xmlWriter->writeEndElement();
}
// XEP-0066: Out of Band Data
if (!d->outOfBandUrl.isEmpty()) {
xmlWriter->writeStartElement("x");
xmlWriter->writeAttribute("xmlns", ns_oob);
xmlWriter->writeTextElement("url", d->outOfBandUrl);
xmlWriter->writeEndElement();
}
// XEP-0308: Last Message Correction
if (!d->replaceId.isEmpty()) {
xmlWriter->writeStartElement("replace");
xmlWriter->writeAttribute("xmlns", ns_message_correct);
xmlWriter->writeAttribute("id", d->replaceId);
xmlWriter->writeEndElement();
}
// XEP-0369: Mediated Information eXchange (MIX)
if (!d->mixUserJid.isEmpty() || !d->mixUserNick.isEmpty()) {
xmlWriter->writeStartElement("mix");
xmlWriter->writeAttribute("xmlns", ns_mix);
helperToXmlAddTextElement(xmlWriter, "jid", d->mixUserJid);
helperToXmlAddTextElement(xmlWriter, "nick", d->mixUserNick);
xmlWriter->writeEndElement();
}
// XEP-0382: Spoiler messages
if (d->isSpoiler) {
xmlWriter->writeStartElement("spoiler");
xmlWriter->writeAttribute("xmlns", ns_spoiler);
xmlWriter->writeCharacters(d->spoilerHint);
xmlWriter->writeEndElement();
}
// other extensions
QXmppStanza::extensionsToXml(xmlWriter);
xmlWriter->writeEndElement();
}
/// \endcond