diff --git a/lib/models/chat_room/chat_room.dart b/lib/models/chat_room/chat_room.dart new file mode 100644 index 0000000..851e977 --- /dev/null +++ b/lib/models/chat_room/chat_room.dart @@ -0,0 +1,35 @@ +import 'last_message.dart'; + +class ChatRoom { + final int id; + final String type; + final String updatedAt; + final int unread; + final LastMessage lastMessage; + + const ChatRoom({ + required this.id, + required this.type, + required this.updatedAt, + required this.unread, + required this.lastMessage, + }); + + factory ChatRoom.fromJson(Map json) => ChatRoom( + id: json['id'], + type: json['type'] == 'ادمین' + ? 'پشتیبانی اپلیکیشن' + : 'سردبیر رادار' + json['type'], + updatedAt: json['updatedAt'], + unread: json['unread'], + lastMessage: LastMessage.fromJson(json['lastMessage']), + ); + + Map toJson() => { + 'id': id, + 'type': type, + 'updatedAt': updatedAt, + 'unread': unread, + 'lastMessage': lastMessage.toJson(), + }; +} diff --git a/lib/models/chat_room/last_message.dart b/lib/models/chat_room/last_message.dart new file mode 100644 index 0000000..23c9f3f --- /dev/null +++ b/lib/models/chat_room/last_message.dart @@ -0,0 +1,27 @@ +class LastMessage { + final String? text; + final String? audio; + final bool writedByAdmin; + final bool readed; + + const LastMessage({ + this.text, + this.audio, + required this.writedByAdmin, + required this.readed, + }); + + factory LastMessage.fromJson(Map json) => LastMessage( + text: json['text'], + audio: json['audio'], + writedByAdmin: json['writedByAdmin'], + readed: json['readed'], + ); + + Map toJson() => { + 'text': text, + 'audio': audio, + 'writedByAdmin': writedByAdmin, + 'readed': readed, + }; +} diff --git a/lib/models/message_data/message_data.dart b/lib/models/message_data/message_data.dart new file mode 100644 index 0000000..8cb4b45 --- /dev/null +++ b/lib/models/message_data/message_data.dart @@ -0,0 +1,43 @@ +import 'radar_attachment.dart'; + +class MessageData { + final int id; + final String? text; + final String? audio; + final bool writedByAdmin; + final bool readed; + final String createdAt; + final RadarAttachment? radar; + + const MessageData({ + required this.id, + required this.writedByAdmin, + required this.readed, + required this.createdAt, + required this.text, + required this.audio, + required this.radar, + }); + + factory MessageData.fromJson(Map json) => MessageData( + id: json['id'], + text: json['text'], + audio: json['audio'], + writedByAdmin: json['writedByAdmin'], + readed: json['readed'], + createdAt: json['createdAt'], + radar: json['radar'] == null + ? null + : RadarAttachment.fromJson(json['radar'] as Map), + ); + + Map toJson() => { + 'id': id, + 'text': text, + 'audio': audio, + 'writedByAdmin': writedByAdmin, + 'readed': readed, + 'createdAt': createdAt, + 'radar': radar?.toJson(), + }; +} diff --git a/lib/models/message_data/radar_attachment.dart b/lib/models/message_data/radar_attachment.dart new file mode 100644 index 0000000..13dbe76 --- /dev/null +++ b/lib/models/message_data/radar_attachment.dart @@ -0,0 +1,36 @@ +class RadarAttachment { + final int id; + final String title; + final String description; + final int timeToRead; + final String image; + final bool forManagers; + + const RadarAttachment({ + required this.id, + required this.title, + required this.description, + required this.timeToRead, + required this.image, + required this.forManagers, + }); + + factory RadarAttachment.fromJson(Map json) => + RadarAttachment( + id: json['id'], + title: json['title'], + description: json['description'], + timeToRead: json['timeToRead'], + image: json['image'], + forManagers: json['forManagers'], + ); + + Map toJson() => { + 'id': id, + 'title': title, + 'description': description, + 'timeToRead': timeToRead, + 'image': image, + 'forManagers': forManagers, + }; +} diff --git a/lib/models/user.dart b/lib/models/user.dart new file mode 100644 index 0000000..a652cb8 --- /dev/null +++ b/lib/models/user.dart @@ -0,0 +1,46 @@ +class User { + final int id; + final String phoneNumber; + final String fullName; + final String? username; + final String? photo; + + const User({ + required this.id, + required this.username, + required this.phoneNumber, + required this.photo, + required this.fullName, + }); + + factory User.fromJson(Map json) => User( + id: json['id'], + username: json['username'], + phoneNumber: json['phoneNumber'], + photo: json['photo'], + fullName: json['fullName']); + + Map toJson() => { + 'id': id, + 'username': username, + 'phoneNumber': phoneNumber, + 'photo': photo, + 'fullName': fullName, + }; + + User copyWith({ + int? id, + String? username, + String? phoneNumber, + String? photo, + String? fullName, + }) { + return User( + id: id ?? this.id, + username: username ?? this.username, + phoneNumber: phoneNumber ?? this.phoneNumber, + photo: photo ?? this.photo, + fullName: fullName ?? this.fullName, + ); + } +}