diff --git a/src/chatview_webkit.cpp b/src/chatview_webkit.cpp index 220307ea..078cefea 100644 --- a/src/chatview_webkit.cpp +++ b/src/chatview_webkit.cpp @@ -139,6 +139,36 @@ class ChatViewPrivate { ret.append(QStringView { msg }.mid(post)); return ret; } + + void sendJsObject(const QVariantMap &map) + { + jsBuffer_.append(map); + checkJsBuffer(); + } + + void checkJsBuffer(); + + void sendReactionsToUI(const QString &nick, const QString &messageId, const QSet &reactions) + { + QVariantMap m; + // m["type"] = "message"; + m["type"] = QLatin1String("reactions"); + m["sender"] = nick; + m["messageid"] = messageId; + auto rl = q->updateReactions(nick, messageId, reactions); + auto vl = QVariantList(); + for (auto &r : std::as_const(rl)) { + auto vmr = QVariantMap(); + if (!r.base.isEmpty()) { + vmr[QLatin1String("base")] = r.base; + } + vmr[QLatin1String("text")] = r.code; + vmr[QLatin1String("nicks")] = r.nicks; + vl << vmr; + } + m[QLatin1String("reactions")] = vl; + sendJsObject(m); + } }; //---------------------------------------------------------------------------- @@ -483,12 +513,12 @@ ChatView::ChatView(QWidget *parent) : QFrame(parent), d(new ChatViewPrivate(this QVariantMap m; m["type"] = "receivehooks"; m["hooks"] = PluginManager::instance()->messageViewJSFilters(); - sendJsObject(m); + d->sendJsObject(m); connect(PluginManager::instance(), &PluginManager::jsFiltersUpdated, this, [this]() { QVariantMap m; m["type"] = "receivehooks"; m["hooks"] = PluginManager::instance()->messageViewJSFilters(); - sendJsObject(m); + d->sendJsObject(m); }); #endif } @@ -538,7 +568,7 @@ void ChatView::markReceived(QString id) m["type"] = "receipt"; m["id"] = id; m["encrypted"] = d->isEncryptionEnabled_; - sendJsObject(m); + d->sendJsObject(m); } QSize ChatView::sizeHint() const { return minimumSizeHint(); } @@ -594,7 +624,7 @@ void ChatView::changeEvent(QEvent *event) || event->type() == QEvent::FontChange) { QVariantMap m; m["type"] = "settings"; - sendJsObject(m); + d->sendJsObject(m); } QFrame::changeEvent(event); } @@ -610,26 +640,11 @@ void ChatView::psiOptionChanged(const QString &option) } } -void ChatView::sendJsObject(const QVariantMap &map) -{ - d->jsBuffer_.append(map); - checkJsBuffer(); -} - -void ChatView::checkJsBuffer() -{ - if (d->sessionReady_) { - while (!d->jsBuffer_.isEmpty()) { - emit d->jsObject->newMessage(d->jsBuffer_.takeFirst()); - } - } -} - void ChatView::sessionInited() { qDebug("Session is initialized"); d->sessionReady_ = true; - checkJsBuffer(); + d->checkJsBuffer(); } bool ChatView::handleCopyEvent(QObject *object, QEvent *event, ChatEdit *chatEdit) @@ -664,8 +679,6 @@ void ChatView::dispatchMessage(const MessageView &mv) types.insert(MessageView::Reactions, "reactions"); } QVariantMap m; - m["time"] = mv.dateTime(); - m["type"] = types.value(mv.type()); switch (mv.type()) { case MessageView::Message: m["message"] = d->prepareShares(ChatViewPrivate::closeIconTags(mv.formattedText())); @@ -724,30 +737,18 @@ void ChatView::dispatchMessage(const MessageView &mv) m["urls"] = vmUrls; break; } - case MessageView::Reactions: - m["sender"] = mv.nick(); - m["messageid"] = mv.reactionsId(); - { - auto n = d->isMuc_ ? mv.nick() : QString::fromLatin1(mv.isLocal() ? "l" : "r"); - auto rl = updateReactions(n, mv.reactionsId(), mv.reactions()); - auto vl = QVariantList(); - for (auto &r : std::as_const(rl)) { - auto vmr = QVariantMap(); - if (!r.base.isEmpty()) { - vmr[QLatin1String("base")] = r.base; - } - vmr[QLatin1String("text")] = r.code; - vmr[QLatin1String("nicks")] = r.nicks; - vl << vmr; - } - m[QLatin1String("reactions")] = vl; - } - break; + case MessageView::Reactions: { + auto n = d->isMuc_ ? mv.nick() : QString::fromLatin1(mv.isLocal() ? "l" : "r"); + d->sendReactionsToUI(n, mv.reactionsId(), mv.reactions()); + return; + } case MessageView::FileTransferRequest: case MessageView::FileTransferFinished: break; } + m["time"] = mv.dateTime(); + m["type"] = types.value(mv.type()); QString replaceId = mv.replaceId(); if (replaceId.isEmpty() && (mv.type() == MessageView::Message || mv.type() == MessageView::Subject) && updateLastMsgTime(mv.dateTime())) { @@ -755,7 +756,7 @@ void ChatView::dispatchMessage(const MessageView &mv) m["date"] = mv.dateTime(); m["type"] = "message"; m["mtype"] = "lastDate"; - sendJsObject(m); + d->sendJsObject(m); } m["encrypted"] = d->isEncryptionEnabled_; @@ -766,7 +767,7 @@ void ChatView::dispatchMessage(const MessageView &mv) m["mtype"] = m["type"]; m["type"] = "message"; } - sendJsObject(m); + d->sendJsObject(m); } void ChatView::sendJsCode(const QString &js) @@ -774,7 +775,7 @@ void ChatView::sendJsCode(const QString &js) QVariantMap m; m["type"] = "js"; m["js"] = js; - sendJsObject(m); + d->sendJsObject(m); } void ChatView::scrollUp() { emit d->jsObject->scrollRequested(-50); } @@ -813,7 +814,7 @@ void ChatView::updateAvatar(const Jid &jid, UserType utype) m["type"] = "avatar"; m["sender"] = jid.resource(); m["avatar"] = ChatViewJSObject::avatarUrl(d->account_->avatarFactory()->userHashes(jid).avatar); - sendJsObject(m); + d->sendJsObject(m); } } @@ -821,14 +822,14 @@ void ChatView::clear() { QVariantMap m; m["type"] = "clear"; - sendJsObject(m); + d->sendJsObject(m); } void ChatView::doTrackBar() { QVariantMap m; m["type"] = "trackbar"; - sendJsObject(m); + d->sendJsObject(m); } WebView *ChatView::textWidget() { return d->webView; } @@ -842,6 +843,19 @@ void ChatView::outgoingReaction(const QString &messageId, const QString &reactio auto n = d->isMuc_ ? d->localNickName : QString::fromLatin1("l"); auto reactions = onReactionSwitched(n, messageId, reaction); emit outgoingReactions(messageId, reactions); + if (!d->isMuc_) { + // with private message we are not going to get it back. so back immediately + d->sendReactionsToUI(n, messageId, reactions); + } +} + +void ChatViewPrivate::checkJsBuffer() +{ + if (sessionReady_) { + while (!jsBuffer_.isEmpty()) { + emit jsObject->newMessage(jsBuffer_.takeFirst()); + } + } } #include "chatview_webkit.moc" diff --git a/src/chatview_webkit.h b/src/chatview_webkit.h index 10ead64a..13599a15 100644 --- a/src/chatview_webkit.h +++ b/src/chatview_webkit.h @@ -58,7 +58,6 @@ class ChatView : public QFrame, public ChatViewCommon { void contextMenuEvent(QContextMenuEvent *event); bool handleCopyEvent(QObject *object, QEvent *event, ChatEdit *chatEdit); - void sendJsObject(const QVariantMap &); void dispatchMessage(const MessageView &m); void sendJsCode(const QString &js); @@ -92,7 +91,6 @@ public slots: void init(); private slots: - void checkJsBuffer(); void sessionInited(); signals: diff --git a/src/chatviewcommon.h b/src/chatviewcommon.h index 33cb41e3..5a146318 100644 --- a/src/chatviewcommon.h +++ b/src/chatviewcommon.h @@ -30,6 +30,8 @@ class QWidget; class ChatViewCommon { public: enum UserType { LocalParty, RemoteParty, Participant }; + enum class Feature { Reactions = 0x1 }; + Q_DECLARE_FLAGS(Features, Feature) ChatViewCommon() : _nickNumber(0) { } void setLooks(QWidget *); @@ -62,12 +64,16 @@ class ChatViewCommon { // to be called from UI stuff. return list of reactions to send over network QSet onReactionSwitched(const QString &senderNickname, const QString &messageId, const QString &reaction); + Features features(); + protected: QDateTime _lastMsgTime; + Features _featuers; private: - QList &generatePalette(); - bool compatibleColors(const QColor &, const QColor &); + QList &generatePalette(); + bool compatibleColors(const QColor &, const QColor &); + int _nickNumber; QMap _nicks; QHash _reactions; // messageId -> reactions diff --git a/themes/chatview/psi/bubble/index.html b/themes/chatview/psi/bubble/index.html index 9c47b9a7..db4c0e2c 100644 --- a/themes/chatview/psi/bubble/index.html +++ b/themes/chatview/psi/bubble/index.html @@ -46,7 +46,7 @@ }, dateFormat : "HH:mm", proxy : function() { //optional - if (shared.cdata.mtype == "reactions") { + if (shared.cdata.type == "reactions") { renderReactions(shared.cdata); return false; } diff --git a/version b/version index a27e85db..601b01d0 100644 --- a/version +++ b/version @@ -1 +1 @@ -1.5.2013 (2024-06-30, c0cd337c) +1.5.2014 (2024-07-01, 3d64d672)