changeset 10451:92d4a25fd33c

[gaim-migrate @ 11717] This is patch 1090620 from Felipe Contreras to improve the handling of the Individuals group on MSN and better buddy updates (modified by me to work in HEAD) Also included is my fix for bug 1090087 "MSN Groupchat Double Invite Crash", a few spelling corrections, and make some more strings translatable. committer: Tailor Script <tailor@pidgin.im>
author Stu Tomlinson <stu@nosnilmot.com>
date Thu, 30 Dec 2004 15:55:19 +0000
parents 577fdf4110fc
children e1c98422f4df
files src/protocols/msn/msg.h src/protocols/msn/msn.c src/protocols/msn/notification.c src/protocols/msn/slpcall.c src/protocols/msn/switchboard.c src/protocols/msn/switchboard.h src/protocols/msn/sync.c src/protocols/msn/user.c src/protocols/msn/user.h
diffstat 9 files changed, 187 insertions(+), 83 deletions(-) [+]
line wrap: on
line diff
--- a/src/protocols/msn/msg.h	Thu Dec 30 06:26:53 2004 +0000
+++ b/src/protocols/msn/msg.h	Thu Dec 30 15:55:19 2004 +0000
@@ -60,7 +60,7 @@
 	MSN_MSG_ERROR_TIMEOUT, /**< The message timedout. */
 	MSN_MSG_ERROR_NAK, /**< The message could not be sent. */
 	MSN_MSG_ERROR_SB, /**< The error comes from the switchboard. */
-	MSN_MSG_ERROR_UNKNOWN /**< An unknown error occured. */
+	MSN_MSG_ERROR_UNKNOWN /**< An unknown error occurred. */
 
 } MsnMsgErrorType;
 
--- a/src/protocols/msn/msn.c	Thu Dec 30 06:26:53 2004 +0000
+++ b/src/protocols/msn/msn.c	Thu Dec 30 15:55:19 2004 +0000
@@ -448,8 +448,7 @@
 	else if (gaim_presence_is_status_active(presence, "busy") ||
 			 gaim_presence_is_status_active(presence, "phone"))
 		emblems[i++] = "occupied";
-	else if (gaim_presence_is_status_active(presence, "away") ||
-			 gaim_presence_is_idle(presence))
+	else if (!gaim_presence_is_available(presence))
 		emblems[i++] = "away";
 
 	if (user == NULL)
@@ -1334,15 +1333,6 @@
 			g_free(nicktext);
 		}
 
-		if (gaim_presence_is_idle(presence))
-		{
-			char *idletime = gaim_str_seconds_to_string(time(NULL) -
-										gaim_presence_get_idle_time(presence));
-			g_string_append_printf(s, _("<b>%s:</b> %s<br>"), _("Idle"),
-					idletime);
-			g_free(idletime);
-		}
-
 		if (statustext)
 		{
 			char *tmp;
--- a/src/protocols/msn/notification.c	Thu Dec 30 06:26:53 2004 +0000
+++ b/src/protocols/msn/notification.c	Thu Dec 30 15:55:19 2004 +0000
@@ -37,6 +37,50 @@
 static MsnTable *cbs_table;
 
 /**************************************************************************
+ * Util
+ **************************************************************************/
+
+static void
+group_error_helper(MsnSession *session, const char *msg, int group_id, int error)
+{
+	GaimAccount *account;
+	GaimConnection *gc;
+	char *reason = NULL;
+	char *title = NULL;
+
+	account = session->account;
+	gc = gaim_account_get_connection(account);
+
+	if (error == 224)
+	{
+		if (group_id == 0)
+		{
+			return;
+		}
+		else
+		{
+			const char *group_name;
+			group_name =
+				msn_userlist_find_group_name(session->userlist,
+											 group_id);
+			reason = g_strdup_printf(_("%s is not a valid group."),
+									 group_name);
+		}
+	}
+	else
+	{
+		reason = g_strdup(_("Unknown error."));
+	}
+
+	title = g_strdup_printf(_("%s on %s (%s)"), msg,
+						  gaim_account_get_username(account),
+						  gaim_account_get_protocol_name(account));
+	gaim_notify_error(gc, NULL, title, reason);
+	g_free(title);
+	g_free(reason);
+}
+
+/**************************************************************************
  * Login
  **************************************************************************/
 
@@ -331,6 +375,7 @@
 		group_id = -1;
 
 	msn_got_add_user(session, user, list_id, group_id);
+	msn_user_update(user);
 }
 
 static void
@@ -353,15 +398,15 @@
 	passport = params[1];
 
 	if (!strcmp(list, "FL"))
