diff --git a/src/irc/nickinfo.h b/src/irc/nickinfo.h --- a/src/irc/nickinfo.h +++ b/src/irc/nickinfo.h @@ -112,6 +112,8 @@ bool isChanged() const { return m_changed; } void setChanged(bool c) { m_changed = c; } + bool isTelegramRelay() { return m_isTelegramRelay; } + private: /** After calling, emitNickInfoChanged is guaranteed to be called _within_ 1 second. * Used to consolidate changed signals. @@ -141,6 +143,7 @@ QString m_account; bool m_changed; + bool m_isTelegramRelay; }; /** A NickInfoPtr is a pointer to a NickInfo object. Since it is a QExplicitlySharedDataPointer, the NickInfo diff --git a/src/irc/nickinfo.cpp b/src/irc/nickinfo.cpp --- a/src/irc/nickinfo.cpp +++ b/src/irc/nickinfo.cpp @@ -134,6 +134,8 @@ if (newMask.isEmpty() || newMask == m_hostmask) return; m_hostmask = newMask; + m_isTelegramRelay = newMask == QLatin1String("telegram@kde/bot/telegram-relay"); + startNickInfoChangedTimer(); } diff --git a/src/viewer/ircview.h b/src/viewer/ircview.h --- a/src/viewer/ircview.h +++ b/src/viewer/ircview.h @@ -23,6 +23,7 @@ #include #include +#include class Server; class ChatWindow; @@ -174,7 +175,7 @@ //// Other stuff public Q_SLOTS: //! FIXME enum { Raw, Query, Query+Action, Channel+Action, Server Message, Command Message, Backlog message } this looks more like a tuple - void append(const QString& nick, const QString& message, const QHash &messageTags = QHash(), const QString& label = QString()); + void append(const QString& nick, QString message, const QHash &messageTags = QHash(), const QString& label = QString()); void appendRaw(const QString& message, bool self = false); void appendLog(const QString& message); @@ -290,10 +291,23 @@ /// Returns a formated timestamp if timestamps are enabled else it returns QString::null QString timeStamp(QHash messageTags); + public: + enum class NickLineOption + { + none = 0, + encapsulateNick = 1, + privMsg = 2, + noClickableNicks = 4, + noBold = 8, + useDefaultColor = 16 + }; + Q_DECLARE_FLAGS(NickLineOptions, NickLineOption); + + protected: /// Returns a formated nick string //! FIXME formatted in what way? QString createNickLine(const QString& nick, const QString& defaultColor, - bool encapsulateNick = true, bool privMsg = false); + NickLineOptions opts = NickLineOption::encapsulateNick); //// Search QTextDocument::FindFlags m_searchFlags; @@ -338,4 +352,7 @@ ChatWindow* m_chatWin; friend class IRCStyleSheet; }; + +Q_DECLARE_OPERATORS_FOR_FLAGS(IRCView::NickLineOptions) + #endif diff --git a/src/viewer/ircview.cpp b/src/viewer/ircview.cpp --- a/src/viewer/ircview.cpp +++ b/src/viewer/ircview.cpp @@ -538,12 +538,28 @@ // Data insertion -void IRCView::append(const QString& nick, const QString& message, const QHash &messageTags, const QString& label) +void IRCView::append(const QString& nick, QString message, const QHash &messageTags, const QString& label) { + emit textToLog(QString("<%1>\t%2").arg(nick, message)); + QString channelColor = Preferences::self()->color(Preferences::ChannelMessage).name(); m_tabNotification = Konversation::tnfNormal; + NickInfoPtr senderNickinfo = m_server->getNickInfo(nick); + bool nickIsProxy = senderNickinfo && senderNickinfo->isTelegramRelay(); + QString proxiedNickLine; + + if (nickIsProxy && message.startsWith(QChar('<', 0))) + { + auto pos = message.indexOf(QChar('>', 0)); + auto proxiedNick = message.mid(1, pos-1); + auto proxiedNickColor = Preferences::self()->nickColor(Konversation::colorForNick(proxiedNick)).name(); + proxiedNickLine = createNickLine(proxiedNick, proxiedNickColor, NickLineOption::noClickableNicks + | NickLineOption::useDefaultColor | NickLineOption::encapsulateNick).arg(proxiedNick); + message.remove(0, pos+2); + } + QString nickLine = createNickLine(nick, channelColor); QChar::Direction dir; @@ -556,16 +572,14 @@ if (!label.isEmpty()) { line += "[%4]"; } - line += "%1" + directionOfLine + nickLine + directionOfLine + " %3"; + line += "%1" + directionOfLine + nickLine + proxiedNickLine + directionOfLine + " %3"; line = line.arg(timeStamp(messageTags), nick, text); if (!label.isEmpty()) { line = line.arg(label); } - emit textToLog(QString("<%1>\t%2").arg(nick, message)); - /* BEGIN: WIPQTQUICK */ Application* konvApp = Application::instance(); MessageModel* msgModel = konvApp->getMessageModel(); @@ -616,7 +630,9 @@ m_tabNotification = Konversation::tnfPrivate; - QString nickLine = createNickLine(nick, queryColor, true, inChannel); + NickLineOptions opts{NickLineOption::encapsulateNick}; + opts.setFlag(NickLineOption::privMsg, inChannel); + QString nickLine = createNickLine(nick, queryColor, opts); QString line; QChar::Direction dir; @@ -667,7 +683,7 @@ QString line; - QString nickLine = createNickLine(nick, actionColor, false); + QString nickLine = createNickLine(nick, actionColor, NickLineOption::none); if (message.isEmpty()) { @@ -911,12 +927,12 @@ return QString(); } -QString IRCView::createNickLine(const QString& nick, const QString& defaultColor, bool encapsulateNick, bool privMsg) +QString IRCView::createNickLine(const QString& nick, const QString& defaultColor, NickLineOptions opts) { QString nickLine = LRM + "%2" + LRM; QString nickColor; - if (Preferences::self()->useColoredNicks()) + if (!opts.testFlag(NickLineOption::useDefaultColor) || Preferences::self()->useColoredNicks()) { if (m_server) { @@ -940,16 +956,16 @@ nickLine = QLatin1String("") + nickLine + QLatin1String(""); - if (Preferences::self()->useClickableNicks()) + if (!opts.testFlag(NickLineOption::noClickableNicks) && Preferences::self()->useClickableNicks()) nickLine = "" + nickLine + ""; - if (privMsg) + if (opts.testFlag(NickLineOption::privMsg)) nickLine.prepend(QLatin1String("-> ")); - if(encapsulateNick) + if (opts.testFlag(NickLineOption::encapsulateNick)) nickLine = QLatin1String("<") + nickLine + QLatin1String(">"); - if(Preferences::self()->useBoldNicks()) + if (!opts.testFlag(NickLineOption::noBold) && Preferences::self()->useBoldNicks()) nickLine = QLatin1String("") + nickLine + QLatin1String(""); return nickLine;