Beispiel #1
0
int ggp_chat_send(PurpleConnection *gc, int local_id, PurpleMessage *msg)
{
	GGPInfo *info = purple_connection_get_protocol_data(gc);
	PurpleChatConversation *conv;
	ggp_chat_local_info *chat;
	gboolean succ = TRUE;
	const gchar *me;
	gchar *gg_msg;

	chat = ggp_chat_get_local(gc, local_id);
	if (!chat) {
		purple_debug_error("gg", "ggp_chat_send: "
			"chat %u doesn't exists\n", local_id);
		return -1;
	}

	conv = purple_conversations_find_chat_with_account(
		ggp_chat_get_name_from_id(chat->id),
		purple_connection_get_account(gc));

	gg_msg = ggp_message_format_to_gg(PURPLE_CONVERSATION(conv),
		purple_message_get_contents(msg));

	if (gg_chat_send_message(info->session, chat->id, gg_msg, TRUE) < 0)
		succ = FALSE;
	g_free(gg_msg);

	me = purple_account_get_username(purple_connection_get_account(gc));
	purple_serv_got_chat_in(gc, chat->local_id, me,
		purple_message_get_flags(msg),
		purple_message_get_contents(msg),
		purple_message_get_time(msg));

	return succ ? 0 : -1;
}
Beispiel #2
0
int ggp_message_send_im(PurpleConnection *gc, const char *who,
	const char *message, PurpleMessageFlags flags)
{
	GGPInfo *info = purple_connection_get_protocol_data(gc);
	PurpleIMConversation *im;
	ggp_buddy_data *buddy_data;
	gchar *gg_msg;
	gboolean succ;

	/* TODO: return -ENOTCONN, if not connected */

	if (message == NULL || message[0] == '\0')
		return 0;

	buddy_data = ggp_buddy_get_data(purple_blist_find_buddy(
		purple_connection_get_account(gc), who));

	if (buddy_data->blocked)
		return -1;

	im = purple_conversations_find_im_with_account(
		who, purple_connection_get_account(gc));

	gg_msg = ggp_message_format_to_gg(PURPLE_CONVERSATION(im), message);

	/* TODO: splitting messages */
	if (strlen(gg_msg) > GG_MSG_MAXSIZE) {
		g_free(gg_msg);
		return -E2BIG;
	}

#if GGP_ENABLE_GG11
	succ = (gg_send_message_html(info->session, GG_CLASS_CHAT,
		ggp_str_to_uin(who), (unsigned char *)gg_msg) >= 0);
#else
	{
		gchar *plain = purple_markup_strip_html(gg_msg);
		succ = (gg_send_message(info->session, GG_CLASS_CHAT,
			ggp_str_to_uin(who), (unsigned char *)plain) >= 0);
		g_free(plain);
	}
#endif

	g_free(gg_msg);

	return succ ? 1 : -1;
}