-		msg = g_strdup_printf("Unable to add user on %s (%s)",
+		msg = g_strdup_printf(_("Unable to add user on %s (%s)"),
 							  gaim_account_get_username(account),
 							  gaim_account_get_protocol_name(account));
 	else if (!strcmp(list, "BL"))
-		msg = g_strdup_printf("Unable to block user on %s (%s)",
+		msg = g_strdup_printf(_("Unable to block user on %s (%s)"),
 							  gaim_account_get_username(account),
 							  gaim_account_get_protocol_name(account));
 	else if (!strcmp(list, "AL"))
-		msg = g_strdup_printf("Unable to permit user on %s (%s)",
+		msg = g_strdup_printf(_("Unable to permit user on %s (%s)"),
 							  gaim_account_get_username(account),
 							  gaim_account_get_protocol_name(account));
 
@@ -369,8 +414,8 @@
 	{
 		if (error == 210)
 		{
-			reason = g_strdup_printf("%s could not be added because "
-									 "your buddy list is full.", passport);
+			reason = g_strdup_printf(_("%s could not be added because "
+									   "your buddy list is full."), passport);
 		}
 	}
 
@@ -378,12 +423,12 @@
 	{
 		if (error == 208)
 		{
-			reason = g_strdup_printf("%s is not a valid passport account.",
+			reason = g_strdup_printf(_("%s is not a valid passport account."),
 									 passport);
 		}
 		else
 		{
-			reason = g_strdup_printf("Unknown error.");
+			reason = g_strdup_printf(_("Unknown error."));
 		}
 	}
 
@@ -446,13 +491,13 @@
 static void
 fln_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd)
 {
-	GaimAccount *account;
-
 	MsnSlpLink *slplink;
+	MsnUser *user;
 
-	account = cmdproc->session->account;
+	user = msn_userlist_find_user(cmdproc->session->userlist, cmd->params[0]);
 
-	gaim_prpl_got_user_status(account, cmd->params[0], "offline", NULL);
+	user->status = "offline";
+	msn_user_update(user);
 
 	slplink = msn_session_find_slplink(cmdproc->session, cmd->params[0]);
 
@@ -461,10 +506,6 @@
 
 }
 
-/*
- * XXX - There is a bit of code duplication between this function
- * and nln_cmd.  Someone should do something about that.
- */
 static void
 iln_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd)
 {
@@ -473,7 +514,7 @@
 	GaimConnection *gc;
 	MsnUser *user;
 	MsnObject *msnobj;
-	const char *status, *state, *passport, *friendly;
+	const char *state, *passport, *friendly;
 
 	session = cmdproc->session;
 	account = session->account;
@@ -485,7 +526,6 @@
 
 	user = msn_userlist_find_user(session->userlist, passport);
 
-	/* serv_got_nick(gc, passport, friendly); */
 	serv_got_alias(gc, passport, friendly);
 
 	msn_user_set_friendly_name(user, friendly);
@@ -496,30 +536,8 @@
 		msn_user_set_object(user, msnobj);
 	}
 
-	/* XXX - What does this do?????
-	if ((b = gaim_find_buddy(account, passport)) != NULL)
-		status |= ((((b->uc) >> 1) & 0xF0) << 1);
-	*/
-
-	if (!g_ascii_strcasecmp(state, "BSY"))
-		status = "busy";
-	else if (!g_ascii_strcasecmp(state, "BRB"))
-		status = "brb";
-	else if (!g_ascii_strcasecmp(state, "AWY"))
-		status = "away";
-	else if (!g_ascii_strcasecmp(state, "PHN"))
-		status = "phone";
-	else if (!g_ascii_strcasecmp(state, "LUN"))
-		status = "lunch";
-	else
-		status = "available";
-
-	gaim_prpl_got_user_status(account, passport, status, NULL);
-
-	if (!g_ascii_strcasecmp(state, "IDL"))
-		gaim_prpl_got_user_idle(account, passport, TRUE, -1);
-	else
-		gaim_prpl_got_user_idle(account, passport, FALSE, 0);
+	msn_user_set_state(user, state);
+	msn_user_update(user);
 }
 
 static void
@@ -545,10 +563,7 @@
 	GaimConnection *gc;
 	MsnUser *user;
 	MsnObject *msnobj;
-	const char *state;
-	const char *passport;
-	const char *friendly;
-	const char *status;
+	const char *state, *passport, *friendly;
 
 	session = cmdproc->session;
 	account = session->account;
@@ -560,7 +575,6 @@
 
 	user = msn_userlist_find_user(session->userlist, passport);
 
-	/* serv_got_nick(gc, passport, friendly); */
 	serv_got_alias(gc, passport, friendly);
 
 	msn_user_set_friendly_name(user, friendly);
@@ -579,25 +593,8 @@
 		}
 	}
 
