Initial commit with Flutter and Node.js code

This commit is contained in:
Hamza-Ayed
2026-05-18 14:04:39 +03:00
commit a60a173b51
21 changed files with 3107 additions and 0 deletions

View File

@@ -0,0 +1,109 @@
class LastMessageModel {
final String body;
final int timestamp;
final bool fromMe;
final bool hasMedia;
LastMessageModel({
required this.body,
required this.timestamp,
required this.fromMe,
required this.hasMedia,
});
factory LastMessageModel.fromJson(Map<String, dynamic> json) {
return LastMessageModel(
body: json['body'] ?? '',
timestamp: json['timestamp'] ?? 0,
fromMe: json['fromMe'] ?? false,
hasMedia: json['hasMedia'] ?? false,
);
}
Map<String, dynamic> toJson() {
return {
'body': body,
'timestamp': timestamp,
'fromMe': fromMe,
'hasMedia': hasMedia,
};
}
}
class ConversationModel {
final String id;
final String name;
final bool isGroup;
final int unreadCount;
final String? avatar;
final LastMessageModel? lastMessage;
final int timestamp;
final bool pinned;
final bool isMuted;
ConversationModel({
required this.id,
required this.name,
required this.isGroup,
required this.unreadCount,
this.avatar,
this.lastMessage,
required this.timestamp,
required this.pinned,
required this.isMuted,
});
factory ConversationModel.fromJson(Map<String, dynamic> json) {
return ConversationModel(
id: json['id'] ?? '',
name: json['name'] ?? '',
isGroup: json['isGroup'] ?? false,
unreadCount: json['unreadCount'] ?? 0,
avatar: json['avatar'],
lastMessage: json['lastMessage'] != null
? LastMessageModel.fromJson(json['lastMessage'])
: null,
timestamp: json['timestamp'] ?? 0,
pinned: json['pinned'] ?? false,
isMuted: json['isMuted'] ?? false,
);
}
Map<String, dynamic> toJson() {
return {
'id': id,
'name': name,
'isGroup': isGroup,
'unreadCount': unreadCount,
'avatar': avatar,
'lastMessage': lastMessage?.toJson(),
'timestamp': timestamp,
'pinned': pinned,
'isMuted': isMuted,
};
}
ConversationModel copyWith({
String? id,
String? name,
bool? isGroup,
int? unreadCount,
String? avatar,
LastMessageModel? lastMessage,
int? timestamp,
bool? pinned,
bool? isMuted,
}) {
return ConversationModel(
id: id ?? this.id,
name: name ?? this.name,
isGroup: isGroup ?? this.isGroup,
unreadCount: unreadCount ?? this.unreadCount,
avatar: avatar ?? this.avatar,
lastMessage: lastMessage ?? this.lastMessage,
timestamp: timestamp ?? this.timestamp,
pinned: pinned ?? this.pinned,
isMuted: isMuted ?? this.isMuted,
);
}
}

View File

@@ -0,0 +1,75 @@
class MessageModel {
final String id;
final String body;
final bool fromMe;
final int timestamp;
final String type; // "chat"|"image"|"video"|"audio"|"document"|"sticker"
final bool hasMedia;
final bool isForwarded;
final String? author;
final int ack; // 0=error/none 1=pending 2=sent 3=delivered 4=read
MessageModel({
required this.id,
required this.body,
required this.fromMe,
required this.timestamp,
required this.type,
required this.hasMedia,
required this.isForwarded,
this.author,
required this.ack,
});
factory MessageModel.fromJson(Map<String, dynamic> json) {
return MessageModel(
id: json['id'] ?? '',
body: json['body'] ?? '',
fromMe: json['fromMe'] ?? false,
timestamp: json['timestamp'] ?? 0,
type: json['type'] ?? 'chat',
hasMedia: json['hasMedia'] ?? false,
isForwarded: json['isForwarded'] ?? false,
author: json['author'],
ack: json['ack'] ?? 0,
);
}
Map<String, dynamic> toJson() {
return {
'id': id,
'body': body,
'fromMe': fromMe,
'timestamp': timestamp,
'type': type,
'hasMedia': hasMedia,
'isForwarded': isForwarded,
'author': author,
'ack': ack,
};
}
MessageModel copyWith({
String? id,
String? body,
bool? fromMe,
int? timestamp,
String? type,
bool? hasMedia,
bool? isForwarded,
String? author,
int? ack,
}) {
return MessageModel(
id: id ?? this.id,
body: body ?? this.body,
fromMe: fromMe ?? this.fromMe,
timestamp: timestamp ?? this.timestamp,
type: type ?? this.type,
hasMedia: hasMedia ?? this.hasMedia,
isForwarded: isForwarded ?? this.isForwarded,
author: author ?? this.author,
ack: ack ?? this.ack,
);
}
}