forked from eatvio/eatvio_app
57 lines
1.8 KiB
Dart
57 lines
1.8 KiB
Dart
import 'package:eatvio_app/features/chat/models/chat_message_model.dart';
|
|
import 'package:freezed_annotation/freezed_annotation.dart';
|
|
|
|
part 'chat_room_preview_model.freezed.dart';
|
|
part 'chat_room_preview_model.g.dart';
|
|
|
|
@freezed
|
|
class ChatRoomPreviewModel with _$ChatRoomPreviewModel {
|
|
const factory ChatRoomPreviewModel({
|
|
@JsonKey(name: "chatRooms") required List<ChatRoom> chatRooms,
|
|
}) = _ChatRoomPreviewModel;
|
|
|
|
factory ChatRoomPreviewModel.fromJson(Map<String, dynamic> json) => _$ChatRoomPreviewModelFromJson(json);
|
|
}
|
|
|
|
@freezed
|
|
class ChatRoom with _$ChatRoom {
|
|
const factory ChatRoom({
|
|
@JsonKey(name: "id") required String id,
|
|
@JsonKey(name: "room_name") required String roomName,
|
|
@JsonKey(name: "last_message", fromJson: parseLastMessage) required ChatMessageModel? lastMessage,
|
|
@JsonKey(name: "users") required Users users,
|
|
@JsonKey(name: "unread_messages_count") required int unreadMessagesCount,
|
|
}) = _ChatRoom;
|
|
|
|
factory ChatRoom.fromJson(Map<String, dynamic> json) => _$ChatRoomFromJson(json);
|
|
}
|
|
|
|
ChatMessageModel? parseLastMessage(dynamic json) {
|
|
if (json is List) {
|
|
return null;
|
|
}
|
|
return ChatMessageModel.fromJson(json);
|
|
}
|
|
|
|
@freezed
|
|
class Users with _$Users {
|
|
const factory Users({
|
|
@JsonKey(name: "from_chat_user") required ChatUser fromChatUser,
|
|
@JsonKey(name: "to_chat_user") required ChatUser toChatUser,
|
|
}) = _Users;
|
|
|
|
factory Users.fromJson(Map<String, dynamic> json) => _$UsersFromJson(json);
|
|
}
|
|
|
|
@freezed
|
|
class ChatUser with _$ChatUser {
|
|
const factory ChatUser({
|
|
@JsonKey(name: "id") required int id,
|
|
@JsonKey(name: "name") required String name,
|
|
@JsonKey(name: "profile_photo_path") required String? profilePhotoPath,
|
|
@JsonKey(name: "profile_photo_url") required String profilePhotoUrl,
|
|
}) = _ChatUser;
|
|
|
|
factory ChatUser.fromJson(Map<String, dynamic> json) => _$ChatUserFromJson(json);
|
|
}
|