-	if (!g_ascii_strcasecmp(state, "BSY"))
-		status = "busy";
-	else if (!g_ascii_strcasecmp(state, "BRB"))
-		status = "brb";
-	else if (!g_ascii_strcasecmp(state, "AWY"))
-		status = "away";
-	else if (!g_ascii_strcasecmp(state, "PHN"))
-		status = "phone";
-	else if (!g_ascii_strcasecmp(state, "LUN"))
-		status = "lunch";
-	else
-		status = "available";
-
-	gaim_prpl_got_user_status(account, passport, status, NULL);
-
-	if (!g_ascii_strcasecmp(state, "IDL"))
-		gaim_prpl_got_user_idle(account, passport, TRUE, -1);
-	else
-		gaim_prpl_got_user_idle(account, passport, FALSE, 0);
+	msn_user_set_state(user, state);
+	msn_user_update(user);
 }
 
 static void
@@ -646,7 +643,7 @@
 static void
 rea_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd)
 {
-	/* TODO: This might be with us too */
+	/* TODO: This might be for us too */
 
 	MsnSession *session;
 	GaimConnection *gc;
@@ -674,6 +671,21 @@
 }
 
 static void
+reg_error(MsnCmdProc *cmdproc, MsnTransaction *trans, int error)
+{
+	int group_id;
+	char **params;
+
+	params = g_strsplit(trans->params, " ", 0);
+
+	group_id = atoi(params[0]);
+
+	group_error_helper(cmdproc->session, _("Unable to rename group"), group_id, error);
+
+	g_strfreev(params);
+}
+
+static void
 rem_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd)
 {
 	MsnSession *session;
@@ -698,6 +710,7 @@
 		group_id = -1;
 
 	msn_got_rem_user(session, user, list_id, group_id);
+	msn_user_update(user);
 }
 
 static void
@@ -713,6 +726,21 @@
 }
 
 static void
+rmg_error(MsnCmdProc *cmdproc, MsnTransaction *trans, int error)
+{
+	int group_id;
+	char **params;
+
+	params = g_strsplit(trans->params, " ", 0);
+
+	group_id = atoi(params[0]);
+
+	group_error_helper(cmdproc->session, "Unable to delete group", group_id, error);
+
+	g_strfreev(params);
+}
+
+static void
 syn_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd)
 {
 	MsnSession *session;
@@ -1276,6 +1304,8 @@
 	msn_table_add_cmd(cbs_table, "fallback", "XFR", xfr_cmd);
 
 	msn_table_add_error(cbs_table, "ADD", add_error);
+	msn_table_add_error(cbs_table, "REG", reg_error);
+	msn_table_add_error(cbs_table, "RMG", rmg_error);
 	/* msn_table_add_error(cbs_table, "REA", rea_error); */
 
 	/* I received a '500' error from the notification server just now.
--- a/src/protocols/msn/slpcall.c	Thu Dec 30 06:26:53 2004 +0000
+++ b/src/protocols/msn/slpcall.c	Thu Dec 30 15:55:19 2004 +0000
@@ -96,7 +96,7 @@
 
 		g_return_if_fail(slpmsg != NULL);
 
-		gaim_debug_info("msn", "slpcall destroy: tryping slp_msg (%p)\n",
+		gaim_debug_info("msn", "slpcall destroy: trying slp_msg (%p)\n",
 						slpmsg);
 
 		if (slpmsg->slpcall == slpcall)
--- a/src/protocols/msn/switchboard.c	Thu Dec 30 06:26:53 2004 +0000
+++ b/src/protocols/msn/switchboard.c	Thu Dec 30 15:55:19 2004 +0000
@@ -306,6 +306,8 @@
 static void
 swboard_error_helper(MsnSwitchBoard *swboard, int reason, const char *passport)
 {
+	g_return_if_fail(swboard != NULL);
+
 	gaim_debug_info("msg", "Error: Unable to call the user %s\n", passport);
 
 	if (swboard->total_users == 0)
@@ -365,7 +367,7 @@
 		if (error == MSN_MSG_ERROR_TIMEOUT)
 		{
 			str_reason = _("Message may have not been sent "
-						   "because a time out occurred:");
+						   "because a timeout occurred:");
 		}
 		else if (error == MSN_MSG_ERROR_SB)
 		{
@@ -962,8 +964,15 @@
 {
 	int reason = MSN_SB_ERROR_UNKNOWN;
 
-	if (error == 217)
+	if (error == 215)
+	{
+		gaim_debug_info("msn", "Invited user already in switchboard\n");
+		return;
+	}
+	else if (error == 217)
+	{
 		reason = MSN_SB_ERROR_USER_OFFLINE;
+	}
 
 	cal_error_helper(trans, reason);
 }
--- a/src/protocols/msn/switchboard.h	Thu Dec 30 06:26:53 2004 +0000
+++ b/src/protocols/msn/switchboard.h	Thu Dec 30 15:55:19 2004 +0000
@@ -45,7 +45,7 @@
 	MSN_SB_ERROR_OFFLINE, /**< The account is offline. */
 	MSN_SB_ERROR_USER_OFFLINE, /**< The user to call is offline. */
 	MSN_SB_ERROR_CONNECTION, /**< There was a connection error. */
-	MSN_SB_ERROR_UNKNOWN /**< An unknown error occured. */
+	MSN_SB_ERROR_UNKNOWN /**< An unknown error occurred. */
 
 } MsnSBErrorType;
 
