Esempio n. 1
0
void
purple_conversations_add(PurpleConversation *conv)
{
	PurpleAccount *account;
	struct _purple_hconv *hc;

	g_return_if_fail(conv != NULL);

	if (g_list_find(conversations, conv) != NULL)
		return;

	conversations = g_list_prepend(conversations, conv);

	if (PURPLE_IS_IM_CONVERSATION(conv))
		ims = g_list_prepend(ims, conv);
	else
		chats = g_list_prepend(chats, conv);

	account = purple_conversation_get_account(conv);

	hc = g_new(struct _purple_hconv, 1);
	hc->name = g_strdup(purple_normalize(account,
				purple_conversation_get_name(conv)));
	hc->account = account;
	hc->im = PURPLE_IS_IM_CONVERSATION(conv);

	g_hash_table_insert(conversation_cache, hc, conv);
}
Esempio n. 2
0
GList *
otrg_conversation_get_contexts(PurpleConversation *conv)
{
	PurpleAccount *account;
	const gchar *accountname, *protocol;
	gchar *username;
	ConnContext *it = NULL;
	GList *contexts = NULL;

	g_return_val_if_fail(conv != NULL, NULL);

	g_return_val_if_fail(PURPLE_IS_IM_CONVERSATION(conv), NULL);

	account = purple_conversation_get_account(conv);
	accountname = purple_account_get_username(account);
	protocol = purple_account_get_protocol_id(account);
	username = g_strdup(purple_normalize(account,
		purple_conversation_get_name(conv)));

	for (it = otrg_plugin_userstate->context_root; it; it = it->next) {
		if (g_strcmp0(it->accountname, accountname) != 0)
			continue;
		if (g_strcmp0(it->protocol, protocol) != 0)
			continue;
		if (g_strcmp0(it->username, username) != 0)
			continue;
		contexts = g_list_append(contexts, it);
	}

	g_free(username);

	return contexts;
}
Esempio n. 3
0
void
_purple_conversations_update_cache(PurpleConversation *conv, const char *name,
		PurpleAccount *account)
{
	PurpleAccount *old_account;
	struct _purple_hconv *hc;

	g_return_if_fail(conv != NULL);
	g_return_if_fail(account != NULL || name != NULL);

	old_account = purple_conversation_get_account(conv);

	hc = g_new(struct _purple_hconv, 1);
	hc->im = PURPLE_IS_IM_CONVERSATION(conv);
	hc->account = old_account;
	hc->name = (gchar *)purple_normalize(old_account,
				purple_conversation_get_name(conv));

	g_hash_table_remove(conversation_cache, hc);

	if (account)
		hc->account = account;
	if (name)
		hc->name = g_strdup(purple_normalize(hc->account, name));

	g_hash_table_insert(conversation_cache, hc, conv);
}
Esempio n. 4
0
PurpleBuddy *
otrg_purple_conversation_get_buddy(PurpleConversation *conv)
{
	if (!PURPLE_IS_IM_CONVERSATION(conv))
		return NULL;

	return purple_blist_find_buddy(
		purple_conversation_get_account(conv),
		purple_conversation_get_name(conv));
}
Esempio n. 5
0
gboolean
otrg_conversation_is_otr_enabled(PurpleConversation *conv)
{
	g_return_val_if_fail(conv != NULL, FALSE);

	if (!PURPLE_IS_IM_CONVERSATION(conv))
		return FALSE;

	return (otrg_conv_get_data(conv, "otr-conv_to_idx") != NULL);
}
Esempio n. 6
0
static gchar *
conversation_id(PurpleConversation *conv)
{
	PurpleAccount *account = purple_conversation_get_account(conv);

	return g_strconcat((PURPLE_IS_IM_CONVERSATION(conv) ? "im" :
				PURPLE_IS_CHAT_CONVERSATION(conv) ? "chat" : "misc"), ":",
			purple_conversation_get_name(conv), ":",
			purple_account_get_username(account), ":",
			purple_account_get_protocol_id(account), NULL);
}
Esempio n. 7
0
/*------------------------------------------------------------------------
 * This gets called when a new chat conversation is opened by the user
 *
 *  @param conv				The conversation object
 *  @param session			The MXit session object
 */
