2014-09-05 02:09:55 +08:00
|
|
|
/*
|
|
|
|
Copyright (C) 2014 by Project Tox <https://tox.im>
|
|
|
|
|
|
|
|
This file is part of qTox, a Qt-based graphical interface for Tox.
|
|
|
|
|
|
|
|
This program is libre software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the COPYING file for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "genericchatform.h"
|
|
|
|
#include "ui_mainwindow.h"
|
|
|
|
#include <QFileDialog>
|
2014-11-02 17:41:58 +08:00
|
|
|
#include <QHBoxLayout>
|
2014-10-08 12:26:25 +08:00
|
|
|
#include "src/misc/smileypack.h"
|
|
|
|
#include "src/widget/emoticonswidget.h"
|
|
|
|
#include "src/misc/style.h"
|
|
|
|
#include "src/widget/widget.h"
|
|
|
|
#include "src/misc/settings.h"
|
|
|
|
#include "src/widget/tool/chatactions/messageaction.h"
|
|
|
|
#include "src/widget/tool/chatactions/systemmessageaction.h"
|
|
|
|
#include "src/widget/tool/chatactions/actionaction.h"
|
2014-10-20 19:05:45 +08:00
|
|
|
#include "src/widget/tool/chatactions/alertaction.h"
|
2014-10-08 12:26:25 +08:00
|
|
|
#include "src/widget/chatareawidget.h"
|
|
|
|
#include "src/widget/tool/chattextedit.h"
|
|
|
|
#include "src/widget/maskablepixmapwidget.h"
|
2014-11-03 01:36:27 +08:00
|
|
|
#include "src/core.h"
|
2014-11-23 23:55:49 +08:00
|
|
|
#include "src/grouplist.h"
|
|
|
|
#include "src/group.h"
|
2014-11-07 22:55:32 +08:00
|
|
|
#include "src/friendlist.h"
|
|
|
|
#include "src/friend.h"
|
2014-09-05 02:09:55 +08:00
|
|
|
|
2014-09-26 00:03:25 +08:00
|
|
|
GenericChatForm::GenericChatForm(QWidget *parent) :
|
2014-10-11 01:32:10 +08:00
|
|
|
QWidget(parent),
|
|
|
|
earliestMessage(nullptr)
|
2014-11-13 20:11:23 +08:00
|
|
|
, audioInputFlag(false)
|
|
|
|
, audioOutputFlag(false)
|
2014-09-05 02:09:55 +08:00
|
|
|
{
|
|
|
|
curRow = 0;
|
|
|
|
|
2014-09-26 00:03:25 +08:00
|
|
|
headWidget = new QWidget();
|
2014-09-05 02:09:55 +08:00
|
|
|
|
2014-09-10 00:28:07 +08:00
|
|
|
nameLabel = new CroppingLabel();
|
2014-10-10 03:20:06 +08:00
|
|
|
nameLabel->setObjectName("nameLabel");
|
2014-10-24 03:53:45 +08:00
|
|
|
nameLabel->setMinimumHeight(Style::getFont(Style::Medium).pixelSize());
|
2014-11-18 10:15:44 +08:00
|
|
|
nameLabel->setEditable(true);
|
2014-10-01 02:10:42 +08:00
|
|
|
|
2014-09-27 22:37:16 +08:00
|
|
|
avatar = new MaskablePixmapWidget(this, QSize(40,40), ":/img/avatar_mask.png");
|
2014-12-17 19:36:34 +08:00
|
|
|
QHBoxLayout *headLayout = new QHBoxLayout(),
|
|
|
|
*mainFootLayout = new QHBoxLayout();
|
|
|
|
|
|
|
|
QVBoxLayout *mainLayout = new QVBoxLayout(),
|
|
|
|
*footButtonsSmall = new QVBoxLayout(),
|
2015-01-06 22:36:03 +08:00
|
|
|
*micButtonsLayout = new QVBoxLayout();
|
|
|
|
|
|
|
|
QGridLayout *buttonsLayout = new QGridLayout();
|
|
|
|
|
2014-12-17 19:36:34 +08:00
|
|
|
headTextLayout = new QVBoxLayout();
|
2014-09-05 02:09:55 +08:00
|
|
|
|
2014-09-07 19:42:06 +08:00
|
|
|
chatWidget = new ChatAreaWidget();
|
2014-09-06 03:27:26 +08:00
|
|
|
|
2014-09-05 02:09:55 +08:00
|
|
|
msgEdit = new ChatTextEdit();
|
|
|
|
|
|
|
|
sendButton = new QPushButton();
|
2014-10-24 06:00:30 +08:00
|
|
|
sendButton->setToolTip(tr("Send message"));
|
2014-09-05 02:09:55 +08:00
|
|
|
emoteButton = new QPushButton();
|
2014-10-24 06:00:30 +08:00
|
|
|
emoteButton->setToolTip(tr("Smileys"));
|
2014-09-05 02:09:55 +08:00
|
|
|
|
2014-10-24 03:53:45 +08:00
|
|
|
// Setting the sizes in the CSS doesn't work (glitch with high DPIs)
|
2014-09-05 02:09:55 +08:00
|
|
|
fileButton = new QPushButton();
|
2014-10-24 15:43:13 +08:00
|
|
|
fileButton->setToolTip(tr("Send file(s)"));
|
2014-09-05 02:09:55 +08:00
|
|
|
callButton = new QPushButton();
|
2014-10-24 03:53:45 +08:00
|
|
|
callButton->setFixedSize(50,40);
|
2014-11-16 01:43:10 +08:00
|
|
|
callButton->setToolTip(tr("Audio call: RED means you're on a call"));
|
2014-09-05 02:09:55 +08:00
|
|
|
videoButton = new QPushButton();
|
2014-10-24 03:53:45 +08:00
|
|
|
videoButton->setFixedSize(50,40);
|
2014-11-16 01:43:10 +08:00
|
|
|
videoButton->setToolTip(tr("Video call: RED means you're on a call"));
|
2014-09-05 02:09:55 +08:00
|
|
|
volButton = new QPushButton();
|
2014-12-17 19:36:34 +08:00
|
|
|
//volButton->setFixedSize(25,20);
|
2014-11-16 01:43:10 +08:00
|
|
|
volButton->setToolTip(tr("Toggle speakers volume: RED is OFF"));
|
2014-09-05 02:09:55 +08:00
|
|
|
micButton = new QPushButton();
|
2014-12-17 19:36:34 +08:00
|
|
|
// micButton->setFixedSize(25,20);
|
2014-11-16 01:35:36 +08:00
|
|
|
micButton->setToolTip(tr("Toggle microphone: RED is OFF"));
|
2014-09-05 02:09:55 +08:00
|
|
|
|
|
|
|
footButtonsSmall->setSpacing(2);
|
|
|
|
|
2014-10-01 02:10:42 +08:00
|
|
|
msgEdit->setStyleSheet(Style::getStylesheet(":/ui/msgEdit/msgEdit.css"));
|
2014-09-05 02:09:55 +08:00
|
|
|
msgEdit->setFixedHeight(50);
|
|
|
|
msgEdit->setFrameStyle(QFrame::NoFrame);
|
|
|
|
|
2014-10-01 02:10:42 +08:00
|
|
|
sendButton->setStyleSheet(Style::getStylesheet(":/ui/sendButton/sendButton.css"));
|
|
|
|
fileButton->setStyleSheet(Style::getStylesheet(":/ui/fileButton/fileButton.css"));
|
|
|
|
emoteButton->setStyleSheet(Style::getStylesheet(":/ui/emoteButton/emoteButton.css"));
|
2014-09-05 02:09:55 +08:00
|
|
|
|
|
|
|
callButton->setObjectName("green");
|
2014-10-01 02:10:42 +08:00
|
|
|
callButton->setStyleSheet(Style::getStylesheet(":/ui/callButton/callButton.css"));
|
2014-09-05 02:09:55 +08:00
|
|
|
|
|
|
|
videoButton->setObjectName("green");
|
2014-10-01 02:10:42 +08:00
|
|
|
videoButton->setStyleSheet(Style::getStylesheet(":/ui/videoButton/videoButton.css"));
|
2014-09-05 02:09:55 +08:00
|
|
|
|
2014-10-01 02:10:42 +08:00
|
|
|
QString volButtonStylesheet = Style::getStylesheet(":/ui/volButton/volButton.css");
|
2014-09-05 02:09:55 +08:00
|
|
|
volButton->setObjectName("green");
|
|
|
|
volButton->setStyleSheet(volButtonStylesheet);
|
|
|
|
|
2014-10-01 02:10:42 +08:00
|
|
|
QString micButtonStylesheet = Style::getStylesheet(":/ui/micButton/micButton.css");
|
2014-09-05 02:09:55 +08:00
|
|
|
micButton->setObjectName("green");
|
|
|
|
micButton->setStyleSheet(micButtonStylesheet);
|
|
|
|
|
2014-09-26 00:03:25 +08:00
|
|
|
setLayout(mainLayout);
|
2014-09-07 19:42:06 +08:00
|
|
|
mainLayout->addWidget(chatWidget);
|
2014-09-05 02:09:55 +08:00
|
|
|
mainLayout->addLayout(mainFootLayout);
|
|
|
|
mainLayout->setMargin(0);
|
|
|
|
|
|
|
|
footButtonsSmall->addWidget(emoteButton);
|
|
|
|
footButtonsSmall->addWidget(fileButton);
|
|
|
|
|
|
|
|
mainFootLayout->addWidget(msgEdit);
|
|
|
|
mainFootLayout->addLayout(footButtonsSmall);
|
|
|
|
mainFootLayout->addSpacing(5);
|
|
|
|
mainFootLayout->addWidget(sendButton);
|
|
|
|
mainFootLayout->setSpacing(0);
|
2014-12-17 19:36:34 +08:00
|
|
|
|
2015-01-06 22:36:03 +08:00
|
|
|
headTextLayout->addStretch();
|
2014-12-17 19:36:34 +08:00
|
|
|
headTextLayout->addWidget(nameLabel);
|
2015-01-06 22:36:03 +08:00
|
|
|
headTextLayout->addStretch();
|
|
|
|
|
|
|
|
micButtonsLayout->addWidget(micButton, Qt::AlignTop | Qt::AlignRight);
|
|
|
|
micButtonsLayout->addWidget(volButton, Qt::AlignTop | Qt::AlignRight);
|
|
|
|
|
|
|
|
buttonsLayout->addLayout(micButtonsLayout, 0, 0, Qt::AlignTop | Qt::AlignRight);
|
|
|
|
buttonsLayout->addWidget(callButton, 0, 1, 2, 1, Qt::AlignTop);
|
|
|
|
buttonsLayout->addWidget(videoButton, 0, 2, 2, 1, Qt::AlignTop);
|
|
|
|
buttonsLayout->setSpacing(1);
|
2014-12-17 19:36:34 +08:00
|
|
|
|
2015-01-06 22:36:03 +08:00
|
|
|
headLayout->addWidget(avatar, Qt::AlignTop | Qt::AlignLeft);
|
2014-11-02 17:41:58 +08:00
|
|
|
headLayout->addSpacing(5);
|
2015-01-06 22:36:03 +08:00
|
|
|
headLayout->addLayout(headTextLayout, Qt::AlignTop | Qt::AlignAbsolute);
|
|
|
|
headLayout->addLayout(buttonsLayout, Qt::AlignTop | Qt::AlignRight);
|
2014-09-05 02:09:55 +08:00
|
|
|
|
2015-01-06 22:36:03 +08:00
|
|
|
headWidget->setLayout(headLayout);
|
|
|
|
|
2014-09-05 02:09:55 +08:00
|
|
|
//Fix for incorrect layouts on OS X as per
|
|
|
|
//https://bugreports.qt-project.org/browse/QTBUG-14591
|
|
|
|
sendButton->setAttribute(Qt::WA_LayoutUsesWidgetRect);
|
|
|
|
fileButton->setAttribute(Qt::WA_LayoutUsesWidgetRect);
|
|
|
|
emoteButton->setAttribute(Qt::WA_LayoutUsesWidgetRect);
|
|
|
|
|
2014-10-09 22:36:24 +08:00
|
|
|
menu.addAction(tr("Save chat log"), this, SLOT(onSaveLogClicked()));
|
2014-10-11 01:32:10 +08:00
|
|
|
menu.addAction(tr("Clear displayed messages"), this, SLOT(clearChatArea(bool)));
|
2014-10-11 00:54:21 +08:00
|
|
|
menu.addSeparator();
|
2014-10-09 22:36:24 +08:00
|
|
|
|
2014-09-05 23:05:57 +08:00
|
|
|
connect(emoteButton, SIGNAL(clicked()), this, SLOT(onEmoteButtonClicked()));
|
2014-09-07 19:42:06 +08:00
|
|
|
connect(chatWidget, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(onChatContextMenuRequested(QPoint)));
|
2014-11-26 05:20:39 +08:00
|
|
|
connect(chatWidget, SIGNAL(onClick()), this, SLOT(onChatWidgetClicked()));
|
2014-10-10 03:20:06 +08:00
|
|
|
|
|
|
|
chatWidget->document()->setDefaultStyleSheet(Style::getStylesheet(":ui/chatArea/innerStyle.css"));
|
|
|
|
chatWidget->setStyleSheet(Style::getStylesheet(":/ui/chatArea/chatArea.css"));
|
|
|
|
headWidget->setStyleSheet(Style::getStylesheet(":/ui/chatArea/chatHead.css"));
|
2014-11-10 00:07:15 +08:00
|
|
|
|
|
|
|
ChatAction::setupFormat();
|
2014-09-05 02:09:55 +08:00
|
|
|
}
|
|
|
|
|
2014-11-08 21:46:26 +08:00
|
|
|
bool GenericChatForm::isEmpty()
|
2014-10-11 18:48:45 +08:00
|
|
|
{
|
2014-11-08 21:46:26 +08:00
|
|
|
return chatWidget->isEmpty();
|
2014-10-11 18:48:45 +08:00
|
|
|
}
|
|
|
|
|
2014-09-05 02:09:55 +08:00
|
|
|
void GenericChatForm::setName(const QString &newName)
|
|
|
|
{
|
|
|
|
nameLabel->setText(newName);
|
|
|
|
nameLabel->setToolTip(newName); // for overlength names
|
|
|
|
}
|
|
|
|
|
|
|
|
void GenericChatForm::show(Ui::MainWindow &ui)
|
|
|
|
{
|
2014-09-26 00:03:25 +08:00
|
|
|
ui.mainContent->layout()->addWidget(this);
|
2014-09-05 02:09:55 +08:00
|
|
|
ui.mainHead->layout()->addWidget(headWidget);
|
|
|
|
headWidget->show();
|
2014-09-26 00:03:25 +08:00
|
|
|
QWidget::show();
|
2014-09-05 02:09:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void GenericChatForm::onChatContextMenuRequested(QPoint pos)
|
|
|
|
{
|
|
|
|
QWidget* sender = (QWidget*)QObject::sender();
|
|
|
|
pos = sender->mapToGlobal(pos);
|
|
|
|
menu.exec(pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GenericChatForm::onSaveLogClicked()
|
|
|
|
{
|
2014-09-06 03:27:26 +08:00
|
|
|
QString path = QFileDialog::getSaveFileName(0, tr("Save chat log"));
|
2014-09-05 02:09:55 +08:00
|
|
|
if (path.isEmpty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
QFile file(path);
|
|
|
|
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
|
|
|
|
return;
|
|
|
|
|
|
|
|
QString log;
|
2014-09-07 19:42:06 +08:00
|
|
|
log = chatWidget->toPlainText();
|
2014-09-05 02:09:55 +08:00
|
|
|
|
|
|
|
file.write(log.toUtf8());
|
|
|
|
file.close();
|
|
|
|
}
|
|
|
|
|
2014-11-10 01:02:43 +08:00
|
|
|
MessageActionPtr GenericChatForm::addMessage(const ToxID& author, const QString &message, bool isAction,
|
|
|
|
const QDateTime &datetime, bool isSent)
|
2014-11-03 01:36:27 +08:00
|
|
|
{
|
2014-11-10 01:02:43 +08:00
|
|
|
MessageActionPtr ca = genMessageActionAction(author, message, isAction, datetime);
|
|
|
|
if (isSent)
|
|
|
|
ca->markAsSent();
|
2014-11-03 01:36:27 +08:00
|
|
|
chatWidget->insertMessage(ca);
|
2014-11-10 01:02:43 +08:00
|
|
|
return ca;
|
2014-11-03 01:36:27 +08:00
|
|
|
}
|
|
|
|
|
2014-11-10 01:02:43 +08:00
|
|
|
MessageActionPtr GenericChatForm::addSelfMessage(const QString &message, bool isAction, const QDateTime &datetime, bool isSent)
|
2014-11-03 01:36:27 +08:00
|
|
|
{
|
2014-11-10 01:02:43 +08:00
|
|
|
MessageActionPtr ca = genSelfActionAction(message, isAction, datetime);
|
|
|
|
if (isSent)
|
|
|
|
ca->markAsSent();
|
2014-11-03 01:36:27 +08:00
|
|
|
chatWidget->insertMessage(ca);
|
2014-11-10 01:02:43 +08:00
|
|
|
return ca;
|
2014-11-03 01:36:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void GenericChatForm::addAlertMessage(const ToxID &author, QString message, QDateTime datetime)
|
|
|
|
{
|
2014-11-23 23:55:49 +08:00
|
|
|
QString authorStr = resolveToxID(author);
|
|
|
|
if (authorStr.isEmpty())
|
|
|
|
authorStr = author.publicKey;
|
|
|
|
|
2014-11-03 01:36:27 +08:00
|
|
|
QString date = datetime.toString(Settings::getInstance().getTimestampFormat());
|
2014-12-04 01:47:07 +08:00
|
|
|
MessageActionPtr ca = MessageActionPtr(new AlertAction(getElidedName(authorStr), message, date));
|
2014-11-25 00:58:57 +08:00
|
|
|
ca->markAsSent();
|
|
|
|
chatWidget->insertMessage(ca);
|
2014-11-03 01:36:27 +08:00
|
|
|
previousId = author;
|
2014-10-20 19:05:45 +08:00
|
|
|
}
|
|
|
|
|
2014-09-05 23:05:57 +08:00
|
|
|
void GenericChatForm::onEmoteButtonClicked()
|
|
|
|
{
|
|
|
|
// don't show the smiley selection widget if there are no smileys available
|
|
|
|
if (SmileyPack::getInstance().getEmoticons().empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
EmoticonsWidget widget;
|
|
|
|
connect(&widget, SIGNAL(insertEmoticon(QString)), this, SLOT(onEmoteInsertRequested(QString)));
|
|
|
|
|
|
|
|
QWidget* sender = qobject_cast<QWidget*>(QObject::sender());
|
|
|
|
if (sender)
|
|
|
|
{
|
|
|
|
QPoint pos = -QPoint(widget.sizeHint().width() / 2, widget.sizeHint().height()) - QPoint(0, 10);
|
|
|
|
widget.exec(sender->mapToGlobal(pos));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-26 05:20:39 +08:00
|
|
|
void GenericChatForm::onChatWidgetClicked()
|
|
|
|
{
|
2014-12-28 02:59:43 +08:00
|
|
|
if (!chatWidget->textCursor().hasSelection())
|
|
|
|
msgEdit->setFocus();
|
2014-11-26 05:20:39 +08:00
|
|
|
}
|
|
|
|
|
2014-09-05 23:05:57 +08:00
|
|
|
void GenericChatForm::onEmoteInsertRequested(QString str)
|
|
|
|
{
|
|
|
|
// insert the emoticon
|
|
|
|
QWidget* sender = qobject_cast<QWidget*>(QObject::sender());
|
|
|
|
if (sender)
|
|
|
|
msgEdit->insertPlainText(str);
|
|
|
|
|
|
|
|
msgEdit->setFocus(); // refocus so that we can continue typing
|
|
|
|
}
|
2014-09-11 05:00:45 +08:00
|
|
|
|
|
|
|
void GenericChatForm::focusInput()
|
|
|
|
{
|
|
|
|
msgEdit->setFocus();
|
|
|
|
}
|
2014-09-24 00:35:06 +08:00
|
|
|
|
|
|
|
void GenericChatForm::addSystemInfoMessage(const QString &message, const QString &type, const QDateTime &datetime)
|
|
|
|
{
|
2014-10-26 23:04:39 +08:00
|
|
|
ChatActionPtr ca = genSystemInfoAction(message, type, datetime);
|
2014-10-11 01:32:10 +08:00
|
|
|
chatWidget->insertMessage(ca);
|
2014-09-24 00:35:06 +08:00
|
|
|
}
|
2014-09-29 00:39:26 +08:00
|
|
|
|
|
|
|
QString GenericChatForm::getElidedName(const QString& name)
|
|
|
|
{
|
2014-10-05 23:34:34 +08:00
|
|
|
// update this whenever you change the font in innerStyle.css
|
|
|
|
QFontMetrics fm(Style::getFont(Style::BigBold));
|
2014-09-29 00:39:26 +08:00
|
|
|
|
|
|
|
return fm.elidedText(name, Qt::ElideRight, chatWidget->nameColWidth());
|
|
|
|
}
|
2014-10-11 00:54:21 +08:00
|
|
|
|
2014-10-11 01:32:10 +08:00
|
|
|
void GenericChatForm::clearChatArea(bool notinform)
|
2014-10-11 00:54:21 +08:00
|
|
|
{
|
|
|
|
chatWidget->clearChatArea();
|
2014-11-03 01:36:27 +08:00
|
|
|
previousId = ToxID();
|
2014-10-11 01:32:10 +08:00
|
|
|
|
|
|
|
if (!notinform)
|
2014-10-14 13:49:27 +08:00
|
|
|
addSystemInfoMessage(tr("Cleared"), "white", QDateTime::currentDateTime());
|
2014-10-11 01:32:10 +08:00
|
|
|
|
|
|
|
if (earliestMessage)
|
|
|
|
{
|
|
|
|
delete earliestMessage;
|
|
|
|
earliestMessage = nullptr;
|
|
|
|
}
|
2014-11-10 21:06:35 +08:00
|
|
|
|
|
|
|
emit chatAreaCleared();
|
2014-10-11 01:32:10 +08:00
|
|
|
}
|
|
|
|
|
2014-11-10 01:02:43 +08:00
|
|
|
MessageActionPtr GenericChatForm::genMessageActionAction(const ToxID& author, QString message, bool isAction, const QDateTime &datetime)
|
2014-11-03 01:36:27 +08:00
|
|
|
{
|
|
|
|
if (earliestMessage == nullptr)
|
|
|
|
{
|
|
|
|
earliestMessage = new QDateTime(datetime);
|
|
|
|
}
|
|
|
|
|
|
|
|
const Core* core = Core::getInstance();
|
|
|
|
|
|
|
|
QString date = datetime.toString(Settings::getInstance().getTimestampFormat());
|
|
|
|
bool isMe = (author == core->getSelfId());
|
|
|
|
QString authorStr;
|
|
|
|
if (isMe)
|
|
|
|
authorStr = core->getUsername();
|
2014-11-07 22:55:32 +08:00
|
|
|
else {
|
2014-11-23 23:55:49 +08:00
|
|
|
authorStr = resolveToxID(author);
|
2014-11-07 22:55:32 +08:00
|
|
|
}
|
2014-11-03 01:36:27 +08:00
|
|
|
|
|
|
|
if (authorStr.isEmpty()) // Fallback if we can't find a username
|
|
|
|
authorStr = author.toString();
|
|
|
|
|
|
|
|
if (!isAction && message.startsWith("/me "))
|
|
|
|
{ // always render actions regardless of what core thinks
|
|
|
|
isAction = true;
|
|
|
|
message = message.right(message.length()-4);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isAction)
|
|
|
|
{
|
|
|
|
previousId = ToxID(); // next msg has a name regardless
|
2014-11-10 01:02:43 +08:00
|
|
|
return MessageActionPtr(new ActionAction (getElidedName(authorStr), message, date, isMe));
|
2014-11-03 01:36:27 +08:00
|
|
|
}
|
|
|
|
|
2014-11-10 01:02:43 +08:00
|
|
|
MessageActionPtr res;
|
2014-11-03 01:36:27 +08:00
|
|
|
if (previousId == author)
|
2014-11-10 01:02:43 +08:00
|
|
|
res = MessageActionPtr(new MessageAction(QString(), message, date, isMe));
|
2014-11-03 01:36:27 +08:00
|
|
|
else
|
2014-11-10 01:02:43 +08:00
|
|
|
res = MessageActionPtr(new MessageAction(getElidedName(authorStr), message, date, isMe));
|
2014-11-03 01:36:27 +08:00
|
|
|
|
|
|
|
previousId = author;
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2014-11-10 01:02:43 +08:00
|
|
|
MessageActionPtr GenericChatForm::genSelfActionAction(QString message, bool isAction, const QDateTime &datetime)
|
2014-11-03 01:36:27 +08:00
|
|
|
{
|
|
|
|
if (earliestMessage == nullptr)
|
|
|
|
{
|
|
|
|
earliestMessage = new QDateTime(datetime);
|
|
|
|
}
|
|
|
|
|
|
|
|
const Core* core = Core::getInstance();
|
|
|
|
|
|
|
|
QString date = datetime.toString(Settings::getInstance().getTimestampFormat());
|
|
|
|
QString author = core->getUsername();;
|
|
|
|
|
|
|
|
if (!isAction && message.startsWith("/me "))
|
|
|
|
{ // always render actions regardless of what core thinks
|
|
|
|
isAction = true;
|
|
|
|
message = message.right(message.length()-4);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isAction)
|
|
|
|
{
|
|
|
|
previousId = ToxID(); // next msg has a name regardless
|
2014-11-10 01:02:43 +08:00
|
|
|
return MessageActionPtr(new ActionAction (getElidedName(author), message, date, true));
|
2014-11-03 01:36:27 +08:00
|
|
|
}
|
|
|
|
|
2014-11-10 01:02:43 +08:00
|
|
|
MessageActionPtr res;
|
2014-11-03 01:36:27 +08:00
|
|
|
if (previousId.isMine())
|
2014-11-10 01:02:43 +08:00
|
|
|
res = MessageActionPtr(new MessageAction(QString(), message, date, true));
|
2014-11-03 01:36:27 +08:00
|
|
|
else
|
2014-11-10 01:02:43 +08:00
|
|
|
res = MessageActionPtr(new MessageAction(getElidedName(author), message, date, true));
|
2014-11-03 01:36:27 +08:00
|
|
|
|
|
|
|
previousId = Core::getInstance()->getSelfId();
|
2014-10-11 01:32:10 +08:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2014-10-26 23:04:39 +08:00
|
|
|
ChatActionPtr GenericChatForm::genSystemInfoAction(const QString &message, const QString &type, const QDateTime &datetime)
|
2014-10-11 01:32:10 +08:00
|
|
|
{
|
2014-11-03 01:36:27 +08:00
|
|
|
previousId = ToxID();
|
2014-10-11 01:32:10 +08:00
|
|
|
QString date = datetime.toString(Settings::getInstance().getTimestampFormat());
|
|
|
|
|
2014-10-26 23:04:39 +08:00
|
|
|
return ChatActionPtr(new SystemMessageAction(message, type, date));
|
2014-10-11 00:54:21 +08:00
|
|
|
}
|
2014-11-23 23:55:49 +08:00
|
|
|
|
|
|
|
QString GenericChatForm::resolveToxID(const ToxID &id)
|
|
|
|
{
|
|
|
|
Friend *f = FriendList::findFriend(id);
|
|
|
|
if (f)
|
|
|
|
{
|
|
|
|
return f->getDisplayedName();
|
|
|
|
} else {
|
|
|
|
for (auto it : GroupList::getAllGroups())
|
|
|
|
{
|
|
|
|
QString res = it->resolveToxID(id);
|
|
|
|
if (res.size())
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return QString();
|
|
|
|
}
|