aboutsummaryrefslogtreecommitdiffstats
path: root/libempathy-gtk
diff options
context:
space:
mode:
authorXavier Claessens <xclaesse@gmail.com>2007-06-02 23:56:53 +0800
committerXavier Claessens <xclaesse@src.gnome.org>2007-06-02 23:56:53 +0800
commit9dde03a4b7e7398df502b05d18d1010b4ee88cab (patch)
tree8d45dac7656d61f2b9487a7567a4ede3227e3f4d /libempathy-gtk
parente1110b246ff83d6add4bbf01c6ec8a8460070491 (diff)
downloadgsoc2013-empathy-9dde03a4b7e7398df502b05d18d1010b4ee88cab.tar
gsoc2013-empathy-9dde03a4b7e7398df502b05d18d1010b4ee88cab.tar.gz
gsoc2013-empathy-9dde03a4b7e7398df502b05d18d1010b4ee88cab.tar.bz2
gsoc2013-empathy-9dde03a4b7e7398df502b05d18d1010b4ee88cab.tar.lz
gsoc2013-empathy-9dde03a4b7e7398df502b05d18d1010b4ee88cab.tar.xz
gsoc2013-empathy-9dde03a4b7e7398df502b05d18d1010b4ee88cab.tar.zst
gsoc2013-empathy-9dde03a4b7e7398df502b05d18d1010b4ee88cab.zip
Log chats and display 10 last messages when opening a new chat.
2007-06-02 Xavier Claessens <xclaesse@gmail.com> * libempathy-gtk/gossip-group-chat.c: * libempathy-gtk/gossip-private-chat.c: * libempathy-gtk/gossip-chat.c: * libempathy/empathy-log-manager.c: * libempathy/empathy-log-manager.h: * libempathy/empathy-log-manager.xsl: * libempathy/Makefile.am: Log chats and display 10 last messages when opening a new chat. svn path=/trunk/; revision=114
Diffstat (limited to 'libempathy-gtk')
-rw-r--r--libempathy-gtk/gossip-chat.c127
-rw-r--r--libempathy-gtk/gossip-group-chat.c2
-rw-r--r--libempathy-gtk/gossip-private-chat.c7
3 files changed, 71 insertions, 65 deletions
diff --git a/libempathy-gtk/gossip-chat.c b/libempathy-gtk/gossip-chat.c
index a29c31818..677cdd258 100644
--- a/libempathy-gtk/gossip-chat.c
+++ b/libempathy-gtk/gossip-chat.c
@@ -36,6 +36,7 @@
#include <glade/glade.h>
#include <libempathy/empathy-contact-manager.h>
+#include <libempathy/empathy-log-manager.h>
#include <libempathy/gossip-debug.h>
#include <libempathy/gossip-utils.h>
#include <libempathy/gossip-conf.h>
@@ -64,6 +65,7 @@
struct _GossipChatPriv {
EmpathyContactManager *manager;
+ EmpathyLogManager *log_manager;
EmpathyTpChat *tp_chat;
GossipChatWindow *window;
GtkTooltips *tooltips;
@@ -74,6 +76,7 @@ struct _GossipChatPriv {
gint sent_messages_index;
GList *compositors;
guint scroll_idle_id;
+ gboolean first_tp_chat;
/* Used to automatically shrink a window that has temporarily
* grown due to long input.
*/
@@ -139,6 +142,7 @@ static void chat_state_changed_cb (EmpathyTpChat *tp_c
GossipContact *contact,
TelepathyChannelChatState state,
GossipChat *chat);
+static void chat_add_logs (GossipChat *chat);
static gboolean chat_scroll_down_idle_func (GossipChat *chat);
enum {
@@ -228,12 +232,14 @@ gossip_chat_init (GossipChat *chat)
priv = GET_PRIV (chat);
priv->manager = empathy_contact_manager_new ();
+ priv->log_manager = empathy_log_manager_new ();
priv->tooltips = g_object_ref_sink (gtk_tooltips_new ());
priv->default_window_height = -1;
priv->vscroll_visible = FALSE;
priv->sensitive = TRUE;
priv->sent_messages = NULL;
priv->sent_messages_index = -1;
+ priv->first_tp_chat = TRUE;
g_signal_connect (chat->input_text_view,
"key_press_event",
@@ -270,51 +276,6 @@ gossip_chat_init (GossipChat *chat)
"misspelled",
"underline", PANGO_UNDERLINE_ERROR,
NULL);
-
-
-
- /* Turn off scrolling temporarily */
- gossip_chat_view_scroll (chat->view, FALSE);
-#if 0
-FIXME:
- /* Add messages from last conversation */
- log_manager = gossip_session_get_log_manager (gossip_app_get_session ());
- messages = gossip_log_get_last_for_contact (log_manager, priv->contact);
- num_messages = g_list_length (messages);
-
- for (l = messages, i = 0; l; l = l->next, i++) {
- message = l->data;
-
- if (num_messages - i > 10) {
- continue;
- }
-
- sender = gossip_message_get_sender (message);
- if (gossip_contact_equal (priv->own_contact, sender)) {
- gossip_chat_view_append_message_from_self (view,
- message,
- priv->own_contact,
- priv->own_avatar);
- } else {
- gossip_chat_view_append_message_from_other (view,
- message,
- sender,
- priv->other_avatar);
- }
- }
-
- g_list_foreach (messages, (GFunc) g_object_unref, NULL);
- g_list_free (messages);
-#endif
- /* Turn back on scrolling */
- gossip_chat_view_scroll (chat->view, TRUE);
-
- /* Scroll to the most recent messages, we reference the chat
- * for the duration of the scroll func.
- */
- priv->scroll_idle_id = g_idle_add ((GSourceFunc) chat_scroll_down_idle_func,
- g_object_ref (chat));
-
}
static void
@@ -337,6 +298,7 @@ chat_finalize (GObject *object)
chat_composing_remove_timeout (chat);
g_object_unref (chat->account);
g_object_unref (priv->manager);
+ g_object_unref (priv->log_manager);
g_object_unref (priv->tooltips);
if (priv->tp_chat) {
@@ -377,10 +339,9 @@ static void
chat_send (GossipChat *chat,
const gchar *msg)
{
- GossipChatPriv *priv;
- //GossipLogManager *log_manager;
- GossipMessage *message;
- GossipContact *own_contact;
+ GossipChatPriv *priv;
+ GossipMessage *message;
+ GossipContact *own_contact;
priv = GET_PRIV (chat);
@@ -398,15 +359,10 @@ chat_send (GossipChat *chat,
/* FIXME: add here something to let group/privrate chat handle
* some special messages */
- /* FIXME: gossip_app_set_not_away ();*/
-
own_contact = empathy_contact_manager_get_user (priv->manager, chat->account);
message = gossip_message_new (msg);
gossip_message_set_sender (message, own_contact);
- //FIXME: log_manager = gossip_session_get_log_manager (gossip_app_get_session ());
- //gossip_log_message_for_contact (log_manager, message, FALSE);
-
empathy_tp_chat_send (priv->tp_chat, message);
g_object_unref (message);
@@ -443,8 +399,7 @@ chat_message_received_cb (EmpathyTpChat *tp_chat,
GossipChat *chat)
{
GossipChatPriv *priv;
- //GossipLogManager *log_manager;
- GossipContact *sender;
+ GossipContact *sender;
priv = GET_PRIV (chat);
@@ -452,10 +407,10 @@ chat_message_received_cb (EmpathyTpChat *tp_chat,
gossip_debug (DEBUG_DOMAIN, "Appending message ('%s')",
gossip_contact_get_name (sender));
-/*FIXME:
- log_manager = gossip_session_get_log_manager (gossip_app_get_session ());
- gossip_log_message_for_contact (log_manager, message, TRUE);
-*/
+ empathy_log_manager_add_message (priv->log_manager,
+ gossip_chat_get_id (chat),
+ message);
+
gossip_chat_view_append_message (chat->view, message);
if (gossip_chat_should_play_sound (chat)) {
@@ -1129,6 +1084,52 @@ chat_state_changed_cb (EmpathyTpChat *tp_chat,
}
}
+static void
+chat_add_logs (GossipChat *chat)
+{
+ GossipChatPriv *priv;
+ GList *messages, *l;
+ guint num_messages;
+ guint i;
+
+ priv = GET_PRIV (chat);
+
+ /* Turn off scrolling temporarily */
+ gossip_chat_view_scroll (chat->view, FALSE);
+
+ /* Add messages from last conversation */
+ messages = empathy_log_manager_get_last_messages (priv->log_manager,
+ chat->account,
+ gossip_chat_get_id (chat));
+ num_messages = g_list_length (messages);
+
+ for (l = messages, i = 0; l; l = l->next, i++) {
+ GossipMessage *message;
+
+ message = l->data;
+
+ /* Only add 10 last messages */
+ if (num_messages - i > 10) {
+ g_object_unref (message);
+ continue;
+ }
+
+
+ gossip_chat_view_append_message (chat->view, message);
+ g_object_unref (message);
+ }
+ g_list_free (messages);
+
+ /* Turn back on scrolling */
+ gossip_chat_view_scroll (chat->view, TRUE);
+
+ /* Scroll to the most recent messages, we reference the chat
+ * for the duration of the scroll func.
+ */
+ priv->scroll_idle_id = g_idle_add ((GSourceFunc) chat_scroll_down_idle_func,
+ g_object_ref (chat));
+}
+
/* Scroll down after the back-log has been received. */
static gboolean
chat_scroll_down_idle_func (GossipChat *chat)
@@ -1308,6 +1309,12 @@ gossip_chat_set_tp_chat (GossipChat *chat,
priv->tp_chat = g_object_ref (tp_chat);
priv->id = g_strdup (empathy_tp_chat_get_id (tp_chat));
+ if (priv->first_tp_chat) {
+ chat_add_logs (chat);
+ priv->first_tp_chat = FALSE;
+ }
+
+
g_signal_connect (tp_chat, "message-received",
G_CALLBACK (chat_message_received_cb),
chat);
diff --git a/libempathy-gtk/gossip-group-chat.c b/libempathy-gtk/gossip-group-chat.c
index 493e07461..8e8aa1967 100644
--- a/libempathy-gtk/gossip-group-chat.c
+++ b/libempathy-gtk/gossip-group-chat.c
@@ -176,9 +176,9 @@ gossip_group_chat_new (McAccount *account,
priv = GET_PRIV (chat);
+ GOSSIP_CHAT (chat)->account = g_object_ref (account);
priv->tp_chat = empathy_tp_chatroom_new (account, tp_chan);
gossip_chat_set_tp_chat (GOSSIP_CHAT (chat), EMPATHY_TP_CHAT (priv->tp_chat));
- GOSSIP_CHAT (chat)->account = g_object_ref (account);
/* FIXME: Ask the user before accepting */
empathy_tp_chatroom_accept_invitation (priv->tp_chat);
diff --git a/libempathy-gtk/gossip-private-chat.c b/libempathy-gtk/gossip-private-chat.c
index 12e83dccc..f047f12e2 100644
--- a/libempathy-gtk/gossip-private-chat.c
+++ b/libempathy-gtk/gossip-private-chat.c
@@ -307,13 +307,12 @@ private_chat_setup (GossipPrivateChat *chat,
priv = GET_PRIV (chat);
- gossip_chat_set_tp_chat (GOSSIP_CHAT (chat), tp_chat);
-
- priv->contact = g_object_ref (contact);
GOSSIP_CHAT (chat)->account = g_object_ref (gossip_contact_get_account (contact));
-
+ priv->contact = g_object_ref (contact);
priv->name = g_strdup (gossip_contact_get_name (contact));
+ gossip_chat_set_tp_chat (GOSSIP_CHAT (chat), tp_chat);
+
g_signal_connect (priv->contact,
"notify::name",
G_CALLBACK (private_chat_contact_updated_cb),