111 lines
2.6 KiB
Dart
111 lines
2.6 KiB
Dart
import 'package:yumi/shared/business_logic/models/res/gift_res.dart';
|
|
import 'package:yumi/shared/data_sources/models/enum/sc_gift_type.dart';
|
|
import 'package:yumi/shared/tools/sc_cp_relation_notice_utils.dart';
|
|
|
|
bool scIsCpGiftTab(String? tabType) {
|
|
final text = tabType?.trim();
|
|
if (text == null || text.isEmpty) {
|
|
return false;
|
|
}
|
|
return text.toUpperCase() == SCGiftType.CP.name ||
|
|
_inferCpRelationTypeFromGiftText(text) != null;
|
|
}
|
|
|
|
bool scIsCpGift(SocialChatGiftRes? gift) {
|
|
if (gift == null) {
|
|
return false;
|
|
}
|
|
return scIsCpGiftTab(gift.giftTab) ||
|
|
_normalizeExplicitGiftRelationType(gift.relationType) != null;
|
|
}
|
|
|
|
String scCpRelationTypeForGift(SocialChatGiftRes gift) {
|
|
final explicit = _normalizeExplicitGiftRelationType(gift.relationType);
|
|
if (explicit != null) {
|
|
return explicit;
|
|
}
|
|
for (final value in <String?>[
|
|
gift.type,
|
|
gift.giftCode,
|
|
gift.giftName,
|
|
gift.special,
|
|
gift.standardId,
|
|
gift.giftTab,
|
|
]) {
|
|
final inferred = _inferCpRelationTypeFromGiftText(value);
|
|
if (inferred != null) {
|
|
return inferred;
|
|
}
|
|
}
|
|
return "CP";
|
|
}
|
|
|
|
String? _normalizeExplicitGiftRelationType(String? relationType) {
|
|
final raw = relationType?.trim();
|
|
if (raw == null || raw.isEmpty) {
|
|
return null;
|
|
}
|
|
final normalized = scNormalizeCpRelationType(raw);
|
|
if (normalized != "CP") {
|
|
return normalized;
|
|
}
|
|
if (_isCpRelationText(raw)) {
|
|
return normalized;
|
|
}
|
|
return _inferCpRelationTypeFromGiftText(raw);
|
|
}
|
|
|
|
bool _isCpRelationText(String value) {
|
|
final upper = value.trim().toUpperCase();
|
|
return upper == "CP" || upper == "COUPLE";
|
|
}
|
|
|
|
String? _inferCpRelationTypeFromGiftText(String? value) {
|
|
final upper = value?.trim().toUpperCase();
|
|
if (upper == null || upper.isEmpty) {
|
|
return null;
|
|
}
|
|
if (_hasRelationToken(upper, const [
|
|
"SIS",
|
|
"SISTER",
|
|
"SISTERS",
|
|
"姐妹",
|
|
"姊妹",
|
|
"闺蜜",
|
|
])) {
|
|
return "SISTERS";
|
|
}
|
|
if (_hasRelationToken(upper, const [
|
|
"BRO",
|
|
"BROS",
|
|
"BROTHER",
|
|
"BROTHERS",
|
|
"SWORN_BRO",
|
|
"SWORN_BROS",
|
|
"SWORN_BROTHER",
|
|
"SWORN_BROTHERS",
|
|
"兄弟",
|
|
"哥们",
|
|
"兄妹",
|
|
])) {
|
|
return "BROTHER";
|
|
}
|
|
if (_hasRelationToken(upper, const ["CP", "COUPLE", "情侣", "恋人", "伴侣"])) {
|
|
return "CP";
|
|
}
|
|
return null;
|
|
}
|
|
|
|
bool _hasRelationToken(String upperText, List<String> tokens) {
|
|
for (final token in tokens) {
|
|
final escaped = RegExp.escape(token);
|
|
if (RegExp(r'[^\x00-\x7F]').hasMatch(token) && upperText.contains(token)) {
|
|
return true;
|
|
}
|
|
if (RegExp('(^|[^A-Z0-9])$escaped([^A-Z0-9]|\$)').hasMatch(upperText)) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|