/soc/2015/igor.gajowiak/chatlog: 3efc9ae96ea1: Implemented loggi...

Igor Gajowiak igor.gajowiak at gmail.com
Mon Aug 10 17:46:48 EDT 2015


Changeset: 3efc9ae96ea1aa17a51461345334ba90b80d98b3
Author:	 Igor Gajowiak <igor.gajowiak at gmail.com>
Date:	 2015-08-10 23:46 +0200
Branch:	 default
URL: https://hg.pidgin.im/soc/2015/igor.gajowiak/chatlog/rev/3efc9ae96ea1

Description:

Implemented logging chat messages. Replaced PurpleBuddy with PurpleBListNode in the log's interface.

diffstat:

 libpurple/conversation.c          |   14 +-
 libpurple/genericlog.c            |   66 ++++-
 libpurple/genericlog.h            |   99 +++++----
 libpurple/plugins/log/legacylog.c |   28 ++-
 libpurple/plugins/log/logsqlite.c |  377 ++++++++++++++++++++-----------------
 pidgin/gtkgenericlog.c            |  165 ++++++++++------
 pidgin/gtkgenericlog.h            |    4 +-
 7 files changed, 442 insertions(+), 311 deletions(-)

diffs (truncated from 1774 to 300 lines):

diff --git a/libpurple/conversation.c b/libpurple/conversation.c
--- a/libpurple/conversation.c
+++ b/libpurple/conversation.c
@@ -623,8 +623,20 @@ void
 			log = log->next;
 		}
 
+		PurpleBlistNode *contact = NULL;
+		if (PURPLE_IS_CHAT_CONVERSATION(conv)) {
+			contact = PURPLE_BLIST_NODE(purple_blist_find_chat(account,
+				purple_conversation_get_name(conv)));
+		}
+		else {
+			contact = PURPLE_BLIST_NODE(purple_blist_find_buddy(account,
+				(purple_message_get_flags(pmsg) & PURPLE_MESSAGE_SEND) ?
+				purple_message_get_recipient(pmsg) :
+				purple_message_get_author(pmsg)));
+		}
+
 		GError *error;
