import 'package:sport/bean/share_info.dart'; class MessageInstance { int fromId; int toId; String type; MessageData data; int read; bool selfSend; String createdAt; MessageUser toUser; MessageUser fromUser; String relate; MessageInstance( {this.fromId, this.toId, this.type, this.data, this.read, this.selfSend, this.createdAt, this.toUser, this.fromUser, this.relate}); MessageInstance.fromJson(Map json) { fromId = json['from_id']; toId = json['to_id']; type = json['type']; data = json['data'] != null ? new MessageData.fromJson(json['data']) : null; read = json['read']; selfSend = json['self_send']; createdAt = json['created_at']; toUser = json['to_user'] != null ? new MessageUser.fromJson(json['to_user']) : null; fromUser = json['from_user'] != null ? new MessageUser.fromJson(json['from_user']) : null; relate = json['relate']; } Map toJson() { final Map data = new Map(); data['from_id'] = this.fromId; data['to_id'] = this.toId; data['type'] = this.type; if (this.data != null) { data['data'] = this.data.toJson(); } data['read'] = this.read; data['self_send'] = this.selfSend; data['created_at'] = this.createdAt; if (this.toUser != null) { data['to_user'] = this.toUser.toJson(); } if (this.fromUser != null) { data['from_user'] = this.fromUser.toJson(); } data['relate'] = this.relate; return data; } } class MessageData { String text; String url; String logo; MessagePostUser user; MessageForum forum; MessageSubject subject; Share share; MessageData({ this.text, this.url, this.logo, this.user, this.forum, this.subject, this.share }); MessageData.fromJson(Map json) { text = json['text']; url = json['url']; logo = json['logo']; user = json['user'] != null ? MessagePostUser.fromJson(json['user']) : null; forum = json['forum'] != null ? MessageForum.fromJson(json['forum']) : null; subject = json['subject'] != null ? MessageSubject.fromJson(json["subject"]) : null; share = json['share'] != null ? Share.fromJson(json['share']):null; } Map toJson() { final Map map = new Map(); map['text'] = this.text; map['url'] = this.url; map['logo'] = this.logo; map['user'] = this.user; map['forum'] = this.forum; map['subject'] = this.subject; map["share"] = this.share; return map; } } class MessageUser { int id; String name; String avatar; bool online; MessageUser({this.id, this.name, this.avatar, this.online}); MessageUser.fromJson(Map json) { id = json['id']; name = json['name']; avatar = json['avatar']; online = json['online']; } Map toJson() { final Map data = new Map(); data['id'] = this.id; data['name'] = this.name; data['avatar'] = this.avatar; data['online'] = this.online; return data; } } // 这里是轮询的消息结构... class Message { int curId; List messages; Message({this.curId, this.messages}); Message.fromJson(Map json) { curId = json['cur_id']; messages = new List(); if (json['messages'] != null) { json['messages'].forEach((v) { messages.add(new MessageInstance.fromJson(v)); }); } } Map toJson() { final Map data = new Map(); data['id'] = this.curId; if (this.messages != null) { data['messages'] = this.messages.map((v) => v.toJson()).toList(); } return data; } } class ChatMessage { MessageUser user; List messages; ChatMessage({this.user, this.messages}); ChatMessage.fromJson(Map json) { user = json['user']; messages = new List(); if (json['message'] != null) { json['message'].forEach((v) { messages.add(new MessageInstance.fromJson(v)); }); } } Map toJson() { final Map data = new Map(); data['user'] = this.user; if (this.messages != null) { data['messages'] = this.messages.map((v) => v.toJson()).toList(); } return data; } } // 聊天首页 class ChatMessageInstance { int id; int fromId; int toId; String type; String relate; bool selfSend; int read; int unreadCount; String createdAt; MessageData data; MessageUser toUser; MessageUser fromUser; ChatMessageInstance({ this.id, this.fromId, this.toId, this.type, this.relate, this.selfSend, this.read, this.unreadCount, this.createdAt, this.data, this.toUser, this.fromUser, }); ChatMessageInstance.fromJson(Map json) { id = json['id']; fromId = json['from_id']; toId = json['to_id']; type = json['type']; relate = json['relate']; selfSend = json['self_send']; read = json['read']; unreadCount = json['unread_count']; createdAt = json['created_at']; data = json['data']; toUser = json['to_user']; fromUser = json['from_user']; } Map toJson() { final Map data = new Map(); data['id'] = this.id; data['from_id'] = this.fromId; data['to_id'] = this.toId; data['type'] = this.type; data['relate'] = this.relate; data['self_send'] = this.selfSend; data['read'] = this.read; data['unread_count'] = this.unreadCount; data['created_at'] = this.createdAt; data['data'] = this.data; data['to_user'] = this.toUser; data['from_user'] = this.fromUser; return data; } } class ChatOnlineInfo { bool online; String relate; int userId; ChatOnlineInfo.fromJson(Map json) { online = json['online']; relate = json['relate']; userId = json['id']; } Map toJson() { final Map data = new Map(); data['online'] = this.online; data['relate'] = this.relate; data['id'] = this.userId; return data; } } class MessageForum { String cover; String name; int id; MessageForum.fromJson(Map json) { cover = json['cover']; name = json['name']; id = json['id']; } Map toJson() { final Map data = new Map(); data['cover'] = this.cover; data['name'] = this.name; data['id'] = this.id; return data; } } class MessageSubject { String title; String content; int id; List images; String cover; MessageSubject.fromJson(Map json) { title = json['title']; content = json['content']; id = json['id']; images = new List(); cover = json['cover']; images = []; if (json['images'] != null && json['images'].length > 0) { json['images'].forEach((v) { images.add(v); }); } } Map toJson() { final Map data = new Map(); data['title'] = this.title; data['content'] = this.content; data['images'] = this.images; data['id'] = this.id; data['cover'] = this.cover; return data; } } class MessagePostUser { int id; String name; MessagePostUser({this.id, this.name}); MessagePostUser.fromJson(Map json) { id = json['id']; name = json['name']; } Map toJson() { final Map data = new Map(); data['name'] = this.name; data['id'] = this.id; return data; } }