soc.2009.transport: c5a3f0d0: Added support for XEP-0203 (Delayed Deli...

hanzz at soc.pidgin.im hanzz at soc.pidgin.im
Tue Apr 28 14:41:10 EDT 2009


-----------------------------------------------------------------
Revision: c5a3f0d04316710c098ea88eb00a96edbc95ded2
Ancestor: 82dbdc88114c43b945d60f04da3368e07df7c693
Author: hanzz at soc.pidgin.im
Date: 2009-04-28T18:37:27
Branch: im.pidgin.soc.2009.transport
URL: http://d.pidgin.im/viewmtn/revision/info/c5a3f0d04316710c098ea88eb00a96edbc95ded2

Modified files:
        main.cpp main.h user.cpp user.h

ChangeLog: 

Added support for XEP-0203 (Delayed Delivery).

-------------- next part --------------
============================================================
--- main.cpp	37b91d3fb250f912efc41c14b6144aedc1dd7ba3
+++ main.cpp	325610a2bde43b6fe6aa27550db689b4f073438e
@@ -87,14 +87,22 @@ namespace gloox {
 };
 
 /*
- * New message from legacy network received
+ * New message from legacy network received (we can create conversation here)
  */
 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);
 }
 
 /*
+ * Called when message from legacy network arrived (we have to resend message)
+ */
+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);
+}
+
+/*
  * Called when user is logged in...
  */
 static void signed_on(PurpleConnection *gc,gpointer unused)
@@ -304,19 +312,43 @@ static PurpleConnectionUiOps conn_ui_ops
 
 static PurpleConnectionUiOps conn_ui_ops =
 {
-        NULL,
-        NULL,
-        NULL,//connection_disconnected,
-        NULL,
-        NULL,
-        NULL,
-        NULL,
-        connection_report_disconnect,
-        NULL,
-        NULL,
-        NULL
+	NULL,
+	NULL,
+	NULL,//connection_disconnected,
+	NULL,
+	NULL,
+	NULL,
+	NULL,
+	connection_report_disconnect,
+	NULL,
+	NULL,
+	NULL
 };
 
+static PurpleConversationUiOps conversation_ui_ops =
+{
+	NULL,//pidgin_conv_new,
+	NULL,//pidgin_conv_destroy,              /* destroy_conversation */
+	NULL,                              /* write_chat           */
+	conv_write_im,             /* write_im             */
+	NULL,//pidgin_conv_write_conv,           /* write_conv           */
+	NULL,//pidgin_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     */
+	NULL,//pidgin_conv_present_conversation, /* present              */
+	NULL,//pidgin_conv_has_focus,            /* has_focus            */
+	NULL,//pidgin_conv_custom_smiley_add,    /* custom_smiley_add    */
+	NULL,//pidgin_conv_custom_smiley_write,  /* custom_smiley_write  */
+	NULL,//pidgin_conv_custom_smiley_close,  /* custom_smiley_close  */
+	NULL,//pidgin_conv_send_confirm,         /* send_confirm         */
+	NULL,
+	NULL,
+	NULL,
+	NULL
+};
+
+
 /***** Core Ui Ops *****/
 static void transport_core_ui_init(void)
 {
@@ -326,6 +358,7 @@ static void transport_core_ui_init(void)
 	purple_request_set_ui_ops(&requestUiOps);
 	purple_xfers_set_ui_ops(&xferUiOps);
 	purple_connections_set_ui_ops(&conn_ui_ops);
+	purple_conversations_set_ui_ops(&conversation_ui_ops);
 }
 
 static PurpleCoreUiOps coreUiOps =
