QXmppMessageReceiptManager.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * Copyright (C) 2008-2012 The QXmpp developers
  3. *
  4. * Author:
  5. * Georg Rudoy
  6. * Jeremy Lainé
  7. *
  8. * Source:
  9. * http://code.google.com/p/qxmpp
  10. *
  11. * This file is a part of QXmpp library.
  12. *
  13. * This library is free software; you can redistribute it and/or
  14. * modify it under the terms of the GNU Lesser General Public
  15. * License as published by the Free Software Foundation; either
  16. * version 2.1 of the License, or (at your option) any later version.
  17. *
  18. * This library is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  21. * Lesser General Public License for more details.
  22. *
  23. */
  24. #include "QXmppMessageReceiptManager.h"
  25. #include <QDomElement>
  26. #include "QXmppConstants.h"
  27. #include "QXmppMessage.h"
  28. #include "QXmppClient.h"
  29. /// Constructs a QXmppMessageReceiptManager to handle incoming and outgoing
  30. /// message delivery receipts.
  31. QXmppMessageReceiptManager::QXmppMessageReceiptManager()
  32. : QXmppClientExtension()
  33. {
  34. }
  35. /// \cond
  36. QStringList QXmppMessageReceiptManager::discoveryFeatures() const
  37. {
  38. return QStringList(ns_message_receipts);
  39. }
  40. bool QXmppMessageReceiptManager::handleStanza(const QDomElement &stanza)
  41. {
  42. if (stanza.tagName() != "message")
  43. return false;
  44. QXmppMessage message;
  45. message.parse(stanza);
  46. // Handle receipts and cancel any further processing.
  47. if (!message.receiptId().isEmpty()) {
  48. emit messageDelivered(message.from(), message.receiptId());
  49. return true;
  50. }
  51. // If requested, send a receipt.
  52. if (message.isReceiptRequested()
  53. && !message.from().isEmpty()
  54. && !message.id().isEmpty()) {
  55. QXmppMessage receipt;
  56. receipt.setTo(message.from());
  57. receipt.setReceiptId(message.id());
  58. client()->sendPacket(receipt);
  59. }
  60. // Continue processing.
  61. return false;
  62. }
  63. /// \endcond