GotyeMessage.h
3.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/****************************************************************************
Copyright(c) 2013-2014, Shanghai AiLiao Information Technology Co.,Ltd
http://www.gotye.com.cn
@author: liugan
@date: 2014-06-20
@version: v2.0
@filename: GotyeMessage.h
@description:
This header file declares gotye message class.
Include "GotyeAPI.h" instead of this.
****************************************************************************/
#ifndef __GOTYE_MESSAGE_H__
#define __GOTYE_MESSAGE_H__
#include "GotyeChatTarget.h"
NS_GOTYEAPI_BEGIN
typedef enum
{
GotyeMessageTypeText, ///< text message
GotyeMessageTypeImage, ///< image message
GotyeMessageTypeAudio, ///< audio message
GotyeMessageTypeUserData, ///< user data
}GotyeMessageType; ///< enum gotye message type
typedef enum
{
GotyeMessageStatusCreated,
GotyeMessageStatusUnread,
GotyeMessageStatusRead,
GotyeMessageStatusSending,
GotyeMessageStatusSent,
GotyeMessageStatusSendingFailed
}GotyeMessageStatus; ///< enum gotye message status.
/**
* @summary: GotyeMessage encapsulates text/audio/image/userdata message used in GotyeAPI.
*/
struct GotyeMessage
{
long long id; ///< message identifier
unsigned date; ///< the time since 1970/1/1 00:00:00, in seconds
long long dbID; ////< unique id in database.
std::string text; ///< text content, for text message only.
GotyeMedia media; ///< saving audio/image/userdata information.
GotyeMedia extra; ///< saving extra data.
GotyeMessageType type; ///< message type
GotyeMessageStatus status; ///< message status
GotyeChatTarget sender, receiver; ///< sender&receiver
bool hasMedia() const; ///< check whether this message has media data or not.
bool hasExtraData() const; ///< check whether this message has extra data or not.
static GotyeMessage createMessage(GotyeChatTarget receiver);///< default sender is yourself
static GotyeMessage createMessage(GotyeChatTarget sender, GotyeChatTarget receiver);
static GotyeMessage createTextMessage(GotyeChatTarget receiver, const std::string& text);
static GotyeMessage createTextMessage(GotyeChatTarget sender, GotyeChatTarget receiver, const std::string& text);
static GotyeMessage createImageMessage(GotyeChatTarget receiver, const std::string& imagePath);
static GotyeMessage createImageMessage(GotyeChatTarget sender, GotyeChatTarget receiver, const std::string& imagePath);
static GotyeMessage createAudioMessage(GotyeChatTarget receiver, const std::string& audioPath, unsigned duration);
static GotyeMessage createAudioMessage(GotyeChatTarget sender, GotyeChatTarget receiver, const std::string& audioPath, unsigned duration);
static GotyeMessage createUserDataMessage(GotyeChatTarget receiver, const std::string& dataPath);
static GotyeMessage createUserDataMessage(GotyeChatTarget sender, GotyeChatTarget receiver, const std::string& dataPath);
static GotyeMessage createUserDataMessage(GotyeChatTarget receiver, const void* data, unsigned len);
static GotyeMessage createUserDataMessage(GotyeChatTarget sender, GotyeChatTarget receiver, const void* data, unsigned len);
GotyeMessage& putExtraData(const void* data, unsigned len); ///< attach extra data to this message (< 2.5KB).
GotyeMessage& putExtraData(const std::string& extraPath); ///< attach extra file to this message(filesize < 2.5KB).
long getExtraData(void *data) const; ///< read extra data
GotyeMessage();
GotyeMessage(long long dbId);
GotyeMessage(GotyeChatTarget sender, GotyeChatTarget receiver, GotyeMessageType type = GotyeMessageTypeText);
GotyeChatTarget getTarget() const;
bool operator < (const GotyeMessage& other) const;
bool operator == (const GotyeMessage& other) const;
};
NS_GOTYEAPI_END
#endif/* defined(__GOTYE_MESSAGE_H__) */