From: Drew Fisher Date: Sat, 26 Apr 2014 08:43:20 +0000 (-0700) Subject: ribbon: plumbing for sending IMs X-Git-Url: http://git.zarvox.org/shortlog/static/%7Bwebsite%7D?a=commitdiff_plain;h=a268fec085559390210814807910804441ae7aab;p=imoo.git ribbon: plumbing for sending IMs I think I might have to create a conv_im object or something before I can actually send messages. --- diff --git a/ribbon/ribbon.pro b/ribbon/ribbon.pro index 8310a56..20a87cb 100644 --- a/ribbon/ribbon.pro +++ b/ribbon/ribbon.pro @@ -23,7 +23,8 @@ HEADERS += ribbonmanager.h \ ribbonconnections.h \ ribbonconversations.h \ ribbonserver.h \ - ribbonsocket.h + ribbonsocket.h \ + ribbonutil.h SOURCES += ribbonmanager.cpp \ ribbonaccount.cpp \ @@ -33,4 +34,5 @@ SOURCES += ribbonmanager.cpp \ ribbonconversations.cpp \ ribbonserver.cpp \ ribbonsocket.cpp \ + ribbonutil.cpp \ main.cpp diff --git a/ribbon/ribbonconversations.cpp b/ribbon/ribbonconversations.cpp index c081e3a..7017c46 100644 --- a/ribbon/ribbonconversations.cpp +++ b/ribbon/ribbonconversations.cpp @@ -1,5 +1,6 @@ #include "ribbonconversations.h" #include "ribbonmanager.h" +#include "ribbonutil.h" #include #include @@ -38,3 +39,26 @@ void RibbonConversations::received_im_msg(PurpleAccount *account, } qDebug() << QDateTime::currentDateTime().toString("hh:mm:ss") << sender << purple_conversation_get_name(conv) << message; } + +void RibbonConversations::send_im(QString protocol, QString account, QString buddy, QString message) +{ + qDebug() << "sending im from" << protocol << account << "to" << buddy << ":" << message; + PurpleAccount* p_acct = purple_accounts_find(account.toUtf8(), protocol.toUtf8()); + PurpleBuddy* p_buddy = purple_find_buddy(p_acct, buddy.toUtf8()); + // TODO: call the purple functions to send an IM + Q_UNUSED(p_buddy); +} + +void RibbonConversations::handleExternalEvent(QString method, QVariantMap context) +{ + if (method == "send_im") { + // TODO: check args, extract args from context, call send_im + if (hasStringMember(context, "proto") && hasStringMember(context, "account") + && hasStringMember(context, "buddy") && hasStringMember(context, "message")) { + send_im(context["protocol"].toString(), context["account"].toString(), + context["buddy"].toString(), context["message"].toString()); + } else { + qWarning() << "Invalid args to send_im:" << context; + } + } +} diff --git a/ribbon/ribbonconversations.h b/ribbon/ribbonconversations.h index 4b72448..c31c026 100644 --- a/ribbon/ribbonconversations.h +++ b/ribbon/ribbonconversations.h @@ -16,10 +16,12 @@ public: void init(); void received_im_msg(PurpleAccount *account, char *sender, char *message, PurpleConversation *conv, PurpleMessageFlags flags); + void handleExternalEvent(QString method, QVariantMap context); signals: void event(QString source, QString signal, QVariantMap context); private: RibbonManager* _manager; + void send_im(QString protocol, QString account, QString buddy, QString message); }; #endif /* RIBBONCONVERSATIONS_H */ diff --git a/ribbon/ribbonmanager.cpp b/ribbon/ribbonmanager.cpp index ffdd018..467bbfa 100644 --- a/ribbon/ribbonmanager.cpp +++ b/ribbon/ribbonmanager.cpp @@ -183,5 +183,7 @@ void RibbonManager::handleExternalEvent(QString destination, QString method, QVa qDebug() << "TODO: do something with" << destination << "." << method << "(" << context << ")"; if (destination == "accounts") { _accounts->handleExternalEvent(method, context); + } else if (destination == "conversations") { + _conversations->handleExternalEvent(method, context); } } diff --git a/ribbon/ribbonserver.cpp b/ribbon/ribbonserver.cpp index e3bbc8a..ba8889e 100644 --- a/ribbon/ribbonserver.cpp +++ b/ribbon/ribbonserver.cpp @@ -1,5 +1,6 @@ #include "ribbonserver.h" #include "ribbonsocket.h" +#include "ribbonutil.h" #include #include @@ -7,17 +8,6 @@ #include #include -// Helper functions for sanitizing external events -static bool hasStringMember(QVariantMap m, QString memberName) -{ - return m.contains(memberName) && m[memberName].type() == QVariant::String; -} - -static bool hasMapMember(QVariantMap m, QString memberName) -{ - return m.contains(memberName) && m[memberName].type() == QVariant::Map; -} - RibbonServer::RibbonServer(QObject* parent) : QObject(parent) { diff --git a/ribbon/ribbonutil.cpp b/ribbon/ribbonutil.cpp new file mode 100644 index 0000000..27ebebb --- /dev/null +++ b/ribbon/ribbonutil.cpp @@ -0,0 +1,12 @@ +#include "ribbonutil.h" + +bool hasStringMember(QVariantMap m, QString memberName) +{ + return m.contains(memberName) && m[memberName].type() == QVariant::String; +} + +bool hasMapMember(QVariantMap m, QString memberName) +{ + return m.contains(memberName) && m[memberName].type() == QVariant::Map; +} + diff --git a/ribbon/ribbonutil.h b/ribbon/ribbonutil.h new file mode 100644 index 0000000..6b78507 --- /dev/null +++ b/ribbon/ribbonutil.h @@ -0,0 +1,12 @@ +#ifndef RIBBONUTIL_H +#define RIBBONUTIL_H + +#include +#include + +// Helper functions for validating parameters +bool hasStringMember(QVariantMap m, QString memberName); +bool hasMapMember(QVariantMap m, QString memberName); + + +#endif // RIBBONUTIL_H