message.dart 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. import 'package:sport/bean/share_info.dart';
  2. class MessageInstance {
  3. int fromId;
  4. int toId;
  5. String type;
  6. MessageData data;
  7. int read;
  8. bool selfSend;
  9. String createdAt;
  10. MessageUser toUser;
  11. MessageUser fromUser;
  12. String relate;
  13. MessageInstance(
  14. {this.fromId,
  15. this.toId,
  16. this.type,
  17. this.data,
  18. this.read,
  19. this.selfSend,
  20. this.createdAt,
  21. this.toUser,
  22. this.fromUser,
  23. this.relate});
  24. MessageInstance.fromJson(Map<String, dynamic> json) {
  25. fromId = json['from_id'];
  26. toId = json['to_id'];
  27. type = json['type'];
  28. data = json['data'] != null ? new MessageData.fromJson(json['data']) : null;
  29. read = json['read'];
  30. selfSend = json['self_send'];
  31. createdAt = json['created_at'];
  32. toUser = json['to_user'] != null
  33. ? new MessageUser.fromJson(json['to_user'])
  34. : null;
  35. fromUser = json['from_user'] != null
  36. ? new MessageUser.fromJson(json['from_user'])
  37. : null;
  38. relate = json['relate'];
  39. }
  40. Map<String, dynamic> toJson() {
  41. final Map<String, dynamic> data = new Map<String, dynamic>();
  42. data['from_id'] = this.fromId;
  43. data['to_id'] = this.toId;
  44. data['type'] = this.type;
  45. if (this.data != null) {
  46. data['data'] = this.data.toJson();
  47. }
  48. data['read'] = this.read;
  49. data['self_send'] = this.selfSend;
  50. data['created_at'] = this.createdAt;
  51. if (this.toUser != null) {
  52. data['to_user'] = this.toUser.toJson();
  53. }
  54. if (this.fromUser != null) {
  55. data['from_user'] = this.fromUser.toJson();
  56. }
  57. data['relate'] = this.relate;
  58. return data;
  59. }
  60. }
  61. class MessageData {
  62. String text;
  63. String url;
  64. String logo;
  65. MessagePostUser user;
  66. MessageForum forum;
  67. MessageSubject subject;
  68. Share share;
  69. MessageData({
  70. this.text,
  71. this.url,
  72. this.logo,
  73. this.user,
  74. this.forum,
  75. this.subject,
  76. this.share
  77. });
  78. MessageData.fromJson(Map<String, dynamic> json) {
  79. text = json['text'];
  80. url = json['url'];
  81. logo = json['logo'];
  82. user = json['user'] != null ? MessagePostUser.fromJson(json['user']) : null;
  83. forum = json['forum'] != null ? MessageForum.fromJson(json['forum']) : null;
  84. subject = json['subject'] != null
  85. ? MessageSubject.fromJson(json["subject"])
  86. : null;
  87. share = json['share'] != null ? Share.fromJson(json['share']):null;
  88. }
  89. Map<String, dynamic> toJson() {
  90. final Map<String, dynamic> map = new Map<String, dynamic>();
  91. map['text'] = this.text;
  92. map['url'] = this.url;
  93. map['logo'] = this.logo;
  94. map['user'] = this.user;
  95. map['forum'] = this.forum;
  96. map['subject'] = this.subject;
  97. map["share"] = this.share;
  98. return map;
  99. }
  100. }
  101. class MessageUser {
  102. int id;
  103. String name;
  104. String avatar;
  105. bool online;
  106. MessageUser({this.id, this.name, this.avatar, this.online});
  107. MessageUser.fromJson(Map<String, dynamic> json) {
  108. id = json['id'];
  109. name = json['name'];
  110. avatar = json['avatar'];
  111. online = json['online'];
  112. }
  113. Map<String, dynamic> toJson() {
  114. final Map<String, dynamic> data = new Map<String, dynamic>();
  115. data['id'] = this.id;
  116. data['name'] = this.name;
  117. data['avatar'] = this.avatar;
  118. data['online'] = this.online;
  119. return data;
  120. }
  121. }
  122. // 这里是轮询的消息结构...
  123. class Message {
  124. int curId;
  125. List<MessageInstance> messages;
  126. Message({this.curId, this.messages});
  127. Message.fromJson(Map<String, dynamic> json) {
  128. curId = json['cur_id'];
  129. messages = new List<MessageInstance>();
  130. if (json['messages'] != null) {
  131. json['messages'].forEach((v) {
  132. messages.add(new MessageInstance.fromJson(v));
  133. });
  134. }
  135. }
  136. Map<String, dynamic> toJson() {
  137. final Map<String, dynamic> data = new Map<String, dynamic>();
  138. data['id'] = this.curId;
  139. if (this.messages != null) {
  140. data['messages'] = this.messages.map((v) => v.toJson()).toList();
  141. }
  142. return data;
  143. }
  144. }
  145. class ChatMessage {
  146. MessageUser user;
  147. List<MessageInstance> messages;
  148. ChatMessage({this.user, this.messages});
  149. ChatMessage.fromJson(Map<String, dynamic> json) {
  150. user = json['user'];
  151. messages = new List<MessageInstance>();
  152. if (json['message'] != null) {
  153. json['message'].forEach((v) {
  154. messages.add(new MessageInstance.fromJson(v));
  155. });
  156. }
  157. }
  158. Map<String, dynamic> toJson() {
  159. final Map<String, dynamic> data = new Map<String, dynamic>();
  160. data['user'] = this.user;
  161. if (this.messages != null) {
  162. data['messages'] = this.messages.map((v) => v.toJson()).toList();
  163. }
  164. return data;
  165. }
  166. }
  167. // 聊天首页
  168. class ChatMessageInstance {
  169. int id;
  170. int fromId;
  171. int toId;
  172. String type;
  173. String relate;
  174. bool selfSend;
  175. int read;
  176. int unreadCount;
  177. String createdAt;
  178. MessageData data;
  179. MessageUser toUser;
  180. MessageUser fromUser;
  181. ChatMessageInstance({
  182. this.id,
  183. this.fromId,
  184. this.toId,
  185. this.type,
  186. this.relate,
  187. this.selfSend,
  188. this.read,
  189. this.unreadCount,
  190. this.createdAt,
  191. this.data,
  192. this.toUser,
  193. this.fromUser,
  194. });
  195. ChatMessageInstance.fromJson(Map<String, dynamic> json) {
  196. id = json['id'];
  197. fromId = json['from_id'];
  198. toId = json['to_id'];
  199. type = json['type'];
  200. relate = json['relate'];
  201. selfSend = json['self_send'];
  202. read = json['read'];
  203. unreadCount = json['unread_count'];
  204. createdAt = json['created_at'];
  205. data = json['data'];
  206. toUser = json['to_user'];
  207. fromUser = json['from_user'];
  208. }
  209. Map<String, dynamic> toJson() {
  210. final Map<String, dynamic> data = new Map<String, dynamic>();
  211. data['id'] = this.id;
  212. data['from_id'] = this.fromId;
  213. data['to_id'] = this.toId;
  214. data['type'] = this.type;
  215. data['relate'] = this.relate;
  216. data['self_send'] = this.selfSend;
  217. data['read'] = this.read;
  218. data['unread_count'] = this.unreadCount;
  219. data['created_at'] = this.createdAt;
  220. data['data'] = this.data;
  221. data['to_user'] = this.toUser;
  222. data['from_user'] = this.fromUser;
  223. return data;
  224. }
  225. }
  226. class ChatOnlineInfo {
  227. bool online;
  228. String relate;
  229. int userId;
  230. ChatOnlineInfo.fromJson(Map<String, dynamic> json) {
  231. online = json['online'];
  232. relate = json['relate'];
  233. userId = json['id'];
  234. }
  235. Map<String, dynamic> toJson() {
  236. final Map<String, dynamic> data = new Map<String, dynamic>();
  237. data['online'] = this.online;
  238. data['relate'] = this.relate;
  239. data['id'] = this.userId;
  240. return data;
  241. }
  242. }
  243. class MessageForum {
  244. String cover;
  245. String name;
  246. int id;
  247. MessageForum.fromJson(Map<String, dynamic> json) {
  248. cover = json['cover'];
  249. name = json['name'];
  250. id = json['id'];
  251. }
  252. Map<String, dynamic> toJson() {
  253. final Map<String, dynamic> data = new Map<String, dynamic>();
  254. data['cover'] = this.cover;
  255. data['name'] = this.name;
  256. data['id'] = this.id;
  257. return data;
  258. }
  259. }
  260. class MessageSubject {
  261. String title;
  262. String content;
  263. int id;
  264. List<String> images;
  265. String cover;
  266. MessageSubject.fromJson(Map<String, dynamic> json) {
  267. title = json['title'];
  268. content = json['content'];
  269. id = json['id'];
  270. images = new List<String>();
  271. cover = json['cover'];
  272. images = [];
  273. if (json['images'] != null && json['images'].length > 0) {
  274. json['images'].forEach((v) {
  275. images.add(v);
  276. });
  277. }
  278. }
  279. Map<String, dynamic> toJson() {
  280. final Map<String, dynamic> data = new Map<String, dynamic>();
  281. data['title'] = this.title;
  282. data['content'] = this.content;
  283. data['images'] = this.images;
  284. data['id'] = this.id;
  285. data['cover'] = this.cover;
  286. return data;
  287. }
  288. }
  289. class MessagePostUser {
  290. int id;
  291. String name;
  292. MessagePostUser({this.id, this.name});
  293. MessagePostUser.fromJson(Map<String, dynamic> json) {
  294. id = json['id'];
  295. name = json['name'];
  296. }
  297. Map<String, dynamic> toJson() {
  298. final Map<String, dynamic> data = new Map<String, dynamic>();
  299. data['name'] = this.name;
  300. data['id'] = this.id;
  301. return data;
  302. }
  303. }