#include <stdlib.h>
#include <glib/gstdio.h>
+#include <telepathy-glib/util.h>
+
#include "empathy-log-manager.h"
#include "empathy-log-source-empathy.h"
#include "empathy-log-source.h"
return g_object_new (EMPATHY_TYPE_LOG_MANAGER, NULL);
}
-void
+gboolean
empathy_log_manager_add_message (EmpathyLogManager *manager,
const gchar *chat_id,
gboolean chatroom,
- EmpathyMessage *message)
+ EmpathyMessage *message,
+ GError **error)
{
EmpathyLogManagerPriv *priv;
GList *l;
+ gboolean out = FALSE;
+ gboolean found = FALSE;
- g_return_if_fail (EMPATHY_IS_LOG_MANAGER (manager));
- g_return_if_fail (chat_id != NULL);
- g_return_if_fail (EMPATHY_IS_MESSAGE (message));
+ /* TODO: When multiple log sources appear with add_message implementations
+ * make this customisable. */
+ const gchar *add_source = "Empathy";
+
+ g_return_val_if_fail (EMPATHY_IS_LOG_MANAGER (manager), FALSE);
+ g_return_val_if_fail (chat_id != NULL, FALSE);
+ g_return_val_if_fail (EMPATHY_IS_MESSAGE (message), FALSE);
priv = GET_PRIV (manager);
for (l = priv->sources; l; l = l->next)
{
- empathy_log_source_add_message (EMPATHY_LOG_SOURCE (l->data),
- chat_id, chatroom, message);
+ if (!tp_strdiff (empathy_log_source_get_name (
+ EMPATHY_LOG_SOURCE (l->data)), add_source))
+ {
+ out = empathy_log_source_add_message (EMPATHY_LOG_SOURCE (l->data),
+ chat_id, chatroom, message, error);
+ found = TRUE;
+ break;
+ }
}
+
+ if (!found)
+ DEBUG ("Failed to find chosen log source to write to.");
+
+ return out;
}
gboolean
GType empathy_log_manager_get_type (void) G_GNUC_CONST;
EmpathyLogManager *empathy_log_manager_dup_singleton (void);
-void empathy_log_manager_add_message (EmpathyLogManager *manager,
- const gchar *chat_id, gboolean chatroom, EmpathyMessage *message);
+gboolean empathy_log_manager_add_message (EmpathyLogManager *manager,
+ const gchar *chat_id, gboolean chatroom, EmpathyMessage *message,
+ GError **error);
gboolean empathy_log_manager_exists (EmpathyLogManager *manager,
McAccount *account, const gchar *chat_id, gboolean chatroom);
GList *empathy_log_manager_get_dates (EmpathyLogManager *manager,
return filename;
}
-static void
+static gboolean
log_source_empathy_add_message (EmpathyLogSource *self,
const gchar *chat_id,
gboolean chatroom,
- EmpathyMessage *message)
+ EmpathyMessage *message,
+ GError **error)
{
FILE *file;
McAccount *account;
gchar *contact_id;
TpChannelTextMessageType msg_type;
- g_return_if_fail (EMPATHY_IS_LOG_SOURCE (self));
- g_return_if_fail (chat_id != NULL);
- g_return_if_fail (EMPATHY_IS_MESSAGE (message));
+ g_return_val_if_fail (EMPATHY_IS_LOG_SOURCE (self), FALSE);
+ g_return_val_if_fail (chat_id != NULL, FALSE);
+ g_return_val_if_fail (EMPATHY_IS_MESSAGE (message), FALSE);
sender = empathy_message_get_sender (message);
account = empathy_contact_get_account (sender);
msg_type = empathy_message_get_tptype (message);
if (G_STR_EMPTY (body_str))
- return;
+ return FALSE;
filename = log_source_empathy_get_filename (self, account, chat_id, chatroom);
basedir = g_path_get_dirname (filename);
g_free (timestamp);
g_free (body);
g_free (avatar_token);
+
+ return TRUE;
}
static gboolean
-void
+gboolean
empathy_log_source_add_message (EmpathyLogSource *self,
const gchar *chat_id,
gboolean chatroom,
- EmpathyMessage *message)
+ EmpathyMessage *message,
+ GError **error)
{
if (!EMPATHY_LOG_SOURCE_GET_INTERFACE (self)->add_message)
- return;
+ return FALSE;
- EMPATHY_LOG_SOURCE_GET_INTERFACE (self)->add_message (
- self, chat_id, chatroom, message);
+ return EMPATHY_LOG_SOURCE_GET_INTERFACE (self)->add_message (
+ self, chat_id, chatroom, message, error);
}
GList *
const gchar * (*get_name) (EmpathyLogSource *self);
gboolean (*exists) (EmpathyLogSource *self, McAccount *account,
const gchar *chat_id, gboolean chatroom);
- void (*add_message) (EmpathyLogSource *self, const gchar *chat_id,
- gboolean chatroom, EmpathyMessage *message);
+ gboolean (*add_message) (EmpathyLogSource *self, const gchar *chat_id,
+ gboolean chatroom, EmpathyMessage *message, GError **error);
GList * (*get_dates) (EmpathyLogSource *self, McAccount *account,
const gchar *chat_id, gboolean chatroom);
GList * (*get_messages_for_date) (EmpathyLogSource *self,
const gchar *empathy_log_source_get_name (EmpathyLogSource *self);
gboolean empathy_log_source_exists (EmpathyLogSource *self,
McAccount *account, const gchar *chat_id, gboolean chatroom);
-void empathy_log_source_add_message (EmpathyLogSource *self,
- const gchar *chat_id, gboolean chatroom, EmpathyMessage *message);
+gboolean empathy_log_source_add_message (EmpathyLogSource *self,
+ const gchar *chat_id, gboolean chatroom, EmpathyMessage *message,
+ GError **error);
GList *empathy_log_source_get_dates (EmpathyLogSource *self,
McAccount *account, const gchar *chat_id, gboolean chatroom);
GList *empathy_log_source_get_messages_for_date (EmpathyLogSource *self,
{
EmpathyLogManager *log_manager;
EmpathyContact *contact;
+ GError *error = NULL;
contact = empathy_tp_chat_get_remote_contact (tp_chat);
log_manager = empathy_log_manager_dup_singleton ();
- empathy_log_manager_add_message (log_manager,
- empathy_contact_get_id (contact), is_chatroom, message);
+ if (!empathy_log_manager_add_message (log_manager,
+ empathy_contact_get_id (contact),
+ is_chatroom,
+ message,
+ &error)) {
+ DEBUG ("Failed to write message: %s",
+ error ? error->message : "No error message");
+ }
+
g_object_unref (contact);
g_object_unref (log_manager);