floo2
bmx_message.h
1 //-------------------------------------------------------------------------------------------------
2 // File : bmx_message.h
3 // Author : Eric Liang <eric@bmxlabs.com>
4 // Purpose : bmx message define file.
5 // Created : 12 Nov 2018 by Eric Liang <eric@bmxlabs.com>
6 //-------------------------------------------------------------------------------------------------
7 //
8 // Copyright (C) 2018-2019 MaxIM.Top
9 //
10 // You may obtain a copy of the licence at http://www.maxim.top/LICENCE-MAXIM.md
11 //
12 //-------------------------------------------------------------------------------------------------
13 
14 #ifndef __bmx_message_h__
15 #define __bmx_message_h__
16 
17 #include <vector>
18 #include <memory>
19 #include <mutex>
20 #include "bmx_base_object.h"
21 #include "bmx_message_attachment.h"
22 #include "bmx_message_config.h"
23 
24 namespace floo {
25 class BMXMessage;
26 typedef std::shared_ptr<BMXMessage> BMXMessagePtr;
27 typedef std::vector<BMXMessagePtr> BMXMessageList;
28 class BMXChatService;
29 
33 class EXPORT_API BMXMessage : public BMXBaseObject
34 {
35 public:
39  enum class DeliveryStatus {
41  New,
43  Delivering,
45  Deliveried,
47  Failed,
49  Recalled
50  };
51 
55  enum class MessageType {
57  Single,
59  Group,
61  System,
62  };
63 
67  enum class ContentType {
69  Text,
71  Image,
73  Voice,
75  Video,
77  File,
79  Location,
81  Command,
83  Forward,
84  };
85 
89  enum class DeliveryQos {
91  AtLastOnce,
93  AtMostOnce,
95  ExactlyOnce
96  };
97 
101  virtual ~BMXMessage();
102 
107  int64_t msgId();
108 
113  int64_t clientMsgId();
114 
119  int64_t fromId();
120 
125  int64_t toId();
126 
131  MessageType type();
132 
137  int64_t conversationId();
138 
143  DeliveryStatus deliveryStatus();
144 
148  void setDeliveryStatus(DeliveryStatus);
149 
154  int64_t serverTimestamp();
155 
159  void setServerTimestamp(int64_t);
160 
165  int64_t clientTimestamp();
166 
170  void setClientTimestamp(int64_t);
171 
176  bool isPlayed();
177 
181  void setIsPlayed(bool);
182 
187  bool isPlayAcked();
188 
189 
193  void setIsPlayAcked(bool);
194 
199  bool isReceiveMsg();
200 
204  void setIsReceiveMsg(bool);
205 
210  bool isRead();
211 
215  void setIsRead(bool);
216 
221  bool isReadAcked();
222 
226  void setIsReadAcked(bool);
227 
232  bool isDeliveryAcked();
233 
237  void setIsDeliveryAcked(bool);
238 
243  const std::string& content();
244 
249  void setContent(const std::string& content);
250 
255  ContentType contentType();
256 
261  BMXMessageAttachmentPtr attachment();
262 
267  BMXMessageConfigPtr config();
268 
272  void setConfig(BMXMessageConfigPtr);
273 
278  const JSON& extension();
279 
283  void setExtension(const JSON&);
284 
289  DeliveryQos deliveryQos();
290 
295  void setDeliveryQos(DeliveryQos qos);
296 
301  const std::string& senderName();
302 
307  void setSenderName(const std::string& senderName);
308 
313  int groupAckCount();
314 
319  void setGroupAckCount(int count);
320 
325  int groupAckUnreadCount();
326 
331  void setGroupAckUnreadCount(int count);
332 
337  bool groupAckReadAll();
338 
343  int groupPlayAckCount();
344 
349  void setGroupPlayAckCount(int count);
350 
355  int groupPlayAckUnreadCount();
356 
361  void setGroupPlayAckUnreadCount(int count);
362 
367  bool groupPlayAckReadAll();
368 
374  void setPriority(int priority);
375 
380  int priority();
381 
385  void setPushMessageMode(bool);
386 
391  bool isPushMessage();
392 
393 public:
402  static BMXMessagePtr createMessage(int64_t from, int64_t to, MessageType type, int64_t conversationId, const std::string& content);
403 
412  static BMXMessagePtr createMessage(int64_t from, int64_t to, MessageType type, int64_t conversationId, BMXMessageAttachmentPtr attachment);
413 
422  static BMXMessagePtr createCommandMessage(int64_t from, int64_t to, MessageType type, int64_t conversationId, const std::string& content);
423 
434  static BMXMessagePtr createMessage(int64_t msgId, int64_t from, int64_t to, MessageType type, int64_t conversationId, const std::string& content, int64_t serverTimestamp);
435 
446  static BMXMessagePtr createMessage(int64_t msgId, int64_t from, int64_t to, MessageType type, int64_t conversationId, BMXMessageAttachmentPtr attachment, int64_t serverTimestamp);
447 
458  static BMXMessagePtr createCommandMessage(int64_t msgId, int64_t from, int64_t to, MessageType type, int64_t conversationId, const std::string& content, int64_t serverTimestamp);
459 
468  static BMXMessagePtr createForwardMessage(BMXMessagePtr msg, int64_t from, int64_t to, MessageType type, int64_t conversationId);
469 
470 private:
471  BMXMessage(const BMXMessage&);
472  BMXMessage(const BMXMessage&&);
473  BMXMessage& operator=(const BMXMessage&);
474  BMXMessage(int64_t msgId, int64_t from, int64_t to, MessageType type, int64_t conversationId, ContentType contentType);
475  friend BMXChatService;
476 
477  int64_t mMsgId;
478  int64_t mClientMsgId;
479  int64_t mFromId;
480  int64_t mToId;
481  MessageType mType;
482  int64_t mConversationId;
483  DeliveryStatus mDeliveryStatus;
484  int64_t mClientTimestamp;
485  int64_t mServerTimestamp;
486  bool mIsPlayed;
487  bool mIsPlayedAcked;
488  bool mIsReceiveMsg;
489  bool mIsRead;
490  bool mIsReadAcked;
491  bool mIsDeliveryAcked;
492  std::string mContent;
493  ContentType mContentType;
494  BMXMessageAttachmentPtr mAttachment;
495  BMXMessageConfigPtr mConfig;
496  JSON mExtension;
497  DeliveryQos mDeliveryQos;
498  std::string mSenderName;
499  bool mIsGroupAck;
500  int mGroupAckCount;
501  int mGroupAckUnreadCount;
502  int mGroupPlayAckCount;
503  int mGroupPlayAckUnreadCount;
504  int mPriority;
505  bool mIsPushMessage;
506  std::recursive_mutex mMutex;
507 };
508 
509 }
510 #endif /* __bmx_message_h__ */
DeliveryQos
消息投递质量
Definition: bmx_message.h:89
DeliveryStatus
消息投递状态
Definition: bmx_message.h:39
聊天Service
Definition: bmx_chat_service.h:29
消息
Definition: bmx_message.h:33
ContentType
消息内容类型
Definition: bmx_message.h:67
Definition: bmx_base_object.h:26
MessageType
消息类型
Definition: bmx_message.h:55