static void mxit_cb_chat_created( PurpleConversation* conv, struct MXitSession* session )
{
	PurpleConnection*	gc;
	struct contact*		contact;
	PurpleBuddy*		buddy;
	const char*			who;
	char*				tmp;

	gc = purple_conversation_get_connection( conv );
	if ( session->con != gc ) {
		/* not our conversation */
		return;
	}
	else if ( !PURPLE_IS_IM_CONVERSATION( conv ) ) {
		/* wrong type of conversation */
		return;
	}

	/* get the contact name */
	who = purple_conversation_get_name( conv );
	if ( !who )
		return;

	purple_debug_info( MXIT_PLUGIN_ID, "Conversation started with '%s'\n", who );

	/* find the buddy object */
	buddy = purple_blist_find_buddy( session->acc, who );
	if ( !buddy )
		return;

	contact = purple_buddy_get_protocol_data( buddy );
	if ( !contact )
		return;

	/* we ignore all conversations with which we have chatted with in this session */
	if ( find_active_chat( session->active_chats, who ) )
		return;

	/* determine if this buddy is a MXit service */
	switch ( contact->type ) {
		case MXIT_TYPE_BOT :
		case MXIT_TYPE_CHATROOM :
		case MXIT_TYPE_GALLERY :
		case MXIT_TYPE_INFO :
				tmp = g_strdup_printf("<font color=\"#999999\">%s</font>\n", _( "Loading menu..." ));
				purple_serv_got_im( session->con, who, tmp, PURPLE_MESSAGE_NOTIFY, time( NULL ) );
				g_free( tmp );
				mxit_send_message( session, who, " ", FALSE, FALSE );
		default :
				break;
	}
}
Esempio n. 8
0
void
purple_conversations_remove(PurpleConversation *conv)
{
	PurpleAccount *account;
	struct _purple_hconv hc;

	g_return_if_fail(conv != NULL);

	conversations = g_list_remove(conversations, conv);

	if (PURPLE_IS_IM_CONVERSATION(conv))
		ims = g_list_remove(ims, conv);
	else
		chats = g_list_remove(chats, conv);

	account = purple_conversation_get_account(conv);

	hc.name = (gchar *)purple_normalize(account,
				purple_conversation_get_name(conv));
	hc.account = account;
	hc.im = PURPLE_IS_IM_CONVERSATION(conv);

	g_hash_table_remove(conversation_cache, &hc);
}
Esempio n. 9
0
int irc_cmd_ctcp_action(struct irc_conn *irc, const char *cmd, const char *target, const char **args)
{
	PurpleConnection *gc = purple_account_get_connection(irc->account);
	char *action, *escaped, *dst, **newargs;
	const char *src;
	char *msg;
	PurpleConversation *convo;
	PurpleMessage *pmsg;

	if (!args || !args[0] || !gc)
		return 0;

	convo = purple_conversations_find_with_account(target, irc->account);

	msg = g_strdup_printf("/me %s", args[0]);

	/* XXX: we'd prefer to keep this in conversation.c */
	if (PURPLE_IS_IM_CONVERSATION(convo)) {
		pmsg = purple_message_new_outgoing(
			purple_conversation_get_name(convo), msg, 0);

		purple_signal_emit(purple_conversations_get_handle(),
			"sending-im-msg", irc->account, pmsg);
	} else {
		pmsg = purple_message_new_outgoing(NULL, msg, 0);

		purple_signal_emit(purple_conversations_get_handle(),
			"sending-chat-msg", irc->account, pmsg,
			purple_chat_conversation_get_id(PURPLE_CHAT_CONVERSATION(convo)));
	}

	g_free(msg);
	if (purple_message_is_empty(pmsg))
		return 0;
	msg = g_strdup(purple_message_get_contents(pmsg)); /* XXX: is it really necessary? */

	if (strncmp(msg, "/me ", 4) != 0) {
		newargs = g_new0(char *, 2);
		newargs[0] = g_strdup(target);
		newargs[1] = msg;

		irc_cmd_privmsg(irc, cmd, target, (const char **)newargs);

		g_free(newargs[0]);
		g_free(newargs);
	} else {
Esempio n. 10
0
static int
notify(PurpleConversation *conv, gboolean increment)
{
	gint count;
	gboolean has_focus;
	PidginConvWindow *purplewin = NULL;

	if (conv == NULL || PIDGIN_CONVERSATION(conv) == NULL)
		return 0;

	/* We want to remove the notifications, but not reset the counter */
	unnotify(conv, FALSE);

	purplewin = PIDGIN_CONVERSATION(conv)->win;

	/* If we aren't doing notifications for this type of conversation, return */
	if ((PURPLE_IS_IM_CONVERSATION(conv) &&
	     !purple_prefs_get_bool("/plugins/gtk/X11/notify/type_im")) ||
	    (PURPLE_IS_CHAT_CONVERSATION(conv) &&
	     !purple_prefs_get_bool("/plugins/gtk/X11/notify/type_chat")))
		return 0;

	g_object_get(G_OBJECT(purplewin->window),
	             "has-toplevel-focus", &has_focus, NULL);

	if (purple_prefs_get_bool("/plugins/gtk/X11/notify/type_focused") ||
	    !has_focus) {
		if (increment) {
			count = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(conv), "notify-message-count"));
			count++;
			g_object_set_data(G_OBJECT(conv), "notify-message-count", GINT_TO_POINTER(count));
		}

		notify_win(purplewin, conv);
	}

	return 0;
}
Esempio n. 11
0
static void historize(PurpleConversation *c)
{
	PurpleAccount *account = purple_conversation_get_account(c);
	const char *name = purple_conversation_get_name(c);
	GList *logs = NULL;
	const char *alias = name;
	guint flags;
	char *history;
	PidginConversation *gtkconv;
#if 0
	/* FIXME: WebView has no options */
	GtkIMHtmlOptions options = GTK_IMHTML_NO_COLOURS;
#endif
	char *header;
#if 0
	/* FIXME: WebView has no protocol setting */
	char *protocol;
#endif
	char *escaped_alias;
	const char *header_date;

	gtkconv = PIDGIN_CONVERSATION(c);
	g_return_if_fail(gtkconv != NULL);

	/* An IM which is the first active conversation. */
	g_return_if_fail(gtkconv->convs != NULL);
	if (PURPLE_IS_IM_CONVERSATION(c) && !gtkconv->convs->next)
	{
		GSList *buddies;
		GSList *cur;

		/* If we're not logging, don't show anything.
		 * Otherwise, we might show a very old log. */
		if (!purple_prefs_get_bool("/purple/logging/log_ims"))
			return;

		/* Find buddies for this conversation. */
		buddies = purple_blist_find_buddies(account, name);

		/* If we found at least one buddy, save the first buddy's alias. */
		if (buddies != NULL)
			alias = purple_buddy_get_contact_alias(PURPLE_BUDDY(buddies->data));

		for (cur = buddies; cur != NULL; cur = cur->next)
		{
			PurpleBlistNode *node = cur->data;
			PurpleBlistNode *prev = purple_blist_node_get_sibling_prev(node);
			PurpleBlistNode *next = purple_blist_node_get_sibling_next(node);
			if ((node != NULL) && ((prev != NULL) || (next != NULL)))
			{
				PurpleBlistNode *node2;
				PurpleBlistNode *parent = purple_blist_node_get_parent(node);
				PurpleBlistNode *child = purple_blist_node_get_first_child(parent);

				alias = purple_buddy_get_contact_alias(PURPLE_BUDDY(node));

				/* We've found a buddy that matches this conversation.  It's part of a
				 * PurpleContact with more than one PurpleBuddy.  Loop through the PurpleBuddies
				 * in the contact and get all the logs. */
				for (node2 = child ; node2 != NULL ; node2 = purple_blist_node_get_sibling_next(node2))
				{
					logs = g_list_concat(purple_log_get_logs(PURPLE_LOG_IM,
							purple_buddy_get_name(PURPLE_BUDDY(node2)),
							purple_buddy_get_account(PURPLE_BUDDY(node2))),
							logs);
				}
				break;
			}
		}
		g_slist_free(buddies);

		if (logs == NULL)
			logs = purple_log_get_logs(PURPLE_LOG_IM, name, account);
		else
			logs = g_list_sort(logs, purple_log_compare);
	}
	else if (PURPLE_IS_CHAT_CONVERSATION(c))
	{
		/* If we're not logging, don't show anything.
		 * Otherwise, we might show a very old log. */
		if (!purple_prefs_get_bool("/purple/logging/log_chats"))
			return;

		logs = purple_log_get_logs(PURPLE_LOG_CHAT, name, account);
	}

	if (logs == NULL)
		return;

	history = purple_log_read((PurpleLog*)logs->data, &flags);
	gtkconv = PIDGIN_CONVERSATION(c);
#if 0
	/* FIXME: WebView has no options */
	if (flags & PURPLE_LOG_READ_NO_NEWLINE)
		options |= GTK_IMHTML_NO_NEWLINE;
#endif

#if 0
	/* FIXME: WebView has no protocol setting */
	protocol = g_strdup(gtk_imhtml_get_protocol_name(GTK_IMHTML(gtkconv->imhtml)));
	gtk_imhtml_set_protocol_name(GTK_IMHTML(gtkconv->imhtml),
			purple_account_get_protocol_name(((PurpleLog*)logs->data)->account));
#endif

#if 0
	/* TODO WebKit: Do this properly... */
	if (!pidgin_webview_is_empty(PIDGIN_WEBVIEW(gtkconv->webview)))
		pidgin_webview_append_html(PIDGIN_WEBVIEW(gtkconv->webview), "<BR>");
#endif

	escaped_alias = g_markup_escape_text(alias, -1);

	if (((PurpleLog *)logs->data)->tm)
		header_date = purple_date_format_full(((PurpleLog *)logs->data)->tm);
	else
		header_date = purple_date_format_full(localtime(&((PurpleLog *)logs->data)->time));

	header = g_strdup_printf(_("<b>Conversation with %s on %s:</b><br>"), escaped_alias, header_date);
	pidgin_webview_append_html(PIDGIN_WEBVIEW(gtkconv->webview), header);
	g_free(header);
	g_free(escaped_alias);

	g_strchomp(history);
	pidgin_webview_append_html(PIDGIN_WEBVIEW(gtkconv->webview), history);
	g_free(history);

	pidgin_webview_append_html(PIDGIN_WEBVIEW(gtkconv->webview), "<hr>");

#if 0
	/* FIXME: WebView has no protocol setting */
	gtk_imhtml_set_protocol_name(GTK_IMHTML(gtkconv->imhtml), protocol);
	g_free(protocol);
#endif

	g_object_ref(G_OBJECT(gtkconv->webview));
	g_idle_add(_scroll_webview_to_end, gtkconv->webview);

	g_list_foreach(logs, (GFunc)purple_log_free, NULL);
	g_list_free(logs);
}