From 029e20edda095872ff44d0d9be3eced53a9d6788 Mon Sep 17 00:00:00 2001 From: Stojce Slavkovski Date: Tue, 29 Apr 2014 20:40:12 +0200 Subject: [PATCH] Added XMPP archive manager --- interface/src/XmppClient.cpp | 2 +- interface/src/ui/ChatWindow.cpp | 30 ++++++++++++++++++++++++++++++ interface/src/ui/ChatWindow.h | 8 ++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/interface/src/XmppClient.cpp b/interface/src/XmppClient.cpp index 7367993a3c..070097d179 100644 --- a/interface/src/XmppClient.cpp +++ b/interface/src/XmppClient.cpp @@ -21,7 +21,7 @@ const QString DEFAULT_CHAT_ROOM = "public@public-chat.highfidelity.io"; XmppClient::XmppClient() : _xmppClient(), _xmppMUCManager() -{ +{ AccountManager& accountManager = AccountManager::getInstance(); connect(&accountManager, SIGNAL(accessTokenChanged()), this, SLOT(connectToServer())); connect(&accountManager, SIGNAL(logoutComplete()), this, SLOT(disconnectFromServer())); diff --git a/interface/src/ui/ChatWindow.cpp b/interface/src/ui/ChatWindow.cpp index 0300ec9202..207ac8a597 100644 --- a/interface/src/ui/ChatWindow.cpp +++ b/interface/src/ui/ChatWindow.cpp @@ -29,6 +29,8 @@ #include const int NUM_MESSAGES_TO_TIME_STAMP = 20; +const int MAX_HISTORY_CHAT_MESSAGES = 100; +const int MAX_HISTORY_DAYS = 7; const QRegularExpression regexLinks("((?:(?:ftp)|(?:https?))://\\S+)"); const QRegularExpression regexHifiLinks("([#@]\\S+)"); @@ -227,10 +229,38 @@ void ChatWindow::connected() { #ifdef HAVE_QXMPP const QXmppMucRoom* publicChatRoom = XmppClient::getInstance().getPublicChatRoom(); connect(publicChatRoom, SIGNAL(participantsChanged()), this, SLOT(participantsChanged())); + + // add archive manager + _archiveManager = new QXmppArchiveManager; + XmppClient::getInstance().getXMPPClient().addExtension(_archiveManager); + + connect(_archiveManager, SIGNAL(archiveChatReceived(QXmppArchiveChat, QXmppResultSetReply)), + SLOT(archiveChatReceived(QXmppArchiveChat, QXmppResultSetReply))); + + connect(_archiveManager, SIGNAL(archiveListReceived(QList, QXmppResultSetReply)), + SLOT(archiveListReceived(QList, QXmppResultSetReply))); + + QXmppResultSetQuery rsmQuery; + rsmQuery.setMax(MAX_HISTORY_CHAT_MESSAGES); + _archiveManager->listCollections(publicChatRoom->jid(), + QDateTime::currentDateTime().addDays(-MAX_HISTORY_DAYS), + QDateTime::currentDateTime(), + rsmQuery); + #endif startTimerForTimeStamps(); } +void ChatWindow::archiveChatReceived(const QXmppArchiveChat &chat, const QXmppResultSetReply &rsmReply) { + foreach (const QXmppArchiveMessage &msg, chat.messages()) { + qDebug() << "message:" << qPrintable(msg.body()); + } +} + +void ChatWindow::archiveListReceived(const QList &chats, const QXmppResultSetReply &rsmReply) { + +} + void ChatWindow::timeout() { if (numMessagesAfterLastTimeStamp >= NUM_MESSAGES_TO_TIME_STAMP) { addTimeStamp(); diff --git a/interface/src/ui/ChatWindow.h b/interface/src/ui/ChatWindow.h index b2956598a9..03ccc1b25e 100644 --- a/interface/src/ui/ChatWindow.h +++ b/interface/src/ui/ChatWindow.h @@ -26,6 +26,9 @@ #include #include +#include "QXmppArchiveIq.h" +#include "QXmppArchiveManager.h" + #endif namespace Ui { @@ -68,6 +71,7 @@ private: QSystemTrayIcon _trayIcon; QStringList _mentionSounds; QMediaPlayer _effectPlayer; + QXmppArchiveManager* _archiveManager; private slots: void connected(); @@ -77,6 +81,10 @@ private slots: void participantsChanged(); void messageReceived(const QXmppMessage& message); void notificationClicked(); + + + void archiveListReceived(const QList &chats, const QXmppResultSetReply &rsmReply); + void archiveChatReceived(const QXmppArchiveChat &chat, const QXmppResultSetReply &rsmReply); #endif };