1 /* Copyright (C) 2016-2019 Shengyu Zhang <i@silverrainz.me> 2 * 3 * This file is part of Srain. 4 * 5 * Srain is free software: you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation, either version 3 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 17 */ 18 19 #ifndef __MESSAGE_H 20 #define __MESSAGE_H 21 22 #include <glib.h> 23 24 #ifndef __IN_CORE_H 25 #error This file should not be included directly, include just core.h 26 #endif 27 28 typedef enum _SrnMessageType SrnMessageType; 29 typedef struct _SrnMessage SrnMessage; 30 31 #include "./chat.h" 32 33 enum _SrnMessageType { 34 SRN_MESSAGE_TYPE_UNKNOWN, 35 SRN_MESSAGE_TYPE_RECV, 36 SRN_MESSAGE_TYPE_SENT, 37 SRN_MESSAGE_TYPE_ACTION, 38 SRN_MESSAGE_TYPE_NOTICE, 39 SRN_MESSAGE_TYPE_MISC, 40 SRN_MESSAGE_TYPE_ERROR, 41 }; 42 43 struct _SrnMessage { 44 SrnChat *chat; 45 SrnChatUser *sender; // Sender of this message 46 SrnMessageType type; 47 48 /* Raw message */ 49 char *content; // Raw message content 50 GDateTime *time; // Local time when creating message 51 52 /* NOTE: All rendered_xxx fields MUST be valid XML and never be NULL */ 53 char *rendered_sender; // Sender name 54 char *rendered_remark; // Message remark 55 char *rendered_content; // Rendered message content in 56 char *rendered_short_time; // Short format message time 57 char *rendered_full_time; // Full format messsage time 58 GList *urls; // URLs in message, like "http://xxx", "irc://xxx" 59 60 bool mentioned; // Whether this message should be mentioned 61 62 SuiMessage *ui; 63 }; 64 65 SrnMessage* srn_message_new(SrnChat *chat, SrnChatUser *user, const char *content, SrnMessageType type); 66 void srn_message_free(SrnMessage *msg); 67 char* srn_message_to_string(const SrnMessage *self); 68 69 #endif /* __MESSAGE_H */ 70