Example #1
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 #2
0
static void
adc_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd)
{
    MsnSession *session;
    PecanContact *user = NULL;
    const gchar *list = NULL;
    const gchar *passport = NULL;
    gchar *friendly = NULL;
    const gchar *user_guid = NULL;
    const gchar *group_guid = NULL;
    MsnListId list_id;
    guint i = 1;

    list = cmd->params[i++];

    for (; i < cmd->param_count; i++)
    {
        const char *chopped_str;

        chopped_str = cmd->params[i] + 2;

        /* Check for Name/email. */
        if (strncmp (cmd->params[i], "N=", 2) == 0)
            passport = chopped_str;
        /* Check for Friendlyname. */
        else if (strncmp (cmd->params[i], "F=", 2) == 0)
            friendly = pecan_url_decode (chopped_str);
        /* Check for Contact GUID. */
        else if (strncmp (cmd->params[i], "C=", 2) == 0)
            user_guid = chopped_str;
        else
            break;
    }

    group_guid = cmd->params[i++];

    session = cmdproc->session;

    if (passport)
        user = pecan_contactlist_find_contact (session->contactlist, passport);
    else if (user_guid)
        user = pecan_contactlist_find_contact_by_guid (session->contactlist, user_guid);

    if (user == NULL)
    {
        user = pecan_contact_new (session->contactlist);
        pecan_contact_set_passport (user, passport);
    }

    list_id = msn_get_list_id(list);

    if (list_id == MSN_LIST_FL)
        pecan_contact_set_guid (user, user_guid);

    msn_got_add_contact(session, user, list_id, group_guid);

    /* There is a user that must me moved to this group */
    if (cmd->trans && cmd->trans->data)
    {
        MsnAddBuddy *data = cmd->trans->data;

        msn_notification_add_buddy (session->notification, "FL", data->who,
                                    user_guid, friendly, data->group_guid);

        g_free (data->who);
        g_free (data->group_guid);
    }

    pecan_contact_update(user);

    g_free (friendly);
}