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); } }
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 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; }
void empathy_tp_chat_send (EmpathyTpChat *chat, EmpathyMessage *message) { EmpathyTpChatPriv *priv = GET_PRIV (chat); const gchar *message_body; TpChannelTextMessageType message_type; g_return_if_fail (EMPATHY_IS_TP_CHAT (chat)); g_return_if_fail (EMPATHY_IS_MESSAGE (message)); g_return_if_fail (priv->ready); message_body = empathy_message_get_body (message); message_type = empathy_message_get_tptype (message); DEBUG ("Sending message: %s", message_body); tp_cli_channel_type_text_call_send (priv->channel, -1, message_type, message_body, tp_chat_send_cb, g_object_ref (message), (GDestroyNotify) g_object_unref, G_OBJECT (chat)); }
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); }