@@ -66,6 +66,7 @@ impl Database {
6666 actions : JsonActions :: new ( notification. actions . clone ( ) ) ,
6767 attachments : JsonAttachments :: new ( notification. attachments . clone ( ) ) ,
6868 is_expanded : i32:: from ( notification. is_expanded ) ,
69+ is_favorite : i32:: from ( notification. is_favorite ) ,
6970 } ;
7071
7172 diesel:: replace_into ( notifications:: table)
@@ -102,6 +103,7 @@ impl Database {
102103 actions : JsonActions :: new ( notification. actions . clone ( ) ) ,
103104 attachments : JsonAttachments :: new ( notification. attachments . clone ( ) ) ,
104105 is_expanded : i32:: from ( notification. is_expanded ) ,
106+ is_favorite : i32:: from ( notification. is_favorite ) ,
105107 } ;
106108
107109 diesel:: insert_or_ignore_into ( notifications:: table)
@@ -135,6 +137,32 @@ impl Database {
135137 Ok ( ( ) )
136138 }
137139
140+ /// Sets the favorite state of a notification.
141+ pub fn set_notification_favorite ( & self , id : & str , favorite : bool ) -> Result < ( ) , AppError > {
142+ let mut conn = self . conn ( ) ?;
143+
144+ diesel:: update ( notifications:: table. filter ( notifications:: id. eq ( id) ) )
145+ . set ( notifications:: is_favorite. eq ( i32:: from ( favorite) ) )
146+ . execute ( & mut * conn) ?;
147+
148+ Ok ( ( ) )
149+ }
150+
151+ /// Gets all favorite notifications, ordered by timestamp descending.
152+ pub fn get_favorite_notifications ( & self ) -> Result < Vec < Notification > , AppError > {
153+ let mut conn = self . conn ( ) ?;
154+
155+ let rows: Vec < NotificationRow > = notifications:: table
156+ . filter ( notifications:: is_favorite. eq ( 1 ) )
157+ . order ( notifications:: timestamp. desc ( ) )
158+ . load ( & mut * conn) ?;
159+
160+ Ok ( rows
161+ . into_iter ( )
162+ . map ( NotificationRow :: into_notification)
163+ . collect ( ) )
164+ }
165+
138166 /// Sets the expanded state of a notification.
139167 pub fn set_notification_expanded ( & self , id : & str , expanded : bool ) -> Result < ( ) , AppError > {
140168 let mut conn = self . conn ( ) ?;
0 commit comments