Easemob Windows SDK
emmessage.h
1 /************************************************************
2  * * EaseMob CONFIDENTIAL
3  * __________________
4  * Copyright (C) 2015 EaseMob Technologies. All rights reserved.
5  *
6  * NOTICE: All information contained herein is, and remains
7  * the property of EaseMob Technologies.
8  * Dissemination of this information or reproduction of this material
9  * is strictly forbidden unless prior written permission is obtained
10  * from EaseMob Technologies.
11  */
12 //
13 // EMMessage.h
14 //
15 // Copyright (c) 2015 EaseMob Inc. All rights reserved.
16 //
17 
18 #ifndef __easemob__EMMessage__
19 #define __easemob__EMMessage__
20 
21 #include <memory>
22 #include <map>
23 
24 #include "embaseobject.h"
25 #include "emmessagebody.h"
26 #include "emcallback.h"
27 #include "emjsonstring.h"
28 
29 namespace easemob {
30 
31 class EMAttributeValue;
32 class EMMessagePrivate;
33 
34 class EASEMOB_API EMMessage : public EMBaseObject
35 {
36 public:
37 
41  typedef enum
42  {
43  SINGLE, //Single chat
44  GROUP, //Group chat
45  CHATROOM //Chatroom chat
46  } EMChatType;
47 
51  typedef enum
52  {
53  NEW, //New message
54  DELIVERING, //Message is delivering
55  SUCCESS, //Message delivering successed
56  FAIL //Message delivering failed
58 
59  typedef enum {
60  SEND,
61  RECEIVE
62  } EMMessageDirection;
63 
70  virtual ~EMMessage();
71 
78  const std::string& msgId();
79 
87  void setMsgId(const std::string &);
88 
95  const std::string& from();
96 
103  void setFrom(const std::string&);
104 
111  const std::string& to();
112 
119  void setTo(const std::string&);
120 
127  const std::string& conversationId();
128 
136  void setConversationId(const std::string&);
137 
144  EMMessageStatus status();
145 
153  void setStatus(EMMessageStatus);
154 
161  EMChatType chatType();
162 
170  void setChatType(EMChatType);
171 
178  EMMessageDirection msgDirection();
179 
187  void setMsgDirection(EMMessageDirection);
188 
195  bool isRead();
196 
204  void setIsRead(bool isRead);
205 
212  bool isListened();
213 
221  void setIsListened(bool isListened);
222 
230  bool isReadAcked();
231 
239  void setIsReadAcked(bool);
240 
248  bool isDeliverAcked();
249 
257  void setIsDeliverAcked(bool);
258 
265  bool isOffline();
266 
274  void setIsOffline(bool);
275 
282  int64_t timestamp();
283 
291  void setTimestamp(int64_t);
292 
299  int64_t localTime();
300 
308  void setLocalTime(int64_t);
309 
316  std::vector<EMMessageBodyPtr> bodies();
317 
324  void clearBodies();
325 
333  void addBody(const EMMessageBodyPtr &body);
334 
343  template<typename T>
344  void setAttribute(const std::string &attribute, const T &value);
345 
354  template<typename T>
355  bool getAttribute(const std::string &attribute, T &value);
356 
363  void removeAttribute(const std::string &attribute);
364 
371  void clearAttributes();
372 
379  std::map<std::string, std::shared_ptr<EMAttributeValue> > ext();
380 
387  EMCallbackPtr callback();
388 
395  void setCallback(EMCallbackPtr);
396 
397  void setProgress(float percent) { mProgress = percent; }
398 
399  float getProgress() { return mProgress; }
400 
401 public:
402  // factory method
413  static std::shared_ptr<EMMessage> createReceiveMessage(const std::string &from, const std::string &to, const EMMessageBodyPtr &body, EMChatType = SINGLE, const std::string &msgId = "");
414 
424  static std::shared_ptr<EMMessage> createSendMessage(const std::string &from, const std::string &to, const EMMessageBodyPtr &body, EMChatType = SINGLE);
425 private:
433  EMMessage(EMChatType = SINGLE);
434  EMMessage(const std::string& msgId, EMChatType = SINGLE);
435  EMMessage(const EMMessage&);
436  EMMessage& operator=(const EMMessage&);
437 private:
438  void *mMutex;
439  std::string mMsgId;
440  std::string mFrom;
441  std::string mTo;
442  std::string mConversationId;
443 
444  EMMessageStatus mStatus;
445  EMChatType mChatType;
446  EMMessageDirection mDirection;
447 
448  bool mIsRead;
449  bool mIsListened;
450  bool mIsReadAcked;
451  bool mIsDeliverAcked;
452  bool mIsOffline;
453  int64_t mTimestamp;
454  int64_t mLocalTime;
455  std::vector<EMMessageBodyPtr> mBodies;
456  std::map<std::string, std::shared_ptr<EMAttributeValue> > mExt;
457  EMCallbackPtr mCallback;
458 
459  EMMessagePrivate* messagePrivate;
460  friend class EMMessagePrivate;
461  friend class EMMessageEncoder;
462  float mProgress;
463 
464 };
465 
466 typedef std::shared_ptr<EMMessage> EMMessagePtr;
467 typedef std::vector<EMMessagePtr> EMMessageList;
468 
469 }
470 
471 #endif /* defined(__easemob__EMMessage__) */
Definition: emmessage.h:34
EMChatType
Definition: emmessage.h:41
Definition: emattributevalue.h:28
EMMessageStatus
Definition: emmessage.h:51
Definition: embaseobject.h:28