1
- import 'package:freedom/tools/time_tools .dart' ;
1
+ import 'package:freedom/store/store .dart' ;
2
2
import 'package:get/get.dart' ;
3
3
import 'package:freedom/data_structures/message.dart' ;
4
4
@@ -7,15 +7,80 @@ class MemoryDatabaseController extends GetxController {
7
7
print ("memory database controller initialized" );
8
8
}
9
9
10
+ int stream_size_for_a_bunch_of_messages = 3 ;
10
11
RxList <Message > messageList = RxList ([]);
11
12
12
13
Future <void > syncMessageList ({required List <Message > newMessageList}) async {
13
14
RxList <Message > tempMessageList = RxList ();
14
15
15
- tempMessageList.addAll (newMessageList.map ((e) => e));
16
- newMessageList.forEach ((element) {
17
- print (convertStringToTime (time: element.date));
18
- });
16
+ tempMessageList.addAll (newMessageList);
17
+
18
+ messageList.assignAll (tempMessageList);
19
+ }
20
+
21
+ Future <void > add_new_message_list_in (
22
+ {required List <Message > new_message_list}) async {
23
+ RxList <Message > tempMessageList = RxList ();
24
+
25
+ tempMessageList.addAll (this .messageList);
26
+ tempMessageList.addAll (new_message_list);
27
+
28
+ messageList.assignAll (tempMessageList);
29
+ }
30
+
31
+ Future <void > show_default_message_list () async {
32
+ if (sqlite_database_controlelr.onlyShowTodayInHistory) {
33
+ //show history in today
34
+ var message_list = await sqlite_database_controlelr
35
+ .search_messages_that_sent_on_the_same_day_of_the_years (
36
+ go_back_to_past_order: true );
37
+ await syncMessageList (newMessageList: message_list);
38
+ return ;
39
+ }
40
+
41
+ RxList <Message > tempMessageList = RxList ();
42
+
43
+ var first_20_messages =
44
+ await sqlite_database_controlelr.get_message_list_by_offset_and_limit (
45
+ offset: 0 , limit: 3 , go_back_to_past_order: true );
46
+
47
+ tempMessageList.addAll (first_20_messages);
48
+ print (first_20_messages);
49
+
50
+ messageList.assignAll (tempMessageList);
51
+ }
52
+
53
+ Future <void > load_more_messages () async {
54
+ if (sqlite_database_controlelr.onlyShowTodayInHistory) {
55
+ // we show all history-in-today message
56
+ // no need to load more
57
+ return ;
58
+ }
59
+
60
+ var current_messages_number = memory_database_controller.messageList.length;
61
+
62
+ List <Message > new_msg_list =
63
+ await sqlite_database_controlelr.get_message_list_by_offset_and_limit (
64
+ offset: current_messages_number,
65
+ limit: stream_size_for_a_bunch_of_messages,
66
+ go_back_to_past_order: true );
67
+
68
+ await add_new_message_list_in (new_message_list: new_msg_list);
69
+ }
70
+
71
+ Future <void > refresh_the_list_view () async {
72
+ RxList <Message > tempMessageList = RxList ();
73
+
74
+ for (Message msg_ in this .messageList) {
75
+ Message ? the_msg = await sqlite_database_controlelr
76
+ .search_message_by_type_and_date (msg: msg_);
77
+ if (the_msg != null ) {
78
+ // update database message to memory
79
+ tempMessageList.add (the_msg);
80
+ } else {
81
+ // delete memory message if it not in database
82
+ }
83
+ }
19
84
20
85
messageList.assignAll (tempMessageList);
21
86
}
0 commit comments