opt: parse sys msg (#1770)

This commit is contained in:
My-Responsitories
2025-12-08 23:06:46 +08:00
committed by GitHub
parent 773bdafec3
commit ff4f97de1a
5 changed files with 46 additions and 46 deletions

View File

@@ -25,7 +25,7 @@ class TimelineResult {
isToday: json['is_today'] as int?, isToday: json['is_today'] as int?,
); );
void operator +(TimelineResult other) { void addAll(TimelineResult other) {
if (dateTs == other.dateTs) { if (dateTs == other.dateTs) {
if (other.episodes case final list?) { if (other.episodes case final list?) {
(episodes ??= <Episode>[]).addAll(list); (episodes ??= <Episode>[]).addAll(list);

View File

@@ -137,29 +137,38 @@ class _SysMsgPageState extends State<SysMsgPage> {
content.splitMapJoin( content.splitMapJoin(
urlRegExp, urlRegExp,
onMatch: (Match match) { onMatch: (Match match) {
String matchStr = match[0]!; final matchStr = match[0]!;
if (matchStr.startsWith('#')) { if (matchStr.startsWith('#')) {
spanChildren.add( try {
TextSpan( final url = match[2]!.replaceAll('"', '');
text: match[1], spanChildren.add(
style: TextStyle(color: theme.colorScheme.primary), TextSpan(
recognizer: TapGestureRecognizer() text: match[1],
..onTap = () { style: TextStyle(color: theme.colorScheme.primary),
try { recognizer: TapGestureRecognizer()
PiliScheme.routePushFromUrl(match[2]!.replaceAll('"', '')); ..onTap = () {
} catch (err) { try {
SmartDialog.showToast(err.toString()); PiliScheme.routePushFromUrl(url);
} } catch (err) {
}, SmartDialog.showToast(err.toString());
), }
); },
),
);
} catch (e) {
spanChildren.add(TextSpan(text: matchStr));
}
} else if (matchStr.startsWith('')) { } else if (matchStr.startsWith('')) {
try { try {
bool isBV = match[3]?.startsWith('BV') == true; final isBV = match[3]!.startsWith('BV');
final int validAv;
final String validBv;
if (isBV) { if (isBV) {
IdUtils.bv2av(match[3]!); validBv = match[3]!;
validAv = IdUtils.bv2av(validBv);
} else { } else {
IdUtils.av2bv(int.parse(match[3]!)); validAv = int.parse(match[3]!);
validBv = IdUtils.av2bv(validAv);
} }
spanChildren spanChildren
..add(const TextSpan(text: '')) ..add(const TextSpan(text: ''))
@@ -169,24 +178,17 @@ class _SysMsgPageState extends State<SysMsgPage> {
style: TextStyle(color: theme.colorScheme.primary), style: TextStyle(color: theme.colorScheme.primary),
recognizer: TapGestureRecognizer() recognizer: TapGestureRecognizer()
..onTap = () { ..onTap = () {
try { PiliScheme.videoPush(validAv, validBv);
PiliScheme.videoPush(
isBV ? null : int.parse(match[3]!),
isBV ? match[3]! : null,
);
} catch (err) {
SmartDialog.showToast(err.toString());
}
}, },
), ),
) )
..add(const TextSpan(text: '')); ..add(const TextSpan(text: ''));
} catch (e) { } catch (e) {
spanChildren.add(TextSpan(text: match[0])); spanChildren.add(TextSpan(text: matchStr));
} }
} else if (matchStr.startsWith('')) { } else if (matchStr.startsWith('')) {
try { try {
match[4]; // dynId final dynId = match[4]!; // check dynId
spanChildren spanChildren
..add(const TextSpan(text: '')) ..add(const TextSpan(text: ''))
..add( ..add(
@@ -195,17 +197,15 @@ class _SysMsgPageState extends State<SysMsgPage> {
style: TextStyle(color: theme.colorScheme.primary), style: TextStyle(color: theme.colorScheme.primary),
recognizer: TapGestureRecognizer() recognizer: TapGestureRecognizer()
..onTap = () { ..onTap = () {
try { PageUtils.pushDynFromId(id: dynId).catchError(
PageUtils.pushDynFromId(id: match[4]); (err) => SmartDialog.showToast(err.toString()),
} catch (err) { );
SmartDialog.showToast(err.toString());
}
}, },
), ),
) )
..add(const TextSpan(text: '')); ..add(const TextSpan(text: ''));
} catch (e) { } catch (e) {
spanChildren.add(TextSpan(text: match[0])); spanChildren.add(TextSpan(text: matchStr));
} }
} else { } else {
spanChildren.add( spanChildren.add(
@@ -214,12 +214,7 @@ class _SysMsgPageState extends State<SysMsgPage> {
style: TextStyle(color: theme.colorScheme.primary), style: TextStyle(color: theme.colorScheme.primary),
recognizer: TapGestureRecognizer() recognizer: TapGestureRecognizer()
..onTap = () { ..onTap = () {
try { PiliScheme.routePushFromUrl(matchStr);
PiliScheme.routePushFromUrl(match[0]!);
} catch (err) {
SmartDialog.showToast(err.toString());
Utils.copyText(match[0] ?? '');
}
}, },
), ),
); );

View File

@@ -75,7 +75,7 @@ class PgcController
list1.isNotEmpty && list1.isNotEmpty &&
list2.isNotEmpty) { list2.isNotEmpty) {
for (var i = 0; i < list1.length; i++) { for (var i = 0; i < list1.length; i++) {
list1[i] + list2[i]; list1[i].addAll(list2[i]);
} }
} else { } else {
list1 ??= list2; list1 ??= list2;

View File

@@ -48,7 +48,7 @@ abstract final class PiliScheme {
Map? parameters, Map? parameters,
int? businessId, int? businessId,
int? oid, int? oid,
}) async { }) {
try { try {
if (url.startsWith('//')) { if (url.startsWith('//')) {
url = 'https:$url'; url = 'https:$url';
@@ -64,7 +64,7 @@ abstract final class PiliScheme {
oid: oid, oid: oid,
); );
} catch (_) { } catch (_) {
return false; return Future.syncValue(false);
} }
} }

View File

@@ -278,7 +278,12 @@ abstract class PageUtils {
); );
} }
static Future<void> pushDynFromId({id, rid, bool off = false}) async { static Future<void> pushDynFromId({
String? id,
Object? rid,
bool off = false,
}) async {
assert(id != null || rid != null);
SmartDialog.showLoading(); SmartDialog.showLoading();
final res = await DynamicsHttp.dynamicDetail( final res = await DynamicsHttp.dynamicDetail(
id: id, id: id,
@@ -292,7 +297,7 @@ abstract class PageUtils {
toDupNamed( toDupNamed(
'/articlePage', '/articlePage',
parameters: { parameters: {
'id': id, 'id': id!,
'type': 'opus', 'type': 'opus',
}, },
off: off, off: off,