soc.2009.transport: 4d759a72: Resend initial presences for MUC and res...
hanzz at soc.pidgin.im
hanzz at soc.pidgin.im
Wed Jun 10 06:10:42 EDT 2009
-----------------------------------------------------------------
Revision: 4d759a72c2b20cc526ba581afce473297d47fb74
Ancestor: 139da6c93682eed4c4c4dc66095f08f7795a2ff2
Author: hanzz at soc.pidgin.im
Date: 2009-06-10T10:08:44
Branch: im.pidgin.soc.2009.transport
URL: http://d.pidgin.im/viewmtn/revision/info/4d759a72c2b20cc526ba581afce473297d47fb74
Modified files:
main.cpp main.h muchandler.cpp muchandler.h protocols/irc.h
user.cpp user.h
ChangeLog:
Resend initial presences for MUC and resend messages.
-------------- next part --------------
============================================================
--- main.cpp 56a639c2cae637cf9ab60d395dbe516e76312131
+++ main.cpp 4e21b7d59869e060b01e4565bb3cdd26cdbacac5
@@ -31,6 +31,7 @@
#include "protocols/facebook.h"
#include "protocols/gg.h"
#include "protocols/msn.h"
+#include "protocols/irc.h"
#include "blistsaving.h"
#include <gloox/tlsbase.h>
@@ -96,7 +97,7 @@ static void newMessageReceived(PurpleAcc
*/
static void newMessageReceived(PurpleAccount* account,char * name,char *msg,PurpleConversation *conv,PurpleMessageFlags flags)
{
- GlooxMessageHandler::instance()->purpleMessageReceived(account,name,msg,conv,flags);
+ GlooxMessageHandler::instance()->purpleMessageReceived(account,name,msg,conv,flags);
}
/*
@@ -104,9 +105,17 @@ static void conv_write_im(PurpleConversa
*/
static void conv_write_im(PurpleConversation *conv, const char *who, const char *message, PurpleMessageFlags flags, time_t mtime)
{
- GlooxMessageHandler::instance()->purpleConversationWriteIM(conv,who,message,flags,mtime);
+ GlooxMessageHandler::instance()->purpleConversationWriteIM(conv,who,message,flags,mtime);
}
+static void conv_write_chat(PurpleConversation *conv, const char *who, const char *message, PurpleMessageFlags flags, time_t mtime) {
+ GlooxMessageHandler::instance()->purpleConversationWriteChat(conv,who,message,flags,mtime);
+}
+
+static void conv_chat_add_users(PurpleConversation *conv, GList *cbuddies, gboolean new_arrivals) {
+ GlooxMessageHandler::instance()->purpleChatAddUsers(conv, cbuddies, new_arrivals);
+}
+
/*
* Called when user is logged in...
*/
@@ -374,10 +383,10 @@ static PurpleConversationUiOps conversat
{
NULL,//pidgin_conv_new,
NULL,//pidgin_conv_destroy, /* destroy_conversation */
- NULL, /* write_chat */
+ conv_write_chat, /* write_chat */
conv_write_im, /* write_im */
NULL,//pidgin_conv_write_conv, /* write_conv */
- NULL,//pidgin_conv_chat_add_users, /* chat_add_users */
+ conv_chat_add_users, /* chat_add_users */
NULL,//pidgin_conv_chat_rename_user, /* chat_rename_user */
NULL,//pidgin_conv_chat_remove_users, /* chat_remove_users */
NULL,//pidgin_conv_chat_update_user, /* chat_update_user */
@@ -551,6 +560,8 @@ void GlooxMessageHandler::loadProtocol()
m_protocol = (AbstractProtocol*) new GGProtocol(this);
else if (configuration().protocol == "msn")
m_protocol = (AbstractProtocol*) new MSNProtocol(this);
+ else if (configuration().protocol == "irc")
+ m_protocol = (AbstractProtocol*) new IRCProtocol(this);
// PurplePlugin *plugin = purple_find_prpl(m_protocol->protocol().c_str());
// if (plugin && PURPLE_PLUGIN_HAS_ACTIONS(plugin)) {
// PurplePluginAction *action = NULL;
@@ -862,7 +873,35 @@ void GlooxMessageHandler::purpleConversa
}
}
+void GlooxMessageHandler::purpleConversationWriteChat(PurpleConversation *conv, const char *who, const char *message, PurpleMessageFlags flags, time_t mtime){
+ if (who==NULL)
+ return;
+ PurpleAccount *account = purple_conversation_get_account(conv);
+ User *user = userManager()->getUserByAccount(account);
+ if (user) {
+ if (user->isConnected()){
+ m_stats->messageFromLegacy();
+ user->purpleConversationWriteChat(conv,who,message,flags,mtime);
+ }
+ else {
+ Log().Get(user->jid()) << "purpleConversationWriteIM called for unconnected user...";
+ }
+ }
+ else {
+ Log().Get("purple") << "purpleConversationWriteIM called, but user does not exist!!!";
+ }
+}
+void GlooxMessageHandler::purpleChatAddUsers(PurpleConversation *conv, GList *cbuddies, gboolean new_arrivals) {
+ PurpleAccount *account = purple_conversation_get_account(conv);
+ User *user = userManager()->getUserByAccount(account);
+ if (user) {
+ if (user->isConnected()){
+ user->purpleChatAddUsers(conv, cbuddies, new_arrivals);
+ }
+ }
+}
+
void GlooxMessageHandler::purpleBuddyChanged(PurpleBuddy* buddy){
if (buddy!=NULL){
PurpleAccount *a=purple_buddy_get_account(buddy);
============================================================
--- main.h 2c3ce2f0d2a657c50f2e9597cffa37f74796c2bb
+++ main.h 69af41e24073ad7b471a2d9263f3a5b565bd0b25
@@ -158,6 +158,8 @@ public:
void purpleConnectionError(PurpleConnection *gc,PurpleConnectionError reason,const char *text);
void purpleMessageReceived(PurpleAccount* account,char * name,char *msg,PurpleConversation *conv,PurpleMessageFlags flags);
void purpleConversationWriteIM(PurpleConversation *conv, const char *who, const char *message, PurpleMessageFlags flags, time_t mtime);
+ void purpleConversationWriteChat(PurpleConversation *conv, const char *who, const char *message, PurpleMessageFlags flags, time_t mtime);
+ void purpleChatAddUsers(PurpleConversation *conv, GList *cbuddies, gboolean new_arrivals);
void * purpleAuthorizeReceived(PurpleAccount *account,const char *remote_user,const char *id,const char *alias,const char *message,gboolean on_list,PurpleAccountRequestAuthorizationCb authorize_cb,PurpleAccountRequestAuthorizationCb deny_cb,void *user_data);
void purpleBuddyTyping(PurpleAccount *account, const char *who);
void purpleBuddyTypingStopped(PurpleAccount *account, const char *who);
============================================================
--- muchandler.cpp 8d54acda5f8db7f01bac9af4b7ed03da3f1a742d
+++ muchandler.cpp 49678e5ff434c0d77c3a5ac60c094a6bd2f89588
@@ -22,9 +22,10 @@
#include "main.h"
#include "user.h"
-MUCHandler::MUCHandler(User *user, const std::string &jid){
+MUCHandler::MUCHandler(User *user, const std::string &jid, const std::string &userJid){
m_user = user;
m_jid = jid;
+ m_userJid = userJid;
}
MUCHandler::~MUCHandler() {}
@@ -34,5 +35,60 @@ Tag * MUCHandler::handlePresence(const P
// tag.setFrom(p->jid());
// return tag.tag();
+ GHashTable *comps = NULL;
+ std::string name = stanza.to().username();
+ PurpleConnection *gc = purple_account_get_connection(m_user->account());
+ if (PURPLE_PLUGIN_PROTOCOL_INFO(gc->prpl)->chat_info_defaults != NULL)
+ comps = PURPLE_PLUGIN_PROTOCOL_INFO(gc->prpl)->chat_info_defaults(gc, name.c_str());
+ if (comps) {
+ serv_join_chat(gc, comps);
+ }
return NULL;
-}
\ No newline at end of file
+}
+
+void MUCHandler::addUsers(GList *cbuddies) {
+ GList *l = cbuddies;
+ while (l != NULL) {
+ PurpleConvChatBuddy *cb = (PurpleConvChatBuddy *)l->data;
+// std::string alias(cb->alias ? cb->alias: "");
+ std::string name(cb->name);
+ int flags = GPOINTER_TO_INT(cb->flags);
+// PURPLE_CBFLAGS_OP
+// <presence
+// from='darkcave at chat.shakespeare.lit/firstwitch'
+// to='hag66 at shakespeare.lit/pda'>
+// <x xmlns='http://jabber.org/protocol/muc#user'>
+// <item affiliation='member' role='participant'/>
+// </x>
+// </presence>
+ Tag *tag = new Tag("presence");
+ tag->addAttribute("from", m_jid + "/" + name);
+ tag->addAttribute("to", m_userJid);
+
+ Tag *x = new Tag("x");
+ x->addAttribute("xmlns", "http://jabber.org/protocol/muc#user");
+
+ Tag *item = new Tag("item");
+ item->addAttribute("affiliation", "member");
+ item->addAttribute("role", "participant");
+
+ x->addChild(item);
+ tag->addChild(x);
+ std::cout << tag->xml() << "\n";
+ m_user->p->j->send(tag);
+
+ l = l->next;
+ }
+}
+
+void MUCHandler::messageReceived(const char *who, const char *msg, PurpleMessageFlags flags, time_t mtime) {
+ std::string name(who);
+
+ // send message to user
+ std::string message(purple_unescape_html(msg));
+ Message s(Message::Groupchat, m_userJid, message);
+ s.setFrom(m_jid + "/" + name);
+
+ m_user->p->j->send( s );
+}
+
============================================================
--- muchandler.h 5afad7f306ee4ddf2fbd423b99c1401800c22088
+++ muchandler.h e8462d50d90e4ce3bac61aeedd815947ee78eaea
@@ -24,6 +24,7 @@
#include "localization.h"
#include "gloox/tag.h"
#include "gloox/presence.h"
+#include "conversation.h"
class User;
extern Localization localization;
@@ -33,13 +34,16 @@ class MUCHandler
class MUCHandler
{
public:
- MUCHandler(User *user,const std::string &jid);
+ MUCHandler(User *user,const std::string &jid, const std::string &userJid);
~MUCHandler();
Tag * handlePresence(const Presence &stanza);
+ void addUsers(GList *cbuddies);
+ void messageReceived(const char *who, const char *msg, PurpleMessageFlags flags, time_t mtime);
private:
User *m_user;
std::string m_jid;
+ std::string m_userJid;
};
#endif
============================================================
--- protocols/irc.h 6c18e4498924256062a92029bd8145a91aeca9f7
+++ protocols/irc.h d460c8418a38f97e977925f314c33c36f6d9e839
@@ -39,7 +39,7 @@ class IRCProtocol : AbstractProtocol
std::list<std::string> buddyFeatures();
std::string text(const std::string &key);
Tag *getVCardTag(User *user, GList *vcardEntries);
- bool isMUC(User *user, const std::string &jid) { return true; }
+ bool isMUC(User *user, const std::string &jid) { return jid.find("#") == 0; }
private:
============================================================
--- user.cpp d174f5b8c7df35f9cd2fa7ca822f59b4dcc3186b
+++ user.cpp 1895a9ef5b54e7e5499ba2a0ed3556ac4ad1f6e9
@@ -476,6 +476,22 @@ void User::purpleMessageReceived(PurpleA
}
}
+void User::purpleConversationWriteChat(PurpleConversation *conv, const char *who, const char *msg, PurpleMessageFlags flags, time_t mtime) {
+ if (who == NULL)
+ return;
+
+ std::string name(who);
+
+ if (!isOpenedConversation(name)) {
+ m_conversations[name] = conv;
+ }
+
+ MUCHandler *muc = (MUCHandler*) g_hash_table_lookup(m_mucs, purple_conversation_get_name(conv));
+ if (muc) {
+ muc->messageReceived(who, msg, flags, mtime);
+ }
+}
+
void User::purpleConversationWriteIM(PurpleConversation *conv, const char *who, const char *msg, PurpleMessageFlags flags, time_t mtime) {
if (who == NULL)
return;
@@ -520,6 +536,17 @@ void User::purpleConversationWriteIM(Pur
p->j->send( s );
}
+void User::purpleChatAddUsers(PurpleConversation *conv, GList *cbuddies, gboolean new_arrivals) {
+ std::string name(purple_conversation_get_name(conv));
+ if (!isOpenedConversation(name)) {
+ m_conversations[name] = conv;
+ }
+ MUCHandler *muc = (MUCHandler*) g_hash_table_lookup(m_mucs, name.c_str());
+ if (muc) {
+ muc->addUsers(cbuddies);
+ }
+}
+
/*
* Called when legacy network user stops typing.
*/
@@ -603,8 +630,13 @@ void User::receivedMessage(const Message
conv = m_conversations[msg.to().username()];
}
// send this message
- PurpleConvIm *im = purple_conversation_get_im_data(conv);
- purple_conv_im_send(im,msg.body().c_str());
+ if (purple_conversation_get_type(conv) == PURPLE_CONV_TYPE_IM) {
+ PurpleConvIm *im = purple_conversation_get_im_data(conv);
+ purple_conv_im_send(im,msg.body().c_str());
+ }
+ else if (purple_conversation_get_type(conv) == PURPLE_CONV_TYPE_CHAT) {
+ purple_conv_chat_send(PURPLE_CONV_CHAT(conv), msg.body().c_str());
+ }
}
/*
@@ -815,24 +847,21 @@ void User::receivedPresence(const Presen
void User::receivedPresence(const Presence &stanza){
// we're connected
- Tag *stanzaTag = stanza.tag();
-
- if (stanza.to().username()!="" && stanzaTag->hasChild ("x", "xmlns", "http://jabber.org/protocol/muc")) {
- MUCHandler *muc = (MUCHandler*) g_hash_table_lookup(m_mucs, stanza.to().bare().c_str());
+ if (stanza.to().username()!="") {
+ MUCHandler *muc = (MUCHandler*) g_hash_table_lookup(m_mucs, stanza.to().username().c_str());
if (muc) {
Tag * ret = muc->handlePresence(stanza);
if (ret)
p->j->send(ret);
}
else if (p->protocol()->isMUC(this, stanza.to().bare())) {
- MUCHandler *muc = new MUCHandler(this, stanza.to().full());
- g_hash_table_replace(m_mucs, g_strdup(stanza.to().bare().c_str()), muc);
+ MUCHandler *muc = new MUCHandler(this, stanza.to().bare(), stanza.from().full());
+ g_hash_table_replace(m_mucs, g_strdup(stanza.to().username().c_str()), muc);
Tag * ret = muc->handlePresence(stanza);
if (ret)
p->j->send(ret);
}
}
- delete stanzaTag;
if (m_connected){
============================================================
--- user.h f18bdd5b164071c004b69a8fec7791be8160366b
+++ user.h 58521a3f3f6c806d4956ff3dd406648709c1b784
@@ -91,6 +91,8 @@ class User {
void purpleBuddyRemoved(PurpleBuddy *buddy);
void purpleMessageReceived(PurpleAccount* account,char * name,char *msg,PurpleConversation *conv,PurpleMessageFlags flags);
void purpleConversationWriteIM(PurpleConversation *conv, const char *who, const char *msg, PurpleMessageFlags flags, time_t mtime);
+ void purpleConversationWriteChat(PurpleConversation *conv, const char *who, const char *msg, PurpleMessageFlags flags, time_t mtime);
+ void purpleChatAddUsers(PurpleConversation *conv, GList *cbuddies, gboolean new_arrivals);
void purpleAuthorizeReceived(PurpleAccount *account,const char *remote_user,const char *id,const char *alias,const char *message,gboolean on_list,PurpleAccountRequestAuthorizationCb authorize_cb,PurpleAccountRequestAuthorizationCb deny_cb,void *user_data);
void purpleBuddyTypingStopped(const std::string &uin);
void purpleBuddyTyping(const std::string &uin);
More information about the Commits
mailing list