pidgin/pidgin

cf58ec89b1e4
Parents df2674f2d982
Children 81f81f5d2f39
Rename message.[ch] to purplemessage.[ch]

Testing Done:
compiled and ran locally.

Reviewed at https://reviews.imfreedom.org/r/408/
--- a/doc/reference/libpurple/libpurple-docs.xml Mon Jan 11 00:20:09 2021 -0600
+++ b/doc/reference/libpurple/libpurple-docs.xml Mon Jan 11 01:08:47 2021 -0600
@@ -109,7 +109,7 @@
<chapter id="messages">
<title>Messaging</title>
- <xi:include href="xml/message.xml" />
+ <xi:include href="xml/purplemessage.xml" />
<xi:include href="xml/purpleattachment.xml" />
<xi:include href="xml/log.xml" />
<xi:include href="xml/cmds.xml" />
--- a/libpurple/conversation.h Mon Jan 11 00:20:09 2021 -0600
+++ b/libpurple/conversation.h Mon Jan 11 01:08:47 2021 -0600
@@ -112,7 +112,7 @@
#include <glib.h>
#include <glib-object.h>
-#include "message.h"
+#include "purplemessage.h"
/**************************************************************************/
/* PurpleConversation */
--- a/libpurple/core.c Mon Jan 11 00:20:09 2021 -0600
+++ b/libpurple/core.c Mon Jan 11 01:08:47 2021 -0600
@@ -31,12 +31,12 @@
#include "idle.h"
#include "image-store.h"
#include "keyring.h"
-#include "message.h"
#include "network.h"
#include "notify.h"
#include "plugins.h"
#include "prefs.h"
#include "proxy.h"
+#include "purplemessage.h"
#include "purpleprivate.h"
#include "savedstatuses.h"
#include "signals.h"
--- a/libpurple/meson.build Mon Jan 11 00:20:09 2021 -0600
+++ b/libpurple/meson.build Mon Jan 11 01:08:47 2021 -0600
@@ -33,7 +33,6 @@
'media.c',
'mediamanager.c',
'memorypool.c',
- 'message.c',
'nat-pmp.c',
'network.c',
'notify.c',
@@ -57,6 +56,7 @@
'purpleimconversation.c',
'purplekeyvaluepair.c',
'purplemarkup.c',
+ 'purplemessage.c',
'purplepresence.c',
'purpleprotocolattention.c',
'purpleprotocolclient.c',
@@ -121,7 +121,6 @@
'media.h',
'mediamanager.h',
'memorypool.h',
- 'message.h',
'nat-pmp.h',
'network.h',
'notify.h',
@@ -145,6 +144,7 @@
'purpleattachment.h',
'purplekeyvaluepair.h',
'purplemarkup.h',
+ 'purplemessage.h',
'purplepresence.h',
'purpleprotocolattention.h',
'purpleprotocolclient.h',
@@ -222,13 +222,13 @@
'conversation.h',
'debug.h',
'eventloop.h',
- 'message.h',
'notify.h',
'plugins.h',
'protocol.h',
'protocols.h',
'purplechatuser.h',
'purpleimconversation.h',
+ 'purplemessage.h',
'roomlist.h',
'status.h',
'xfer.h',
--- a/libpurple/message.c Mon Jan 11 00:20:09 2021 -0600
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,572 +0,0 @@
-/* purple
- *
- * Purple is the legal property of its developers, whose names are too numerous
- * to list here. Please refer to the COPYRIGHT file distributed with this
- * source distribution.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
- */
-
-#include <glib/gi18n-lib.h>
-
-#include "internal.h"
-
-#include "debug.h"
-#include "enums.h"
-#include "message.h"
-#include "purpleprivate.h"
-
-/**
- * PurpleMessage:
- *
- * A message data container.
- */
-struct _PurpleMessage {
- GObject parent;
-
- guint id;
- gchar *author;
- gchar *author_alias;
- gchar *recipient;
-
- gchar *contents;
- PurpleMessageContentType content_type;
-
- GDateTime *timestamp;
- PurpleMessageFlags flags;
-
- GHashTable *attachments;
-};
-
-enum {
- PROP_0,
- PROP_ID,
- PROP_AUTHOR,
- PROP_AUTHOR_ALIAS,
- PROP_RECIPIENT,
- PROP_CONTENTS,
- PROP_CONTENT_TYPE,
- PROP_TIMESTAMP,
- PROP_FLAGS,
- N_PROPERTIES
-};
-static GParamSpec *properties[N_PROPERTIES];
-
-G_DEFINE_TYPE(PurpleMessage, purple_message, G_TYPE_OBJECT)
-
-/******************************************************************************
- * Helpers
- *****************************************************************************/
-static void
-purple_message_set_id(PurpleMessage *message, guint id) {
- message->id = id;
-
- g_object_notify_by_pspec(G_OBJECT(message), properties[PROP_ID]);
-}
-
-static void
-purple_message_set_author(PurpleMessage *message, const gchar *author) {
- g_free(message->author);
- message->author = g_strdup(author);
-
- g_object_notify_by_pspec(G_OBJECT(message), properties[PROP_AUTHOR]);
-}
-
-/******************************************************************************
- * GObject Implementation
- *****************************************************************************/
-static void
-purple_message_get_property(GObject *object, guint param_id, GValue *value,
- GParamSpec *pspec)
-{
- PurpleMessage *message = PURPLE_MESSAGE(object);
-
- switch(param_id) {
- case PROP_ID:
- g_value_set_uint(value, purple_message_get_id(message));
- break;
- case PROP_AUTHOR:
- g_value_set_string(value, purple_message_get_author(message));
- break;
- case PROP_AUTHOR_ALIAS:
- g_value_set_string(value, purple_message_get_author_alias(message));
- break;
- case PROP_RECIPIENT:
- g_value_set_string(value, purple_message_get_recipient(message));
- break;
- case PROP_CONTENTS:
- g_value_set_string(value, purple_message_get_contents(message));
- break;
- case PROP_CONTENT_TYPE:
- g_value_set_enum(value, purple_message_get_content_type(message));
- break;
- case PROP_TIMESTAMP:
- g_value_set_boxed(value, purple_message_get_timestamp(message));
- break;
- case PROP_FLAGS:
- g_value_set_flags(value, purple_message_get_flags(message));
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID(object, param_id, pspec);
- break;
- }
-}
-
-static void
-purple_message_set_property(GObject *object, guint param_id,
- const GValue *value, GParamSpec *pspec)
-{
- PurpleMessage *message = PURPLE_MESSAGE(object);
-
- switch(param_id) {
- case PROP_ID:
- purple_message_set_id(message, g_value_get_uint(value));
- break;
- case PROP_AUTHOR:
- purple_message_set_author(message, g_value_get_string(value));
- break;
- case PROP_AUTHOR_ALIAS:
- purple_message_set_author_alias(message, g_value_get_string(value));
- break;
- case PROP_RECIPIENT:
- purple_message_set_recipient(message, g_value_get_string(value));
- break;
- case PROP_CONTENTS:
- purple_message_set_contents(message, g_value_get_string(value));
- break;
- case PROP_CONTENT_TYPE:
- purple_message_set_content_type(message, g_value_get_enum(value));
- break;
- case PROP_TIMESTAMP:
- purple_message_set_timestamp(message, g_value_get_boxed(value));
- break;
- case PROP_FLAGS:
- purple_message_set_flags(message, g_value_get_flags(value));
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID(object, param_id, pspec);
- break;
- }
-}
-
-static void
-purple_message_finalize(GObject *obj) {
- PurpleMessage *message = PURPLE_MESSAGE(obj);
-
- g_free(message->author);
- g_free(message->author_alias);
- g_free(message->recipient);
- g_free(message->contents);
-
- if(message->timestamp != NULL) {
- g_date_time_unref(message->timestamp);
- }
-
- g_hash_table_destroy(message->attachments);
-
- G_OBJECT_CLASS(purple_message_parent_class)->finalize(obj);
-}
-
-static void
-purple_message_init(PurpleMessage *message) {
- message->attachments = g_hash_table_new_full(g_int64_hash, g_int64_equal,
- NULL, g_object_unref);
-}
-
-static void
-purple_message_class_init(PurpleMessageClass *klass) {
- GObjectClass *obj_class = G_OBJECT_CLASS(klass);
-
- obj_class->get_property = purple_message_get_property;
- obj_class->set_property = purple_message_set_property;
- obj_class->finalize = purple_message_finalize;
-
- /**
- * PurpleMessage::id:
- *
- * The account specific identifier of the message.
- */
- properties[PROP_ID] = g_param_spec_uint(
- "id", "ID",
- "The session-unique message id",
- 0, G_MAXUINT, 0,
- G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
-
- /**
- * PurpleMessage::author:
- *
- * The author of the message.
- */
- properties[PROP_AUTHOR] = g_param_spec_string(
- "author", "Author",
- "The username of the person, who sent the message.",
- NULL,
- G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
-
- /**
- * PurpleMessage::author-alias:
- *
- * The alias of the author.
- */
- properties[PROP_AUTHOR_ALIAS] = g_param_spec_string(
- "author-alias", "Author's alias",
- "The alias of the sender",
- NULL,
- G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
-
- /**
- * PurpleMessage::recipient:
- *
- * The recipient of the message.
- */
- properties[PROP_RECIPIENT] = g_param_spec_string(
- "recipient", "Recipient",
- "The username of the recipient.",
- NULL,
- G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
-
- /**
- * PurpleMessage::content:
- *
- * The contents of the message.
- */
- properties[PROP_CONTENTS] = g_param_spec_string(
- "contents", "Contents",
- "The message text",
- NULL,
- G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
-
- /**
- * PurpleMessage::content-type:
- *
- * The content-type of the message.
- */
- properties[PROP_CONTENT_TYPE] = g_param_spec_enum(
- "content-type", "content-type",
- "The content-type of the message.",
- PURPLE_TYPE_MESSAGE_CONTENT_TYPE, PURPLE_MESSAGE_CONTENT_TYPE_PLAIN,
- G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
-
- /**
- * PurpleMessage::timestamp:
- *
- * The timestamp of the message.
- */
- properties[PROP_TIMESTAMP] = g_param_spec_boxed(
- "timestamp", "timestamp",
- "The timestamp of the message",
- G_TYPE_DATE_TIME,
- G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
-
- /**
- * PurpleMessage::flags:
- *
- * The #PurpleMessageFlags for the message.
- */
- properties[PROP_FLAGS] = g_param_spec_flags(
- "flags", "Flags",
- "Bitwise set of #PurpleMessageFlags flags",
- PURPLE_TYPE_MESSAGE_FLAGS, 0,
- G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
-
- g_object_class_install_properties(obj_class, N_PROPERTIES, properties);
-}
-
-/******************************************************************************
- * Public API
- *****************************************************************************/
-PurpleMessage *
-purple_message_new_outgoing(const gchar *author, const gchar *recipient,
- const gchar *contents, PurpleMessageFlags flags)
-{
- PurpleMessage *message = NULL;
- GDateTime *dt = NULL;
-
- g_warn_if_fail(!(flags & PURPLE_MESSAGE_RECV));
- g_warn_if_fail(!(flags & PURPLE_MESSAGE_SYSTEM));
-
- flags |= PURPLE_MESSAGE_SEND;
- dt = g_date_time_new_now_local();
-
- /* who may be NULL for outgoing MUC messages */
- message = PURPLE_MESSAGE(g_object_new(PURPLE_TYPE_MESSAGE,
- "author", author,
- "recipient", recipient,
- "contents", contents,
- "timestamp", dt,
- "flags", flags,
- NULL));
-
- g_date_time_unref(dt);
-
- return message;
-}
-
-PurpleMessage *
-purple_message_new_incoming(const gchar *who, const gchar *contents,
- PurpleMessageFlags flags, guint64 timestamp)
-{
- PurpleMessage *message = NULL;
- GDateTime *dt = NULL;
-
- g_warn_if_fail(!(flags & PURPLE_MESSAGE_SEND));
- g_warn_if_fail(!(flags & PURPLE_MESSAGE_SYSTEM));
-
- flags |= PURPLE_MESSAGE_RECV;
-
- if(timestamp == 0) {
- dt = g_date_time_new_now_local();
- } else {
- dt = g_date_time_new_from_unix_local((gint64)timestamp);
- }
-
- message = PURPLE_MESSAGE(g_object_new(PURPLE_TYPE_MESSAGE,
- "author", who,
- "author-alias", who,
- "contents", contents,
- "timestamp", dt,
- "flags", flags,
- NULL));
-
- g_date_time_unref(dt);
-
- return message;
-}
-
-PurpleMessage *
-purple_message_new_system(const gchar *contents, PurpleMessageFlags flags) {
- PurpleMessage *message = NULL;
- GDateTime *dt = NULL;
-
- g_warn_if_fail(!(flags & PURPLE_MESSAGE_SEND));
- g_warn_if_fail(!(flags & PURPLE_MESSAGE_RECV));
-
- flags |= PURPLE_MESSAGE_SYSTEM;
- dt = g_date_time_new_now_local();
-
- message = PURPLE_MESSAGE(g_object_new(PURPLE_TYPE_MESSAGE,
- "contents", contents,
- "timestamp", dt,
- "flags", flags,
- NULL));
-
- g_date_time_unref(dt);
-
- return message;
-}
-
-guint
-purple_message_get_id(PurpleMessage *message) {
- g_return_val_if_fail(PURPLE_IS_MESSAGE(message), 0);
-
- return message->id;
-}
-
-const gchar *
-purple_message_get_author(PurpleMessage *message) {
- g_return_val_if_fail(PURPLE_IS_MESSAGE(message), NULL);
-
- return message->author;
-}
-
-void
-purple_message_set_recipient(PurpleMessage *message, const gchar *recipient) {
- g_return_if_fail(PURPLE_IS_MESSAGE(message));
-
- g_free(message->recipient);
- message->recipient = g_strdup(recipient);
-
- g_object_notify_by_pspec(G_OBJECT(message), properties[PROP_RECIPIENT]);
-}
-
-const gchar *
-purple_message_get_recipient(PurpleMessage *message) {
- g_return_val_if_fail(PURPLE_IS_MESSAGE(message), NULL);
-
- return message->recipient;
-}
-
-void
-purple_message_set_author_alias(PurpleMessage *message,
- const gchar *author_alias)
-{
- g_return_if_fail(PURPLE_IS_MESSAGE(message));
-
- g_free(message->author_alias);
- message->author_alias = g_strdup(author_alias);
-
- g_object_notify_by_pspec(G_OBJECT(message), properties[PROP_AUTHOR_ALIAS]);
-}
-
-const gchar *
-purple_message_get_author_alias(PurpleMessage *message) {
- g_return_val_if_fail(PURPLE_IS_MESSAGE(message), NULL);
-
- if (message->author_alias == NULL)
- return purple_message_get_author(message);
-
- return message->author_alias;
-}
-
-void
-purple_message_set_contents(PurpleMessage *message, const gchar *contents) {
- g_return_if_fail(PURPLE_IS_MESSAGE(message));
-
- g_free(message->contents);
- message->contents = g_strdup(contents);
-
- g_object_notify_by_pspec(G_OBJECT(message), properties[PROP_CONTENTS]);
-}
-
-const gchar *
-purple_message_get_contents(PurpleMessage *message) {
- g_return_val_if_fail(PURPLE_IS_MESSAGE(message), NULL);
-
- return message->contents;
-}
-
-void
-purple_message_set_content_type(PurpleMessage *message,
- PurpleMessageContentType content_type)
-{
- g_return_if_fail(PURPLE_IS_MESSAGE(message));
-
- message->content_type = content_type;
-
- g_object_notify_by_pspec(G_OBJECT(message), properties[PROP_CONTENT_TYPE]);
-}
-
-PurpleMessageContentType
-purple_message_get_content_type(PurpleMessage *message) {
- g_return_val_if_fail(PURPLE_IS_MESSAGE(message),
- PURPLE_MESSAGE_CONTENT_TYPE_PLAIN);
-
- return message->content_type;
-}
-
-gboolean
-purple_message_is_empty(PurpleMessage *message) {
- return (message->contents == NULL || message->contents[0] == '\0');
-}
-
-void
-purple_message_set_timestamp(PurpleMessage *message, GDateTime *timestamp) {
- g_return_if_fail(PURPLE_IS_MESSAGE(message));
-
- g_clear_pointer(&message->timestamp, g_date_time_unref);
- if(timestamp != NULL) {
- message->timestamp = g_date_time_ref(timestamp);
- }
-
- g_object_notify_by_pspec(G_OBJECT(message), properties[PROP_TIMESTAMP]);
-}
-
-GDateTime *
-purple_message_get_timestamp(PurpleMessage *message) {
- g_return_val_if_fail(PURPLE_IS_MESSAGE(message), 0);
-
- if(message->timestamp == NULL) {
- GDateTime *dt = g_date_time_new_now_local();
- purple_message_set_timestamp(message, dt);
- g_date_time_unref(dt);
- }
-
- return message->timestamp;
-}
-
-gchar *
-purple_message_format_timestamp(PurpleMessage *message, const gchar *format) {
- GDateTime *dt = NULL;
-
- g_return_val_if_fail(PURPLE_IS_MESSAGE(message), NULL);
- g_return_val_if_fail(format != NULL, NULL);
-
- dt = purple_message_get_timestamp(message);
-
- return g_date_time_format(dt, format);
-}
-
-void
-purple_message_set_flags(PurpleMessage *message, PurpleMessageFlags flags) {
- g_return_if_fail(PURPLE_IS_MESSAGE(message));
-
- message->flags = flags;
-
- g_object_notify_by_pspec(G_OBJECT(message), properties[PROP_FLAGS]);
-}
-
-PurpleMessageFlags
-purple_message_get_flags(PurpleMessage *message) {
- g_return_val_if_fail(PURPLE_IS_MESSAGE(message), 0);
-
- return message->flags;
-}
-
-gboolean
-purple_message_add_attachment(PurpleMessage *message,
- PurpleAttachment *attachment)
-{
- g_return_val_if_fail(PURPLE_IS_MESSAGE(message), FALSE);
- g_return_val_if_fail(PURPLE_IS_ATTACHMENT(attachment), FALSE);
-
- return g_hash_table_insert(message->attachments,
- purple_attachment_get_hash_key(attachment),
- g_object_ref(G_OBJECT(attachment)));
-}
-
-gboolean
-purple_message_remove_attachment(PurpleMessage *message, guint64 id) {
- g_return_val_if_fail(PURPLE_IS_MESSAGE(message), FALSE);
-
- return g_hash_table_remove(message->attachments, &id);
-}
-
-PurpleAttachment *
-purple_message_get_attachment(PurpleMessage *message, guint64 id) {
- PurpleAttachment *attachment = NULL;
-
- g_return_val_if_fail(PURPLE_IS_MESSAGE(message), NULL);
-
- attachment = g_hash_table_lookup(message->attachments, &id);
- if(PURPLE_IS_ATTACHMENT(attachment)) {
- return PURPLE_ATTACHMENT(g_object_ref(G_OBJECT(attachment)));
- }
-
- return NULL;
-}
-
-void
-purple_message_foreach_attachment(PurpleMessage *message,
- PurpleAttachmentForeachFunc func,
- gpointer data)
-{
- GHashTableIter iter;
- gpointer value;
-
- g_return_if_fail(PURPLE_IS_MESSAGE(message));
- g_return_if_fail(func != NULL);
-
- g_hash_table_iter_init(&iter, message->attachments);
- while(g_hash_table_iter_next(&iter, NULL, &value)) {
- func(PURPLE_ATTACHMENT(value), data);
- }
-}
-
-void
-purple_message_clear_attachments(PurpleMessage *message) {
- g_return_if_fail(PURPLE_IS_MESSAGE(message));
-
- g_hash_table_remove_all(message->attachments);
-}
--- a/libpurple/message.h Mon Jan 11 00:20:09 2021 -0600
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,431 +0,0 @@
-/*
- * purple
- *
- * Purple is the legal property of its developers, whose names are too numerous
- * to list here. Please refer to the COPYRIGHT file distributed with this
- * source distribution.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public
- * License along with this library; if not, see <https://www.gnu.org/licenses/>.
- */
-
-#if !defined(PURPLE_GLOBAL_HEADER_INSIDE) && !defined(PURPLE_COMPILATION)
-# error "only <purple.h> may be included directly"
-#endif
-
-#ifndef PURPLE_MESSAGE_H
-#define PURPLE_MESSAGE_H
-
-/**
- * SECTION:message
- * @include:message.h
- * @section_id: libpurple-message
- * @short_description: serializable messages
- * @title: Message model
- *
- * #PurpleMessage object collects data about a certain (incoming or outgoing) message.
- * It (TODO: will be) serializable, so it can be stored in log and retrieved
- * with any metadata.
- */
-
-#include <glib-object.h>
-
-#include <libpurple/purpleattachment.h>
-
-G_BEGIN_DECLS
-
-/**
- * PURPLE_TYPE_MESSAGE:
- *
- * The standard _get_type macro for #PurpleMessage.
- *
- * Since: 3.0.0
- */
-#define PURPLE_TYPE_MESSAGE purple_message_get_type()
-
-/**
- * PurpleMessageFlags:
- * @PURPLE_MESSAGE_SEND: Outgoing message.
- * @PURPLE_MESSAGE_RECV: Incoming message.
- * @PURPLE_MESSAGE_SYSTEM: System message.
- * @PURPLE_MESSAGE_AUTO_RESP: Auto response.
- * @PURPLE_MESSAGE_ACTIVE_ONLY: Hint to the UI that this message should not be
- * shown in conversations which are only open for
- * internal UI purposes (e.g. for contact-aware
- * conversations).
- * @PURPLE_MESSAGE_NICK: Contains your nick.
- * @PURPLE_MESSAGE_NO_LOG: Do not log.
- * @PURPLE_MESSAGE_ERROR: Error message.
- * @PURPLE_MESSAGE_DELAYED: Delayed message.
- * @PURPLE_MESSAGE_RAW: "Raw" message - don't apply formatting
- * @PURPLE_MESSAGE_IMAGES: Message contains images
- * @PURPLE_MESSAGE_NOTIFY: Message is a notification
- * @PURPLE_MESSAGE_NO_LINKIFY: Message should not be auto-linkified
- * @PURPLE_MESSAGE_INVISIBLE: Message should not be displayed
- * @PURPLE_MESSAGE_REMOTE_SEND: Message sent from another location,
- * not an echo of a local one
- * Since: 2.12.0
- *
- * Flags applicable to a message. Most will have send, recv or system.
- */
-typedef enum /*< flags >*/
-{
- PURPLE_MESSAGE_SEND = 1 << 0,
- PURPLE_MESSAGE_RECV = 1 << 1,
- PURPLE_MESSAGE_SYSTEM = 1 << 2,
- PURPLE_MESSAGE_AUTO_RESP = 1 << 3,
- PURPLE_MESSAGE_ACTIVE_ONLY = 1 << 4,
- PURPLE_MESSAGE_NICK = 1 << 5,
- PURPLE_MESSAGE_NO_LOG = 1 << 6,
- PURPLE_MESSAGE_ERROR = 1 << 7,
- PURPLE_MESSAGE_DELAYED = 1 << 8,
- PURPLE_MESSAGE_RAW = 1 << 9,
- PURPLE_MESSAGE_IMAGES = 1 << 10,
- PURPLE_MESSAGE_NOTIFY = 1 << 11,
- PURPLE_MESSAGE_NO_LINKIFY = 1 << 12,
- PURPLE_MESSAGE_INVISIBLE = 1 << 13,
- PURPLE_MESSAGE_REMOTE_SEND = 1 << 14,
-} PurpleMessageFlags;
-
-/**
- * PurpleMessageContentType:
- * @PURPLE_MESSAGE_CONTENT_TYPE_PLAIN: The message has no formatting.
- * @PURPLE_MESSAGE_CONTENT_TYPE_HTML: The message is formatted in HTML.
- * @PURPLE_MESSAGE_CONTENT_TYPE_XHTML: The mesage is formatted in XHTML.
- * @PURPLE_MESSAGE_CONTENT_TYPE_MARKDOWN: The message is formatted in Markdown.
- *
- * The message formatting for the message.
- *
- * Since: 3.0.0
- */
-typedef enum /*< prefix=PURPLE_MESSAGE_CONTENT_TYPE,underscore_name=PURPLE_MESSAGE_CONTENT_TYPE >*/
-{
- PURPLE_MESSAGE_CONTENT_TYPE_PLAIN = 0,
- PURPLE_MESSAGE_CONTENT_TYPE_HTML,
- PURPLE_MESSAGE_CONTENT_TYPE_XHTML,
- PURPLE_MESSAGE_CONTENT_TYPE_MARKDOWN,
-} PurpleMessageContentType;
-
-/**
- * purple_message_get_type:
- *
- * Returns: the #GType for a message.
- *
- * Since: 3.0.0
- */
-G_DECLARE_FINAL_TYPE(PurpleMessage, purple_message, PURPLE, MESSAGE, GObject)
-
-/**
- * purple_message_new_outgoing:
- * @author: The author.
- * @recipient: The recipient.
- * @contents: The contents.
- * @flags: The #PurpleMessageFlags.
- *
- * Creates new outgoing message to @recipient.
- *
- * You don't need to set the #PURPLE_MESSAGE_SEND flag. If the message is not
- * plain text be sure to call purple_message_set_content_type().
- *
- * Returns: (transfer full): The new #PurpleMessage instance.
- *
- * Since: 3.0.0
- */
-PurpleMessage *purple_message_new_outgoing(const gchar *author, const gchar *recipient, const gchar *contents, PurpleMessageFlags flags);
-
-/**
- * purple_message_new_incoming:
- * @who: Message's author.
- * @contents: The contents of a message.
- * @flags: The message flags.
- * @timestamp: The time of transmitting a message. May be 0 for a current time.
- *
- * Creates new incoming message (the user is the recipient).
- *
- * You don't need to set the #PURPLE_MESSAGE_RECV flag.
- *
- * Returns: the new #PurpleMessage.
- *
- * Since: 3.0.0
- */
-PurpleMessage *purple_message_new_incoming(const gchar *who, const gchar *contents, PurpleMessageFlags flags, guint64 timestamp);
-
-/**
- * purple_message_new_system:
- * @contents: The contents of a message.
- * @flags: The message flags.
- *
- * Creates new system message.
- *
- * You don't need to set the #PURPLE_MESSAGE_SYSTEM flag.
- *
- * Returns: the new #PurpleMessage.
- *
- * Since: 3.0.0
- */
-PurpleMessage *purple_message_new_system(const gchar *contents, PurpleMessageFlags flags);
-
-/**
- * purple_message_get_id:
- * @message: The message.
- *
- * Returns the unique identifier of the message. These identifiers are not
- * serialized - it's a per-session id.
- *
- * Returns: the global identifier of @message.
- *
- * Since: 3.0.0
- */
-guint purple_message_get_id(PurpleMessage *message);
-
-/**
- * purple_message_get_author:
- * @message: The message.
- *
- * Returns the author of the message, not a local alias.
- *
- * Returns: the author of @message.
- *
- * Since: 3.0.0
- */
-const gchar *purple_message_get_author(PurpleMessage *message);
-
-/**
- * purple_message_set_recipient:
- * @message: The #PurpleMessage instance.
- * @recipient: The name of the recipient.
- *
- * Sets the recipient of @message to @recipient.
- *
- * Since: 3.0.0
- */
-void purple_message_set_recipient(PurpleMessage *message, const gchar *recipient);
-
-/**
- * purple_message_get_recipient:
- * @message: The message.
- *
- * Returns the recipient of the message, not a local alias.
- *
- * Returns: the recipient of @message.
- *
- * Since: 3.0.0
- */
-const gchar *purple_message_get_recipient(PurpleMessage *message);
-
-/**
- * purple_message_set_author_alias:
- * @message: The message.
- * @alias: The alias.
- *
- * Sets the alias of @message's author. You don't normally need to call this.
- *
- * Since: 3.0.0
- */
-void purple_message_set_author_alias(PurpleMessage *message, const gchar *alias);
-
-/**
- * purple_message_get_author_alias:
- * @message: The message.
- *
- * Returns the alias of @message author.
- *
- * Returns: the @message author's alias.
- *
- * Since: 3.0.0
- */
-const gchar *purple_message_get_author_alias(PurpleMessage *message);
-
-/**
- * purple_message_set_contents:
- * @message: The message.
- * @cont: The contents.
- *
- * Sets the contents of the @message. It might be HTML.
- *
- * Since: 3.0.0
- */
-void purple_message_set_contents(PurpleMessage *message, const gchar *cont);
-
-/**
- * purple_message_get_contents:
- * @message: The message.
- *
- * Returns the contents of the message.
- *
- * Returns: the contents of @message.
- *
- * Since: 3.0.0
- */
-const gchar *purple_message_get_contents(PurpleMessage *message);
-
-/**
- * purple_message_set_content_type:
- * @message: The #PurpleMessage instance.
- * @content_type: The #PurpleMessageContentType value.
- *
- * Sets the content-type of @message to @content_type.
- *
- * Since: 3.0.0
- */
-void purple_message_set_content_type(PurpleMessage *message, PurpleMessageContentType content_type);
-
-/**
- * purple_message_get_content_type:
- * @message: The #PurpleMessage instance.
- *
- * Gets the content-type of @message.
- *
- * Returns: The #PurpleMessageContentType of @message.
- *
- * Since: 3.0.0
- */
-PurpleMessageContentType purple_message_get_content_type(PurpleMessage *message);
-
-/**
- * purple_message_is_empty:
- * @message: The message.
- *
- * Checks, if the message's body is empty.
- *
- * Returns: %TRUE, if @message is empty.
- *
- * Since: 3.0.0
- */
-gboolean purple_message_is_empty(PurpleMessage *message);
-
-/**
- * purple_message_set_timestamp:
- * @message: The #PurpleMessage instance.
- * @timestamp: (nullable): The #GDateTime of the message.
- *
- * Sets the timestamp of @message.
- *
- * Since: 3.0.0
- */
-void purple_message_set_timestamp(PurpleMessage *message, GDateTime *timestamp);
-
-/**
- * purple_message_get_timestamp:
- * @message: The message.
- *
- * Returns a @message's timestamp. If @message does not currently have a
- * timestamp, the current time will be set as the time stamp and returned.
- *
- * Returns: (transfer none): The #GDateTime timestamp from @message.
- *
- * Since: 3.0.0
- */
-GDateTime *purple_message_get_timestamp(PurpleMessage *message);
-
-/**
- * purple_message_format_timestamp:
- * @message: The #PurpleMessage instance.
- * @format: The format to output the time stamp as.
- *
- * Formats the timestamp of @message and returns it.
- *
- * Returns: The formatted timestamp.
- */
-gchar *purple_message_format_timestamp(PurpleMessage *message, const gchar *format);
-
-/**
- * purple_message_set_flags:
- * @message: The message.
- * @flags: The message flags.
- *
- * Sets flags for @message. It shouldn't be in a conflict with a message type,
- * so use it carefully.
- *
- * Since: 3.0.0
- */
-void purple_message_set_flags(PurpleMessage *message, PurpleMessageFlags flags);
-
-/**
- * purple_message_get_flags:
- * @message: The message.
- *
- * Returns the flags of a @message.
- *
- * Returns: the flags of a @message.
- *
- * Since: 3.0.0
- */
-PurpleMessageFlags purple_message_get_flags(PurpleMessage *message);
-
-/**
- * purple_message_add_attachment:
- * @message: The #PurpleMessage instance.
- * @attachment: The #PurpleAttachment instance.
- *
- * Adds @attachment to @message.
- *
- * Returns %TRUE if an attachment with the same ID did not already exist.
- *
- * Since: 3.0.0
- */
-gboolean purple_message_add_attachment(PurpleMessage *message, PurpleAttachment *attachment);
-
-/**
- * purple_message_remove_attachment:
- * @message: The #PurpleMessage instance.
- * @id: The id of the #PurpleAttachment
- *
- * Removes the #PurpleAttachment identified by @id if it exists.
- *
- * Returns: %TRUE if the #PurpleAttachment was found and removed, %FALSE
- * otherwise.
- *
- * Since: 3.0.0
- */
-gboolean purple_message_remove_attachment(PurpleMessage *message, guint64 id);
-
-/**
- * purple_message_get_attachment:
- * @message: The #PurpleMessage instance.
- * @id: The id of the #PurpleAttachment to get.
- *
- * Retrieves the #PurpleAttachment identified by @id from @message.
- *
- * Returns: (transfer full): The #PurpleAttachment if it was found, otherwise
- * %NULL.
- *
- * Since: 3.0.0
- */
-PurpleAttachment *purple_message_get_attachment(PurpleMessage *message, guint64 id);
-
-/**
- * purple_message_foreach_attachment:
- * @message: The #PurpleMessage instance.
- * @func: (scope call): The #PurpleAttachmentForeachFunc to call.
- * @data: User data to pass to @func.
- *
- * Calls @func for each #PurpleAttachment that's attached to @message.
- *
- * Since: 3.0.0
- */
-void purple_message_foreach_attachment(PurpleMessage *message, PurpleAttachmentForeachFunc func, gpointer data);
-
-/**
- * purple_message_clear_attachments:
- * @message: The #PurpleMessage instance.
- *
- * Removes all attachments from @message.
- *
- * Since: 3.0.0
- */
-void purple_message_clear_attachments(PurpleMessage *message);
-
-G_END_DECLS
-
-#endif /* PURPLE_MESSAGE_H */
--- a/libpurple/protocol.h Mon Jan 11 00:20:09 2021 -0600
+++ b/libpurple/protocol.h Mon Jan 11 01:08:47 2021 -0600
@@ -55,11 +55,11 @@
#include "debug.h"
#include "xfer.h"
#include "image.h"
-#include "message.h"
#include "notify.h"
#include "plugins.h"
#include "purpleaccountoption.h"
#include "purpleaccountusersplit.h"
+#include "purplemessage.h"
#include "purplewhiteboard.h"
#include "purplewhiteboardops.h"
#include "roomlist.h"
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/libpurple/purplemessage.c Mon Jan 11 01:08:47 2021 -0600
@@ -0,0 +1,573 @@
+/*
+ * Purple - Internet Messaging Library
+ * Copyright (C) Pidgin Developers <devel@pidgin.im>
+ *
+ * Purple is the legal property of its developers, whose names are too numerous
+ * to list here. Please refer to the COPYRIGHT file distributed with this
+ * source distribution.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <https://www.gnu.org/licenses/>.
+ */
+
+#include <glib/gi18n-lib.h>
+
+#include "internal.h"
+
+#include "debug.h"
+#include "purplemessage.h"
+#include "enums.h"
+#include "purpleprivate.h"
+
+/**
+ * PurpleMessage:
+ *
+ * A message data container.
+ */
+struct _PurpleMessage {
+ GObject parent;
+
+ guint id;
+ gchar *author;
+ gchar *author_alias;
+ gchar *recipient;
+
+ gchar *contents;
+ PurpleMessageContentType content_type;
+
+ GDateTime *timestamp;
+ PurpleMessageFlags flags;
+
+ GHashTable *attachments;
+};
+
+enum {
+ PROP_0,
+ PROP_ID,
+ PROP_AUTHOR,
+ PROP_AUTHOR_ALIAS,
+ PROP_RECIPIENT,
+ PROP_CONTENTS,
+ PROP_CONTENT_TYPE,
+ PROP_TIMESTAMP,
+ PROP_FLAGS,
+ N_PROPERTIES
+};
+static GParamSpec *properties[N_PROPERTIES];
+
+G_DEFINE_TYPE(PurpleMessage, purple_message, G_TYPE_OBJECT)
+
+/******************************************************************************
+ * Helpers
+ *****************************************************************************/
+static void
+purple_message_set_id(PurpleMessage *message, guint id) {
+ message->id = id;
+
+ g_object_notify_by_pspec(G_OBJECT(message), properties[PROP_ID]);
+}
+
+static void
+purple_message_set_author(PurpleMessage *message, const gchar *author) {
+ g_free(message->author);
+ message->author = g_strdup(author);
+
+ g_object_notify_by_pspec(G_OBJECT(message), properties[PROP_AUTHOR]);
+}
+
+/******************************************************************************
+ * GObject Implementation
+ *****************************************************************************/
+static void
+purple_message_get_property(GObject *object, guint param_id, GValue *value,
+ GParamSpec *pspec)
+{
+ PurpleMessage *message = PURPLE_MESSAGE(object);
+
+ switch(param_id) {
+ case PROP_ID:
+ g_value_set_uint(value, purple_message_get_id(message));
+ break;
+ case PROP_AUTHOR:
+ g_value_set_string(value, purple_message_get_author(message));
+ break;
+ case PROP_AUTHOR_ALIAS:
+ g_value_set_string(value, purple_message_get_author_alias(message));
+ break;
+ case PROP_RECIPIENT:
+ g_value_set_string(value, purple_message_get_recipient(message));
+ break;
+ case PROP_CONTENTS:
+ g_value_set_string(value, purple_message_get_contents(message));
+ break;
+ case PROP_CONTENT_TYPE:
+ g_value_set_enum(value, purple_message_get_content_type(message));
+ break;
+ case PROP_TIMESTAMP:
+ g_value_set_boxed(value, purple_message_get_timestamp(message));
+ break;
+ case PROP_FLAGS:
+ g_value_set_flags(value, purple_message_get_flags(message));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, param_id, pspec);
+ break;
+ }
+}
+
+static void
+purple_message_set_property(GObject *object, guint param_id,
+ const GValue *value, GParamSpec *pspec)
+{
+ PurpleMessage *message = PURPLE_MESSAGE(object);
+
+ switch(param_id) {
+ case PROP_ID:
+ purple_message_set_id(message, g_value_get_uint(value));
+ break;
+ case PROP_AUTHOR:
+ purple_message_set_author(message, g_value_get_string(value));
+ break;
+ case PROP_AUTHOR_ALIAS:
+ purple_message_set_author_alias(message, g_value_get_string(value));
+ break;
+ case PROP_RECIPIENT:
+ purple_message_set_recipient(message, g_value_get_string(value));
+ break;
+ case PROP_CONTENTS:
+ purple_message_set_contents(message, g_value_get_string(value));
+ break;
+ case PROP_CONTENT_TYPE:
+ purple_message_set_content_type(message, g_value_get_enum(value));
+ break;
+ case PROP_TIMESTAMP:
+ purple_message_set_timestamp(message, g_value_get_boxed(value));
+ break;
+ case PROP_FLAGS:
+ purple_message_set_flags(message, g_value_get_flags(value));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, param_id, pspec);
+ break;
+ }
+}
+
+static void
+purple_message_finalize(GObject *obj) {
+ PurpleMessage *message = PURPLE_MESSAGE(obj);
+
+ g_free(message->author);
+ g_free(message->author_alias);
+ g_free(message->recipient);
+ g_free(message->contents);
+
+ if(message->timestamp != NULL) {
+ g_date_time_unref(message->timestamp);
+ }
+
+ g_hash_table_destroy(message->attachments);
+
+ G_OBJECT_CLASS(purple_message_parent_class)->finalize(obj);
+}
+
+static void
+purple_message_init(PurpleMessage *message) {
+ message->attachments = g_hash_table_new_full(g_int64_hash, g_int64_equal,
+ NULL, g_object_unref);
+}
+
+static void
+purple_message_class_init(PurpleMessageClass *klass) {
+ GObjectClass *obj_class = G_OBJECT_CLASS(klass);
+
+ obj_class->get_property = purple_message_get_property;
+ obj_class->set_property = purple_message_set_property;
+ obj_class->finalize = purple_message_finalize;
+
+ /**
+ * PurpleMessage::id:
+ *
+ * The account specific identifier of the message.
+ */
+ properties[PROP_ID] = g_param_spec_uint(
+ "id", "ID",
+ "The session-unique message id",
+ 0, G_MAXUINT, 0,
+ G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
+
+ /**
+ * PurpleMessage::author:
+ *
+ * The author of the message.
+ */
+ properties[PROP_AUTHOR] = g_param_spec_string(
+ "author", "Author",
+ "The username of the person, who sent the message.",
+ NULL,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+
+ /**
+ * PurpleMessage::author-alias:
+ *
+ * The alias of the author.
+ */
+ properties[PROP_AUTHOR_ALIAS] = g_param_spec_string(
+ "author-alias", "Author's alias",
+ "The alias of the sender",
+ NULL,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+
+ /**
+ * PurpleMessage::recipient:
+ *
+ * The recipient of the message.
+ */
+ properties[PROP_RECIPIENT] = g_param_spec_string(
+ "recipient", "Recipient",
+ "The username of the recipient.",
+ NULL,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+
+ /**
+ * PurpleMessage::content:
+ *
+ * The contents of the message.
+ */
+ properties[PROP_CONTENTS] = g_param_spec_string(
+ "contents", "Contents",
+ "The message text",
+ NULL,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+
+ /**
+ * PurpleMessage::content-type:
+ *
+ * The content-type of the message.
+ */
+ properties[PROP_CONTENT_TYPE] = g_param_spec_enum(
+ "content-type", "content-type",
+ "The content-type of the message.",
+ PURPLE_TYPE_MESSAGE_CONTENT_TYPE, PURPLE_MESSAGE_CONTENT_TYPE_PLAIN,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+
+ /**
+ * PurpleMessage::timestamp:
+ *
+ * The timestamp of the message.
+ */
+ properties[PROP_TIMESTAMP] = g_param_spec_boxed(
+ "timestamp", "timestamp",
+ "The timestamp of the message",
+ G_TYPE_DATE_TIME,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+
+ /**
+ * PurpleMessage::flags:
+ *
+ * The #PurpleMessageFlags for the message.
+ */
+ properties[PROP_FLAGS] = g_param_spec_flags(
+ "flags", "Flags",
+ "Bitwise set of #PurpleMessageFlags flags",
+ PURPLE_TYPE_MESSAGE_FLAGS, 0,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+
+ g_object_class_install_properties(obj_class, N_PROPERTIES, properties);
+}
+
+/******************************************************************************
+ * Public API
+ *****************************************************************************/
+PurpleMessage *
+purple_message_new_outgoing(const gchar *author, const gchar *recipient,
+ const gchar *contents, PurpleMessageFlags flags)
+{
+ PurpleMessage *message = NULL;
+ GDateTime *dt = NULL;
+
+ g_warn_if_fail(!(flags & PURPLE_MESSAGE_RECV));
+ g_warn_if_fail(!(flags & PURPLE_MESSAGE_SYSTEM));
+
+ flags |= PURPLE_MESSAGE_SEND;
+ dt = g_date_time_new_now_local();
+
+ /* who may be NULL for outgoing MUC messages */
+ message = PURPLE_MESSAGE(g_object_new(PURPLE_TYPE_MESSAGE,
+ "author", author,
+ "recipient", recipient,
+ "contents", contents,
+ "timestamp", dt,
+ "flags", flags,
+ NULL));
+
+ g_date_time_unref(dt);
+
+ return message;
+}
+
+PurpleMessage *
+purple_message_new_incoming(const gchar *who, const gchar *contents,
+ PurpleMessageFlags flags, guint64 timestamp)
+{
+ PurpleMessage *message = NULL;
+ GDateTime *dt = NULL;
+
+ g_warn_if_fail(!(flags & PURPLE_MESSAGE_SEND));
+ g_warn_if_fail(!(flags & PURPLE_MESSAGE_SYSTEM));
+
+ flags |= PURPLE_MESSAGE_RECV;
+
+ if(timestamp == 0) {
+ dt = g_date_time_new_now_local();
+ } else {
+ dt = g_date_time_new_from_unix_local((gint64)timestamp);
+ }
+
+ message = PURPLE_MESSAGE(g_object_new(PURPLE_TYPE_MESSAGE,
+ "author", who,
+ "author-alias", who,
+ "contents", contents,
+ "timestamp", dt,
+ "flags", flags,
+ NULL));
+
+ g_date_time_unref(dt);
+
+ return message;
+}
+
+PurpleMessage *
+purple_message_new_system(const gchar *contents, PurpleMessageFlags flags) {
+ PurpleMessage *message = NULL;
+ GDateTime *dt = NULL;
+
+ g_warn_if_fail(!(flags & PURPLE_MESSAGE_SEND));
+ g_warn_if_fail(!(flags & PURPLE_MESSAGE_RECV));
+
+ flags |= PURPLE_MESSAGE_SYSTEM;
+ dt = g_date_time_new_now_local();
+
+ message = PURPLE_MESSAGE(g_object_new(PURPLE_TYPE_MESSAGE,
+ "contents", contents,
+ "timestamp", dt,
+ "flags", flags,
+ NULL));
+
+ g_date_time_unref(dt);
+
+ return message;
+}
+
+guint
+purple_message_get_id(PurpleMessage *message) {
+ g_return_val_if_fail(PURPLE_IS_MESSAGE(message), 0);
+
+ return message->id;
+}
+
+const gchar *
+purple_message_get_author(PurpleMessage *message) {
+ g_return_val_if_fail(PURPLE_IS_MESSAGE(message), NULL);
+
+ return message->author;
+}
+
+void
+purple_message_set_recipient(PurpleMessage *message, const gchar *recipient) {
+ g_return_if_fail(PURPLE_IS_MESSAGE(message));
+
+ g_free(message->recipient);
+ message->recipient = g_strdup(recipient);
+
+ g_object_notify_by_pspec(G_OBJECT(message), properties[PROP_RECIPIENT]);
+}
+
+const gchar *
+purple_message_get_recipient(PurpleMessage *message) {
+ g_return_val_if_fail(PURPLE_IS_MESSAGE(message), NULL);
+
+ return message->recipient;
+}
+
+void
+purple_message_set_author_alias(PurpleMessage *message,
+ const gchar *author_alias)
+{
+ g_return_if_fail(PURPLE_IS_MESSAGE(message));
+
+ g_free(message->author_alias);
+ message->author_alias = g_strdup(author_alias);
+
+ g_object_notify_by_pspec(G_OBJECT(message), properties[PROP_AUTHOR_ALIAS]);
+}
+
+const gchar *
+purple_message_get_author_alias(PurpleMessage *message) {
+ g_return_val_if_fail(PURPLE_IS_MESSAGE(message), NULL);
+
+ if (message->author_alias == NULL)
+ return purple_message_get_author(message);
+
+ return message->author_alias;
+}
+
+void
+purple_message_set_contents(PurpleMessage *message, const gchar *contents) {
+ g_return_if_fail(PURPLE_IS_MESSAGE(message));
+
+ g_free(message->contents);
+ message->contents = g_strdup(contents);
+
+ g_object_notify_by_pspec(G_OBJECT(message), properties[PROP_CONTENTS]);
+}
+
+const gchar *
+purple_message_get_contents(PurpleMessage *message) {
+ g_return_val_if_fail(PURPLE_IS_MESSAGE(message), NULL);
+
+ return message->contents;
+}
+
+void
+purple_message_set_content_type(PurpleMessage *message,
+ PurpleMessageContentType content_type)
+{
+ g_return_if_fail(PURPLE_IS_MESSAGE(message));
+
+ message->content_type = content_type;
+
+ g_object_notify_by_pspec(G_OBJECT(message), properties[PROP_CONTENT_TYPE]);
+}
+
+PurpleMessageContentType
+purple_message_get_content_type(PurpleMessage *message) {
+ g_return_val_if_fail(PURPLE_IS_MESSAGE(message),
+ PURPLE_MESSAGE_CONTENT_TYPE_PLAIN);
+
+ return message->content_type;
+}
+
+gboolean
+purple_message_is_empty(PurpleMessage *message) {
+ return (message->contents == NULL || message->contents[0] == '\0');
+}
+
+void
+purple_message_set_timestamp(PurpleMessage *message, GDateTime *timestamp) {
+ g_return_if_fail(PURPLE_IS_MESSAGE(message));
+
+ g_clear_pointer(&message->timestamp, g_date_time_unref);
+ if(timestamp != NULL) {
+ message->timestamp = g_date_time_ref(timestamp);
+ }
+
+ g_object_notify_by_pspec(G_OBJECT(message), properties[PROP_TIMESTAMP]);
+}
+
+GDateTime *
+purple_message_get_timestamp(PurpleMessage *message) {
+ g_return_val_if_fail(PURPLE_IS_MESSAGE(message), 0);
+
+ if(message->timestamp == NULL) {
+ GDateTime *dt = g_date_time_new_now_local();
+ purple_message_set_timestamp(message, dt);
+ g_date_time_unref(dt);
+ }
+
+ return message->timestamp;
+}
+
+gchar *
+purple_message_format_timestamp(PurpleMessage *message, const gchar *format) {
+ GDateTime *dt = NULL;
+
+ g_return_val_if_fail(PURPLE_IS_MESSAGE(message), NULL);
+ g_return_val_if_fail(format != NULL, NULL);
+
+ dt = purple_message_get_timestamp(message);
+
+ return g_date_time_format(dt, format);
+}
+
+void
+purple_message_set_flags(PurpleMessage *message, PurpleMessageFlags flags) {
+ g_return_if_fail(PURPLE_IS_MESSAGE(message));
+
+ message->flags = flags;
+
+ g_object_notify_by_pspec(G_OBJECT(message), properties[PROP_FLAGS]);
+}
+
+PurpleMessageFlags
+purple_message_get_flags(PurpleMessage *message) {
+ g_return_val_if_fail(PURPLE_IS_MESSAGE(message), 0);
+
+ return message->flags;
+}
+
+gboolean
+purple_message_add_attachment(PurpleMessage *message,
+ PurpleAttachment *attachment)
+{
+ g_return_val_if_fail(PURPLE_IS_MESSAGE(message), FALSE);
+ g_return_val_if_fail(PURPLE_IS_ATTACHMENT(attachment), FALSE);
+
+ return g_hash_table_insert(message->attachments,
+ purple_attachment_get_hash_key(attachment),
+ g_object_ref(G_OBJECT(attachment)));
+}
+
+gboolean
+purple_message_remove_attachment(PurpleMessage *message, guint64 id) {
+ g_return_val_if_fail(PURPLE_IS_MESSAGE(message), FALSE);
+
+ return g_hash_table_remove(message->attachments, &id);
+}
+
+PurpleAttachment *
+purple_message_get_attachment(PurpleMessage *message, guint64 id) {
+ PurpleAttachment *attachment = NULL;
+
+ g_return_val_if_fail(PURPLE_IS_MESSAGE(message), NULL);
+
+ attachment = g_hash_table_lookup(message->attachments, &id);
+ if(PURPLE_IS_ATTACHMENT(attachment)) {
+ return PURPLE_ATTACHMENT(g_object_ref(G_OBJECT(attachment)));
+ }
+
+ return NULL;
+}
+
+void
+purple_message_foreach_attachment(PurpleMessage *message,
+ PurpleAttachmentForeachFunc func,
+ gpointer data)
+{
+ GHashTableIter iter;
+ gpointer value;
+
+ g_return_if_fail(PURPLE_IS_MESSAGE(message));
+ g_return_if_fail(func != NULL);
+
+ g_hash_table_iter_init(&iter, message->attachments);
+ while(g_hash_table_iter_next(&iter, NULL, &value)) {
+ func(PURPLE_ATTACHMENT(value), data);
+ }
+}
+
+void
+purple_message_clear_attachments(PurpleMessage *message) {
+ g_return_if_fail(PURPLE_IS_MESSAGE(message));
+
+ g_hash_table_remove_all(message->attachments);
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/libpurple/purplemessage.h Mon Jan 11 01:08:47 2021 -0600
@@ -0,0 +1,429 @@
+/*
+ * Purple - Internet Messaging Library
+ * Copyright (C) Pidgin Developers <devel@pidgin.im>
+ *
+ * Purple is the legal property of its developers, whose names are too numerous
+ * to list here. Please refer to the COPYRIGHT file distributed with this
+ * source distribution.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <https://www.gnu.org/licenses/>.
+ */
+
+#if !defined(PURPLE_GLOBAL_HEADER_INSIDE) && !defined(PURPLE_COMPILATION)
+# error "only <purple.h> may be included directly"
+#endif
+
+#ifndef PURPLE_MESSAGE_H
+#define PURPLE_MESSAGE_H
+
+/**
+ * SECTION:purplemessage
+ * @section_id: libpurple-purplemessage
+ * @short_description: Message Object
+ * @title: Message Object
+ *
+ * #PurpleMessage represents any message passed between users in libpurple.
+ */
+
+#include <glib-object.h>
+
+#include <libpurple/purpleattachment.h>
+
+G_BEGIN_DECLS
+
+/**
+ * PURPLE_TYPE_MESSAGE:
+ *
+ * The standard _get_type macro for #PurpleMessage.
+ *
+ * Since: 3.0.0
+ */
+#define PURPLE_TYPE_MESSAGE purple_message_get_type()
+
+/**
+ * PurpleMessageFlags:
+ * @PURPLE_MESSAGE_SEND: Outgoing message.
+ * @PURPLE_MESSAGE_RECV: Incoming message.
+ * @PURPLE_MESSAGE_SYSTEM: System message.
+ * @PURPLE_MESSAGE_AUTO_RESP: Auto response.
+ * @PURPLE_MESSAGE_ACTIVE_ONLY: Hint to the UI that this message should not be
+ * shown in conversations which are only open for
+ * internal UI purposes (e.g. for contact-aware
+ * conversations).
+ * @PURPLE_MESSAGE_NICK: Contains your nick.
+ * @PURPLE_MESSAGE_NO_LOG: Do not log.
+ * @PURPLE_MESSAGE_ERROR: Error message.
+ * @PURPLE_MESSAGE_DELAYED: Delayed message.
+ * @PURPLE_MESSAGE_RAW: "Raw" message - don't apply formatting.
+ * @PURPLE_MESSAGE_IMAGES: Message contains images.
+ * @PURPLE_MESSAGE_NOTIFY: Message is a notification.
+ * @PURPLE_MESSAGE_NO_LINKIFY: Message should not be auto-linkified.
+ * @PURPLE_MESSAGE_INVISIBLE: Message should not be displayed.
+ * @PURPLE_MESSAGE_REMOTE_SEND: Message sent from another location, not an echo
+ * of a local one.
+ * Since: 2.12.0
+ *
+ * Flags applicable to a message. Most will have send, recv or system.
+ */
+typedef enum /*< flags >*/
+{
+ PURPLE_MESSAGE_SEND = 1 << 0,
+ PURPLE_MESSAGE_RECV = 1 << 1,
+ PURPLE_MESSAGE_SYSTEM = 1 << 2,
+ PURPLE_MESSAGE_AUTO_RESP = 1 << 3,
+ PURPLE_MESSAGE_ACTIVE_ONLY = 1 << 4,
+ PURPLE_MESSAGE_NICK = 1 << 5,
+ PURPLE_MESSAGE_NO_LOG = 1 << 6,
+ PURPLE_MESSAGE_ERROR = 1 << 7,
+ PURPLE_MESSAGE_DELAYED = 1 << 8,
+ PURPLE_MESSAGE_RAW = 1 << 9,
+ PURPLE_MESSAGE_IMAGES = 1 << 10,
+ PURPLE_MESSAGE_NOTIFY = 1 << 11,
+ PURPLE_MESSAGE_NO_LINKIFY = 1 << 12,
+ PURPLE_MESSAGE_INVISIBLE = 1 << 13,
+ PURPLE_MESSAGE_REMOTE_SEND = 1 << 14,
+} PurpleMessageFlags;
+
+/**
+ * PurpleMessageContentType:
+ * @PURPLE_MESSAGE_CONTENT_TYPE_PLAIN: The message has no formatting.
+ * @PURPLE_MESSAGE_CONTENT_TYPE_HTML: The message is formatted in HTML.
+ * @PURPLE_MESSAGE_CONTENT_TYPE_XHTML: The mesage is formatted in XHTML.
+ * @PURPLE_MESSAGE_CONTENT_TYPE_MARKDOWN: The message is formatted in Markdown.
+ *
+ * The message formatting for the message.
+ *
+ * Since: 3.0.0
+ */
+typedef enum /*< prefix=PURPLE_MESSAGE_CONTENT_TYPE,underscore_name=PURPLE_MESSAGE_CONTENT_TYPE >*/
+{
+ PURPLE_MESSAGE_CONTENT_TYPE_PLAIN = 0,
+ PURPLE_MESSAGE_CONTENT_TYPE_HTML,
+ PURPLE_MESSAGE_CONTENT_TYPE_XHTML,
+ PURPLE_MESSAGE_CONTENT_TYPE_MARKDOWN,
+} PurpleMessageContentType;
+
+/**
+ * purple_message_get_type:
+ *
+ * Returns: the #GType for a message.
+ *
+ * Since: 3.0.0
+ */
+G_DECLARE_FINAL_TYPE(PurpleMessage, purple_message, PURPLE, MESSAGE, GObject)
+
+/**
+ * purple_message_new_outgoing:
+ * @author: The author.
+ * @recipient: The recipient.
+ * @contents: The contents.
+ * @flags: The #PurpleMessageFlags.
+ *
+ * Creates new outgoing message to @recipient.
+ *
+ * You don't need to set the #PURPLE_MESSAGE_SEND flag. If the message is not
+ * plain text be sure to call purple_message_set_content_type().
+ *
+ * Returns: (transfer full): The new #PurpleMessage instance.
+ *
+ * Since: 3.0.0
+ */
+PurpleMessage *purple_message_new_outgoing(const gchar *author, const gchar *recipient, const gchar *contents, PurpleMessageFlags flags);
+
+/**
+ * purple_message_new_incoming:
+ * @who: Message's author.
+ * @contents: The contents of a message.
+ * @flags: The message flags.
+ * @timestamp: The time of transmitting a message. May be 0 for a current time.
+ *
+ * Creates new incoming message (the user is the recipient).
+ *
+ * You don't need to set the #PURPLE_MESSAGE_RECV flag.
+ *
+ * Returns: the new #PurpleMessage.
+ *
+ * Since: 3.0.0
+ */
+PurpleMessage *purple_message_new_incoming(const gchar *who, const gchar *contents, PurpleMessageFlags flags, guint64 timestamp);
+
+/**
+ * purple_message_new_system:
+ * @contents: The contents of a message.
+ * @flags: The message flags.
+ *
+ * Creates new system message.
+ *
+ * You don't need to set the #PURPLE_MESSAGE_SYSTEM flag.
+ *
+ * Returns: the new #PurpleMessage.
+ *
+ * Since: 3.0.0
+ */
+PurpleMessage *purple_message_new_system(const gchar *contents, PurpleMessageFlags flags);
+
+/**
+ * purple_message_get_id:
+ * @message: The message.
+ *
+ * Returns the unique identifier of the message. These identifiers are not
+ * serialized - it's a per-session id.
+ *
+ * Returns: the global identifier of @message.
+ *
+ * Since: 3.0.0
+ */
+guint purple_message_get_id(PurpleMessage *message);
+
+/**
+ * purple_message_get_author:
+ * @message: The message.
+ *
+ * Returns the author of the message, not a local alias.
+ *
+ * Returns: the author of @message.
+ *
+ * Since: 3.0.0
+ */
+const gchar *purple_message_get_author(PurpleMessage *message);
+
+/**
+ * purple_message_set_recipient:
+ * @message: The #PurpleMessage instance.
+ * @recipient: The name of the recipient.
+ *
+ * Sets the recipient of @message to @recipient.
+ *
+ * Since: 3.0.0
+ */
+void purple_message_set_recipient(PurpleMessage *message, const gchar *recipient);
+
+/**
+ * purple_message_get_recipient:
+ * @message: The message.
+ *
+ * Returns the recipient of the message, not a local alias.
+ *
+ * Returns: the recipient of @message.
+ *
+ * Since: 3.0.0
+ */
+const gchar *purple_message_get_recipient(PurpleMessage *message);
+
+/**
+ * purple_message_set_author_alias:
+ * @message: The message.
+ * @alias: The alias.
+ *
+ * Sets the alias of @message's author. You don't normally need to call this.
+ *
+ * Since: 3.0.0
+ */
+void purple_message_set_author_alias(PurpleMessage *message, const gchar *alias);
+
+/**
+ * purple_message_get_author_alias:
+ * @message: The message.
+ *
+ * Returns the alias of @message author.
+ *
+ * Returns: the @message author's alias.
+ *
+ * Since: 3.0.0
+ */
+const gchar *purple_message_get_author_alias(PurpleMessage *message);
+
+/**
+ * purple_message_set_contents:
+ * @message: The message.
+ * @cont: The contents.
+ *
+ * Sets the contents of the @message. It might be HTML.
+ *
+ * Since: 3.0.0
+ */
+void purple_message_set_contents(PurpleMessage *message, const gchar *cont);
+
+/**
+ * purple_message_get_contents:
+ * @message: The message.
+ *
+ * Returns the contents of the message.
+ *
+ * Returns: the contents of @message.
+ *
+ * Since: 3.0.0
+ */
+const gchar *purple_message_get_contents(PurpleMessage *message);
+
+/**
+ * purple_message_set_content_type:
+ * @message: The #PurpleMessage instance.
+ * @content_type: The #PurpleMessageContentType value.
+ *
+ * Sets the content-type of @message to @content_type.
+ *
+ * Since: 3.0.0
+ */
+void purple_message_set_content_type(PurpleMessage *message, PurpleMessageContentType content_type);
+
+/**
+ * purple_message_get_content_type:
+ * @message: The #PurpleMessage instance.
+ *
+ * Gets the content-type of @message.
+ *
+ * Returns: The #PurpleMessageContentType of @message.
+ *
+ * Since: 3.0.0
+ */
+PurpleMessageContentType purple_message_get_content_type(PurpleMessage *message);
+
+/**
+ * purple_message_is_empty:
+ * @message: The message.
+ *
+ * Checks, if the message's body is empty.
+ *
+ * Returns: %TRUE, if @message is empty.
+ *
+ * Since: 3.0.0
+ */
+gboolean purple_message_is_empty(PurpleMessage *message);
+
+/**
+ * purple_message_set_timestamp:
+ * @message: The #PurpleMessage instance.
+ * @timestamp: (nullable): The #GDateTime of the message.
+ *
+ * Sets the timestamp of @message.
+ *
+ * Since: 3.0.0
+ */
+void purple_message_set_timestamp(PurpleMessage *message, GDateTime *timestamp);
+
+/**
+ * purple_message_get_timestamp:
+ * @message: The message.
+ *
+ * Returns a @message's timestamp. If @message does not currently have a
+ * timestamp, the current time will be set as the time stamp and returned.
+ *
+ * Returns: (transfer none): The #GDateTime timestamp from @message.
+ *
+ * Since: 3.0.0
+ */
+GDateTime *purple_message_get_timestamp(PurpleMessage *message);
+
+/**
+ * purple_message_format_timestamp:
+ * @message: The #PurpleMessage instance.
+ * @format: The format to output the time stamp as.
+ *
+ * Formats the timestamp of @message and returns it.
+ *
+ * Returns: The formatted timestamp.
+ */
+gchar *purple_message_format_timestamp(PurpleMessage *message, const gchar *format);
+
+/**
+ * purple_message_set_flags:
+ * @message: The message.
+ * @flags: The message flags.
+ *
+ * Sets flags for @message. It shouldn't be in a conflict with a message type,
+ * so use it carefully.
+ *
+ * Since: 3.0.0
+ */
+void purple_message_set_flags(PurpleMessage *message, PurpleMessageFlags flags);
+
+/**
+ * purple_message_get_flags:
+ * @message: The message.
+ *
+ * Returns the flags of a @message.
+ *
+ * Returns: the flags of a @message.
+ *
+ * Since: 3.0.0
+ */
+PurpleMessageFlags purple_message_get_flags(PurpleMessage *message);
+
+/**
+ * purple_message_add_attachment:
+ * @message: The #PurpleMessage instance.
+ * @attachment: The #PurpleAttachment instance.
+ *
+ * Adds @attachment to @message.
+ *
+ * Returns %TRUE if an attachment with the same ID did not already exist.
+ *
+ * Since: 3.0.0
+ */
+gboolean purple_message_add_attachment(PurpleMessage *message, PurpleAttachment *attachment);
+
+/**
+ * purple_message_remove_attachment:
+ * @message: The #PurpleMessage instance.
+ * @id: The id of the #PurpleAttachment
+ *
+ * Removes the #PurpleAttachment identified by @id if it exists.
+ *
+ * Returns: %TRUE if the #PurpleAttachment was found and removed, %FALSE
+ * otherwise.
+ *
+ * Since: 3.0.0
+ */
+gboolean purple_message_remove_attachment(PurpleMessage *message, guint64 id);
+
+/**
+ * purple_message_get_attachment:
+ * @message: The #PurpleMessage instance.
+ * @id: The id of the #PurpleAttachment to get.
+ *
+ * Retrieves the #PurpleAttachment identified by @id from @message.
+ *
+ * Returns: (transfer full): The #PurpleAttachment if it was found, otherwise
+ * %NULL.
+ *
+ * Since: 3.0.0
+ */
+PurpleAttachment *purple_message_get_attachment(PurpleMessage *message, guint64 id);
+
+/**
+ * purple_message_foreach_attachment:
+ * @message: The #PurpleMessage instance.
+ * @func: (scope call): The #PurpleAttachmentForeachFunc to call.
+ * @data: User data to pass to @func.
+ *
+ * Calls @func for each #PurpleAttachment that's attached to @message.
+ *
+ * Since: 3.0.0
+ */
+void purple_message_foreach_attachment(PurpleMessage *message, PurpleAttachmentForeachFunc func, gpointer data);
+
+/**
+ * purple_message_clear_attachments:
+ * @message: The #PurpleMessage instance.
+ *
+ * Removes all attachments from @message.
+ *
+ * Since: 3.0.0
+ */
+void purple_message_clear_attachments(PurpleMessage *message);
+
+G_END_DECLS
+
+#endif /* PURPLE_MESSAGE_H */
--- a/libpurple/server.h Mon Jan 11 00:20:09 2021 -0600
+++ b/libpurple/server.h Mon Jan 11 01:08:47 2021 -0600
@@ -40,9 +40,9 @@
#include "accounts.h"
#include "conversations.h"
#include "group.h"
-#include "message.h"
#include "protocols.h"
#include "purpleattentiontype.h"
+#include "purplemessage.h"
G_BEGIN_DECLS
--- a/po/POTFILES.in Mon Jan 11 00:20:09 2021 -0600
+++ b/po/POTFILES.in Mon Jan 11 01:08:47 2021 -0600
@@ -57,7 +57,6 @@
libpurple/media/enum-types.c
libpurple/mediamanager.c
libpurple/memorypool.c
-libpurple/message.c
libpurple/nat-pmp.c
libpurple/network.c
libpurple/notify.c
@@ -255,6 +254,7 @@
libpurple/purplecredentialprovider.c
libpurple/purpleimconversation.c
libpurple/purplemarkup.c
+libpurple/purplemessage.c
libpurple/purplepresence.c
libpurple/purpleprotocolattention.c
libpurple/purpleprotocolclient.c