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;
}
int yahoo_c_send(PurpleConnection *gc, int id, PurpleMessage *msg)
{
	PurpleChatConversation *c;
	int ret;
	YahooData *yd;
	const gchar *what = purple_message_get_contents(msg);
	PurpleMessageFlags flags = purple_message_get_flags(msg);

	yd = purple_connection_get_protocol_data(gc);
	if (!yd)
		return -1;

	c = purple_conversations_find_chat(gc, id);
	if (!c)
		return -1;

	if (id != YAHOO_CHAT_ID) {
		GList *users;
		users = purple_chat_conversation_get_users(c);
		ret = yahoo_conf_send(gc,
			purple_connection_get_display_name(gc),
			purple_conversation_get_name(PURPLE_CONVERSATION(c)),
			users, what);
		g_list_free(users);
	} else {
		ret = yahoo_chat_send(gc, purple_connection_get_display_name(gc),
						purple_conversation_get_name(PURPLE_CONVERSATION(c)), what, flags);
		if (!ret)
			purple_serv_got_chat_in(gc, purple_chat_conversation_get_id(c),
					purple_connection_get_display_name(gc), flags, what, time(NULL));
	}
	return ret;
}
Beispiel #3
0
static gboolean
message_displayed_cb(PurpleConversation *conv, PurpleMessage *msg, gpointer _unused)
{
	PurpleMessageFlags flags = purple_message_get_flags(msg);

	if ((PURPLE_IS_CHAT_CONVERSATION(conv) && alert_chat_nick &&
			!(flags & PURPLE_MESSAGE_NICK)))
		return FALSE;

	if ((flags & PURPLE_MESSAGE_RECV) && !(flags & PURPLE_MESSAGE_DELAYED))
		alert(conv);

	return FALSE;
}
Beispiel #4
0
static void wrote_msg(PurpleConversation *conv, PurpleMessage *pmsg,
	gpointer _unused)
{
	GList *urls;

	if (purple_message_get_flags(pmsg) & PURPLE_MESSAGE_SEND)
		return;

	urls = g_object_get_data(G_OBJECT(conv), "TinyURLs");
	if (urls == NULL)
		return;

	process_urls(conv, urls);
	g_object_set_data(G_OBJECT(conv), "TinyURLs", NULL);
}
Beispiel #5
0
static gboolean writing_msg(PurpleConversation *conv, PurpleMessage *msg, gpointer _unused)
{
	GString *t;
	GList *iter, *urls, *next;
	int c = 0;

	if (purple_message_get_flags(msg) & (PURPLE_MESSAGE_SEND | PURPLE_MESSAGE_INVISIBLE))
		return FALSE;

	urls = g_object_get_data(G_OBJECT(conv), "TinyURLs");
	if (urls != NULL) /* message was cancelled somewhere? Reset. */
		g_list_foreach(urls, free_urls, NULL);
	g_list_free(urls);
	urls = extract_urls(purple_message_get_contents(msg));
	if (!urls)
		return FALSE;

	t = g_string_new(g_strdup(purple_message_get_contents(msg)));
	for (iter = urls; iter; iter = next) {
		next = iter->next;
		if (g_utf8_strlen((char *)iter->data, -1) >= purple_prefs_get_int(PREF_LENGTH)) {
			int pos, x = 0;
			gchar *j, *s, *str, *orig;
			glong len = g_utf8_strlen(iter->data, -1);
			s = g_strdup(t->str);
			orig = s;
			str = g_strdup_printf("[%d]", ++c);
			while ((j = strstr(s, iter->data))) { /* replace all occurrences */
				pos = j - orig + (x++ * 3);
				s = j + len;
				t = g_string_insert(t, pos + len, str);
				if (*s == '\0') break;
			}
			g_free(orig);
			g_free(str);
			continue;
		} else {
			g_free(iter->data);
			urls = g_list_delete_link(urls, iter);
		}
	}
	purple_message_set_contents(msg, t->str);
	g_string_free(t, TRUE);
	if (conv != NULL)
		g_object_set_data(G_OBJECT(conv), "TinyURLs", urls);
	return FALSE;
}