mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-12 17:14:52 -07:00
Merge pull request #1510 from woogerboy21/room_message_history
Added chat history to a room that is displayed on join
This commit is contained in:
commit
385455e77c
23 changed files with 141 additions and 16 deletions
|
|
@ -12,6 +12,7 @@
|
|||
#include "settingscache.h"
|
||||
#include "tab_userlists.h"
|
||||
#include "soundengine.h"
|
||||
#include "room_message_type.h"
|
||||
|
||||
const QColor DEFAULT_MENTION_COLOR = QColor(194, 31, 47);
|
||||
const QColor OTHER_USER_COLOR = QColor(0, 65, 255); // dark blue
|
||||
|
|
@ -121,7 +122,7 @@ void ChatView::appendUrlTag(QTextCursor &cursor, QString url)
|
|||
cursor.setCharFormat(oldFormat);
|
||||
}
|
||||
|
||||
void ChatView::appendMessage(QString message, QString sender, UserLevelFlags userLevel, bool playerBold)
|
||||
void ChatView::appendMessage(QString message, RoomMessageTypeFlags messageType, QString sender, UserLevelFlags userLevel, bool playerBold)
|
||||
{
|
||||
bool atBottom = verticalScrollBar()->value() >= verticalScrollBar()->maximum();
|
||||
bool sameSender = (sender == lastSender) && !lastSender.isEmpty();
|
||||
|
|
@ -129,7 +130,7 @@ void ChatView::appendMessage(QString message, QString sender, UserLevelFlags use
|
|||
lastSender = sender;
|
||||
|
||||
// timestamp
|
||||
if (showTimestamps && !sameSender) {
|
||||
if (showTimestamps && !sameSender && !sender.isEmpty()) {
|
||||
QTextCharFormat timeFormat;
|
||||
timeFormat.setForeground(QColor(SERVER_MESSAGE_COLOR));
|
||||
if (sender.isEmpty())
|
||||
|
|
@ -168,8 +169,17 @@ void ChatView::appendMessage(QString message, QString sender, UserLevelFlags use
|
|||
// use different color for server messages
|
||||
defaultFormat = QTextCharFormat();
|
||||
if (sender.isEmpty()) {
|
||||
defaultFormat.setForeground(Qt::darkGreen);
|
||||
defaultFormat.setFontWeight(QFont::Bold);
|
||||
switch (messageType) {
|
||||
case Event_RoomSay::Welcome:
|
||||
defaultFormat.setForeground(Qt::darkGreen);
|
||||
defaultFormat.setFontWeight(QFont::Bold);
|
||||
break;
|
||||
case Event_RoomSay::ChatHistory:
|
||||
defaultFormat.setForeground(Qt::gray);
|
||||
defaultFormat.setFontWeight(QFont::Light);
|
||||
defaultFormat.setFontItalic(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
cursor.setCharFormat(defaultFormat);
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
#include <QAction>
|
||||
#include "userlist.h"
|
||||
#include "user_level.h"
|
||||
#include "room_message_type.h"
|
||||
#include "tab_supervisor.h"
|
||||
|
||||
class QTextTable;
|
||||
|
|
@ -59,7 +60,7 @@ public:
|
|||
void retranslateUi();
|
||||
void appendHtml(const QString &html);
|
||||
void appendHtmlServerMessage(const QString &html, bool optionalIsBold = false, QString optionalFontColor = QString());
|
||||
void appendMessage(QString message, QString sender = QString(), UserLevelFlags userLevel = UserLevelFlags(), bool playerBold = false);
|
||||
void appendMessage(QString message, RoomMessageTypeFlags messageType = 0, QString sender = QString(), UserLevelFlags userLevel = UserLevelFlags(), bool playerBold = false);
|
||||
void clearChat();
|
||||
protected:
|
||||
void enterEvent(QEvent *event);
|
||||
|
|
|
|||
|
|
@ -483,6 +483,9 @@ MessagesSettingsPage::MessagesSettingsPage()
|
|||
mentionPopups.setChecked(settingsCache->getShowMentionPopup());
|
||||
connect(&mentionPopups, SIGNAL(stateChanged(int)), settingsCache, SLOT(setShowMentionPopups(int)));
|
||||
|
||||
roomHistory.setChecked(settingsCache->getRoomHistory());
|
||||
connect(&roomHistory, SIGNAL(stateChanged(int)), settingsCache, SLOT(setRoomHistory(int)));
|
||||
|
||||
customAlertString = new QLineEdit();
|
||||
customAlertString->setPlaceholderText("Word1 Word2 Word3");
|
||||
customAlertString->setText(settingsCache->getHighlightWords());
|
||||
|
|
@ -498,6 +501,7 @@ MessagesSettingsPage::MessagesSettingsPage()
|
|||
chatGrid->addWidget(&ignoreUnregUserMessages, 3, 0);
|
||||
chatGrid->addWidget(&messagePopups, 4, 0);
|
||||
chatGrid->addWidget(&mentionPopups, 5, 0);
|
||||
chatGrid->addWidget(&roomHistory, 6, 0);
|
||||
chatGroupBox = new QGroupBox;
|
||||
chatGroupBox->setLayout(chatGrid);
|
||||
|
||||
|
|
@ -626,7 +630,8 @@ void MessagesSettingsPage::retranslateUi()
|
|||
invertMentionForeground.setText(tr("Invert text color"));
|
||||
invertHighlightForeground.setText(tr("Invert text color"));
|
||||
messagePopups.setText(tr("Enable desktop notifications for private messages"));
|
||||
mentionPopups.setText(tr("Enable desktop notification for mentions."));
|
||||
mentionPopups.setText(tr("Enable desktop notification for mentions"));
|
||||
roomHistory.setText(tr("Enable room message history on join"));
|
||||
hexLabel.setText(tr("(Color is hexadecimal)"));
|
||||
hexHighlightLabel.setText(tr("(Color is hexadecimal)"));
|
||||
customAlertStringLabel.setText(tr("Separate words with a space, alphanumeric characters only"));
|
||||
|
|
|
|||
|
|
@ -153,6 +153,7 @@ private:
|
|||
QCheckBox ignoreUnregUserMessages;
|
||||
QCheckBox messagePopups;
|
||||
QCheckBox mentionPopups;
|
||||
QCheckBox roomHistory;
|
||||
QGroupBox *chatGroupBox;
|
||||
QGroupBox *highlightGroupBox;
|
||||
QGroupBox *messageShortcuts;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ LocalServer::LocalServer(QObject *parent)
|
|||
: Server(false, parent)
|
||||
{
|
||||
setDatabaseInterface(new LocalServer_DatabaseInterface(this));
|
||||
addRoom(new Server_Room(0, QString(), QString(), QString(), false, QString(), QStringList(), this));
|
||||
addRoom(new Server_Room(0, 0, QString(), QString(), QString(), false, QString(), QStringList(), this));
|
||||
}
|
||||
|
||||
LocalServer::~LocalServer()
|
||||
|
|
|
|||
|
|
@ -168,12 +168,12 @@ void MessageLogWidget::logConnectionStateChanged(Player *player, bool connection
|
|||
|
||||
void MessageLogWidget::logSay(Player *player, QString message)
|
||||
{
|
||||
appendMessage(message, player->getName(), UserLevelFlags(player->getUserInfo()->user_level()), true);
|
||||
appendMessage(message, 0, player->getName(), UserLevelFlags(player->getUserInfo()->user_level()), true);
|
||||
}
|
||||
|
||||
void MessageLogWidget::logSpectatorSay(QString spectatorName, UserLevelFlags spectatorUserLevel, QString message)
|
||||
{
|
||||
appendMessage(message, spectatorName, spectatorUserLevel, false);
|
||||
appendMessage(message, 0, spectatorName, spectatorUserLevel, false);
|
||||
}
|
||||
|
||||
void MessageLogWidget::logShuffle(Player *player, CardZone *zone)
|
||||
|
|
|
|||
|
|
@ -208,6 +208,7 @@ SettingsCache::SettingsCache()
|
|||
scaleCards = settings->value("cards/scaleCards", true).toBool();
|
||||
showMessagePopups = settings->value("chat/showmessagepopups", true).toBool();
|
||||
showMentionPopups = settings->value("chat/showmentionpopups", true).toBool();
|
||||
roomHistory = settings->value("chat/roomhistory", true).toBool();
|
||||
|
||||
leftJustified = settings->value("interface/leftjustified", false).toBool();
|
||||
|
||||
|
|
@ -265,6 +266,11 @@ void SettingsCache::setShowMentionPopups(const int _showMentionPopus) {
|
|||
settings->setValue("chat/showmentionpopups", showMentionPopups);
|
||||
}
|
||||
|
||||
void SettingsCache::setRoomHistory(const int _roomHistory) {
|
||||
roomHistory = _roomHistory;
|
||||
settings->setValue("chat/roomhistory", roomHistory);
|
||||
}
|
||||
|
||||
void SettingsCache::setLang(const QString &_lang)
|
||||
{
|
||||
lang = _lang;
|
||||
|
|
|
|||
|
|
@ -95,6 +95,7 @@ private:
|
|||
bool scaleCards;
|
||||
bool showMessagePopups;
|
||||
bool showMentionPopups;
|
||||
bool roomHistory;
|
||||
bool leftJustified;
|
||||
int masterVolume;
|
||||
int cardInfoViewMode;
|
||||
|
|
@ -166,6 +167,7 @@ public:
|
|||
bool getScaleCards() const { return scaleCards; }
|
||||
bool getShowMessagePopup() const { return showMessagePopups; }
|
||||
bool getShowMentionPopup() const { return showMentionPopups; }
|
||||
bool getRoomHistory() const { return roomHistory; }
|
||||
bool getLeftJustified() const { return leftJustified; }
|
||||
int getMasterVolume() const { return masterVolume; }
|
||||
int getCardInfoViewMode() const { return cardInfoViewMode; }
|
||||
|
|
@ -236,6 +238,7 @@ public slots:
|
|||
void setCardScaling(const int _scaleCards);
|
||||
void setShowMessagePopups(const int _showMessagePopups);
|
||||
void setShowMentionPopups(const int _showMentionPopups);
|
||||
void setRoomHistory(const int _roomHistory);
|
||||
void setLeftJustified( const int _leftJustified);
|
||||
void setMasterVolume(const int _masterVolume);
|
||||
void setCardInfoViewMode(const int _viewMode);
|
||||
|
|
|
|||
|
|
@ -111,7 +111,7 @@ void TabMessage::actLeave()
|
|||
void TabMessage::processUserMessageEvent(const Event_UserMessage &event)
|
||||
{
|
||||
const UserLevelFlags userLevel(event.sender_name() == otherUserInfo->name() ? otherUserInfo->user_level() : ownUserInfo->user_level());
|
||||
chatView->appendMessage(QString::fromStdString(event.message()), QString::fromStdString(event.sender_name()), userLevel, true);
|
||||
chatView->appendMessage(QString::fromStdString(event.message()), 0,QString::fromStdString(event.sender_name()), userLevel, true);
|
||||
if (tabSupervisor->currentIndex() != tabSupervisor->indexOf(this))
|
||||
soundEngine->playSound("private_message");
|
||||
if (settingsCache->getShowMessagePopup() && shouldShowSystemPopup(event))
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@
|
|||
#include <QSystemTrayIcon>
|
||||
#include <QCompleter>
|
||||
#include <QWidget>
|
||||
#include <QtCore/qdatetime.h>
|
||||
#include "tab_supervisor.h"
|
||||
#include "tab_room.h"
|
||||
#include "tab_userlists.h"
|
||||
|
|
@ -34,6 +35,7 @@
|
|||
#include "pending_command.h"
|
||||
#include "dlg_settings.h"
|
||||
|
||||
|
||||
TabRoom::TabRoom(TabSupervisor *_tabSupervisor, AbstractClient *_client, ServerInfo_User *_ownUser, const ServerInfo_Room &info)
|
||||
: Tab(_tabSupervisor), client(_client), roomId(info.room_id()), roomName(QString::fromStdString(info.name())), ownUser(_ownUser)
|
||||
{
|
||||
|
|
@ -265,8 +267,11 @@ void TabRoom::processLeaveRoomEvent(const Event_LeaveRoom &event)
|
|||
void TabRoom::processRoomSayEvent(const Event_RoomSay &event)
|
||||
{
|
||||
QString senderName = QString::fromStdString(event.name());
|
||||
QString message = QString::fromStdString(event.message());
|
||||
|
||||
if (tabSupervisor->getUserListsTab()->getIgnoreList()->getUsers().contains(senderName))
|
||||
return;
|
||||
|
||||
UserListTWI *twi = userList->getUsers().value(senderName);
|
||||
UserLevelFlags userLevel;
|
||||
if (twi) {
|
||||
|
|
@ -274,7 +279,15 @@ void TabRoom::processRoomSayEvent(const Event_RoomSay &event)
|
|||
if (settingsCache->getIgnoreUnregisteredUsers() && !userLevel.testFlag(ServerInfo_User::IsRegistered))
|
||||
return;
|
||||
}
|
||||
chatView->appendMessage(QString::fromStdString(event.message()), senderName, userLevel, true);
|
||||
|
||||
if (event.message_type() == Event_RoomSay::ChatHistory && !settingsCache->getRoomHistory())
|
||||
return;
|
||||
|
||||
if (event.message_type() == Event_RoomSay::ChatHistory)
|
||||
message = "[" + QString(QDateTime::fromMSecsSinceEpoch(event.time_of()).toLocalTime().toString("d MMM yyyy HH:mm:ss")) + "] " + message;
|
||||
|
||||
|
||||
chatView->appendMessage(message, event.message_type(), senderName, userLevel, true);
|
||||
emit userEvent(false);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue