Skip to content

Commit 7f60d81

Browse files
authored
Merge pull request #461 from kooWZ/dev
fix announcements
2 parents 8474620 + 9b15825 commit 7f60d81

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

lib/model/announcement.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ class Announcement {
4040

4141
Announcement(this.content);
4242

43-
// FIXME: Use maxVersion as objectId requires maxVersion to be unique
43+
// FIXME: Use updatedAt as objectId requires updatedAt to be unique
4444
Announcement.fromToml(Map<String, dynamic> notice){
4545
updatedAt = notice['updatedAt'];
4646
content = notice['content'];
4747
maxVersion = notice['build'];
4848
createdAt = updatedAt;
49-
objectId = maxVersion.toString();
49+
objectId = updatedAt;
5050
}
5151
}

lib/repository/app/announcement_repository.dart

+19-12
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class AnnouncementRepository {
7272
}
7373

7474
List<Announcement>? getAnnouncements() {
75-
if (_tomlCache == null){
75+
if (_tomlCache == null) {
7676
return null;
7777
}
7878

@@ -81,26 +81,33 @@ class AnnouncementRepository {
8181
return [];
8282
}
8383
final list = (_tomlCache!['dev_notice'] as List<Map<String, dynamic>>)
84-
.where((element) => (element['maxVersion'] as int) >= version)
84+
.where((element) => (element['build'] as int) >= version)
8585
.toList();
86-
return list.map<Announcement>((e) => Announcement.fromToml(e)).toList();
86+
final announcements =
87+
list.map<Announcement>((e) => Announcement.fromToml(e)).toList();
88+
announcements.sort((a, b) =>
89+
(DateTime.parse(b.updatedAt!)).compareTo(DateTime.parse(a.updatedAt!)));
90+
return announcements;
8791
}
8892

8993
List<Announcement>? getAllAnnouncements() {
90-
if (_tomlCache == null){
94+
if (_tomlCache == null) {
9195
return null;
9296
}
9397

9498
if (_tomlCache!['dev_notice'] == null) {
9599
return [];
96100
}
97-
return _tomlCache!['dev_notice']
101+
final announcements = _tomlCache!['dev_notice']
98102
.map<Announcement>((e) => Announcement.fromToml(e))
99103
.toList();
104+
announcements?.sort((a, b) =>
105+
(DateTime.parse(b.updatedAt!)).compareTo(DateTime.parse(a.updatedAt!)));
106+
return announcements;
100107
}
101108

102109
TimeTableExtra? getStartDates() {
103-
if (_tomlCache == null){
110+
if (_tomlCache == null) {
104111
return null;
105112
}
106113

@@ -113,23 +120,23 @@ class AnnouncementRepository {
113120
}
114121

115122
String? getUserAgent() {
116-
if (_tomlCache == null){
123+
if (_tomlCache == null) {
117124
return null;
118125
}
119126

120127
return _tomlCache!['user_agent'];
121128
}
122129

123130
List<String?>? getStopWords() {
124-
if (_tomlCache == null){
131+
if (_tomlCache == null) {
125132
return null;
126133
}
127134

128135
return _tomlCache!['stop_words'].cast<String>();
129136
}
130137

131138
List<BannerExtra?>? getBannerExtras() {
132-
if (_tomlCache == null){
139+
if (_tomlCache == null) {
133140
return null;
134141
}
135142

@@ -140,15 +147,15 @@ class AnnouncementRepository {
140147
}
141148

142149
List<String?>? getCareWords() {
143-
if (_tomlCache == null){
150+
if (_tomlCache == null) {
144151
return null;
145152
}
146153

147154
return _tomlCache!['care_words'].cast<String>();
148155
}
149156

150157
UpdateInfo? checkVersion() {
151-
if (_tomlCache == null){
158+
if (_tomlCache == null) {
152159
return null;
153160
}
154161

@@ -163,7 +170,7 @@ class AnnouncementRepository {
163170
}
164171

165172
List<Celebration>? getCelebrations() {
166-
if (_tomlCache == null){
173+
if (_tomlCache == null) {
167174
return null;
168175
}
169176

0 commit comments

Comments
 (0)