@@ -14,9 +14,6 @@ final class AppVM: ObservableObject {
14
14
@Published var alertMsg = " " // 警告信息
15
15
@Published var webLinkStr = " " // 导航上的外部链接
16
16
17
- // 仓库动态
18
- @Published var reposNotis = [ String: Int] ( )
19
- @Published var reposCountNotis = 0
20
17
// 开发者动态
21
18
@Published var devsNotis = [ String: Int] ( )
22
19
@Published var devsCountNotis = 0
@@ -29,6 +26,19 @@ final class AppVM: ObservableObject {
29
26
@Published var expCountNotis = 0
30
27
@Published var exps = [ SPReposModel] ( )
31
28
29
+ // MARK: - Combine
30
+ private var cc : [ AnyCancellable ] = [ ]
31
+ private let apiSev : APISev
32
+
33
+ // MARK: - Timer for get intervals data
34
+
35
+ // 开发者动态
36
+ private var stepCountDevs = 0
37
+ private var devsNotisKeys = [ String] ( )
38
+ // 探索库
39
+ private var stepCountExp = 0
40
+ private var expNotisKeys = [ String] ( )
41
+
32
42
// MARK: - RSS 读取
33
43
func rssFetch( ) {
34
44
Task {
@@ -72,15 +82,9 @@ final class AppVM: ObservableObject {
72
82
73
83
Task {
74
84
var expDic = [ String: DBRepoStore] ( )
75
- let gAPI = RESTful ( host: . github)
76
85
do {
77
- let issueModel = try await gAPI. value ( for: Github . repos ( SPC . pamphletIssueRepoName) . issues ( 108 ) . get)
78
- let str = issueModel. body? . base64Decoded ( ) ?? " "
79
- let data = str. data ( using: String . Encoding. utf8) !
80
86
var grs = [ SPReposModel] ( )
81
-
82
- let decoder = JSONDecoder ( )
83
- grs = try decoder. decode ( [ SPReposModel ] . self, from: data)
87
+ grs = loadBundleJSONFile ( " repos.json " )
84
88
85
89
for gr in grs {
86
90
for r in gr. repos {
@@ -129,15 +133,6 @@ final class AppVM: ObservableObject {
129
133
}
130
134
131
135
// MARK: - Timer for get intervals data
132
- // 仓库动态
133
- private var stepCountRepos = 0
134
- private var reposNotisKeys = [ String] ( )
135
- // 开发者动态
136
- private var stepCountDevs = 0
137
- private var devsNotisKeys = [ String] ( )
138
- // 探索库
139
- private var stepCountExp = 0
140
- private var expNotisKeys = [ String] ( )
141
136
142
137
// 探索库
143
138
func timeForExpEvent( ) {
@@ -231,94 +226,22 @@ final class AppVM: ObservableObject {
231
226
}
232
227
}
233
228
234
- // 仓库动态
235
- @MainActor
236
- func timeForReposEvent( ) -> String ? {
237
- if reposNotis. count > 0 {
238
- if stepCountRepos >= reposNotis. count {
239
- stepCountRepos = 0
240
- }
241
- if reposNotisKeys. count == 0 {
242
- for (k, _) in reposNotis {
243
- reposNotisKeys. append ( k)
244
- }
245
- }
246
- if stepCountRepos >= reposNotisKeys. count {
247
- stepCountRepos = 0
248
- return nil
249
- } else {
250
- let repoName = reposNotisKeys [ stepCountRepos]
251
- updateAlertMsg ( msg: " 已同步 \( repoName) " )
252
- loadDBReposLoal ( )
253
- calculateReposCountNotis ( )
254
- stepCountRepos += 1
255
- return repoName
256
- } // end if else
257
-
258
- } else {
259
- return nil
260
- }
261
- }
262
-
263
229
// MARK: - On Appear Event
264
230
func onAppearEvent( ) {
265
231
nsck ( )
266
- // 仓库数据读取
267
- loadDBReposLoal ( )
268
- apReposSj. send ( ( ) )
269
232
// 开发者数据读取
270
233
loadDBDevsLoal ( )
271
- apDevsSj. send ( ( ) )
272
234
// 探索更多库
273
235
loadDBExpLoal ( )
274
236
loadExpFromServer ( )
275
237
}
276
238
277
-
278
-
279
- // MARK: - Combine
280
-
281
- private var cc : [ AnyCancellable ] = [ ]
282
-
283
- private let apiSev : APISev
284
239
285
- private let apReposSj = PassthroughSubject < Void , Never > ( )
286
- private let resReposSj = PassthroughSubject < IssueModel , Never > ( )
287
- private let apDevsSj = PassthroughSubject < Void , Never > ( )
288
- private let resDevsSj = PassthroughSubject < IssueModel , Never > ( )
289
-
290
- init ( ) {
291
- self . apiSev = APISev ( )
292
- // MARK: - 初始化数据库
293
- let db = DB . shared
294
- do {
295
- try db. cTbs ( )
296
- } catch {
297
-
298
- }
240
+ func refreshDev( ) {
299
241
300
- // MARK: - 获取所有开发者通知信息
301
- let reqDevsCustomIssues = IssueRequest ( repoName: SPC . pamphletIssueRepoName, issueNumber: 30 )
302
- let resDevsSm = apDevsSj
303
- . flatMap { [ apiSev] in
304
- apiSev. response ( from: reqDevsCustomIssues)
305
- . catch { error -> Empty < IssueModel , Never > in
306
- return . init( )
307
- }
308
- }
309
- . share ( )
310
- . subscribe ( resDevsSj)
311
- var devsDic = [ String: Int] ( )
312
- func switchToDevsDic( issueModel: IssueModel ) -> [ String : Int ] {
313
- let str = issueModel. body? . base64Decoded ( ) ?? " "
314
- let data = str. data ( using: String . Encoding. utf8) !
315
- var ads = [ SPActiveDevelopersModel] ( )
316
- do {
317
- let decoder = JSONDecoder ( )
318
- ads = try decoder. decode ( [ SPActiveDevelopersModel ] . self, from: data)
319
- } catch {
320
- return devsDic
321
- }
242
+ func switchToDevsDic( ) -> [ String : Int ] {
243
+ var devsDic = [ String: Int] ( )
244
+ let ads : [ SPActiveDevelopersModel ] = loadBundleJSONFile ( " developers.json " )
322
245
for ad in ads {
323
246
for d in ad. users {
324
247
do {
@@ -361,88 +284,22 @@ final class AppVM: ObservableObject {
361
284
362
285
return devsDic
363
286
}
364
- let repDevsSm = resDevsSj
365
- . map { issueModel in
366
- return switchToDevsDic ( issueModel: issueModel)
367
- } // end map
368
- . assign ( to: \. devsNotis, on: self )
369
-
370
-
371
- // MARK: - 获取所有仓库通知信息
372
- let reqReposCustomIssues = IssueRequest ( repoName: SPC . pamphletIssueRepoName, issueNumber: 31 )
373
- let resReposSm = apReposSj
374
- . flatMap { [ apiSev] in
375
- apiSev. response ( from: reqReposCustomIssues)
376
- . catch { error -> Empty < IssueModel , Never > in
377
- return . init( )
378
- }
379
- }
380
- . share ( )
381
- . subscribe ( resReposSj)
382
- var reposDic = [ String: Int] ( )
383
- func switchToReposDic( issueModel: IssueModel ) -> [ String : Int ] {
384
- let str = issueModel. body? . base64Decoded ( ) ?? " "
385
- let data = str. data ( using: String . Encoding. utf8) !
386
- var grs = [ SPReposModel] ( )
387
- do {
388
- let decoder = JSONDecoder ( )
389
- grs = try decoder. decode ( [ SPReposModel ] . self, from: data)
390
- } catch {
391
- return reposDic
392
- }
393
- for gr in grs {
394
- for r in gr. repos {
395
- do {
396
- if let fd = try ReposNotiDataHelper . find ( sFullName: r. id) {
397
- reposDic [ fd. fullName] = fd. unRead
398
- } else {
399
- do {
400
- let _ = try ReposNotiDataHelper . insert ( i: DBRepoNoti ( fullName: r. id, lastReadCommitSha: " " , unRead: 0 ) )
401
- reposDic [ r. id] = 0
402
- } catch {
403
- return reposDic
404
- }
405
- }
406
- } catch {
407
- return reposDic
408
- }
409
-
410
- } // end for
411
- } // end for
412
-
413
- // 远程已经删除的仓库,同步本地删除
414
- if !( reposDic. count > 0 ) {
415
- return reposDic
416
- }
417
- let reposDicKeys = reposDic. keys
418
- do {
419
- if let rpsn = try ReposNotiDataHelper . findAll ( ) {
420
- for rpn in rpsn {
421
- if !reposDicKeys. contains ( rpn. fullName) {
422
- do {
423
- try ReposNotiDataHelper . delete ( i: rpn)
424
- } catch {
425
- return reposDic
426
- } // end do
427
- } // end if
428
- } // end for
429
- } // end if let
430
- } catch {
431
- return reposDic
432
- }
287
+ devsNotis = switchToDevsDic ( )
288
+ }
289
+
290
+ // MARK: Combine
291
+
292
+ init ( ) {
293
+ self . apiSev = APISev ( )
294
+ // MARK: - 初始化数据库
295
+ let db = DB . shared
296
+ do {
297
+ try db. cTbs ( )
298
+ } catch {
433
299
434
- return reposDic
435
300
}
436
- let repReposSm = resReposSj
437
- . map { issueModel in
438
- return switchToReposDic ( issueModel: issueModel)
439
- } // end map
440
- . assign ( to: \. reposNotis, on: self )
441
301
442
- cc += [
443
- resReposSm, repReposSm,
444
- resDevsSm, repDevsSm
445
- ]
302
+
446
303
}
447
304
448
305
// MARK: 探索更多库,本地数据库读取
@@ -468,26 +325,6 @@ final class AppVM: ObservableObject {
468
325
}
469
326
}
470
327
471
-
472
- // MARK: 仓库动态,本地数据库读取
473
- func loadDBReposLoal( ) {
474
- do {
475
- if let arr = try ReposNotiDataHelper . findAll ( ) {
476
- if arr. count > 0 {
477
- var ReposDic = [ String: Int] ( )
478
- for i in arr {
479
- if reposNotis [ i. fullName] ?? 0 >= SPC . unreadMagicNumber {
480
- ReposDic [ i. fullName] = SPC . unreadMagicNumber
481
- } else {
482
- ReposDic [ i. fullName] = i. unRead
483
- }
484
- } // end for
485
- reposNotis = ReposDic
486
- } // end if
487
- } // end if
488
- } catch { }
489
- }
490
-
491
328
// MARK: 开发者动态,本地数据库读取
492
329
func loadDBDevsLoal( ) {
493
330
do {
@@ -524,23 +361,6 @@ final class AppVM: ObservableObject {
524
361
showAppBadgeLabel ( )
525
362
}
526
363
527
- @MainActor
528
- func calculateReposCountNotis( ) {
529
- var count = 0
530
- for i in reposNotis {
531
- count += i. value
532
- if count > SPC . unreadMagicNumber * 10 {
533
- break
534
- }
535
- }
536
- if count >= SPC . unreadMagicNumber {
537
- count = count - SPC. unreadMagicNumber
538
- }
539
- reposCountNotis = count
540
- showAppBadgeLabel ( )
541
-
542
- }
543
-
544
364
@MainActor
545
365
func calculateDevsCountNotis( ) {
546
366
var count = 0
@@ -558,7 +378,7 @@ final class AppVM: ObservableObject {
558
378
}
559
379
560
380
func showAppBadgeLabel( ) {
561
- var count = reposCountNotis + devsCountNotis + expCountNotis + rssCountNotis
381
+ var count = devsCountNotis + expCountNotis + rssCountNotis
562
382
if count > 0 {
563
383
if count > SPC . unreadMagicNumber * 10 {
564
384
count = SPC . unreadMagicNumber * 10
0 commit comments