Skip to content

Commit

Permalink
fix: merge errors v2
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahmed-Aladdiin committed Dec 17, 2024
1 parent 2a891a3 commit b090007
Show file tree
Hide file tree
Showing 4 changed files with 237 additions and 1,031 deletions.
11 changes: 10 additions & 1 deletion lib/core/models/chat_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,18 @@ class ChatModel {
List<MessageModel> messages;
@HiveField(14)
final DateTime? muteUntil; // Add this field
@HiveField(15)
final List<String>? creators;

ChatModel({
required this.title,
required this.userIds,
this.admins,
this.creators,
this.photo,
required this.type,
this.id,
this.photoBytes,
this.admins,
this.description,
this.lastMessageTimestamp,
this.isArchived = false,
Expand Down Expand Up @@ -92,6 +95,7 @@ class ChatModel {
other.photo == photo &&
other.id == id &&
other.admins == admins &&
other.creators == creators &&
other.description == description &&
other.lastMessageTimestamp == lastMessageTimestamp &&
other.isArchived == isArchived &&
Expand All @@ -115,6 +119,7 @@ class ChatModel {
isArchived.hashCode ^
isMuted.hashCode ^
draft.hashCode ^
creators.hashCode ^
isMentioned.hashCode ^
messages.hashCode; // Include messages in hashCode
}
Expand All @@ -128,6 +133,7 @@ class ChatModel {
'photo: $photo,\n'
'id: $id,\n'
'admins: $admins,\n'
'creators: $creators,\n'
'description: $description,\n'
'lastMessageTimestamp: $lastMessageTimestamp,\n'
'isArchived: $isArchived,\n'
Expand All @@ -146,6 +152,7 @@ class ChatModel {
String? id,
Uint8List? photoBytes,
List<String>? admins,
List<String>? creators,
String? description,
DateTime? lastMessageTimestamp,
bool? isArchived,
Expand All @@ -163,6 +170,7 @@ class ChatModel {
id: id ?? this.id,
photoBytes: photoBytes ?? this.photoBytes,
admins: admins ?? this.admins,
creators: creators ?? this.creators,
description: description ?? this.description,
lastMessageTimestamp: lastMessageTimestamp ?? this.lastMessageTimestamp,
isArchived: isArchived ?? this.isArchived,
Expand All @@ -182,6 +190,7 @@ class ChatModel {
'photo': photo,
'id': id,
'admins': admins,
'creators': creators,
'description': description,
'lastMessageTimestamp': lastMessageTimestamp?.toIso8601String(),
'isArchived': isArchived,
Expand Down
19 changes: 17 additions & 2 deletions lib/features/chat/repository/chat_remote_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ class ChatRemoteRepository {
mediaUrl: lastMessage['mediaUrl'],
);

// todo(ahmed): add (isForward, isPinned, isAnnouncement, parentMsgId)
final threadMessages = (lastMessage['threadMessages'] as List).map((e) => e as String).toList();

// todo(ahmed): add (parentMsgId)
// the connumicationType attribute is extra
lastMessageMap[message['chatId']] = MessageModel(
id: lastMessage['id'],
Expand All @@ -99,6 +101,10 @@ class ChatRemoteRepository {
? DateTime.parse(lastMessage['timestamp'])
: DateTime.now(),
userStates: userStates,
isForward: lastMessage['isForward'] ?? false,
isPinned: lastMessage['isPinned'] ?? false,
isAnnouncement: lastMessage['isAnnouncement'],
threadMessages: threadMessages
);
}

Expand Down Expand Up @@ -132,7 +138,15 @@ class ChatRemoteRepository {
if (otherUsers.isEmpty) {
continue;
}
chatTitle = otherUsers[0]?.username ?? 'Private Chat';

chatTitle =
'${otherUsers[0]?.screenFirstName} ${otherUsers[0]?.screenLastName}';
if (chatTitle.isEmpty) {
chatTitle = (otherUsers[0]?.username != null &&
otherUsers[0]!.username.isNotEmpty)
? otherUsers[0]!.username
: 'Private Chat';
}
} else if (chat['chat']['type'] == 'group') {
chatTitle = 'Group Chat';
} else if (chat['chat']['type'] == 'channel') {
Expand All @@ -155,6 +169,7 @@ class ChatRemoteRepository {
messages: messages,
draft: chat['draft'],
isMuted: chat['isMuted'],
creators: creators,
);

chats.add(chatModel);
Expand Down
14 changes: 8 additions & 6 deletions lib/features/chat/view_model/event_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ class EventHandler {
processQueue();
}

void clear() {
stopProcessing();
_queue.clear();
_socket.disconnect();
}

void addEvent(MessageEvent event) {
debugPrint('!!! event added');
_queue.add(event);
Expand All @@ -48,6 +54,7 @@ class EventHandler {
}

void stopProcessing() {
if (!_isProcessing) return;
_stopRequested = true; // Gracefully request stopping the loop
}

Expand All @@ -65,12 +72,7 @@ class EventHandler {
final currentEvent = _queue.first;

if (!_socket.isConnected) {
_socket.connect(
serverUrl: SOCKET_URL,
userId: _userId,
onConnect: _onSocketConnect,
sessionId: _sessionId,
);
_socket.onError();
break;
}

Expand Down
Loading

0 comments on commit b090007

Please sign in to comment.