From: Drew Fisher Date: Sun, 18 May 2014 02:04:42 +0000 (-0700) Subject: ribbon: emit signal when IMs are sent successfully X-Git-Url: https://git.zarvox.org/shortlog/month?a=commitdiff_plain;h=d0a510bfeeed34f47140872b10d5883e5c4f5a3c;p=imoo.git ribbon: emit signal when IMs are sent successfully --- diff --git a/ribbon/ribbonconversations.cpp b/ribbon/ribbonconversations.cpp index 8f2dd5a..15cd11b 100644 --- a/ribbon/ribbonconversations.cpp +++ b/ribbon/ribbonconversations.cpp @@ -25,6 +25,22 @@ static void static_buddy_typing_stopped(PurpleAccount* account, const char* name c->buddy_typing(account, name, RibbonConversations::STOPPED); } +static void static_sent_im_msg(PurpleAccount* account, const char* receiver, + const char* message, void* data) +{ + RibbonConversations* c = (RibbonConversations*)data; + c->sent_im_msg(account, receiver, message); +} + +static QString canonicalized(QString buddy) +{ + // Strips everything right of the slash to remove a Jabber resource ID. + int slash_pos = buddy.indexOf("/"); + if (slash_pos != -1) + return buddy.left(slash_pos); + return buddy; +} + RibbonConversations::RibbonConversations(RibbonManager* parent) : QObject((QObject*)parent) { _manager = parent; @@ -44,6 +60,8 @@ void RibbonConversations::init() PURPLE_CALLBACK(static_buddy_typing), this); purple_signal_connect(conversations_handle, "buddy-typing-stopped", &handle, PURPLE_CALLBACK(static_buddy_typing_stopped), this); + purple_signal_connect(conversations_handle, "sent-im-msg", &handle, + PURPLE_CALLBACK(static_sent_im_msg), this); } void RibbonConversations::received_im_msg(PurpleAccount *account, @@ -54,7 +72,7 @@ void RibbonConversations::received_im_msg(PurpleAccount *account, conv = purple_conversation_new(PURPLE_CONV_TYPE_IM, account, sender); } QVariantMap m = RibbonAccounts::context(account); - m["buddy"] = QString::fromUtf8(sender); + m["buddy"] = canonicalized(QString::fromUtf8(sender)); m["timestamp"] = QDateTime::currentDateTimeUtc(); m["message"] = QString::fromUtf8(message); emit event(QString::fromUtf8("conversations"), @@ -66,7 +84,7 @@ void RibbonConversations::received_im_msg(PurpleAccount *account, void RibbonConversations::buddy_typing(PurpleAccount *account, const char* buddy, TypingState state) { QVariantMap m = RibbonAccounts::context(account); - m["buddy"] = QString::fromUtf8(buddy); + m["buddy"] = canonicalized(QString::fromUtf8(buddy)); switch (state) { case STOPPED: m["state"] = QString::fromUtf8("stopped"); break; case TYPING: m["state"] = QString::fromUtf8("typing"); break; @@ -86,15 +104,27 @@ void RibbonConversations::send_im(QString protocol, QString account, QString bud return; } PurpleConversation* p_conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, - buddy.toUtf8(), p_acct); + canonicalized(buddy).toUtf8(), p_acct); if (!p_conv) { // Lazily create conversation objects if needed - p_conv = purple_conversation_new(PURPLE_CONV_TYPE_IM, p_acct, buddy.toUtf8()); + p_conv = purple_conversation_new(PURPLE_CONV_TYPE_IM, p_acct, canonicalized(buddy).toUtf8()); } PurpleConvIm* p_conv_im = purple_conversation_get_im_data(p_conv); purple_conv_im_send(p_conv_im, message.toUtf8()); } +void RibbonConversations::sent_im_msg(PurpleAccount* account, const char* buddy, + const char* message) +{ + QVariantMap m = RibbonAccounts::context(account); + m["buddy"] = canonicalized(QString::fromUtf8(buddy)); + m["message"] = QString::fromUtf8(message); + qDebug() << "successfully sent message to" << m["buddy"]; + emit event(QString::fromUtf8("conversations"), + QString::fromUtf8("sent_im"), + m); +} + void RibbonConversations::handleExternalEvent(QString method, QVariantMap context) { if (method == "send_im") { diff --git a/ribbon/ribbonconversations.h b/ribbon/ribbonconversations.h index 99e50d8..efba2bc 100644 --- a/ribbon/ribbonconversations.h +++ b/ribbon/ribbonconversations.h @@ -22,6 +22,7 @@ public: PurpleConversation *conv, PurpleMessageFlags flags); void buddy_typing(PurpleAccount *account, const char* buddy, TypingState state); void handleExternalEvent(QString method, QVariantMap context); + void sent_im_msg(PurpleAccount* account, const char* buddy, const char* message); signals: void event(QString source, QString signal, QVariantMap context); private: