improved mention positioning

removed achive manager
This commit is contained in:
Stojce Slavkovski 2014-04-30 00:25:27 +02:00
parent ca2c8d2fff
commit 785c9a3024
2 changed files with 19 additions and 39 deletions

View file

@ -29,12 +29,11 @@
#include <QMessageBox>
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<QXmppArchiveChat>, QXmppResultSetReply)),
SLOT(archiveListReceived(QList<QXmppArchiveChat>, 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<QXmppArchiveChat> &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

View file

@ -26,9 +26,6 @@
#include <QXmppClient.h>
#include <QXmppMessage.h>
#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<QXmppArchiveChat> &chats, const QXmppResultSetReply &rsmReply);
void archiveChatReceived(const QXmppArchiveChat &chat, const QXmppResultSetReply &rsmReply);
#endif
};