Skip to content

Commit

Permalink
bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
ChenDoxiu committed Jun 16, 2024
1 parent 7046cde commit f6d8497
Show file tree
Hide file tree
Showing 25 changed files with 871 additions and 198 deletions.
27 changes: 27 additions & 0 deletions lib/apis/models/note.dart
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,33 @@ class NoteModel {
String toJson() => json.encode(toMap());

factory NoteModel.fromJson(String str) => NoteModel.fromMap(json.decode(str));

static create() {
return NoteModel(
id: "1",
clippedCount: 0,
createdAt: DateTime.now(),
emojis: {},
files: [],
localOnly: false,
reactionEmojis: {},
reactions: {},
renoteCount: 0,
repliesCount: 0,
user: UserLiteModel(
avatarDecorations: [],
emojis: {},
id: "id",
name: "数据加载失败",
onlineStatus: OnlineStatus.ACTIVE,
username: "username",
avatarBlurhash: null,
avatarUrl: null,
host: ''),
userId: "userId",
visibility: NoteVisibility.home,
);
}
}

class NotePollModelChoices {
Expand Down
29 changes: 29 additions & 0 deletions lib/apis/services/notes_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,35 @@ class NotesService extends MisskeyApiServices {
return List<NoteModel>.from(data.map((e) => NoteModel.fromMap(e)));
}

Future<List<NoteModel>> pollsRecommendation(
{int limit = 10, String? untilId}) async {
var data = await client.post<List?>(
"/notes/polls/recommendation",
data: {
"limit": limit,
if (untilId != null) "untilId": untilId,
},
);
if (data == null) {
return [];
}
return List<NoteModel>.from(data.map((e) => NoteModel.fromMap(e)));
}

Future<List<NoteModel>> featured({int limit = 10, String? untilId}) async {
var data = await client.post<List?>(
"/notes/featured",
data: {
"limit": limit,
if (untilId != null) "untilId": untilId,
},
);
if (data == null) {
return [];
}
return List<NoteModel>.from(data.map((e) => NoteModel.fromMap(e)));
}

Future<NoteModel?> reNote({required String renoteId}) async {
var data = await client.post("/notes/create", data: {
"localOnly": false,
Expand Down
8 changes: 8 additions & 0 deletions lib/apis/services/user_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,12 @@ class UserService extends MisskeyApiServices {
(e) => ClipsModel.fromMap(e),
));
}

/// 获取全站置顶用户
Future<List<UserFullModel>> pinnedUsers() async {
var res = await client.post<List>("/pinned-users");
return List<UserFullModel>.from(res.map(
(e) => UserFullModel.fromMap(e),
));
}
}
5 changes: 4 additions & 1 deletion lib/database/link_preview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ import 'init_database.dart';
import '../apis/models/note.dart' as note;

class LinkPreviewDatabase {
LazyBox<String>? _box;

Future<LazyBox<String>> _getDatabase() async {
return openLazyDatabase<String>(name: "link_preview");
_box ??= await openLazyDatabase<String>(name: "link_preview");
return _box!;
}

put(String src, note.LinkPreview link) async {
Expand Down
19 changes: 15 additions & 4 deletions lib/database/notes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,34 @@ import 'init_database.dart';
class NotesDatabase {
/// 服务器地址
String server;
LazyBox? _box;
final Map<String, NoteModel> _noteMap = {};

NotesDatabase({required this.server});

Future<LazyBox<String>> _getDatabase() async {
return openLazyDatabase<String>(name: "notes_cache", server: server);
Future<LazyBox> _getDatabase() async {
_box ??=
await openLazyDatabase<String>(name: "notes_cache", server: server);
return _box!;
}

put(String noteId, NoteModel note) async {
// if (kDebugMode) {
// _noteMap[noteId] = note;
// return;
// }
var db = await _getDatabase();
await db.put(noteId, await compute((note) => note.toJson(), note));
await db.put(noteId, note.toJson());
}

Future<NoteModel?> get(String noteId) async {
// if (kDebugMode) {
// return _noteMap[noteId];
// }
var db = await _getDatabase();
var res = await db.get(noteId);
if (res != null) {
return compute((res) => NoteModel.fromJson(res), res);
return NoteModel.fromJson(res);
}
return null;
}
Expand Down
33 changes: 33 additions & 0 deletions lib/database/users.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import 'dart:convert';

import 'package:flutter/foundation.dart';
import 'package:hive/hive.dart';
import 'package:moekey/apis/models/note.dart';
import 'package:moekey/apis/models/user_full.dart';
import 'package:moekey/database/init_database.dart';

class UsersDatabase {
/// 服务器地址
String server;

/// 用户ID
String userId;

UsersDatabase({required this.server, required this.userId});

Future<LazyBox<String>> _getDatabase() async {
return openLazyDatabase<String>(name: "users_cache");
}

put(UserFullModel userFullModel) async {
var db = await _getDatabase();
compute((message) {
var json = jsonEncode(message);
db.put(message.id, json);
}, userFullModel);
}

get(String id) async {
var db = await _getDatabase();
}
}
7 changes: 4 additions & 3 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:io';

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
Expand All @@ -22,9 +23,9 @@ class HttpProxy extends HttpOverrides {

@override
String findProxyFromEnvironment(Uri url, Map<String, String>? environment) {
// if (kDebugMode) {
// proxyServer = "172.20.1.200:7890";
// }
if (kDebugMode) {
proxyServer = "127.0.0.1:7890";
}
if (proxyServer == "") {
return super.findProxyFromEnvironment(url, environment);
}
Expand Down
82 changes: 82 additions & 0 deletions lib/pages/explore/explore.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:flutter_tabler_icons/flutter_tabler_icons.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:moekey/pages/explore/hot.dart';
import 'package:moekey/pages/explore/users.dart';
import 'package:moekey/status/themes.dart';
import 'package:moekey/widgets/mk_header.dart';
import 'package:moekey/widgets/mk_scaffold.dart';

import '../../widgets/keep_alive_wrapper.dart';

class ExplorePage extends HookConsumerWidget {
const ExplorePage({super.key});

@override
Widget build(BuildContext context, WidgetRef ref) {
var themes = ref.watch(themeColorsProvider);
var tabs = const [
Tab(
child: Row(
children: [
Icon(
TablerIcons.bolt,
size: 14,
),
Text("热门", style: TextStyle(fontSize: 12)),
],
),
),
Tab(
child: Row(
children: [
Icon(TablerIcons.users, size: 14),
Text("用户", style: TextStyle(fontSize: 12)),
],
),
)
];

var tabController = useTabController(initialLength: tabs.length);

var currentIndex = useState(0);
tabController.addListener(() {
currentIndex.value = tabController.index;
});

return LayoutBuilder(
builder: (context, constraints) {
return MkScaffold(
body: TabBarView(
children: [
KeepAliveWrapper(child: ExploreHotPage()),
KeepAliveWrapper(child: ExploreUsersPage()),
],
controller: tabController,
),
header: MkAppbar(
leading: Padding(
padding: const EdgeInsets.symmetric(horizontal: 8),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(TablerIcons.hash, color: themes.fgColor, size: 18),
const SizedBox(width: 4),
const Text(
"发现",
)
],
),
),
isSmallLeadingCenter: constraints.maxWidth < 500,
bottom: MkTabBar(controller: tabController, tabs: tabs),
trailing: SizedBox(
width: 100,
),
),
);
},
);
}
}
Loading

0 comments on commit f6d8497

Please sign in to comment.