]> git.zarvox.org Git - imoo.git/commitdiff
ribbon: plumbing for sending IMs
authorDrew Fisher <drew.m.fisher@gmail.com>
Sat, 26 Apr 2014 08:43:20 +0000 (01:43 -0700)
committerDrew Fisher <drew.m.fisher@gmail.com>
Sat, 26 Apr 2014 08:43:20 +0000 (01:43 -0700)
I think I might have to create a conv_im object or something before I can
actually send messages.

ribbon/ribbon.pro
ribbon/ribbonconversations.cpp
ribbon/ribbonconversations.h
ribbon/ribbonmanager.cpp
ribbon/ribbonserver.cpp
ribbon/ribbonutil.cpp [new file with mode: 0644]
ribbon/ribbonutil.h [new file with mode: 0644]

index 8310a56df99f5212986394fc9f514a9f00996911..20a87cb485bc0befe256b02832bc8f10ba18b6f9 100644 (file)
@@ -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
index c081e3ae05afdab24fc1d2311948dda59900c849..7017c46f95d1c8ec8d6779afcafbe3818eb80513 100644 (file)
@@ -1,5 +1,6 @@
 #include "ribbonconversations.h"
 #include "ribbonmanager.h"
+#include "ribbonutil.h"
 
 #include <QDebug>
 #include <QDateTime>
@@ -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;
+               }
+       }
+}
index 4b724484d0addec9042828248f686995e45cf817..c31c026f591fc85d01d698d2c77880ec7268606d 100644 (file)
@@ -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 */
index ffdd018d081030089bfe0f1dea7fdc81cef5363d..467bbfa9b7131475ae14cec35c79b9065af107b3 100644 (file)
@@ -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);
        }
 }
index e3bbc8a2213db4d72f153116a9e8b7a2846f23d7..ba8889e34b50f40cba1054e35df260fb1bdfd864 100644 (file)
@@ -1,5 +1,6 @@
 #include "ribbonserver.h"
 #include "ribbonsocket.h"
+#include "ribbonutil.h"
 
 #include <QtNetwork/QTcpServer>
 #include <QtNetwork/QTcpSocket>
@@ -7,17 +8,6 @@
 #include <QJsonObject>
 #include <QDebug>
 
-// 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 (file)
index 0000000..27ebebb
--- /dev/null
@@ -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 (file)
index 0000000..6b78507
--- /dev/null
@@ -0,0 +1,12 @@
+#ifndef RIBBONUTIL_H
+#define RIBBONUTIL_H
+
+#include <QString>
+#include <QVariantMap>
+
+// Helper functions for validating parameters
+bool hasStringMember(QVariantMap m, QString memberName);
+bool hasMapMember(QVariantMap m, QString memberName);
+
+
+#endif // RIBBONUTIL_H