17
17
class Entry
18
18
property zip_path : String , book : Title , title : String ,
19
19
size : String , pages : Int32 , id : String , title_id : String ,
20
- encoded_path : String , encoded_title : String , mtime : Time
20
+ encoded_path : String , encoded_title : String , mtime : Time ,
21
+ date_added : Time
21
22
22
23
def initialize (path, @book , @title_id , storage)
23
24
@zip_path = path
@@ -33,6 +34,7 @@ class Entry
33
34
file.close
34
35
@id = storage.get_id @zip_path , false
35
36
@mtime = File .info(@zip_path ).modification_time
37
+ @date_added = load_date_added
36
38
end
37
39
38
40
def to_json (json : JSON ::Builder )
@@ -89,6 +91,20 @@ class Entry
89
91
end
90
92
end
91
93
end
94
+
95
+ private def load_date_added
96
+ date_added = nil
97
+ TitleInfo .new @book .dir do |info |
98
+ info_da = info.date_added[@title ]?
99
+ if info_da.nil?
100
+ date_added = info.date_added[@title ] = ctime @zip_path
101
+ info.save
102
+ else
103
+ date_added = info_da
104
+ end
105
+ end
106
+ date_added.not_nil! # is it ok to set not_nil! here?
107
+ end
92
108
end
93
109
94
110
class Title
@@ -384,6 +400,7 @@ class TitleInfo
384
400
property cover_url = " "
385
401
property entry_cover_url = {} of String => String
386
402
property last_read = {} of String => Hash (String , Time )
403
+ property date_added = {} of String => Time
387
404
388
405
@[JSON ::Field (ignore: true )]
389
406
property dir : String = " "
@@ -486,7 +503,7 @@ class Library
486
503
get_continue_reading_entry username, t
487
504
}.select Entry
488
505
489
- continue_reading = continue_reading_entries.map_with_index { |e , i |
506
+ continue_reading = continue_reading_entries.map { |e |
490
507
{
491
508
entry: e,
492
509
percentage: e.book.load_percentage(username, e.title),
@@ -495,12 +512,26 @@ class Library
495
512
}
496
513
497
514
# Sort by by last_read, most recent first (nils at the end)
498
- continue_reading.sort! do |a , b |
515
+ continue_reading.sort! { |a , b |
499
516
next 0 if a[:last_read ].nil? && b[:last_read ].nil?
500
517
next 1 if a[:last_read ].nil?
501
518
next -1 if b[:last_read ].nil?
502
519
b[:last_read ].not_nil! <=> a[:last_read ].not_nil!
520
+ }[0 ..11]
521
+ end
522
+
523
+ def get_recently_added_entries (username )
524
+ entries = [] of Entry
525
+ titles.each do |t |
526
+ t.entries.each { |e | entries << e }
503
527
end
528
+ recently_added = entries.map { |e |
529
+ {
530
+ entry: e,
531
+ percentage: e.book.load_percentage(username, e.title)
532
+ }
533
+ }
534
+ recently_added.sort! { |a , b | b[:entry ].date_added <=> a[:entry ].date_added }[0 ..11]
504
535
end
505
536
506
537
0 commit comments