@@ -721,7 +754,6 @@ void GlooxMessageHandler::purpleMessageR
 
 
 void GlooxMessageHandler::purpleMessageReceived(PurpleAccount* account,char * name,char *msg,PurpleConversation *conv,PurpleMessageFlags flags){
-	m_stats->messageFromLegacy();
 	User *user = userManager()->getUserByAccount(account);
 	if (user){
 		if (user->isConnected()){
@@ -736,6 +768,26 @@ void GlooxMessageHandler::purpleMessageR
 	}
 }
 
+void GlooxMessageHandler::purpleConversationWriteIM(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->purpleConversationWriteIM(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::purpleBuddyChanged(PurpleBuddy* buddy){
 	if (buddy!=NULL){
 		PurpleAccount *a=purple_buddy_get_account(buddy);
============================================================
--- main.h	9bd7b3ba7bf94444a044850327ead3c5898b65e7
+++ main.h	150338a243569e9b1f3b92f448349cc40ea281d2
@@ -138,6 +138,7 @@ public:
 	void purpleBuddyChanged(PurpleBuddy* buddy);
 	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 * 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);
============================================================
--- user.cpp	7c4f15e79b910b681f3d45f9652ac389901e7d9a
+++ user.cpp	7d781067878152da8f9b388d5dce7e25c7418161
@@ -218,15 +218,8 @@ Tag *User::generatePresenceStanza(Purple
 	if (stat==NULL)
 		return NULL;
 	int s = purple_status_type_get_primitive(purple_status_get_type(stat));
-	char *text = NULL;
-	char *statusMessage = NULL;
+	const char *statusMessage = purple_status_get_attr_string(stat, "message");
 
-	PurplePluginProtocolInfo *prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(purple_account_get_connection(m_account)->prpl);
-
-	if (prpl_info && prpl_info->status_text) {
-		statusMessage = prpl_info->status_text(buddy);
-	}
-
 	Log().Get(m_jid) << "Generating presence stanza for user " << name;
 	Tag *tag = new Tag("presence");
 	std::string from;
@@ -239,7 +232,6 @@ Tag *User::generatePresenceStanza(Purple
 		std::string _status(statusMessage);
 		Log().Get(m_jid) << "Raw status message: " << _status;
 		tag->addChild( new Tag("status", stripHTMLTags(_status)));
-		g_free(statusMessage);
 	}
 	
 	switch(s) {
@@ -356,7 +348,7 @@ void User::purpleBuddyChanged(PurpleBudd
 		return;
 	int s = purple_status_type_get_primitive(purple_status_get_type(stat));
 	// TODO: rewrite me to use prpl_info->status_text(buddy)
-	const char *statusMessage = purple_status_get_attr_string(stat, "message");
+// 	const char *statusMessage = purple_status_get_attr_string(stat, "message");
 
 	Log().Get(m_jid) << "purpleBuddyChanged: " << name << " ("<< alias <<") (" << s << ")";
 
@@ -428,22 +420,46 @@ void User::purpleMessageReceived(PurpleA
 		conv = purple_conversation_new(PURPLE_CONV_TYPE_IM,account,name);
 		m_conversations[(std::string)name]=conv;
 	}
+}
+
+void User::purpleConversationWriteIM(PurpleConversation *conv, const char *who, const char *msg, PurpleMessageFlags flags, time_t mtime) {
+	if (who == NULL)
+		return;
+	std::string name = (std::string) purple_conversation_get_name(conv);
+	// new message from legacy network has been received
+	if (!isOpenedConversation(name)) {
+			m_conversations[name] = conv;
+	}
+
+	Log().Get(m_jid) <<  "purpleConversationWriteIM:" << name;
+
 	// send message to user
 	std::string message(purple_unescape_html(msg));
 	Stanza *s = Stanza::createMessageStanza(m_jid, message);
 	std::string from;
-	from.append((std::string)name);
+	from.append(name);
 	from.append("@");
-	from.append(p->jid()+"/bot");
+	from.append(p->jid() + "/bot");
 	s->addAttribute("from",from);
-	
+
 	// chatstates
-	if (hasFeature(GLOOX_FEATURE_CHATSTATES)){
+	if (hasFeature(GLOOX_FEATURE_CHATSTATES)) {
 		Tag *active = new Tag("active");
 		active->addAttribute("xmlns","http://jabber.org/protocol/chatstates");
 		s->addChild(active);
 	}
 	
+	// Delayed messages, we have to count with some delay
+	if (int(time(NULL))-10>int(mtime)) {
+		char buf[80];
+		strftime(buf, sizeof(buf), "%Y%m%dT%H:%M:%S", localtime(&mtime));
+		std::string timestamp(buf);
+		Tag *delay = new Tag("delay");
+		delay->addAttribute("xmlns","urn:xmpp:delay");
+		delay->addAttribute("stamp",timestamp);
+		s->addChild(delay);
+	}
+
 	p->j->send( s );
 }
 
============================================================
--- user.h	55551fef6e6dcc3792d093c0b9e62426b54c49a7
+++ user.h	bc9a40b41bf1f77c0b111973a6e1e3e88fadd27e
@@ -82,6 +82,7 @@ class User {
 		// Libpurple callbacks
 		void purpleBuddyChanged(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 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