static void theme_boxes_append_message (EmpathyChatTextView *view, EmpathyMessage *message) { EmpathyContact *sender; theme_boxes_maybe_append_header (EMPATHY_THEME_BOXES (view), message); sender = empathy_message_get_sender (message); if (empathy_message_get_tptype (message) == TP_CHANNEL_TEXT_MESSAGE_TYPE_ACTION) { gchar *body; body = g_strdup_printf (" * %s %s", empathy_contact_get_alias (sender), empathy_message_get_body (message)); empathy_chat_text_view_append_body (EMPATHY_CHAT_TEXT_VIEW (view), body, EMPATHY_CHAT_TEXT_VIEW_TAG_ACTION); } else { empathy_chat_text_view_append_body (EMPATHY_CHAT_TEXT_VIEW (view), empathy_message_get_body (message), EMPATHY_CHAT_TEXT_VIEW_TAG_BODY); } }
void empathy_tp_chat_acknowledge_message (EmpathyTpChat *chat, EmpathyMessage *message) { EmpathyTpChatPriv *priv = GET_PRIV (chat); GArray *message_ids; GList *m; guint id; g_return_if_fail (EMPATHY_IS_TP_CHAT (chat)); g_return_if_fail (priv->ready); if (empathy_message_get_sender (message) == priv->user) goto out; message_ids = g_array_sized_new (FALSE, FALSE, sizeof (guint), 1); id = empathy_message_get_id (message); g_array_append_val (message_ids, id); acknowledge_messages (chat, message_ids); g_array_free (message_ids, TRUE); out: m = g_queue_find (priv->pending_messages_queue, message); g_assert (m != NULL); g_queue_delete_link (priv->pending_messages_queue, m); g_object_unref (message); }
static void theme_irc_append_message (EmpathyChatTextView *view, EmpathyMessage *message) { GtkTextBuffer *buffer; const gchar *name; const gchar *nick_tag; GtkTextIter iter; gchar *tmp; EmpathyContact *contact; buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)); contact = empathy_message_get_sender (message); name = empathy_contact_get_logged_alias (contact); if (empathy_message_get_tptype (message) == TP_CHANNEL_TEXT_MESSAGE_TYPE_ACTION) { tmp = g_strdup_printf (" * %s %s", empathy_contact_get_logged_alias (contact), empathy_message_get_body (message)); empathy_chat_text_view_append_body (view, tmp, EMPATHY_CHAT_TEXT_VIEW_TAG_ACTION); g_free (tmp); return; } if (empathy_contact_is_user (contact)) { nick_tag = EMPATHY_THEME_IRC_TAG_NICK_SELF; } else { if (empathy_message_should_highlight (message)) { nick_tag = EMPATHY_THEME_IRC_TAG_NICK_HIGHLIGHT; } else { nick_tag = EMPATHY_THEME_IRC_TAG_NICK_OTHER; } } gtk_text_buffer_get_end_iter (buffer, &iter); /* The nickname. */ tmp = g_strdup_printf ("%s: ", name); gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, tmp, -1, "cut", nick_tag, NULL); g_free (tmp); /* The text body. */ empathy_chat_text_view_append_body (view, empathy_message_get_body (message), EMPATHY_CHAT_TEXT_VIEW_TAG_BODY); }
static void tp_chat_emit_queued_messages (EmpathyTpChat *chat) { EmpathyTpChatPriv *priv = GET_PRIV (chat); EmpathyMessage *message; /* Check if we can now emit some queued messages */ while ((message = g_queue_peek_head (priv->messages_queue)) != NULL) { if (empathy_message_get_sender (message) == NULL) { break; } DEBUG ("Queued message ready"); g_queue_pop_head (priv->messages_queue); g_queue_push_tail (priv->pending_messages_queue, message); g_signal_emit (chat, signals[MESSAGE_RECEIVED], 0, message); } }
void empathy_tp_chat_acknowledge_messages (EmpathyTpChat *chat, const GList *messages) { EmpathyTpChatPriv *priv = GET_PRIV (chat); /* Copy messages as the messges list (probably is) our own */ GList *msgs = g_list_copy ((GList *) messages); GList *l; guint length; GArray *message_ids; g_return_if_fail (EMPATHY_IS_TP_CHAT (chat)); g_return_if_fail (priv->ready); length = g_list_length ((GList *) messages); if (length == 0) return; message_ids = g_array_sized_new (FALSE, FALSE, sizeof (guint), length); for (l = msgs; l != NULL; l = g_list_next (l)) { GList *m; EmpathyMessage *message = EMPATHY_MESSAGE (l->data); m = g_queue_find (priv->pending_messages_queue, message); g_assert (m != NULL); g_queue_delete_link (priv->pending_messages_queue, m); if (empathy_message_get_sender (message) != priv->user) { guint id = empathy_message_get_id (message); g_array_append_val (message_ids, id); } g_object_unref (message); } if (message_ids->len > 0) acknowledge_messages (chat, message_ids); g_array_free (message_ids, TRUE); g_list_free (msgs); }
static void chat_text_view_append_message (EmpathyChatView *view, EmpathyMessage *msg) { EmpathyChatTextView *text_view = EMPATHY_CHAT_TEXT_VIEW (view); EmpathyChatTextViewPriv *priv = GET_PRIV (text_view); gboolean bottom; gint64 timestamp; g_return_if_fail (EMPATHY_IS_CHAT_TEXT_VIEW (view)); g_return_if_fail (EMPATHY_IS_MESSAGE (msg)); if (!empathy_message_get_body (msg)) { return; } bottom = chat_text_view_is_scrolled_down (text_view); chat_text_view_maybe_trim_buffer (EMPATHY_CHAT_TEXT_VIEW (view)); timestamp = empathy_message_get_timestamp (msg); chat_text_maybe_append_date_and_time (text_view, timestamp); if (EMPATHY_CHAT_TEXT_VIEW_GET_CLASS (view)->append_message) { EMPATHY_CHAT_TEXT_VIEW_GET_CLASS (view)->append_message (text_view, msg); } if (bottom) { chat_text_view_scroll_down (view); } if (priv->last_contact) { g_object_unref (priv->last_contact); } priv->last_contact = g_object_ref (empathy_message_get_sender (msg)); g_object_notify (G_OBJECT (view), "last-contact"); priv->last_timestamp = timestamp; }
static void theme_boxes_maybe_append_header (EmpathyThemeBoxes *theme, EmpathyMessage *msg) { EmpathyChatTextView *view = EMPATHY_CHAT_TEXT_VIEW (theme); EmpathyThemeBoxesPriv*priv = GET_PRIV (theme); EmpathyContact *contact; EmpathyContact *last_contact; GdkPixbuf *avatar = NULL; GtkTextBuffer *buffer; const gchar *name; GtkTextIter iter; GtkWidget *label1, *label2; GtkTextChildAnchor *anchor; GtkWidget *box; gchar *str; time_t time_; gchar *tmp; GtkTextIter start; gboolean color_set; GtkTextTagTable *table; GtkTextTag *tag; GString *str_obj; gboolean consecutive; contact = empathy_message_get_sender (msg); name = empathy_contact_get_alias (contact); last_contact = empathy_chat_text_view_get_last_contact (view); buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (theme)); time_ = empathy_message_get_timestamp (msg); consecutive = (time_ - empathy_chat_text_view_get_last_timestamp (view) < MESSAGE_JOIN_PERIOD); DEBUG ("Maybe add fancy header"); /* Only insert a header if * - the previously inserted block is not the same as this one. * - the delay between two messages is lower then MESSAGE_JOIN_PERIOD */ if (empathy_contact_equal (last_contact, contact) && consecutive) { return; } empathy_chat_text_view_append_spacing (view); /* Insert header line */ gtk_text_buffer_get_end_iter (buffer, &iter); gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, "\n", -1, EMPATHY_THEME_BOXES_TAG_HEADER_LINE, NULL); gtk_text_buffer_get_end_iter (buffer, &iter); anchor = gtk_text_buffer_create_child_anchor (buffer, &iter); /* Create a hbox for the header and resize it when the view allocation * changes */ box = gtk_hbox_new (FALSE, 0); g_signal_connect_object (view, "size-allocate", G_CALLBACK (table_size_allocate_cb), box, 0); /* Add avatar to the box if needed */ if (priv->show_avatars) { avatar = theme_boxes_get_avatar_pixbuf_with_cache (contact); if (avatar) { GtkWidget *image; image = gtk_image_new_from_pixbuf (avatar); gtk_box_pack_start (GTK_BOX (box), image, FALSE, TRUE, 2); } } /* Add contact alias */ str = g_markup_printf_escaped ("<b>%s</b>", name); label1 = g_object_new (GTK_TYPE_LABEL, "label", str, "use-markup", TRUE, "xalign", 0.0, NULL); g_free (str); /* Add the message receive time */ tmp = empathy_time_to_string_local (time_, EMPATHY_TIME_FORMAT_DISPLAY_SHORT); str = g_strdup_printf ("<i>%s</i>", tmp); label2 = g_object_new (GTK_TYPE_LABEL, "label", str, "use-markup", TRUE, "xalign", 1.0, NULL); str_obj = g_string_new ("\n- "); g_string_append (str_obj, name); g_string_append (str_obj, ", "); g_string_append (str_obj, tmp); g_string_append (str_obj, " -"); g_free (tmp); g_free (str); /* Set foreground color of labels to the same color than the header tag. */ table = gtk_text_buffer_get_tag_table (buffer); tag = gtk_text_tag_table_lookup (table, EMPATHY_THEME_BOXES_TAG_HEADER); g_object_get (tag, "foreground-set", &color_set, NULL); if (color_set) { GdkColor *color; g_object_get (tag, "foreground-gdk", &color, NULL); gtk_widget_modify_fg (label1, GTK_STATE_NORMAL, color); gtk_widget_modify_fg (label2, GTK_STATE_NORMAL, color); gdk_color_free (color); } /* Pack labels into the box */ gtk_misc_set_alignment (GTK_MISC (label1), 0.0, 0.5); gtk_misc_set_alignment (GTK_MISC (label2), 1.0, 0.5); gtk_box_pack_start (GTK_BOX (box), label1, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (box), label2, TRUE, TRUE, 0); /* Add the header box to the text view */ g_object_set_data_full (G_OBJECT (box), "str_obj", g_string_free (str_obj, FALSE), g_free); gtk_text_view_add_child_at_anchor (GTK_TEXT_VIEW (view), box, anchor); gtk_widget_show_all (box); /* Insert a header line */ gtk_text_buffer_get_end_iter (buffer, &iter); start = iter; gtk_text_iter_backward_char (&start); gtk_text_buffer_apply_tag_by_name (buffer, EMPATHY_THEME_BOXES_TAG_HEADER, &start, &iter); gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, "\n", -1, EMPATHY_THEME_BOXES_TAG_HEADER, NULL); gtk_text_buffer_get_end_iter (buffer, &iter); gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, "\n", -1, EMPATHY_THEME_BOXES_TAG_HEADER_LINE, NULL); }
void empathy_log_manager_add_message (EmpathyLogManager *manager, const gchar *chat_id, gboolean chatroom, EmpathyMessage *message) { FILE *file; McAccount *account; EmpathyContact *sender; const gchar *body_str; const gchar *str; EmpathyAvatar *avatar; gchar *avatar_token = NULL; gchar *filename; gchar *basedir; gchar *body; gchar *timestamp; gchar *contact_name; gchar *contact_id; TpChannelTextMessageType msg_type; g_return_if_fail (EMPATHY_IS_LOG_MANAGER (manager)); g_return_if_fail (chat_id != NULL); g_return_if_fail (EMPATHY_IS_MESSAGE (message)); sender = empathy_message_get_sender (message); account = empathy_contact_get_account (sender); body_str = empathy_message_get_body (message); msg_type = empathy_message_get_tptype (message); if (EMP_STR_EMPTY (body_str)) { return; } filename = log_manager_get_filename (manager, account, chat_id, chatroom); basedir = g_path_get_dirname (filename); if (!g_file_test (basedir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) { DEBUG ("Creating directory:'%s'", basedir); g_mkdir_with_parents (basedir, LOG_DIR_CREATE_MODE); } g_free (basedir); DEBUG ("Adding message: '%s' to file: '%s'", body_str, filename); if (!g_file_test (filename, G_FILE_TEST_EXISTS)) { file = g_fopen (filename, "w+"); if (file) { g_fprintf (file, LOG_HEADER); } g_chmod (filename, LOG_FILE_CREATE_MODE); } else { file = g_fopen (filename, "r+"); if (file) { fseek (file, - strlen (LOG_FOOTER), SEEK_END); } } body = g_markup_escape_text (body_str, -1); timestamp = log_manager_get_timestamp_from_message (message); str = empathy_contact_get_name (sender); contact_name = g_markup_escape_text (str, -1); str = empathy_contact_get_id (sender); contact_id = g_markup_escape_text (str, -1); avatar = empathy_contact_get_avatar (sender); if (avatar) { avatar_token = g_markup_escape_text (avatar->token, -1); } g_fprintf (file, "<message time='%s' id='%s' name='%s' token='%s' isuser='******' type='%s'>%s</message>\n" LOG_FOOTER, timestamp, contact_id, contact_name, avatar_token ? avatar_token : "", empathy_contact_is_user (sender) ? "true" : "false", empathy_message_type_to_str (msg_type), body); fclose (file); g_free (filename); g_free (contact_id); g_free (contact_name); g_free (timestamp); g_free (body); g_free (avatar_token); }