message.dart 8.9 KB

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