1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

fix(ui): groupcolors fix2

This commit is contained in:
Monsterovich 2018-10-22 18:23:41 +02:00
parent ab89ca2d8e
commit a4a8e361d0
5 changed files with 16 additions and 15 deletions

View File

@ -44,7 +44,7 @@ ChatMessage::ChatMessage()
} }
ChatMessage::Ptr ChatMessage::createChatMessage(const QString& sender, const QString& rawMessage, ChatMessage::Ptr ChatMessage::createChatMessage(const QString& sender, const QString& rawMessage,
MessageType type, bool isMe, const QDateTime& date) MessageType type, bool isMe, const QDateTime& date, bool colorizeName)
{ {
ChatMessage::Ptr msg = ChatMessage::Ptr(new ChatMessage); ChatMessage::Ptr msg = ChatMessage::Ptr(new ChatMessage);
@ -91,7 +91,7 @@ ChatMessage::Ptr ChatMessage::createChatMessage(const QString& sender, const QSt
QColor color = QColor(0, 0, 0); QColor color = QColor(0, 0, 0);
if (Settings::getInstance().getEnableGroupChatsColor()) if (colorizeName && Settings::getInstance().getEnableGroupChatsColor())
{ {
QByteArray hash = QCryptographicHash::hash((sender.toUtf8()), QCryptographicHash::Md5); QByteArray hash = QCryptographicHash::hash((sender.toUtf8()), QCryptographicHash::Md5);
quint8 *data = (quint8*)hash.data(); quint8 *data = (quint8*)hash.data();

View File

@ -49,7 +49,7 @@ public:
static ChatMessage::Ptr createChatMessage(const QString& sender, const QString& rawMessage, static ChatMessage::Ptr createChatMessage(const QString& sender, const QString& rawMessage,
MessageType type, bool isMe, MessageType type, bool isMe,
const QDateTime& date = QDateTime()); const QDateTime& date = QDateTime(), bool colorizeName = false);
static ChatMessage::Ptr createChatInfoMessage(const QString& rawMessage, SystemMessageType type, static ChatMessage::Ptr createChatInfoMessage(const QString& rawMessage, SystemMessageType type,
const QDateTime& date); const QDateTime& date);
static ChatMessage::Ptr createFileTransferMessage(const QString& sender, ToxFile file, static ChatMessage::Ptr createFileTransferMessage(const QString& sender, ToxFile file,

View File

@ -372,7 +372,7 @@ bool GenericChatForm::needsToHideName(const ToxPk& messageAuthor, const QDateTim
* @return ChatMessage object * @return ChatMessage object
*/ */
ChatMessage::Ptr GenericChatForm::createMessage(const ToxPk& author, const QString& message, ChatMessage::Ptr GenericChatForm::createMessage(const ToxPk& author, const QString& message,
const QDateTime& dt, bool isAction, bool isSent) const QDateTime& dt, bool isAction, bool isSent, bool colorizeName)
{ {
const Core* core = Core::getInstance(); const Core* core = Core::getInstance();
bool isSelf = author == core->getSelfId().getPublicKey(); bool isSelf = author == core->getSelfId().getPublicKey();
@ -383,10 +383,10 @@ ChatMessage::Ptr GenericChatForm::createMessage(const ToxPk& author, const QStri
ChatMessage::Ptr msg; ChatMessage::Ptr msg;
if (isAction) { if (isAction) {
msg = ChatMessage::createChatMessage(authorStr, message, ChatMessage::ACTION, isSelf); msg = ChatMessage::createChatMessage(authorStr, message, ChatMessage::ACTION, isSelf, QDateTime(), colorizeName);
previousId = ToxPk{}; previousId = ToxPk{};
} else { } else {
msg = ChatMessage::createChatMessage(authorStr, message, ChatMessage::NORMAL, isSelf); msg = ChatMessage::createChatMessage(authorStr, message, ChatMessage::NORMAL, isSelf, QDateTime(), colorizeName);
const QDateTime newMsgDateTime = QDateTime::currentDateTime(); const QDateTime newMsgDateTime = QDateTime::currentDateTime();
if (needsToHideName(author, newMsgDateTime)) { if (needsToHideName(author, newMsgDateTime)) {
msg->hideSender(); msg->hideSender();
@ -418,9 +418,9 @@ ChatMessage::Ptr GenericChatForm::createSelfMessage(const QString& message, cons
* @brief Inserts message into ChatLog * @brief Inserts message into ChatLog
*/ */
void GenericChatForm::addMessage(const ToxPk& author, const QString& message, const QDateTime& dt, void GenericChatForm::addMessage(const ToxPk& author, const QString& message, const QDateTime& dt,
bool isAction) bool isAction, bool colorizeName)
{ {
createMessage(author, message, dt, isAction, true); createMessage(author, message, dt, isAction, true, colorizeName);
} }
/** /**
@ -431,11 +431,11 @@ void GenericChatForm::addSelfMessage(const QString& message, const QDateTime& da
createSelfMessage(message, datetime, isAction, true); createSelfMessage(message, datetime, isAction, true);
} }
void GenericChatForm::addAlertMessage(const ToxPk& author, const QString& msg, const QDateTime& dt) void GenericChatForm::addAlertMessage(const ToxPk& author, const QString& msg, const QDateTime& dt, bool colorizeName)
{ {
QString authorStr = resolveToxPk(author); QString authorStr = resolveToxPk(author);
bool isSelf = author == Core::getInstance()->getSelfId().getPublicKey(); bool isSelf = author == Core::getInstance()->getSelfId().getPublicKey();
auto chatMsg = ChatMessage::createChatMessage(authorStr, msg, ChatMessage::ALERT, isSelf, dt); auto chatMsg = ChatMessage::createChatMessage(authorStr, msg, ChatMessage::ALERT, isSelf, dt, colorizeName);
const QDateTime newMsgDateTime = QDateTime::currentDateTime(); const QDateTime newMsgDateTime = QDateTime::currentDateTime();
if (needsToHideName(author, newMsgDateTime)) { if (needsToHideName(author, newMsgDateTime)) {
chatMsg->hideSender(); chatMsg->hideSender();

View File

@ -75,11 +75,11 @@ public:
virtual void show(ContentLayout* contentLayout); virtual void show(ContentLayout* contentLayout);
void addMessage(const ToxPk& author, const QString& message, const QDateTime& datetime, void addMessage(const ToxPk& author, const QString& message, const QDateTime& datetime,
bool isAction); bool isAction, bool colorizeName = false);
void addSelfMessage(const QString& message, const QDateTime& datetime, bool isAction); void addSelfMessage(const QString& message, const QDateTime& datetime, bool isAction);
void addSystemInfoMessage(const QString& message, ChatMessage::SystemMessageType type, void addSystemInfoMessage(const QString& message, ChatMessage::SystemMessageType type,
const QDateTime& datetime); const QDateTime& datetime);
void addAlertMessage(const ToxPk& author, const QString& message, const QDateTime& datetime); void addAlertMessage(const ToxPk& author, const QString& message, const QDateTime& datetime, bool colorizeName = false);
static QString resolveToxPk(const ToxPk& pk); static QString resolveToxPk(const ToxPk& pk);
QDate getLatestDate() const; QDate getLatestDate() const;
QDate getFirstDate() const; QDate getFirstDate() const;
@ -127,7 +127,7 @@ private:
protected: protected:
ChatMessage::Ptr createMessage(const ToxPk& author, const QString& message, ChatMessage::Ptr createMessage(const ToxPk& author, const QString& message,
const QDateTime& datetime, bool isAction, bool isSent); const QDateTime& datetime, bool isAction, bool isSent, bool colorizeName = false);
ChatMessage::Ptr createSelfMessage(const QString& message, const QDateTime& datetime, ChatMessage::Ptr createSelfMessage(const QString& message, const QDateTime& datetime,
bool isAction, bool isSent); bool isAction, bool isSent);
bool needsToHideName(const ToxPk& messageAuthor, const QDateTime& messageTime) const; bool needsToHideName(const ToxPk& messageAuthor, const QDateTime& messageTime) const;

View File

@ -1750,10 +1750,11 @@ void Widget::onGroupMessageReceived(int groupnumber, int peernumber, const QStri
const auto groupId = g->getId(); const auto groupId = g->getId();
const auto date = QDateTime::currentDateTime(); const auto date = QDateTime::currentDateTime();
auto form = groupChatForms[groupId]; auto form = groupChatForms[groupId];
if (targeted && !isAction) { if (targeted && !isAction) {
form->addAlertMessage(author, message, date); form->addAlertMessage(author, message, date, true);
} else { } else {
form->addMessage(author, message, date, isAction); form->addMessage(author, message, date, isAction, true);
} }
newGroupMessageAlert(groupId, targeted || Settings::getInstance().getGroupAlwaysNotify()); newGroupMessageAlert(groupId, targeted || Settings::getInstance().getGroupAlwaysNotify());