Example #1
0
void
msn_userlist_move_buddy(MsnUserList *userlist, const char *who,
			const char *old_group_name, const char *new_group_name)
{
	const char *new_group_id;
	MsnCallbackState *state;

	g_return_if_fail(userlist != NULL);
	g_return_if_fail(userlist->session != NULL);

	state = msn_callback_state_new(userlist->session);
	msn_callback_state_set_who(state, who);
	msn_callback_state_set_action(state, MSN_MOVE_BUDDY);
	msn_callback_state_set_old_group_name(state, old_group_name);
	msn_callback_state_set_new_group_name(state, new_group_name);

	new_group_id = msn_userlist_find_group_id(userlist, new_group_name);

	if (new_group_id == NULL)
	{
		msn_add_group(userlist->session, state, new_group_name);
		return;
	}

	/* add the contact to the new group, and remove it from the old one in
	 * the callback
	*/
	msn_add_contact_to_group(userlist->session, state, who, new_group_id);
}
Example #2
0
gboolean
msn_userlist_rem_buddy_from_group(MsnUserList *userlist, const char *who,
				const char *group_name)
{
	const gchar * group_id;
	MsnUser *user;

	g_return_val_if_fail(userlist != NULL, FALSE);
	g_return_val_if_fail(group_name != NULL, FALSE);
	g_return_val_if_fail(who != NULL, FALSE);

	purple_debug_info("msn", "Removing buddy with passport %s from group %s\n", who, group_name);

	if ( (group_id = msn_userlist_find_group_id(userlist, group_name)) == NULL) {
		purple_debug_error("msn", "Group %s has no guid!\n", group_name);
		return FALSE;
	}

	if ( (user = msn_userlist_find_user(userlist, who)) == NULL) {
		purple_debug_error("msn", "User %s not found!\n", who);
		return FALSE;
	}

	msn_user_remove_group_id(user, group_id);

	return TRUE;
}
Example #3
0
void
msn_userlist_add_buddy(MsnUserList *userlist,
					   const char *who, int list_id,
					   const char *group_name)
{
	MsnUser *user;
	int group_id;
	const char *list;
	const char *friendly_name;

	group_id = -1;

	if (!purple_email_is_valid(who))
	{
		/* only notify the user about problems adding to the friends list
		 * maybe we should do something else for other lists, but it probably
		 * won't cause too many problems if we just ignore it */
		if (list_id == MSN_LIST_FL)
		{
			char *str = g_strdup_printf(_("Unable to add \"%s\"."), who);
			purple_notify_error(NULL, NULL, str,
							  _("The username specified is invalid."));
			g_free(str);
		}

		return;
	}

	if (group_name != NULL)
	{
		group_id = msn_userlist_find_group_id(userlist, group_name);

		if (group_id < 0)
		{
			/* Whoa, we must add that group first. */
			msn_request_add_group(userlist, who, NULL, group_name);
			return;
		}
	}

	user = msn_userlist_find_user(userlist, who);

	/* First we're going to check if it's already there. */
	if (user_is_there(user, list_id, group_id))
	{
		list = lists[list_id];
		purple_debug_error("msn", "User '%s' is already there: %s\n", who, list);
		return;
	}

	friendly_name = (user != NULL) ? get_friendly_name(user) : who;

	/* Then request the add to the server. */
	list = lists[list_id];

	msn_notification_add_buddy(userlist->session->notification, list, who,
							   friendly_name, group_id);
}
Example #4
0
void
msn_userlist_move_buddy(MsnUserList *userlist, const char *who,
						const char *old_group_name, const char *new_group_name)
{
	int new_group_id;

	new_group_id = msn_userlist_find_group_id(userlist, new_group_name);

	if (new_group_id < 0)
	{
		msn_request_add_group(userlist, who, old_group_name, new_group_name);
		return;
	}

	msn_userlist_add_buddy(userlist, who, MSN_LIST_FL, new_group_name);
	msn_userlist_rem_buddy(userlist, who, MSN_LIST_FL, old_group_name);
}
Example #5
0
void
msn_userlist_rem_buddy(MsnUserList *userlist,
					   const char *who, int list_id, const char *group_name)
{
	MsnUser *user;
	int group_id;
	const char *list;

	user = msn_userlist_find_user(userlist, who);
	group_id = -1;

	if (group_name != NULL)
	{
		group_id = msn_userlist_find_group_id(userlist, group_name);

		if (group_id < 0)
		{
			/* Whoa, there is no such group. */
			purple_debug_error("msn", "Group doesn't exist: %s\n", group_name);
			return;
		}
	}

	/* First we're going to check if not there. */
	if (!(user_is_there(user, list_id, group_id)))
	{
		list = lists[list_id];
		purple_debug_error("msn", "User '%s' is not there: %s\n",
						 who, list);
		return;
	}

	/* Then request the rem to the server. */
	list = lists[list_id];

	msn_notification_rem_buddy(userlist->session->notification, list, who, group_id);
}
Example #6
0
static void
msn_session_sync_users(MsnSession *session)
{
	PurpleBlistNode *gnode, *cnode, *bnode;
	PurpleConnection *gc = purple_account_get_connection(session->account);
	GList *to_remove = NULL;

	g_return_if_fail(gc != NULL);

	/* The core used to use msn_add_buddy to add all buddies before
	 * being logged in. This no longer happens, so we manually iterate
	 * over the whole buddy list to identify sync issues. */

	for (gnode = purple_blist_get_root(); gnode; gnode = gnode->next) {
		PurpleGroup *group = (PurpleGroup *)gnode;
		const char *group_name = group->name;
		if(!PURPLE_BLIST_NODE_IS_GROUP(gnode))
			continue;
		for(cnode = gnode->child; cnode; cnode = cnode->next) {
			if(!PURPLE_BLIST_NODE_IS_CONTACT(cnode))
				continue;
			for(bnode = cnode->child; bnode; bnode = bnode->next) {
				PurpleBuddy *b;
				if(!PURPLE_BLIST_NODE_IS_BUDDY(bnode))
					continue;
				b = (PurpleBuddy *)bnode;
				if(purple_buddy_get_account(b) == purple_connection_get_account(gc)) {
					MsnUser *remote_user;
					gboolean found = FALSE;

					remote_user = msn_userlist_find_user(session->userlist, purple_buddy_get_name(b));

					if ((remote_user != NULL) && (remote_user->list_op & MSN_LIST_FL_OP))
					{
						int group_id;
						GList *l;

						group_id = msn_userlist_find_group_id(remote_user->userlist,
								group_name);

						for (l = remote_user->group_ids; l != NULL; l = l->next)
						{
							if (group_id == GPOINTER_TO_INT(l->data))
							{
								found = TRUE;
								break;
							}
						}

					}

					/* We don't care if they're in a different group, as long as they're on the
					 * list somewhere. If we check for the group, we cause pain, agony and
					 * suffering for people who decide to re-arrange their buddy list elsewhere.
					 */
					if (!found)
					{
						if ((remote_user == NULL) || !(remote_user->list_op & MSN_LIST_FL_OP)) {
							/* The user is not on the server list */
							msn_show_sync_issue(session, purple_buddy_get_name(b), group_name);
						} else {
							/* The user is not in that group on the server list */
							to_remove = g_list_prepend(to_remove, b);
						}
					}
				}
			}
		}
	}

	if (to_remove != NULL) {
		g_list_foreach(to_remove, (GFunc)purple_blist_remove_buddy, NULL);
		g_list_free(to_remove);
	}
}
Example #7
0
/*add buddy*/
void
msn_userlist_add_buddy(MsnUserList *userlist, const char *who, const char *group_name)
{
	MsnUser *user;
	MsnCallbackState *state = NULL;
	const char *group_id = NULL, *new_group_name;

	new_group_name = group_name == NULL ? MSN_INDIVIDUALS_GROUP_NAME : group_name;

	g_return_if_fail(userlist != NULL);
	g_return_if_fail(userlist->session != NULL);

	purple_debug_info("msn", "Add user: %s to group: %s\n", who, new_group_name);

	if (!msn_email_is_valid(who))
	{
		/* only notify the user about problems adding to the friends list
		 * maybe we should do something else for other lists, but it probably
		 * won't cause too many problems if we just ignore it */

		char *str = g_strdup_printf(_("Unable to add \"%s\"."), who);

		purple_notify_error(NULL, NULL, str,
				  _("The username specified is invalid."));
		g_free(str);

		return;
	}

	state = msn_callback_state_new(userlist->session);
	msn_callback_state_set_who(state, who);
	msn_callback_state_set_new_group_name(state, new_group_name);

	group_id = msn_userlist_find_group_id(userlist, new_group_name);

	if (group_id == NULL)
	{
		/* Whoa, we must add that group first. */
		purple_debug_info("msn", "Adding user %s to a new group, creating group %s first\n", who, new_group_name);

		msn_callback_state_set_action(state, MSN_ADD_BUDDY);

		msn_add_group(userlist->session, state, new_group_name);
		return;
	} else {
		msn_callback_state_set_guid(state, group_id);
	}

	/* XXX: adding user here may not be correct (should add them in the
 	 * ACK to the ADL command), but for now we need to make sure they exist
	 * early enough that the ILN command doesn't screw us up */

	user = msn_userlist_find_add_user(userlist, who, who);

	if ( msn_userlist_user_is_in_list(user, MSN_LIST_FL) ) {

		purple_debug_info("msn", "User %s already exists\n", who);

		msn_userlist_rem_buddy_from_list(userlist, who, MSN_LIST_BL);

		if (msn_userlist_user_is_in_group(user, group_id)) {
			purple_debug_info("msn", "User %s is already in group %s, returning\n", who, new_group_name);
			msn_callback_state_free(state);
			return;
		}
	}

	purple_debug_info("msn", "Adding user: %s to group id: %s\n", who, group_id);

	msn_callback_state_set_action(state, MSN_ADD_BUDDY);

	/* Add contact in the Contact server with a SOAP request and if
	   successful, send ADL with MSN_LIST_AL and MSN_LIST_FL and a FQY */
	msn_add_contact_to_group(userlist->session, state, who, group_id);
}
Example #8
0
static void
msn_session_sync_users(MsnSession *session)
{
	PurpleBlistNode *gnode, *cnode, *bnode;
	PurpleConnection *gc = purple_account_get_connection(session->account);

	g_return_if_fail(gc != NULL);

	/* The core used to use msn_add_buddy to add all buddies before
	 * being logged in. This no longer happens, so we manually iterate
	 * over the whole buddy list to identify sync issues. */

	for (gnode = purple_blist_get_root(); gnode; gnode = gnode->next) {
		PurpleGroup *group = (PurpleGroup *)gnode;
		const char *group_name = group->name;
		if(!PURPLE_BLIST_NODE_IS_GROUP(gnode))
			continue;
		for(cnode = gnode->child; cnode; cnode = cnode->next) {
			if(!PURPLE_BLIST_NODE_IS_CONTACT(cnode))
				continue;
			for(bnode = cnode->child; bnode; bnode = bnode->next) {
				PurpleBuddy *b;
				if(!PURPLE_BLIST_NODE_IS_BUDDY(bnode))
					continue;
				b = (PurpleBuddy *)bnode;
				if(purple_buddy_get_account(b) == purple_connection_get_account(gc)) {
					MsnUser *remote_user;
					gboolean found = FALSE;

					remote_user = msn_userlist_find_user(session->userlist, purple_buddy_get_name(b));

					if ((remote_user != NULL) && (remote_user->list_op & MSN_LIST_FL_OP))
					{
						int group_id;
						GList *l;

						group_id = msn_userlist_find_group_id(remote_user->userlist,
								group_name);

						for (l = remote_user->group_ids; l != NULL; l = l->next)
						{
							if (group_id == GPOINTER_TO_INT(l->data))
							{
								found = TRUE;
								break;
							}
						}

					}

					if (!found)
					{
						/* The user was not on the server list or not in that group
						 * on the server list */
						msn_show_sync_issue(session, purple_buddy_get_name(b), group_name);
					}
				}
			}
		}
	}
}