void Core::Process (QObject *msgObj) { IMessage *msg = qobject_cast<IMessage*> (msgObj); if (msg->GetMessageType () != IMessage::Type::ChatMessage && msg->GetMessageType () != IMessage::Type::MUCMessage) return; if (msg->GetBody ().isEmpty ()) return; if (msg->GetDirection () == IMessage::Direction::Out && msg->GetMessageType () == IMessage::Type::MUCMessage) return; const double secsDiff = msg->GetDateTime ().secsTo (QDateTime::currentDateTime ()); if (msg->GetMessageType () == IMessage::Type::MUCMessage && std::abs (secsDiff) >= 2) return; ICLEntry *entry = qobject_cast<ICLEntry*> (msg->ParentCLEntry ()); if (!entry) { qWarning () << Q_FUNC_INFO << "message's other part doesn't implement ICLEntry" << msg->GetQObject () << msg->OtherPart (); return; } if (DisabledIDs_.contains (entry->GetEntryID ())) return; const auto acc = entry->GetParentAccount (); QVariantMap data; data ["EntryID"] = entry->GetEntryID (); data ["AccountID"] = acc->GetAccountID (); data ["DateTime"] = msg->GetDateTime (); data ["Direction"] = msg->GetDirection () == IMessage::Direction::In ? "IN" : "OUT"; data ["Body"] = msg->GetBody (); data ["OtherVariant"] = msg->GetOtherVariant (); data ["Type"] = static_cast<int> (msg->GetMessageType ()); data ["EscapePolicy"] = msg->GetEscapePolicy () == IMessage::EscapePolicy::Escape ? "Esc" : "NEs"; if (const auto irtm = qobject_cast<IRichTextMessage*> (msgObj)) data ["RichBody"] = irtm->GetRichBody (); if (entry->GetEntryType () == ICLEntry::EntryType::PrivateChat) { const auto parent = entry->GetParentCLEntry (); data ["VisibleName"] = parent->GetEntryName () + "/" + entry->GetEntryName (); } else data ["VisibleName"] = entry->GetEntryName (); QMetaObject::invokeMethod (StorageThread_->GetStorage (), "addMessage", Qt::QueuedConnection, Q_ARG (QVariantMap, data)); }
void Core::Process (QObject *msgObj) { IMessage *msg = qobject_cast<IMessage*> (msgObj); if (msg->GetMessageType () != IMessage::MTChatMessage && msg->GetMessageType () != IMessage::MTMUCMessage) return; if (msg->GetBody ().isEmpty ()) return; if (msg->GetDirection () == IMessage::DOut && msg->GetMessageType () == IMessage::MTMUCMessage) return; ICLEntry *entry = qobject_cast<ICLEntry*> (msg->ParentCLEntry ()); if (!entry) { qWarning () << Q_FUNC_INFO << "message's other part doesn't implement ICLEntry" << msg->GetObject () << msg->OtherPart (); return; } if (DisabledIDs_.contains (entry->GetEntryID ())) return; IAccount *acc = qobject_cast<IAccount*> (entry->GetParentAccount ()); if (!acc) { qWarning () << Q_FUNC_INFO << "message's account doesn't implement IAccount" << entry->GetParentAccount (); return; } QVariantMap data; data ["EntryID"] = entry->GetEntryID (); data ["VisibleName"] = entry->GetEntryName (); data ["AccountID"] = acc->GetAccountID (); data ["DateTime"] = msg->GetDateTime (); data ["Direction"] = msg->GetDirection () == IMessage::DIn ? "IN" : "OUT"; data ["Body"] = msg->GetBody (); data ["OtherVariant"] = msg->GetOtherVariant (); data ["MessageType"] = static_cast<int> (msg->GetMessageType ()); QMetaObject::invokeMethod (StorageThread_->GetStorage (), "addMessage", Qt::QueuedConnection, Q_ARG (QVariantMap, data)); }
void Plugin::hookFormatBodyEnd (IHookProxy_ptr proxy, QObject *chatTab, QString body, QObject *msgObj) { IMessage *msg = qobject_cast<IMessage*> (msgObj); if (msg->GetDirection () != IMessage::DIn || msg->GetMessageType () != IMessage::MTChatMessage) return; ICLEntry *other = qobject_cast<ICLEntry*> (msg->OtherPart ()); if (!other->GetEntryID ().contains ("*****@*****.**")) return; proxy->SetValue ("body", FormatBody (body)); }
void Plugin::hookFormatBodyEnd (IHookProxy_ptr proxy, QObject*, QString body, QObject *msgObj) { IMessage *msg = qobject_cast<IMessage*> (msgObj); if (msg->GetDirection () != IMessage::DIn || msg->GetMessageType () != IMessage::MTChatMessage) return; ICLEntry *other = qobject_cast<ICLEntry*> (msg->OtherPart ()); if (!other) { qWarning () << Q_FUNC_INFO << "NULL other part for message" << msgObj << msg->GetBody (); return; } if (!other->GetEntryID ().contains ("*****@*****.**")) return; proxy->SetValue ("body", FormatBody (body)); }
bool Plugin::ShouldHandle (QObject* msgObj, IMessage::Direction direction, IMessage::Type type) { IMessage *msg = qobject_cast<IMessage*> (msgObj); if (!msg) { qWarning () << Q_FUNC_INFO << "unable to cast" << msgObj << "to IMessage"; return false; } if (msg->GetDirection () != direction || msg->GetMessageType () != type) { return false; } ICLEntry *other = qobject_cast<ICLEntry*> (msg->OtherPart ()); if (!other) { qWarning () << Q_FUNC_INFO << "unable to cast" << msg->OtherPart () << "to ICLEntry"; return false; } if (!other->GetEntryID ().contains ("*****@*****.**")) return false; return true; }