хм
This commit is contained in:
@@ -75,13 +75,13 @@ class CachedMessage {
|
||||
}
|
||||
|
||||
return CachedMessage(
|
||||
id: row['id'] as String,
|
||||
accountId: row['account_id'] as int,
|
||||
chatId: row['chat_id'] as int,
|
||||
senderId: row['sender_id'] as int,
|
||||
text: row['text'] as String?,
|
||||
time: row['time'] as int,
|
||||
status: row['status'] as String?,
|
||||
id: row['id']?.toString() ?? '',
|
||||
accountId: row['account_id'] is int ? row['account_id'] as int : int.tryParse(row['account_id']?.toString() ?? '') ?? 0,
|
||||
chatId: row['chat_id'] is int ? row['chat_id'] as int : int.tryParse(row['chat_id']?.toString() ?? '') ?? 0,
|
||||
senderId: row['sender_id'] is int ? row['sender_id'] as int : int.tryParse(row['sender_id']?.toString() ?? '') ?? 0,
|
||||
text: row['text']?.toString(),
|
||||
time: row['time'] is int ? row['time'] as int : int.tryParse(row['time']?.toString() ?? '') ?? 0,
|
||||
status: row['status']?.toString(),
|
||||
payload: payload,
|
||||
attachments: attachments,
|
||||
);
|
||||
@@ -209,15 +209,22 @@ class MessagesModule {
|
||||
id: id,
|
||||
accountId: accountId,
|
||||
chatId: chatId,
|
||||
senderId: (m['sender'] as int?) ?? 0,
|
||||
text: m['text'] as String?,
|
||||
time: (m['time'] as int?) ?? 0,
|
||||
status: m['status'] as String?,
|
||||
senderId: _parseIntField(m['sender']),
|
||||
text: m['text']?.toString(),
|
||||
time: _parseIntField(m['time']),
|
||||
status: m['status']?.toString(),
|
||||
payload: Map<String, dynamic>.from(m.cast()),
|
||||
attachments: attachments,
|
||||
);
|
||||
}
|
||||
|
||||
int _parseIntField(dynamic value) {
|
||||
if (value == null) return 0;
|
||||
if (value is int) return value;
|
||||
if (value is String) return int.tryParse(value) ?? 0;
|
||||
return int.tryParse(value.toString()) ?? 0;
|
||||
}
|
||||
|
||||
Future<void> sendMessage(
|
||||
int accountId,
|
||||
int chatId,
|
||||
@@ -356,6 +363,8 @@ class MessagesModule {
|
||||
final cached = ContactCache.get(contactId);
|
||||
if (cached != null) return cached;
|
||||
|
||||
if (_api.state != SessionState.online) return null;
|
||||
|
||||
try {
|
||||
final response = await _api.sendRequest(Opcode.contactInfo, {
|
||||
'contactIds': [contactId],
|
||||
|
||||
@@ -1028,8 +1028,6 @@ class _ChatListScreenState extends State<ChatListScreen>
|
||||
|
||||
if (chat.type.isNotEmpty && chat.type == "DIALOG" && chat.id != 0) {
|
||||
final secondId = chat.participants.entries.where((entry) => entry.key != _profile?.id).first.key;
|
||||
// TODO: Нормальное кеширование контактов
|
||||
final ss = messagesModule.searchContactById(secondId);
|
||||
final name = ContactCache.get(secondId);
|
||||
final avatar = ContactCache.getAvatar(secondId);
|
||||
|
||||
@@ -1045,10 +1043,6 @@ class _ChatListScreenState extends State<ChatListScreen>
|
||||
chatType: "DIALOG",
|
||||
);
|
||||
} else {
|
||||
if (chat.lastMsgSenderId != null ) {
|
||||
final ss = messagesModule.searchContactById(chat.lastMsgSenderId!);
|
||||
}
|
||||
|
||||
final name = chat.lastMsgSenderId != null
|
||||
? ContactCache.get(chat.lastMsgSenderId!)
|
||||
: null;
|
||||
|
||||
@@ -289,8 +289,6 @@ class MessageBubble extends StatelessWidget {
|
||||
final cs = Theme.of(context).colorScheme;
|
||||
final isDark = cs.brightness == Brightness.dark;
|
||||
|
||||
// TODO: Нормальное кеширование контактов
|
||||
final ss = messagesModule.searchContactById(message.senderId);
|
||||
String? senderAvatar = ContactCache.getAvatar(message.senderId);
|
||||
String? displaySender = ContactCache.get(message.senderId);
|
||||
|
||||
@@ -382,8 +380,6 @@ class MessageBubble extends StatelessWidget {
|
||||
final forwarded = _getForwardedAttachment();
|
||||
final isForwarded = forwarded != null && !isForwardedContact;
|
||||
|
||||
// TODO: Нормальное кеширование контактов
|
||||
final ss = messagesModule.searchContactById(message.senderId);
|
||||
String? displaySender = ContactCache.get(message.senderId);
|
||||
|
||||
return Column(
|
||||
|
||||
+14
-14
@@ -344,15 +344,15 @@ class ContactAttachment extends MessageAttachment {
|
||||
|
||||
factory ContactAttachment.fromMap(Map<String, dynamic> map) {
|
||||
return ContactAttachment(
|
||||
previewData: map['previewData'] as String?,
|
||||
baseUrl: map['baseUrl'] as String?,
|
||||
userId: map['userId'] as String?,
|
||||
firstName: map['firstName'] as String?,
|
||||
lastName: map['lastName'] as String?,
|
||||
phoneNumber: map['phoneNumber'] as String?,
|
||||
photoUrl: map['photoUrl'] as String?,
|
||||
contactId: map['contactId'] as int?,
|
||||
name: map['name'] as String?,
|
||||
previewData: map['previewData']?.toString(),
|
||||
baseUrl: map['baseUrl']?.toString(),
|
||||
userId: map['userId']?.toString(),
|
||||
firstName: map['firstName']?.toString(),
|
||||
lastName: map['lastName']?.toString(),
|
||||
phoneNumber: map['phoneNumber']?.toString(),
|
||||
photoUrl: map['photoUrl']?.toString(),
|
||||
contactId: map['contactId'] is int ? map['contactId'] as int : int.tryParse(map['contactId']?.toString() ?? ''),
|
||||
name: map['name']?.toString(),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -426,11 +426,11 @@ class ControlAttachment extends MessageAttachment {
|
||||
|
||||
factory ControlAttachment.fromMap(Map<String, dynamic> map) {
|
||||
return ControlAttachment(
|
||||
previewData: map['previewData'] as String?,
|
||||
baseUrl: map['baseUrl'] as String?,
|
||||
event: map['event'] as String?,
|
||||
title: map['title'] as String?,
|
||||
userIds: (map['userIds'] as List?)?.cast<int>(),
|
||||
previewData: map['previewData']?.toString(),
|
||||
baseUrl: map['baseUrl']?.toString(),
|
||||
event: map['event']?.toString(),
|
||||
title: map['title']?.toString(),
|
||||
userIds: (map['userIds'] as List?)?.map((e) => e is int ? e : int.tryParse(e?.toString() ?? '') ?? 0).toList(),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user