-		if (!purple_genericlog_logim(account, pmsg, &error)) {
+		if (!purple_genericlog_log_msg(account, contact, pmsg, &error)) {
 			purple_debug_error("conversation", "Logging failed: %s (code=%d)",
 				error->message, error->code);
 			g_error_free(error);
diff --git a/libpurple/genericlog.c b/libpurple/genericlog.c
--- a/libpurple/genericlog.c
+++ b/libpurple/genericlog.c
@@ -246,12 +246,28 @@ purple_genericlog_set_active_log(PurpleG
 																  \
 	return TRUE;
 
+#ifdef GENERICLOG_CHECK_CONTACT
+# error "GENERICLOG_CHECK_CONTACT is already defined"
+#endif
+#define GENERICLOG_CHECK_CONTACT(contact)                             \
+	if (!PURPLE_IS_BUDDY(contact) && !PURPLE_IS_CHAT(contact)) {      \
+		if (error) {                                                  \
+			*error = g_error_new(purple_genericlog_error_domain(),    \
+				PURPLE_GENERICLOG_ERROR_INTERNAL,                     \
+				"The contact is neither PurpleBuddy nor PurpleChat"); \
+		}                                                             \
+		return FALSE;                                                 \
+	}
+
 gboolean
-purple_genericlog_logim(PurpleAccount *account, PurpleMessage *msg,
-	GError **error)
+purple_genericlog_log_msg(PurpleAccount *account, PurpleBlistNode *contact,
+	PurpleMessage *msg, GError **error)
 {
-	DEFINE_GENERICLOG_FUNC_WITH_RETURN(log_im, "%s does not support IM logging",
-		"Failed to log IM in %s", account, msg);
+	GENERICLOG_CHECK_CONTACT(contact);
+
+	DEFINE_GENERICLOG_FUNC_WITH_RETURN(log_msg,
+		"%s does not support IM logging",
+		"Failed to log IM in %s", account, contact, msg);
 }
 
 gboolean
@@ -272,22 +288,26 @@ purple_genericlog_get_unseen_msgs(Purple
 }
 
 gboolean
-purple_genericlog_get_all_msgs(PurpleBuddy *buddy, guint64 day, GList **result,
-	GError **error)
+purple_genericlog_get_all_msgs(PurpleBlistNode *contact, guint64 day,
+	GList **result, GError **error)
 {
+	GENERICLOG_CHECK_CONTACT(contact);
+
 	DEFINE_GENERICLOG_FUNC_WITH_RETURN(get_all_msgs,
 		"%s does not support getting all messages",
-		"Getting all messages from %s failed", buddy, day, result);
+		"Getting all messages from %s failed", contact, day, result);
 }
 
 gboolean
-purple_genericlog_get_older_msgs(PurpleBuddy *buddy, guint64 timestamp,
+purple_genericlog_get_older_msgs(PurpleBlistNode *contact, guint64 timestamp,
 	PurpleMessage *message, GList **result, GError **error)
 {
+	GENERICLOG_CHECK_CONTACT(contact);
+
 	DEFINE_GENERICLOG_FUNC_WITH_RETURN(get_older_msgs,
 		"%s does not support getting older messages",
 		"Getting older messages from %s failed",
-		buddy, timestamp, message, result);
+		contact, timestamp, message, result);
 }
 
 gboolean
@@ -299,22 +319,27 @@ purple_genericlog_get_all_buddies(GList*
 }
 
 gboolean
-purple_genericlog_get_all_days(PurpleBuddy *buddy, GArray **result,
+purple_genericlog_get_all_days(PurpleBlistNode *contact, GArray **result,
 	GError **error)
 {
+	GENERICLOG_CHECK_CONTACT(contact);
+
 	DEFINE_GENERICLOG_FUNC_WITH_RETURN(get_all_days,
 		"%s does not support getting all days",
-		"Getting all days from %s failed", buddy, result);
+		"Getting all days from %s failed", contact, result);
 }
 
 gboolean
-purple_genericlog_wipe_log_for_buddy(PurpleBuddy *buddy, GError **error)
+purple_genericlog_wipe_log_for_contact(PurpleBlistNode *contact, GError **error)
 {
-	DEFINE_GENERICLOG_FUNC_WITH_RETURN(wipe_log_for_buddy,
+	GENERICLOG_CHECK_CONTACT(contact);
+
+	DEFINE_GENERICLOG_FUNC_WITH_RETURN(wipe_log_for_contact,
 		"%s does not support removing messages",
-		"Removing messages from %s failed", buddy);
+		"Removing messages from %s failed", contact);
 }
 
+#undef GENERICLOG_CHECK_CONTACT
 #undef DEFINE_GENERICLOG_FUNC_WITH_RETURN
 
 static void
@@ -345,11 +370,14 @@ run_import_iteration(gpointer unused)
 	GArray *accounts = g_array_new(FALSE, FALSE, sizeof(PurpleAccount*));
 	g_array_set_clear_func(accounts, unref_g_object_pointee);
 
+	GArray *contacts = g_array_new(FALSE, FALSE, sizeof(PurpleBlistNode*));
+	g_array_set_clear_func(contacts, unref_g_object_pointee);
+
 	GArray *messages = g_array_new(FALSE, FALSE, sizeof(PurpleMessage*));
 	g_array_set_clear_func(messages, unref_g_object_pointee);
 
 	gboolean status = klass->read_chunk(import_state->export_state,
-		PURPLE_GENERICLOG_IMPORT_CHUNK_SIZE, accounts, messages);
+		PURPLE_GENERICLOG_IMPORT_CHUNK_SIZE, accounts, contacts, messages);
 
 	if (!status || messages->len == 0) {
 		g_array_unref(accounts);
@@ -371,14 +399,16 @@ run_import_iteration(gpointer unused)
 
 	for (guint i = 0; i < messages->len; ++i) {
 		PurpleAccount *account = g_array_index(accounts, PurpleAccount*, i);
+		PurpleBlistNode *contact = g_array_index(contacts, PurpleBlistNode*, i);
 		PurpleMessage *message = g_array_index(messages, PurpleMessage*, i);
 
 		/* Should we stop if logging fails? */
-		if (purple_genericlog_logim(account, message, NULL))
+		if (purple_genericlog_log_msg(account, contact, message, NULL))
 			++(import_state->imported_messages_count);
 	}
 
 	g_array_free(accounts, TRUE);
+	g_array_free(contacts, TRUE);
 	g_array_free(messages, TRUE);
 
 	return TRUE;
@@ -528,14 +558,14 @@ purple_genericlog_class_init(PurpleGener
 	 */
 	klass->activate = NULL;
 	klass->deactivate = NULL;
-	klass->log_im = NULL;
+	klass->log_msg = NULL;
 	klass->mark_as_seen = NULL;
 	klass->get_unseen_msgs = NULL;
 	klass->get_all_msgs = NULL;
 	klass->get_older_msgs = NULL;
 	klass->get_all_buddies = NULL;
 	klass->get_all_days = NULL;
-	klass->wipe_log_for_buddy = NULL;
+	klass->wipe_log_for_contact = NULL;
 	klass->init_export = NULL;
 	klass->read_chunk = NULL;
 	klass->finalize_export = NULL;
diff --git a/libpurple/genericlog.h b/libpurple/genericlog.h
--- a/libpurple/genericlog.h
+++ b/libpurple/genericlog.h
@@ -52,7 +52,7 @@ struct _PurpleGenericLog
  * @activate:        Activates this log. Returns %TRUE if activation
  *                   succeds, %FALSE otherwise.
  * @deactivate:      Deactivates this log. This method never fails.
- * @log_im:          Logs a message. Returns %TRUE if logging succeeds,
+ * @log_msg          Logs a message. Returns %TRUE if logging succeeds,
  *                   %FALSE otherwise.
  * @mark_as_seen:    Marks a message as seen. Returns %TRUE if
  *                   operation succeeds, %FALSE otherwise.
@@ -61,30 +61,34 @@ struct _PurpleGenericLog
  *                   In case of any error the result is not set.
  *                   The client is responsible for freeing the result with
  *                   g_list_free_full(result, g_object_unref).
- * @get_all_msgs:    Gets all messages sent to or received from a buddy on
- *                   a given day. Messages are sorted by their timestamp
- *                   in ascending order. Returns %TRUE if operation succeeds,
- *                   %FALSE otherwise. In case of any error the result is not
- *                   set. The client is responsible for freeing the result with
+ * @get_all_msgs:    Gets all messages sent to or received from a
+ *                   contact (PurpleChat or PurpleBuddy) on a given day.
+ *                   Messages are sorted by their timestamp in ascending order.
+ *                   Returns %TRUE if operation succeeds, %FALSE otherwise.
+ *                   In case of any error the result is not set. The client is
+ *                   responsible for freeing the result using
  *                   g_list_free_full(result, g_object_unref).
- * @get_older_msgs:  Gets all messages sent to or received from a buddy, older
- *                   than the message and not older than the timestamp.
- *                   If message is %NULL then upper bound check is skipped.
- *                   Messages are sorted by their timestamp in descending order.
+ * @get_older_msgs:  Gets all messages sent to or received from a contact
+ *                   (PurpleChat or PurpleBuddy), older than the message
+ *                   and not older than the timestamp. If message is %NULL
+ *                   then upper bound check is skipped. Messages are sorted
+ *                   by their timestamp in descending order.
  *                   Returns %TRUE if operation succeeds, %FALSE otherwise.
- * @get_all_buddies: Gets a list of all #PurpleBuddy objects with at least one
- *                   message in the log. Returns %TRUE if operation succeeds,
- *                   %FALSE otherwise. The client is responsible for freeing
- *                   the result with g_list_free_full(result, g_object_unref).
+ * @get_all_buddies: Gets a list of all #PurpleBlistNode objects with at least
+ *                   one message in the log. Returns %TRUE if operation
+ *                   succeeds, %FALSE otherwise. The client is responsible for
+ *                   freeing the result using
+ *                   g_list_free_full(result, g_object_unref).
  * @get_all_days:    Gets an array of all days with at least one message
- *                   received from or sent to a given buddy. The days are sorted
- *                   in ascending order. Day is represented as unix timestamp
+ *                   received from or sent to a given contact
+ *                   (PurpleChat or PurpleBuddy). The days are sorted
+ *                   in ascending order. Day is represented as an unix timestamp
  *                   (guint64) (at 00:00). Returns %TRUE if operation succeeds,
  *                   %FALSE otherwise. The client is responsible for freeing
  *                   the result with g_array_unref.
  * @wipe_log_for_buddy: Deletes all messages sent to or received from
- *                      a given buddy. Returns %TRUE if operation succeeds,
- *                      %FALSE otherwise.
+ *                      a given contact (PurpleChat or PurpleBuddy).
+ *                      Returns %TRUE if operation succeeds, %FALSE otherwise.
  * @init_export:     Initializes an export procedure. Plugins should store their
  *                   export state in an output parameter. The state will be used
  *                   for future calls to export_chunk. Returns %TRUE if
@@ -110,27 +114,29 @@ struct _PurpleGenericLogClass
 
 	void (*deactivate)(void);
 
-	gboolean (*log_im) (PurpleAccount *account, PurpleMessage *message);
+	gboolean (*log_msg) (PurpleAccount *account, PurpleBlistNode* contact,
+		PurpleMessage *message);
 
 	gboolean (*mark_as_seen)(PurpleMessage *message);
 
 	gboolean (*get_unseen_msgs)(PurpleAccount *account, GList **result);
 
-	gboolean (*get_all_msgs)(PurpleBuddy *buddy, guint64 day, GList **result);
+	gboolean (*get_all_msgs)(PurpleBlistNode *contact, guint64 day,
+		GList **result);
 
-	gboolean (*get_older_msgs)(PurpleBuddy *buddy, guint64 timestamp,
+	gboolean (*get_older_msgs)(PurpleBlistNode *contact, guint64 timestamp,
 		PurpleMessage *message, GList **result);
 
 	gboolean (*get_all_buddies)(GList **result);
 
-	gboolean (*get_all_days)(PurpleBuddy *buddy, GArray **result);
+	gboolean (*get_all_days)(PurpleBlistNode *contact, GArray **result);
 
-	gboolean (*wipe_log_for_buddy)(PurpleBuddy *buddy);
+	gboolean (*wipe_log_for_contact)(PurpleBlistNode *contact);
 
 	gboolean (*init_export) (void **export_state);
 
 	gboolean (*read_chunk) (void *export_state, guint chunk_size,
-		GArray *accounts, GArray *messages);
+		GArray *accounts, GArray *contacts, GArray *messages);
 
 	void (*finalize_export) (void *export_state);
 
@@ -258,17 +264,18 @@ purple_genericlog_set_active_log(PurpleG
 /**
  * purple_genericlog_logim:
  * @account: The account.
+ * @contact  The contact, must be PurpleChat or PurpleBuddy.
  * @msg:     The message.
  * @error:   Return location for a #GError or %NULL. If provided, this
  *           will be set to the reason if logging fails.
  *
- * Logs a message for a given account to the active log.
+ * Logs a message for a given account and a contact to the active log.
  *
  * Returns: %TRUE if succeeds, %FALSE otherwise.
  */
 gboolean
-purple_genericlog_logim(PurpleAccount *account, PurpleMessage *msg,
-	GError **error);
+purple_genericlog_log_msg(PurpleAccount *account, PurpleBlistNode* contact,
+	PurpleMessage *msg, GError **error);
 
 /**
  * purple_genericlog_mark_as_seen:
@@ -304,7 +311,7 @@ purple_genericlog_get_unseen_msgs(Purple



More information about the Commits mailing list