void SessionChildItem::receiveMessage(IrcMessage* message) { AbstractSessionItem::receiveMessage(message); if (message->type() == IrcMessage::Private) { IrcPrivateMessage* privMsg = static_cast<IrcPrivateMessage*>(message); QString alertText; if (isChannel()) { if (privMsg->message().contains(m_parent->session()->nickName(), Qt::CaseInsensitive)) { setHighlighted(true); if (!isCurrent()) alertText = tr("%1 on %2:\n%3").arg(privMsg->sender().name()).arg(title()).arg(privMsg->message()); } } else { setHighlighted(true); if (!isCurrent()) alertText = tr("%1 in private:\n%2").arg(privMsg->sender().name()).arg(privMsg->message()); } if (!alertText.isEmpty()) { setAlertText(alertText); emit alert(this); } if (!isCurrent()) setUnreadCount(unreadCount() + 1); } else if (message->type() == IrcMessage::Numeric) { IrcNumericMessage* numMsg = static_cast<IrcNumericMessage*>(message); if (isChannel() && numMsg->code() == Irc::RPL_TOPIC) setSubtitle(numMsg->parameters().value(2)); else if (!isChannel() && numMsg->code() == Irc::RPL_WHOISUSER) setSubtitle(numMsg->parameters().value(5)); } }
void RowPainter::paint(Painter &p, const Row *row, int fullWidth, bool active, bool selected, bool onlyBackground, TimeMs ms) { auto history = row->history(); auto item = history->lastMsg; auto cloudDraft = history->cloudDraft(); if (Data::draftIsNull(cloudDraft)) { cloudDraft = nullptr; } auto displayDate = [item, cloudDraft]() { if (item) { if (cloudDraft) { return (item->date > cloudDraft->date) ? item->date : cloudDraft->date; } return item->date; } return cloudDraft ? cloudDraft->date : QDateTime(); }; int unreadCount = history->unreadCount(); if (history->peer->migrateFrom()) { if (auto migrated = App::historyLoaded(history->peer->migrateFrom()->id)) { unreadCount += migrated->unreadCount(); } } if (item && cloudDraft && unreadCount > 0) { cloudDraft = nullptr; // Draw item, if draft is older. } paintRow(p, row, history, item, cloudDraft, displayDate(), fullWidth, active, selected, onlyBackground, ms, [&p, fullWidth, active, selected, ms, history, unreadCount](int nameleft, int namewidth, HistoryItem *item) { int availableWidth = namewidth; int texttop = st::dialogsPadding.y() + st::msgNameFont->height + st::dialogsSkip; if (unreadCount) { auto counter = QString::number(unreadCount); auto mutedCounter = history->mute(); auto unreadRight = fullWidth - st::dialogsPadding.x(); auto unreadTop = texttop + st::dialogsTextFont->ascent - st::dialogsUnreadFont->ascent - (st::dialogsUnreadHeight - st::dialogsUnreadFont->height) / 2; auto unreadWidth = 0; UnreadBadgeStyle st; st.active = active; st.muted = history->mute(); paintUnreadCount(p, counter, unreadRight, unreadTop, st, &unreadWidth); availableWidth -= unreadWidth + st.padding; } else if (history->isPinnedDialog()) { auto &icon = (active ? st::dialogsPinnedIconActive : (selected ? st::dialogsPinnedIconOver : st::dialogsPinnedIcon)); icon.paint(p, fullWidth - st::dialogsPadding.x() - icon.width(), texttop, fullWidth); availableWidth -= icon.width() + st::dialogsUnreadPadding; } auto &color = active ? st::dialogsTextFgServiceActive : (selected ? st::dialogsTextFgServiceOver : st::dialogsTextFgService); if (!history->paintSendAction(p, nameleft, texttop, availableWidth, fullWidth, color, ms)) { item->drawInDialog(p, QRect(nameleft, texttop, availableWidth, st::dialogsTextFont->height), active, selected, history->textCachedFor, history->lastItemTextCache); } }, [&p, fullWidth, active, selected, ms, history, unreadCount] { if (unreadCount) { auto counter = QString::number(unreadCount); if (counter.size() > 4) { counter = qsl("..") + counter.mid(counter.size() - 3); } auto mutedCounter = history->mute(); auto unreadRight = st::dialogsPadding.x() + st::dialogsPhotoSize; auto unreadTop = st::dialogsPadding.y() + st::dialogsPhotoSize - st::dialogsUnreadHeight; auto unreadWidth = 0; UnreadBadgeStyle st; st.active = active; st.muted = history->mute(); paintUnreadCount(p, counter, unreadRight, unreadTop, st, &unreadWidth); } }); }
void SessionChildItem::receiveMessage(IrcMessage* message) { if (m_usermodel) m_usermodel->processMessage(message); if (message->type() == IrcMessage::Numeric) { IrcNumericMessage* numeric = static_cast<IrcNumericMessage*>(message); switch (numeric->code()) { case Irc::RPL_NAMREPLY: if (m_sent.contains(IrcCommand::Names)) return; break; case Irc::RPL_ENDOFNAMES: if (m_sent.contains(IrcCommand::Names)) { emit namesReceived(m_usermodel->users()); m_sent.remove(IrcCommand::Names); return; } break; case Irc::RPL_TOPIC: if (isChannel()) { setSubtitle(message->parameters().value(2)); setDescription(IrcUtil::messageToHtml(subtitle())); } break; case Irc::RPL_WHOISUSER: if (!isChannel()) { setSubtitle(message->parameters().value(5)); setDescription(IrcUtil::messageToHtml(subtitle())); } if (m_sent.contains(IrcCommand::Whois)) { m_whois.append(tr("Ident: %1").arg(message->parameters().value(2))); m_whois.append(tr("Host: %1").arg(message->parameters().value(3))); m_whois.append(tr("Name: %1").arg(message->parameters().value(5))); return; } break; case Irc::RPL_WHOISSERVER: if (m_sent.contains(IrcCommand::Whois)) { m_whois.append(tr("Server: %1 (%2)").arg(message->parameters().value(2), message->parameters().value(3))); return; } break; case Irc::RPL_WHOISOPERATOR: if (m_sent.contains(IrcCommand::Whois)) { m_whois.append(tr("IRC operator")); return; } break; case Irc::RPL_WHOISACCOUNT: if (m_sent.contains(IrcCommand::Whois)) { m_whois.append(tr("Logged in as: %1").arg(message->parameters().value(2))); return; } break; case Irc::RPL_WHOISREGNICK: if (m_sent.contains(IrcCommand::Whois)) { m_whois.append(tr("Registered nick")); return; } break; case Irc::RPL_WHOISSECURE: if (m_sent.contains(IrcCommand::Whois)) { m_whois.append(tr("Secure connection")); return; } break; case Irc::RPL_WHOISIDLE: if (m_sent.contains(IrcCommand::Whois)) { QDateTime signon = QDateTime::fromTime_t(message->parameters().value(3).toInt()); QTime idle = QTime().addSecs(message->parameters().value(2).toInt()); m_whois.append(tr("Connected: %1").arg(signon.toString())); m_whois.append(tr("Idle: %1").arg(idle.toString())); return; } break; case Irc::RPL_WHOISCHANNELS: if (m_sent.contains(IrcCommand::Whois)) { m_whois.append(tr("Channels: %1").arg(message->parameters().value(2))); return; } break; case Irc::RPL_WHOISHOST: case Irc::RPL_WHOISMODES: if (m_sent.contains(IrcCommand::Whois)) { return; } break; case Irc::RPL_ENDOFWHOIS: if (m_sent.contains(IrcCommand::Whois)) { emit whoisReceived(m_whois); m_sent.remove(IrcCommand::Whois); m_whois.clear(); } case Irc::RPL_WHOISHELPOP: case Irc::RPL_WHOISSPECIAL: return; default: break; } } if (message->type() == IrcMessage::Private) { IrcPrivateMessage* privMsg = static_cast<IrcPrivateMessage*>(message); QString alertText; if (isChannel()) { if (privMsg->message().contains(m_parent->session()->nickName(), Qt::CaseInsensitive)) { setHighlighted(true); if (!isCurrent()) alertText = tr("%1 on %2:\n%3").arg(privMsg->sender().name()).arg(title()).arg(privMsg->message()); } } else { setHighlighted(true); if (!isCurrent()) alertText = tr("%1 in private:\n%2").arg(privMsg->sender().name()).arg(privMsg->message()); } if (!alertText.isEmpty()) emit alerted(alertText); if (!isCurrent()) setUnreadCount(unreadCount() + 1); } const QString formatted = messageFormatter()->formatMessage(message, m_usermodel); if (!formatted.isEmpty()) appendMessage(formatted); }