From 785c9a302409663672f1cf08753b82a756e6731f Mon Sep 17 00:00:00 2001 From: Stojce Slavkovski Date: Wed, 30 Apr 2014 00:25:27 +0200 Subject: [PATCH] improved mention positioning removed achive manager --- interface/src/ui/ChatWindow.cpp | 50 +++++++++++++-------------------- interface/src/ui/ChatWindow.h | 8 ------ 2 files changed, 19 insertions(+), 39 deletions(-) diff --git a/interface/src/ui/ChatWindow.cpp b/interface/src/ui/ChatWindow.cpp index 207ac8a597..d6e8e46b8e 100644 --- a/interface/src/ui/ChatWindow.cpp +++ b/interface/src/ui/ChatWindow.cpp @@ -29,12 +29,11 @@ #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+)"); const QString mentionSoundsPath("/sounds/mention/"); +const QString mentionRegex("@(\\b%1\\b)"); ChatWindow::ChatWindow(QWidget* parent) : FramelessDialog(parent, 0, POSITION_RIGHT), @@ -101,6 +100,22 @@ void ChatWindow::notificationClicked() { if (isHidden()) { show(); } + + // find last mention + int messageCount = ui->messagesVBoxLayout->count(); + for (unsigned int i = messageCount; i > 0; i--) { + ChatMessageArea* area = (ChatMessageArea*)ui->messagesVBoxLayout->itemAt(i - 1)->widget(); + QRegularExpression usernameMention(mentionRegex.arg(AccountManager::getInstance().getUsername())); + if (area->toPlainText().contains(usernameMention)) { + int top = area->geometry().top(); + int height = area->geometry().height(); + + QScrollBar* verticalScrollBar = ui->messagesScrollArea->verticalScrollBar(); + verticalScrollBar->setSliderPosition(top - verticalScrollBar->size().height() + height); + return; + } + } + scrollToBottom(); } @@ -126,6 +141,7 @@ void ChatWindow::keyPressEvent(QKeyEvent* event) { void ChatWindow::showEvent(QShowEvent* event) { FramelessDialog::showEvent(event); + if (!event->spontaneous()) { ui->messagePlainTextEdit->setFocus(); } @@ -229,38 +245,10 @@ 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(); @@ -359,7 +347,7 @@ void ChatWindow::messageReceived(const QXmppMessage& message) { lastMessageStamp = QDateTime::currentDateTime(); } - QRegularExpression usernameMention("@(\\b" + AccountManager::getInstance().getUsername() + "\\b)"); + QRegularExpression usernameMention(mentionRegex.arg(AccountManager::getInstance().getUsername())); if (isHidden() && message.body().contains(usernameMention)) { if (_effectPlayer.state() != QMediaPlayer::PlayingState) { // get random sound diff --git a/interface/src/ui/ChatWindow.h b/interface/src/ui/ChatWindow.h index 03ccc1b25e..b2956598a9 100644 --- a/interface/src/ui/ChatWindow.h +++ b/interface/src/ui/ChatWindow.h @@ -26,9 +26,6 @@ #include #include -#include "QXmppArchiveIq.h" -#include "QXmppArchiveManager.h" - #endif namespace Ui { @@ -71,7 +68,6 @@ private: QSystemTrayIcon _trayIcon; QStringList _mentionSounds; QMediaPlayer _effectPlayer; - QXmppArchiveManager* _archiveManager; private slots: void connected(); @@ -81,10 +77,6 @@ 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 };