@@ -86,7 +86,7 @@
 	GQueue *im_queue; /**< Queue of messages to send. */
 	GList *ack_list; /**< List of messages waiting for an ack. */
 
-	MsnSBErrorType error; /**< The error that occured in this switchboard
+	MsnSBErrorType error; /**< The error that occurred in this switchboard
 							(if applicable). */
 	MsnSlpLink *slplink; /**< The slplink that is using this switchboard. */
 };
--- a/src/protocols/msn/sync.c	Thu Dec 30 06:26:53 2004 +0000
+++ b/src/protocols/msn/sync.c	Thu Dec 30 15:55:19 2004 +0000
@@ -99,6 +99,11 @@
 
 	group = msn_group_new(session->userlist, group_id, name);
 
+	/* HACK */
+	if (group_id == 0)
+		/* Group of ungroupped buddies */
+		return;
+
 	if ((g = gaim_find_group(name)) == NULL)
 	{
 		g = gaim_group_new(name);
--- a/src/protocols/msn/user.c	Thu Dec 30 06:26:53 2004 +0000
+++ b/src/protocols/msn/user.c	Thu Dec 30 15:55:19 2004 +0000
@@ -86,6 +86,49 @@
 }
 
 void
+msn_user_update(MsnUser *user)
+{
+	GaimAccount *account;
+	GaimConnection *gc;
+
+	account = user->userlist->session->account;
+	gc = gaim_account_get_connection(account);
+
+	gaim_prpl_got_user_status(account, user->passport, user->status, NULL);
+
+	if (user->idle)
+		gaim_prpl_got_user_idle(account, user->passport, TRUE, -1);
+	else
+		gaim_prpl_got_user_idle(account, user->passport, FALSE, 0);
+}
+
+void
+msn_user_set_state(MsnUser *user, const char *state)
+{
+	const char *status;
+
+	if (!g_ascii_strcasecmp(state, "BSY"))
+		status = "busy";
+	else if (!g_ascii_strcasecmp(state, "BRB"))
+		status = "brb";
+	else if (!g_ascii_strcasecmp(state, "AWY"))
+		status = "away";
+	else if (!g_ascii_strcasecmp(state, "PHN"))
+		status = "phone";
+	else if (!g_ascii_strcasecmp(state, "LUN"))
+		status = "lunch";
+	else
+		status = "available";
+
+	if (!g_ascii_strcasecmp(state, "IDL"))
+		user->idle = TRUE;
+	else
+		user->idle = FALSE;
+
+	user->status = status;
+}
+
+void
 msn_user_set_passport(MsnUser *user, const char *passport)
 {
 	g_return_if_fail(user != NULL);
@@ -222,6 +265,12 @@
 
 	g = gaim_find_group(group_name);
 
+	if ((id == 0) && (g == NULL))
+	{
+		g = gaim_group_new(group_name);
+		gaim_blist_add_group(g, NULL);
+	}
+
 	b = gaim_find_buddy_in_group(account, passport, g);
 
 	if (b == NULL)
--- a/src/protocols/msn/user.h	Thu Dec 30 06:26:53 2004 +0000
+++ b/src/protocols/msn/user.h	Thu Dec 30 15:55:19 2004 +0000
@@ -45,6 +45,9 @@
 	char *store_name;       /**< The name stored in the server. */
 	char *friendly_name;    /**< The friendly name.             */
 
+	const char *status;     /**< The state of the user.         */
+	gboolean idle;          /**< The idle state of the user.    */
+
 	struct
 	{
 		char *home;         /**< Home phone number.             */
@@ -89,6 +92,24 @@
  */
 void msn_user_destroy(MsnUser *user);
 
+
+/**
+ * Updates the user.
+ *
+ * Communicates with the core to update the ui, etc.
+ *
+ * @param user The user to update.
+ */
+void msn_user_update(MsnUser *user);
+
+/**
+ * Sets the new state of user.
+ *
+ * @param user The user.
+ * @param state The state string.
+ */
+void msn_user_set_state(MsnUser *user, const char *state);
+
 /**
  * Sets the passport account for a user.
  *