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;
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,
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"),
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;
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") {