mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-13 22:27:13 +02:00
Add chat mention notifications
This commit is contained in:
parent
91d7bd252d
commit
5c7fb3eca5
8 changed files with 45 additions and 27 deletions
BIN
interface/resources/sounds/mention/chatMention1.wav
Normal file
BIN
interface/resources/sounds/mention/chatMention1.wav
Normal file
Binary file not shown.
BIN
interface/resources/sounds/mention/chatMention2.wav
Normal file
BIN
interface/resources/sounds/mention/chatMention2.wav
Normal file
Binary file not shown.
BIN
interface/resources/sounds/mention/chatMention3.wav
Normal file
BIN
interface/resources/sounds/mention/chatMention3.wav
Normal file
Binary file not shown.
|
@ -209,6 +209,9 @@ Menu::Menu() :
|
|||
toggleChat();
|
||||
connect(&xmppClient, SIGNAL(connected()), this, SLOT(toggleChat()));
|
||||
connect(&xmppClient, SIGNAL(disconnected()), this, SLOT(toggleChat()));
|
||||
|
||||
// init chat window to listen chat
|
||||
_chatWindow = new ChatWindow(Application::getInstance()->getWindow());
|
||||
#endif
|
||||
|
||||
QMenu* viewMenu = addMenu("View");
|
||||
|
|
|
@ -16,19 +16,15 @@
|
|||
#include "XmppClient.h"
|
||||
|
||||
const QString DEFAULT_XMPP_SERVER = "chat.highfidelity.io";
|
||||
const QString DEFAULT_CHAT_ROOM = "public@public-chat.highfidelity.io";
|
||||
const QString DEFAULT_CHAT_ROOM = "test@public-chat.highfidelity.io";
|
||||
|
||||
XmppClient::XmppClient() :
|
||||
_xmppClient(),
|
||||
_xmppMUCManager(),
|
||||
_archiveManager()
|
||||
_xmppMUCManager()
|
||||
{
|
||||
AccountManager& accountManager = AccountManager::getInstance();
|
||||
connect(&accountManager, SIGNAL(accessTokenChanged()), this, SLOT(connectToServer()));
|
||||
connect(&accountManager, SIGNAL(logoutComplete()), this, SLOT(disconnectFromServer()));
|
||||
|
||||
_archiveManager = new QXmppArchiveManager;
|
||||
_xmppClient.addExtension(_archiveManager);
|
||||
}
|
||||
|
||||
XmppClient& XmppClient::getInstance() {
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
#include <QObject>
|
||||
#include <QXmppClient.h>
|
||||
#include <QXmppMucManager.h>
|
||||
#include "QXmppArchiveManager.h"
|
||||
|
||||
/// Generalized threaded processor for handling received inbound packets.
|
||||
class XmppClient : public QObject {
|
||||
|
@ -28,7 +27,6 @@ public:
|
|||
|
||||
QXmppClient& getXMPPClient() { return _xmppClient; }
|
||||
const QXmppMucRoom* getPublicChatRoom() const { return _publicChatRoom; }
|
||||
QXmppArchiveManager* getArchiveManager() const { return _archiveManager; }
|
||||
|
||||
private slots:
|
||||
void xmppConnected();
|
||||
|
@ -45,7 +43,6 @@ private:
|
|||
QXmppClient _xmppClient;
|
||||
QXmppMucManager _xmppMUCManager;
|
||||
QXmppMucRoom* _publicChatRoom;
|
||||
QXmppArchiveManager* _archiveManager;
|
||||
};
|
||||
|
||||
#endif // __interface__XmppClient__
|
||||
|
|
|
@ -26,6 +26,8 @@
|
|||
|
||||
#include "ChatWindow.h"
|
||||
|
||||
#include <QMessageBox>
|
||||
|
||||
const int NUM_MESSAGES_TO_TIME_STAMP = 20;
|
||||
|
||||
const QRegularExpression regexLinks("((?:(?:ftp)|(?:https?))://\\S+)");
|
||||
|
@ -36,7 +38,9 @@ ChatWindow::ChatWindow(QWidget* parent) :
|
|||
ui(new Ui::ChatWindow),
|
||||
numMessagesAfterLastTimeStamp(0),
|
||||
_mousePressed(false),
|
||||
_mouseStartPosition()
|
||||
_mouseStartPosition(),
|
||||
_trayIcon(parent),
|
||||
_effectPlayer()
|
||||
{
|
||||
setAttribute(Qt::WA_DeleteOnClose, false);
|
||||
|
||||
|
@ -80,8 +84,21 @@ ChatWindow::ChatWindow(QWidget* parent) :
|
|||
connect(&xmppClient, SIGNAL(connected()), this, SLOT(connected()));
|
||||
}
|
||||
connect(&xmppClient, SIGNAL(messageReceived(QXmppMessage)), this, SLOT(messageReceived(QXmppMessage)));
|
||||
|
||||
connect(&_trayIcon, SIGNAL(messageClicked()), this, SLOT(notificationClicked()));
|
||||
#endif
|
||||
|
||||
QDir mentionSoundsDir(Application::resourcesPath() + "/sounds/mention/");
|
||||
_mentionSounds = mentionSoundsDir.entryList(QDir::Files);
|
||||
}
|
||||
|
||||
void ChatWindow::notificationClicked() {
|
||||
if (parentWidget()->isMinimized()) {
|
||||
parentWidget()->showNormal();
|
||||
}
|
||||
if (isHidden()) {
|
||||
show();
|
||||
}
|
||||
scrollToBottom();
|
||||
}
|
||||
|
||||
ChatWindow::~ChatWindow() {
|
||||
|
@ -205,17 +222,6 @@ void ChatWindow::connected() {
|
|||
const QXmppMucRoom* publicChatRoom = XmppClient::getInstance().getPublicChatRoom();
|
||||
connect(publicChatRoom, SIGNAL(participantsChanged()), this, SLOT(participantsChanged()));
|
||||
|
||||
|
||||
// set limits
|
||||
QDateTime m_startDate = QDateTime::currentDateTime().addDays(-2);
|
||||
QDateTime m_endDate = QDateTime::currentDateTime();
|
||||
|
||||
QXmppResultSetQuery rsmQuery;
|
||||
rsmQuery.setMax(100);
|
||||
|
||||
QXmppArchiveManager* archiveManager = XmppClient::getInstance().getArchiveManager();
|
||||
archiveManager->listCollections("", m_startDate, m_endDate, rsmQuery);
|
||||
|
||||
#endif
|
||||
startTimerForTimeStamps();
|
||||
}
|
||||
|
@ -317,6 +323,21 @@ void ChatWindow::messageReceived(const QXmppMessage& message) {
|
|||
} else {
|
||||
lastMessageStamp = QDateTime::currentDateTime();
|
||||
}
|
||||
|
||||
QRegularExpression usernameMention("@(\\b" + AccountManager::getInstance().getUsername() + "\\b)");
|
||||
qDebug() << "message: " << message.body();
|
||||
|
||||
if (isHidden() && message.body().contains(usernameMention)) {
|
||||
if (_effectPlayer.state() != QMediaPlayer::PlayingState) {
|
||||
// get random sound
|
||||
QFileInfo inf = QFileInfo(Application::resourcesPath() + "/sounds/mention/" + _mentionSounds.at(rand() % _mentionSounds.size()));
|
||||
_effectPlayer.setMedia(QUrl::fromLocalFile(inf.absoluteFilePath()));
|
||||
_effectPlayer.play();
|
||||
}
|
||||
|
||||
_trayIcon.show();
|
||||
_trayIcon.showMessage(windowTitle(), message.body());
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
|
||||
#include <QDateTime>
|
||||
#include <QDockWidget>
|
||||
#include <QMediaPlayer>
|
||||
#include <QSystemTrayIcon.h>
|
||||
#include <QTimer>
|
||||
|
||||
#include <Application.h>
|
||||
|
@ -24,10 +26,6 @@
|
|||
#include <QXmppClient.h>
|
||||
#include <QXmppMessage.h>
|
||||
|
||||
class QXmppArchiveChat;
|
||||
class QXmppArchiveManager;
|
||||
class QXmppResultSetReply;
|
||||
|
||||
#endif
|
||||
|
||||
namespace Ui {
|
||||
|
@ -67,6 +65,9 @@ private:
|
|||
QDateTime lastMessageStamp;
|
||||
bool _mousePressed;
|
||||
QPoint _mouseStartPosition;
|
||||
QSystemTrayIcon _trayIcon;
|
||||
QStringList _mentionSounds;
|
||||
QMediaPlayer _effectPlayer;
|
||||
|
||||
private slots:
|
||||
void connected();
|
||||
|
@ -75,7 +76,7 @@ private slots:
|
|||
void error(QXmppClient::Error error);
|
||||
void participantsChanged();
|
||||
void messageReceived(const QXmppMessage& message);
|
||||
|
||||
void notificationClicked();
|
||||
#endif
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue