diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 1 | ||||
-rw-r--r-- | src/tpl-log-entry-text.c | 16 | ||||
-rw-r--r-- | src/tpl-log-manager.c | 16 | ||||
-rw-r--r-- | src/tpl-log-store-empathy.c | 94 | ||||
-rw-r--r-- | src/tpl-log-store.c | 7 | ||||
-rw-r--r-- | src/tpl-text-channel-context.c | 110 |
6 files changed, 150 insertions, 94 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index a3a5fbf..be491a5 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -24,6 +24,7 @@ telepathy_logger_handwritten_source = \ tpl-headless-logger-init.c \ tpl-channel.c \ tpl-text-channel-context.c \ + tpl-log-entry.c \ tpl-log-entry-text.c \ tpl-contact.c \ tpl-log-manager.c \ diff --git a/src/tpl-log-entry-text.c b/src/tpl-log-entry-text.c index a2f05cf..cb036d5 100644 --- a/src/tpl-log-entry-text.c +++ b/src/tpl-log-entry-text.c @@ -65,8 +65,6 @@ tpl_log_entry_text_dispose (GObject *obj) g_debug("TplLogEntryText: disposed\n"); } - - static void tpl_log_entry_text_finalize (GObject *obj) { @@ -184,13 +182,6 @@ tpl_log_entry_text_get_direction (TplLogEntryText *self) return self->direction; } -time_t -tpl_log_entry_text_get_timestamp (TplLogEntryText *self) -{ - g_return_val_if_fail(TPL_IS_LOG_ENTRY_TEXT(self), -1); - return self->timestamp; -} - guint tpl_log_entry_text_get_message_id (TplLogEntryText *self) { @@ -268,13 +259,6 @@ void tpl_log_entry_text_set_direction (TplLogEntryText *self, TplLogEntryTextDir self->direction = data; } -void tpl_log_entry_text_set_timestamp (TplLogEntryText *self, time_t data) -{ - g_return_if_fail(TPL_IS_LOG_ENTRY_TEXT(self)); - - self->timestamp = data; -} - void tpl_log_entry_text_set_message_id (TplLogEntryText *self, guint data) { g_return_if_fail(TPL_IS_LOG_ENTRY_TEXT(self)); diff --git a/src/tpl-log-manager.c b/src/tpl-log-manager.c index 7f47b67..dce5c67 100644 --- a/src/tpl-log-manager.c +++ b/src/tpl-log-manager.c @@ -30,6 +30,7 @@ #include <telepathy-glib/util.h> #include <telepathy-glib/interfaces.h> +#include <tpl-log-entry.h> #include <tpl-log-manager.h> #include <tpl-log-store-empathy.h> #include <tpl-log-store.h> @@ -125,7 +126,7 @@ gboolean tpl_log_manager_add_message (TplLogManager *manager, const gchar *chat_id, gboolean chatroom, - TplLogEntryText *message, + TplLogEntry *message, GError **error) { TplLogManagerPriv *priv; @@ -139,7 +140,7 @@ tpl_log_manager_add_message (TplLogManager *manager, g_return_val_if_fail (TPL_IS_LOG_MANAGER (manager), FALSE); g_return_val_if_fail (chat_id != NULL, FALSE); - g_return_val_if_fail (TPL_IS_LOG_ENTRY_TEXT (message), FALSE); + g_return_val_if_fail (TPL_IS_LOG_ENTRY (message), FALSE); priv = GET_PRIV (manager); @@ -150,7 +151,6 @@ tpl_log_manager_add_message (TplLogManager *manager, { out = tpl_log_store_add_message (TPL_LOG_STORE (l->data), chat_id, chatroom, message, error); - g_message("YEAH\n"); found = TRUE; break; } @@ -252,14 +252,14 @@ static gint log_manager_message_date_cmp (gconstpointer a, gconstpointer b) { - TplLogEntryText *one = (TplLogEntryText *) a; - TplLogEntryText *two = (TplLogEntryText *) b; + TplLogEntry *one = (TplLogEntry *) a; + TplLogEntry *two = (TplLogEntry *) b; time_t one_time, two_time; - one_time = tpl_log_entry_text_get_timestamp (one); - two_time = tpl_log_entry_text_get_timestamp (two); + one_time = tpl_log_entry_get_timestamp (one); + two_time = tpl_log_entry_get_timestamp (two); - /* Return -1 of message1 is older than message2 */ + /* Return -1 of message1 is older than message2 */ return one_time < two_time ? -1 : one_time - two_time; } diff --git a/src/tpl-log-store-empathy.c b/src/tpl-log-store-empathy.c index 4137a33..65fd395 100644 --- a/src/tpl-log-store-empathy.c +++ b/src/tpl-log-store-empathy.c @@ -193,11 +193,11 @@ log_store_empathy_get_timestamp_filename (void) } static gchar * -log_store_empathy_get_timestamp_from_message (TplLogEntryText *message) +log_store_empathy_get_timestamp_from_message (TplLogEntry *message) { time_t t; - t = tpl_log_entry_text_get_timestamp (message); + t = tpl_log_entry_get_timestamp (message); /* We keep the timestamps in the messages as UTC. */ return tpl_time_to_string_utc (t, LOG_TIME_FORMAT_FULL); @@ -268,11 +268,11 @@ static gboolean _log_store_empathy_write_to_store ( TplLogStore *self, } static gboolean -_log_store_empathy_add_message_status_changed ( +_log_store_empathy_add_message_text_status_changed ( TplLogStore *self, const gchar *chat_id, gboolean chatroom, - TplLogEntryText *message, + TplLogEntry *message, GError **error) { @@ -286,10 +286,12 @@ _log_store_empathy_add_message_status_changed ( gchar *contact_presence; gchar *entry; gboolean ret = FALSE; + TplLogEntryText *tmessage; - sender = tpl_log_entry_text_get_sender (message); + tmessage = tpl_log_entry_get_entry(message); + sender = tpl_log_entry_text_get_sender (tmessage); account = tpl_channel_get_account ( - tpl_log_entry_text_get_tpl_channel (message) ); + tpl_log_entry_text_get_tpl_channel (tmessage) ); timestamp = log_store_empathy_get_timestamp_from_message (message); @@ -329,10 +331,10 @@ _log_store_empathy_add_message_status_changed ( static gboolean -_log_store_empathy_add_message_chat (TplLogStore *self, +_log_store_empathy_add_message_text_chat (TplLogStore *self, const gchar *chat_id, gboolean chatroom, - TplLogEntryText *message, + TplLogEntry *message, GError **error) { gboolean ret; @@ -348,12 +350,15 @@ _log_store_empathy_add_message_chat (TplLogStore *self, gchar *contact_id; gchar *entry; TpChannelTextMessageType msg_type; + TplLogEntryText *tmessage; - sender = tpl_log_entry_text_get_sender (message); + tmessage = tpl_log_entry_get_entry(message); + + sender = tpl_log_entry_text_get_sender (tmessage); account = tpl_channel_get_account ( - tpl_log_entry_text_get_tpl_channel (message) ); - body_str = tpl_log_entry_text_get_message (message); - msg_type = tpl_log_entry_text_get_message_type (message); + tpl_log_entry_text_get_tpl_channel (tmessage) ); + body_str = tpl_log_entry_text_get_message (tmessage); + msg_type = tpl_log_entry_text_get_message_type (tmessage); if (TPL_STR_EMPTY (body_str)) return FALSE; @@ -365,6 +370,8 @@ _log_store_empathy_add_message_chat (TplLogStore *self, contact_name = g_markup_escape_text (str, -1); str = tpl_contact_get_identifier (sender); + + g_message("%s\n", tpl_contact_get_identifier(sender)); contact_id = g_markup_escape_text (str, -1); /* avatar = empathy_contact_get_avatar (sender); @@ -372,10 +379,10 @@ _log_store_empathy_add_message_chat (TplLogStore *self, avatar_token = g_markup_escape_text (avatar->token, -1); */ entry = g_strdup_printf ( - "<message time='%s' cm_id='%d' id='%s' name='%s'" + "<message time='%s' cm_id='%d' id='%s' name='%s' " "token='%s' isuser='%s' type='%s'>" "%s</message>\n" LOG_FOOTER, timestamp, - tpl_log_entry_text_get_message_id (message), + tpl_log_entry_text_get_message_id (tmessage), contact_id, contact_name, //avatar_token ? avatar_token : "", // instead force to "" as //follow @@ -398,29 +405,30 @@ _log_store_empathy_add_message_chat (TplLogStore *self, static gboolean -log_store_empathy_add_message (TplLogStore *self, +_log_store_empathy_add_message_text (TplLogStore *self, const gchar *chat_id, gboolean chatroom, - TplLogEntryText *message, + TplLogEntry *message, GError **error) { TplLogEntryTextSignalType signal_type; + TplLogEntryText *tmessage; g_return_val_if_fail (TPL_IS_LOG_STORE (self), FALSE); g_return_val_if_fail (chat_id != NULL, FALSE); - g_return_val_if_fail (TPL_IS_LOG_ENTRY_TEXT (message), FALSE); + g_return_val_if_fail (TPL_IS_LOG_ENTRY (message), FALSE); - - signal_type = tpl_log_entry_text_get_signal_type (message); + tmessage = tpl_log_entry_get_entry(message); + signal_type = tpl_log_entry_text_get_signal_type (tmessage); switch (signal_type) { case TPL_LOG_ENTRY_TEXT_SIGNAL_SENT: case TPL_LOG_ENTRY_TEXT_SIGNAL_RECEIVED: - return _log_store_empathy_add_message_chat(self, + return _log_store_empathy_add_message_text_chat(self, chat_id, chatroom, message, error); break; case TPL_LOG_ENTRY_TEXT_SIGNAL_CHAT_STATUS_CHANGED: - return _log_store_empathy_add_message_status_changed(self, + return _log_store_empathy_add_message_text_status_changed(self, chat_id, chatroom, message, error); break; case TPL_LOG_ENTRY_TEXT_SIGNAL_SEND_ERROR: @@ -431,6 +439,28 @@ log_store_empathy_add_message (TplLogStore *self, } } + +/* First of two phases selection: understand the type LogEntry */ +static gboolean +log_store_empathy_add_message(TplLogStore *self, + const gchar *chat_id, + gboolean chatroom, + TplLogEntry *message, + GError **error) +{ + g_return_val_if_fail(TPL_IS_LOG_ENTRY(message), FALSE); + + switch(tpl_log_entry_get_entry_type(message)) { + case TPL_LOG_ENTRY_TEXT: + return _log_store_empathy_add_message_text( + self, chat_id, chatroom, + message, error); + default: + return FALSE; + } +} + + static gboolean log_store_empathy_exists (TplLogStore *self, TpAccount *account, @@ -623,7 +653,8 @@ log_store_empathy_get_messages_for_file (TplLogStore *self, /* Now get the messages. */ for (node = log_node->children; node; node = node->next) { - TplLogEntryText *message; + TplLogEntry *message; + TplLogEntryText *tmessage; TplContact *sender; gchar *time_; time_t t; @@ -663,9 +694,7 @@ log_store_empathy_get_messages_for_file (TplLogStore *self, cm_id = atoi (cm_id_str); t = tpl_time_parse (time_); -//TODO remove me - //sender = empathy_contact_new_for_log (account, sender_id, sender_name, - // is_user); + sender = tpl_contact_new(); tpl_contact_set_account(sender, account); tpl_contact_set_identifier(sender, sender_id); @@ -677,16 +706,19 @@ log_store_empathy_get_messages_for_file (TplLogStore *self, sender_avatar_token); */ - message = tpl_log_entry_text_new(); - tpl_log_entry_text_set_message(message, body); - tpl_log_entry_text_set_sender (message, sender); - tpl_log_entry_text_set_timestamp (message, t); - tpl_log_entry_text_set_message_type (message, msg_type); + tmessage = tpl_log_entry_text_new(); + tpl_log_entry_text_set_message(tmessage, body); + tpl_log_entry_text_set_sender (tmessage, sender); + tpl_log_entry_text_set_message_type (tmessage, msg_type); //TODO uderstand if useful //tpl_log_entry_text_set_is_backlog (message, TRUE); + message = tpl_log_entry_new (); + tpl_log_entry_set_timestamp (message, t); + tpl_log_entry_set_entry (message, tmessage); + if (cm_id_str) - tpl_log_entry_text_set_message_id (message, cm_id); + tpl_log_entry_text_set_message_id (tmessage, cm_id); messages = g_list_append (messages, message); diff --git a/src/tpl-log-store.c b/src/tpl-log-store.c index 228db0e..7ed6a98 100644 --- a/src/tpl-log-store.c +++ b/src/tpl-log-store.c @@ -72,7 +72,7 @@ gboolean tpl_log_store_add_message (TplLogStore *self, const gchar *chat_id, gboolean chatroom, - TplLogEntryText *message, + TplLogEntry *message, GError **error) { if (!TPL_LOG_STORE_GET_INTERFACE (self)->add_message) @@ -149,13 +149,12 @@ void tpl_log_store_ack_message (TplLogStore *self, const gchar *chat_id, gboolean chatroom, - TplLogEntryText *message) + TplLogEntry *message) { if (!TPL_LOG_STORE_GET_INTERFACE (self)->ack_message) return; - TPL_LOG_STORE_GET_INTERFACE (self)->ack_message ( - self, chat_id, chatroom, message); + TPL_LOG_STORE_GET_INTERFACE (self)->ack_message (self, chat_id, chatroom, message); } GList * diff --git a/src/tpl-text-channel-context.c b/src/tpl-text-channel-context.c index e13413e..bd43586 100644 --- a/src/tpl-text-channel-context.c +++ b/src/tpl-text-channel-context.c @@ -31,6 +31,7 @@ #include <tpl-observer.h> #include <tpl-text-channel-context.h> #include <tpl-channel.h> +#include <tpl-log-entry.h> #include <tpl-log-entry-text.h> #include <tpl-log-manager.h> #include <tpl-contact.h> @@ -101,7 +102,8 @@ _channel_on_sent_signal_cb (TpChannel *proxy, TpContact *remote,*me; TplContact *tpl_contact_sender; TplContact *tpl_contact_receiver; - TplLogEntryText *log; + TplLogEntryText *tlog; + TplLogEntry *log; TplLogManager *logmanager; gchar *chat_id; @@ -112,6 +114,10 @@ _channel_on_sent_signal_cb (TpChannel *proxy, me = tpl_text_channel_get_my_contact(tpl_text); remote = tpl_text_channel_get_remote_contact(tpl_text); + if(!tpl_text_channel_is_chatroom(tpl_text) && remote==NULL) { + g_error("Sending message: Remote TplContact NULL on 1-1 Chat\n"); + } + tpl_contact_sender = tpl_contact_from_tp_contact(me); tpl_contact_set_contact_type(tpl_contact_sender, TPL_CONTACT_USER); @@ -125,20 +131,23 @@ _channel_on_sent_signal_cb (TpChannel *proxy, arg_Text); /* Initialize TplLogEntryText */ - log = tpl_log_entry_text_new(); - tpl_log_entry_text_set_tpl_text_channel(log, tpl_text); - tpl_log_entry_text_set_sender(log, tpl_contact_sender); - tpl_log_entry_text_set_receiver(log, tpl_contact_receiver); - tpl_log_entry_text_set_message(log, arg_Text); - tpl_log_entry_text_set_message_type(log, arg_Type); - tpl_log_entry_text_set_signal_type(log, + log = tpl_log_entry_new (); + tlog = tpl_log_entry_text_new (); + + tpl_log_entry_text_set_tpl_text_channel(tlog, tpl_text); + tpl_log_entry_text_set_sender(tlog, tpl_contact_sender); + tpl_log_entry_text_set_receiver(tlog, tpl_contact_receiver); + tpl_log_entry_text_set_message(tlog, arg_Text); + tpl_log_entry_text_set_message_type(tlog, arg_Type); + tpl_log_entry_text_set_signal_type(tlog, TPL_LOG_ENTRY_TEXT_SIGNAL_SENT); - tpl_log_entry_text_set_timestamp(log, (time_t) arg_Timestamp); - tpl_log_entry_text_set_message_id(log, 123); + tpl_log_entry_text_set_message_id(tlog, 123); - /* Initialized LogStore and send the message */ + tpl_log_entry_set_entry (log, tlog); + tpl_log_entry_set_timestamp(log, (time_t) arg_Timestamp); + + /* Initialized LogStore and send the log entry */ - // TODO use the log-manager if (!tpl_text_channel_is_chatroom(tpl_text)) chat_id = g_strdup (tpl_contact_get_identifier( tpl_contact_receiver)); @@ -146,12 +155,14 @@ _channel_on_sent_signal_cb (TpChannel *proxy, chat_id = g_strdup (tpl_text_channel_get_chatroom_id( tpl_text)); - tpl_log_entry_text_set_chat_id(log, chat_id); + tpl_log_entry_text_set_chat_id(tlog, chat_id); logmanager = tpl_log_manager_dup_singleton(); + tpl_log_manager_add_message(logmanager, chat_id, tpl_text_channel_is_chatroom(tpl_text), log, &error); + if(error!=NULL) { g_error("LogStore: %s", error->message); @@ -176,36 +187,49 @@ _channel_on_received_signal_with_contact_cb(TpConnection *connection, gpointer user_data, GObject *weak_object) { - TplLogEntryText *log = TPL_LOG_ENTRY_TEXT(user_data); - TplTextChannel *tpl_text = tpl_log_entry_text_get_tpl_text_channel(log); + TplLogEntry *log = TPL_LOG_ENTRY(user_data); + TplLogEntryText *tlog = + TPL_LOG_ENTRY_TEXT(tpl_log_entry_get_entry(log)); + TplTextChannel *tpl_text = tpl_log_entry_text_get_tpl_text_channel(tlog); GError *e = NULL; TplLogManager *logmanager; TplContact *tpl_contact_sender; TpContact *remote; gchar *chat_id; - g_assert(TPL_IS_LOG_ENTRY_TEXT(log)); - g_return_if_fail(TPL_IS_LOG_ENTRY_TEXT(log)); + g_return_if_fail(TPL_IS_LOG_ENTRY(log)); + g_return_if_fail(TPL_IS_LOG_ENTRY_TEXT(tlog)); if(error!=NULL) { - g_error("Retrieving remote contact information: %s\n", error->message); + g_error("Unrecoverable error retrieving remote contact " + "information: %s\n", error->message); g_error("Not able to log the received message: %s\n", - tpl_log_entry_text_get_message(log)); + tpl_log_entry_text_get_message(tlog)); return; } - remote = tpl_text_channel_get_remote_contact(tpl_text); + if(n_failed>0) { + g_error("%d invalid handle(s) passed to " + "tp_connection_get_contacts_by_handle()\n", + n_failed); + g_error("Not able to log the received message: %s\n", + tpl_log_entry_text_get_message(tlog)); + return; + } + + remote = contacts[0]; + tpl_text_channel_set_remote_contact(tpl_text, remote); tpl_contact_sender = tpl_contact_from_tp_contact(remote); tpl_contact_set_contact_type(tpl_contact_sender, TPL_CONTACT_USER); - tpl_log_entry_text_set_sender(log, tpl_contact_sender); + tpl_log_entry_text_set_sender(tlog, tpl_contact_sender); g_message("%s (%s): %s\n", tpl_contact_get_identifier(tpl_contact_sender), tpl_contact_get_alias(tpl_contact_sender), - tpl_log_entry_text_get_message(log)); + tpl_log_entry_text_get_message(tlog)); /* Initialize LogStore and store the message */ @@ -216,12 +240,11 @@ _channel_on_received_signal_with_contact_cb(TpConnection *connection, chat_id = g_strdup (tpl_text_channel_get_chatroom_id( tpl_text)); - tpl_log_entry_text_set_chat_id(log, chat_id); + tpl_log_entry_text_set_chat_id(tlog, chat_id); logmanager = tpl_log_manager_dup_singleton(); - g_assert(TPL_IS_LOG_ENTRY_TEXT(log)); tpl_log_manager_add_message(logmanager, - tpl_log_entry_text_get_chat_id(log), + tpl_log_entry_text_get_chat_id(tlog), tpl_text_channel_is_chatroom (tpl_text), log, &e); if(e!=NULL) @@ -247,32 +270,49 @@ _channel_on_received_signal_cb (TpChannel *proxy, gpointer user_data, GObject *weak_object) { + TpHandle remote_handle = (TpHandle) arg_Sender; TplTextChannel *tpl_text = TPL_TEXT_CHANNEL(user_data); TplChannel *tpl_chan = tpl_text_channel_get_tpl_channel(tpl_text); TpContact *me; TplContact *tpl_contact_receiver; - TplLogEntryText *log; + TplLogEntry *log; + TplLogEntryText *tlog; + + // TODO use the Message iface to check the delivery + // notification and handle it correctly + if(arg_Flags & TP_CHANNEL_TEXT_MESSAGE_FLAG_NON_TEXT_CONTENT) { + g_debug("Non text contenct flag set." + "Probably a delivery notification for a sent message." + "Ignoring\n"); + return; + } /* Initialize TplLogEntryText (part 1) */ - log = tpl_log_entry_text_new(); - tpl_log_entry_text_set_tpl_text_channel(log, tpl_text); - tpl_log_entry_text_set_message(log, arg_Text); - tpl_log_entry_text_set_message_type(log, arg_Type); - tpl_log_entry_text_set_signal_type(log, + log = tpl_log_entry_new(); + tlog = tpl_log_entry_text_new(); + tpl_log_entry_set_entry(log, tlog); + + tpl_log_entry_text_set_tpl_text_channel(tlog, tpl_text); + tpl_log_entry_text_set_message(tlog, arg_Text); + tpl_log_entry_text_set_message_type(tlog, arg_Type); + tpl_log_entry_text_set_signal_type(tlog, TPL_LOG_ENTRY_TEXT_SIGNAL_RECEIVED); - tpl_log_entry_text_set_timestamp(log, (time_t) arg_Timestamp); - tpl_log_entry_text_set_message_id(log, 123); //TODO set a real Id + tpl_log_entry_text_set_message_id(tlog, 123); //TODO set a real Id me = tpl_text_channel_get_my_contact(tpl_text); tpl_contact_receiver = tpl_contact_from_tp_contact(me); tpl_contact_set_contact_type(tpl_contact_receiver, TPL_CONTACT_USER); - tpl_log_entry_text_set_receiver(log, tpl_contact_receiver); + tpl_log_entry_text_set_receiver(tlog, tpl_contact_receiver); + + tpl_log_entry_set_timestamp(log, (time_t) arg_Timestamp); + + g_debug("remote handler: %d\n", arg_Sender); tp_connection_get_contacts_by_handle( tpl_channel_get_connection(tpl_chan), - 1, &arg_Sender, + 1, &remote_handle, TP_CONTACT_FEATURES_LEN, features, _channel_on_received_signal_with_contact_cb, log, g_object_unref, NULL); |