File tree Expand file tree Collapse file tree 2 files changed +16
-6
lines changed Expand file tree Collapse file tree 2 files changed +16
-6
lines changed Original file line number Diff line number Diff line change @@ -317,9 +317,6 @@ class Notification(BaseModel):
317
317
318
318
def read (self ) -> bool :
319
319
self .viewed = True
320
- mail = MailMessage .get_or_none (MailMessage .notification == self )
321
- if mail :
322
- mail .delete_instance ()
323
320
return bool (self .save ())
324
321
325
322
@classmethod
@@ -398,11 +395,24 @@ def distincit_users(cls):
398
395
399
396
@classmethod
400
397
def by_user (cls , user : User ) -> Iterable ['MailMessage' ]:
401
- return cls .select ().where (cls .user == user )
398
+ return (
399
+ cls
400
+ .select ()
401
+ .where (cls .user == user )
402
+ .join (Notification )
403
+ .where (Notification .viewed == False ) # NOQA: E712
404
+ )
402
405
403
406
@classmethod
404
407
def user_messages_number (cls , user : User ) -> int :
405
- return cls .select (fn .Count (cls .id )).where (cls .user == user ).scalar ()
408
+ return (
409
+ cls
410
+ .select (fn .Count (cls .id ))
411
+ .where (cls .user == user )
412
+ .join (Notification )
413
+ .where (Notification .viewed == False ) # NOQA: E712
414
+ .scalar ()
415
+ )
406
416
407
417
@classmethod
408
418
def get_instances_number (cls ):
Original file line number Diff line number Diff line change @@ -97,7 +97,7 @@ def build_notification_message(mails: Iterable[MailMessage]) -> str:
97
97
98
98
@webscheduler .task (
99
99
'interval' , id = 'mail_notifications' ,
100
- hours = config . DEFAULT_DO_TASKS_EVERY_HOURS ,
100
+ seconds = 30 ,
101
101
)
102
102
def send_all_notifications_mails ():
103
103
for mail_message_user in MailMessage .distincit_users ():
You can’t perform that action at this time.
0 commit comments