51 lines
1.2 KiB
Dart
51 lines
1.2 KiB
Dart
import 'dart:convert';
|
|
|
|
import 'package:yumi/shared/business_logic/models/res/login_res.dart';
|
|
|
|
const String scChatBubbleCloudDataKey = 'scChatBubble';
|
|
|
|
String? scEncodeChatBubbleCloudCustomData(PropsResources? chatBubble) {
|
|
if (!_hasChatBubbleImage(chatBubble)) {
|
|
return null;
|
|
}
|
|
return jsonEncode(<String, dynamic>{
|
|
scChatBubbleCloudDataKey: chatBubble!.toJson(),
|
|
});
|
|
}
|
|
|
|
PropsResources? scDecodeChatBubbleFromCloudCustomData(String? cloudCustomData) {
|
|
final raw = cloudCustomData?.trim();
|
|
if (raw == null || raw.isEmpty) {
|
|
return null;
|
|
}
|
|
try {
|
|
final decoded = jsonDecode(raw);
|
|
if (decoded is! Map) {
|
|
return null;
|
|
}
|
|
final data = decoded[scChatBubbleCloudDataKey];
|
|
if (data is Map) {
|
|
return PropsResources.fromJson(data);
|
|
}
|
|
} catch (_) {}
|
|
return null;
|
|
}
|
|
|
|
bool _hasChatBubbleImage(PropsResources? resource) {
|
|
if (resource == null) {
|
|
return false;
|
|
}
|
|
return <String?>[
|
|
resource.imSendCoverUrl,
|
|
resource.imOpenedUrl,
|
|
resource.imOpenedUrlTwo,
|
|
resource.imNotOpenedUrl,
|
|
resource.roomSendCoverUrl,
|
|
resource.roomOpenedUrl,
|
|
resource.roomNotOpenedUrl,
|
|
resource.cover,
|
|
resource.expand,
|
|
resource.sourceUrl,
|
|
].any((value) => (value?.trim() ?? '').isNotEmpty);
|
|
}
|