mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-20 00:56:31 +08:00
opt: unread & zan grpc & readlist open with browser (#852)
* opt: unread * opt: zan grpc * feat: readlist open with browser
This commit is contained in:
committed by
GitHub
parent
8d34e6f340
commit
72734d4b4e
@@ -1,8 +1,7 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:PiliPlus/grpc/dyn.dart';
|
||||
import 'package:PiliPlus/http/api.dart';
|
||||
import 'package:PiliPlus/http/init.dart';
|
||||
import 'package:PiliPlus/grpc/im.dart';
|
||||
import 'package:PiliPlus/models/common/dynamic/dynamic_badge_mode.dart';
|
||||
import 'package:PiliPlus/models/common/msg/msg_unread_type.dart';
|
||||
import 'package:PiliPlus/models/common/nav_bar_config.dart';
|
||||
@@ -83,92 +82,51 @@ class MainController extends GetxController {
|
||||
msgUnReadCount.value = '';
|
||||
return;
|
||||
}
|
||||
try {
|
||||
bool shouldCheckPM = msgUnReadTypes.contains(MsgUnReadType.pm);
|
||||
bool shouldCheckFeed =
|
||||
shouldCheckPM ? msgUnReadTypes.length > 1 : msgUnReadTypes.isNotEmpty;
|
||||
List res = await Future.wait([
|
||||
if (shouldCheckPM) _queryPMUnread(),
|
||||
if (shouldCheckFeed) _queryMsgFeedUnread(),
|
||||
]);
|
||||
dynamic count = 0;
|
||||
if (shouldCheckPM && res.firstOrNull?['status'] == true) {
|
||||
count = (res.first['data'] as int?) ?? 0;
|
||||
}
|
||||
if ((shouldCheckPM.not && res.firstOrNull?['status'] == true) ||
|
||||
(shouldCheckPM && res.getOrNull(1)?['status'] == true)) {
|
||||
int index = shouldCheckPM.not ? 0 : 1;
|
||||
dynamic data = res[index]['data'];
|
||||
|
||||
int count = 0;
|
||||
final res = await ImGrpc.getTotalUnread();
|
||||
if (res.isSuccess) {
|
||||
final data = res.data;
|
||||
if (msgUnReadTypes.length == MsgUnReadType.values.length) {
|
||||
count = data.hasTotalUnread() ? data.totalUnread : 0;
|
||||
} else {
|
||||
final msgUnread = data.msgFeedUnread.unread;
|
||||
for (final item in msgUnReadTypes) {
|
||||
switch (item) {
|
||||
case MsgUnReadType.pm:
|
||||
final pmUnread = data.sessionSingleUnread;
|
||||
count += (pmUnread.followUnread +
|
||||
pmUnread.unfollowUnread +
|
||||
pmUnread.dustbinUnread)
|
||||
.toInt();
|
||||
break;
|
||||
case MsgUnReadType.reply:
|
||||
count += (data['reply'] as int?) ?? 0;
|
||||
count += msgUnread['reply']?.toInt() ?? 0;
|
||||
break;
|
||||
case MsgUnReadType.at:
|
||||
count += (data['at'] as int?) ?? 0;
|
||||
count += msgUnread['at']?.toInt() ?? 0;
|
||||
break;
|
||||
case MsgUnReadType.like:
|
||||
count += (data['like'] as int?) ?? 0;
|
||||
count += msgUnread['like']?.toInt() ?? 0;
|
||||
break;
|
||||
case MsgUnReadType.sysMsg:
|
||||
count += (data['sys_msg'] as int?) ?? 0;
|
||||
count += msgUnread['sys_msg']?.toInt() ?? 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
count = count == 0
|
||||
? ''
|
||||
: count > 99
|
||||
? '99+'
|
||||
: count.toString();
|
||||
if (msgUnReadCount.value == count) {
|
||||
msgUnReadCount.refresh();
|
||||
} else {
|
||||
msgUnReadCount.value = count;
|
||||
}
|
||||
} catch (e) {
|
||||
debugPrint('failed to get unread count: $e');
|
||||
}
|
||||
}
|
||||
|
||||
Future _queryPMUnread() async {
|
||||
try {
|
||||
dynamic res = await Request().get(Api.msgUnread);
|
||||
if (res.data['code'] == 0) {
|
||||
return {
|
||||
'status': true,
|
||||
'data': ((res.data['data']?['unfollow_unread'] as int?) ?? 0) +
|
||||
((res.data['data']?['follow_unread'] as int?) ?? 0),
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
'status': false,
|
||||
'msg': res.data['message'],
|
||||
};
|
||||
}
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
Future _queryMsgFeedUnread() async {
|
||||
if (isLogin.value.not) {
|
||||
return;
|
||||
final countStr = count == 0
|
||||
? ''
|
||||
: count > 99
|
||||
? '99+'
|
||||
: count.toString();
|
||||
if (msgUnReadCount.value == countStr) {
|
||||
msgUnReadCount.refresh();
|
||||
} else {
|
||||
msgUnReadCount.value = countStr;
|
||||
}
|
||||
try {
|
||||
dynamic res = await Request().get(Api.msgFeedUnread);
|
||||
if (res.data['code'] == 0) {
|
||||
return {
|
||||
'status': true,
|
||||
'data': res.data['data'],
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
'status': false,
|
||||
'msg': res.data['message'],
|
||||
};
|
||||
}
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
Future<void> getUnreadDynamic() async {
|
||||
|
||||
Reference in New Issue
Block a user