PageRenderTime 32ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/src/main/java/com/linbox/im/message/Message.java

https://gitlab.com/Mr.Tomato/linbox_server
Java | 75 lines | 48 code | 15 blank | 12 comment | 0 complexity | c8a07e4bb1be3921fa14e34cc1f5bd13 MD5 | raw file
  1. package com.linbox.im.message;
  2. import com.alibaba.fastjson.annotation.JSONField;
  3. import com.linbox.im.server.storage.entity.GroupMessageEntity;
  4. import com.linbox.im.server.storage.entity.SessionMessageEntity;
  5. /**
  6. * Created by lrsec on 6/29/15.
  7. */
  8. public class Message {
  9. // 消息发送时的 rId
  10. @JSONField(name = "r_id")
  11. public long rId;
  12. // 发送方 id
  13. @JSONField(name = "from_user_id")
  14. public String fromUserId;
  15. // 目的方 id
  16. @JSONField(name = "to_user_id")
  17. public String toUserId;
  18. // 群组 id
  19. @JSONField(name = "group_id")
  20. public String groupId;
  21. // message id
  22. @JSONField(name = "msg_id")
  23. public long msgId;
  24. // 消息体类型
  25. @JSONField(name = "mime_type")
  26. public String mimeType;
  27. // 消息体内容
  28. @JSONField(name = "content")
  29. public String content;
  30. // 服务器端接收到消息的时间
  31. @JSONField(name = "send_time")
  32. public long sendTime;
  33. // 消息的类型
  34. @JSONField(name = "type")
  35. public int type;
  36. public static Message convertToMsg(SessionMessageEntity dao, String userId) {
  37. Message m = new Message();
  38. m.rId = dao.RId;
  39. m.fromUserId = Long.toString(dao.FromUserID);
  40. m.toUserId = Long.toString(dao.ToUserID);
  41. m.msgId = dao.MsgID;
  42. m.mimeType = dao.MimeType;
  43. m.content = dao.Content;
  44. m.sendTime = dao.SendTime;
  45. m.type = MessageType.Session.getValue();
  46. return m;
  47. }
  48. public static Message convertToMsg(GroupMessageEntity dao, String fromUserId, String groupId) {
  49. Message m = new Message();
  50. m.rId = dao.RId;
  51. m.fromUserId = fromUserId;
  52. m.groupId = groupId;
  53. m.msgId = dao.MsgID;
  54. m.mimeType = dao.MimeType;
  55. m.content = dao.Content;
  56. m.sendTime = dao.SendTime;
  57. m.type = MessageType.Group.getValue();
  58. return m;
  59. }
  60. }