diff --git a/swad_assignment.c b/swad_assignment.c index 19fb5d04..a94e28f1 100644 --- a/swad_assignment.c +++ b/swad_assignment.c @@ -522,9 +522,7 @@ static void Asg_ShowOneAssignment (struct Asg_Assignments *Assignments, Gbl.RowEvenOdd = 1 - Gbl.RowEvenOdd; /***** Mark possible notification as seen *****/ - Ntf_DB_MarkNotifAsSeen (Ntf_EVENT_ASSIGNMENT, - AsgCod,Gbl.Hierarchy.Crs.CrsCod, - Gbl.Usrs.Me.UsrDat.UsrCod); + Ntf_DB_MarkNotifAsSeenByMe (Ntf_EVENT_ASSIGNMENT,AsgCod); } /*****************************************************************************/ diff --git a/swad_browser.c b/swad_browser.c index bff6a70e..fc0021ef 100644 --- a/swad_browser.c +++ b/swad_browser.c @@ -8163,29 +8163,25 @@ void Brw_ShowFileMetadata (void) case Brw_SHOW_DOC_GRP: case Brw_ADMI_DOC_CRS: case Brw_ADMI_DOC_GRP: - Ntf_DB_MarkNotifAsSeen (Ntf_EVENT_DOCUMENT_FILE, - FileMetadata.FilCod,Gbl.Hierarchy.Crs.CrsCod, - Gbl.Usrs.Me.UsrDat.UsrCod); + Ntf_DB_MarkNotifAsSeenByMe (Ntf_EVENT_DOCUMENT_FILE, + FileMetadata.FilCod); break; case Brw_ADMI_TCH_CRS: case Brw_ADMI_TCH_GRP: - Ntf_DB_MarkNotifAsSeen (Ntf_EVENT_TEACHERS_FILE, - FileMetadata.FilCod,Gbl.Hierarchy.Crs.CrsCod, - Gbl.Usrs.Me.UsrDat.UsrCod); + Ntf_DB_MarkNotifAsSeenByMe (Ntf_EVENT_TEACHERS_FILE, + FileMetadata.FilCod); break; case Brw_ADMI_SHR_CRS: case Brw_ADMI_SHR_GRP: - Ntf_DB_MarkNotifAsSeen (Ntf_EVENT_SHARED_FILE, - FileMetadata.FilCod,Gbl.Hierarchy.Crs.CrsCod, - Gbl.Usrs.Me.UsrDat.UsrCod); + Ntf_DB_MarkNotifAsSeenByMe (Ntf_EVENT_SHARED_FILE, + FileMetadata.FilCod); break; case Brw_SHOW_MRK_CRS: case Brw_SHOW_MRK_GRP: case Brw_ADMI_MRK_CRS: case Brw_ADMI_MRK_GRP: - Ntf_DB_MarkNotifAsSeen (Ntf_EVENT_MARKS_FILE, - FileMetadata.FilCod,Gbl.Hierarchy.Crs.CrsCod, - Gbl.Usrs.Me.UsrDat.UsrCod); + Ntf_DB_MarkNotifAsSeenByMe (Ntf_EVENT_MARKS_FILE, + FileMetadata.FilCod); break; default: break; @@ -8313,29 +8309,25 @@ void Brw_DownloadFile (void) case Brw_SHOW_DOC_GRP: case Brw_ADMI_DOC_CRS: case Brw_ADMI_DOC_GRP: - Ntf_DB_MarkNotifAsSeen (Ntf_EVENT_DOCUMENT_FILE, - FileMetadata.FilCod,Gbl.Hierarchy.Crs.CrsCod, - Gbl.Usrs.Me.UsrDat.UsrCod); + Ntf_DB_MarkNotifAsSeenByMe (Ntf_EVENT_DOCUMENT_FILE, + FileMetadata.FilCod); break; case Brw_ADMI_TCH_CRS: case Brw_ADMI_TCH_GRP: - Ntf_DB_MarkNotifAsSeen (Ntf_EVENT_TEACHERS_FILE, - FileMetadata.FilCod,Gbl.Hierarchy.Crs.CrsCod, - Gbl.Usrs.Me.UsrDat.UsrCod); + Ntf_DB_MarkNotifAsSeenByMe (Ntf_EVENT_TEACHERS_FILE, + FileMetadata.FilCod); break; case Brw_ADMI_SHR_CRS: case Brw_ADMI_SHR_GRP: - Ntf_DB_MarkNotifAsSeen (Ntf_EVENT_SHARED_FILE, - FileMetadata.FilCod,Gbl.Hierarchy.Crs.CrsCod, - Gbl.Usrs.Me.UsrDat.UsrCod); + Ntf_DB_MarkNotifAsSeenByMe (Ntf_EVENT_SHARED_FILE, + FileMetadata.FilCod); break; case Brw_SHOW_MRK_CRS: case Brw_SHOW_MRK_GRP: case Brw_ADMI_MRK_CRS: case Brw_ADMI_MRK_GRP: - Ntf_DB_MarkNotifAsSeen (Ntf_EVENT_MARKS_FILE, - FileMetadata.FilCod,Gbl.Hierarchy.Crs.CrsCod, - Gbl.Usrs.Me.UsrDat.UsrCod); + Ntf_DB_MarkNotifAsSeenByMe (Ntf_EVENT_MARKS_FILE, + FileMetadata.FilCod); break; default: break; diff --git a/swad_call_for_exam.c b/swad_call_for_exam.c index 7c6f2e1d..f788b4f7 100644 --- a/swad_call_for_exam.c +++ b/swad_call_for_exam.c @@ -551,9 +551,7 @@ void Cfe_ListCallsForExamsSee (void) Cfe_ListCallsForExams (&CallsForExams,Cfe_NORMAL_VIEW); /***** Mark possible notifications as seen *****/ - Ntf_DB_MarkNotifAsSeen (Ntf_EVENT_CALL_FOR_EXAM, - -1L,Gbl.Hierarchy.Crs.CrsCod, - Gbl.Usrs.Me.UsrDat.UsrCod); + Ntf_DB_MarkNotifsInCrsAsSeenByMe (Ntf_EVENT_CALL_FOR_EXAM); } /*****************************************************************************/ diff --git a/swad_changelog.h b/swad_changelog.h index 0bfbf2a1..0622a0e8 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -602,13 +602,14 @@ TODO: FIX BUG, URGENT! En las fechas como par TODO: En las encuestas, que los estudiantes no puedan ver los resultados hasta que no finalice el plazo. */ -#define Log_PLATFORM_VERSION "SWAD 21.54.5 (2021-11-09)" +#define Log_PLATFORM_VERSION "SWAD 21.54.6 (2021-11-09)" #define CSS_FILE "swad20.45.css" #define JS_FILE "swad20.69.1.js" /* TODO: Rename CENTRE to CENTER in help wiki. TODO: Rename ASSESSMENT.Announcements to ASSESSMENT.Calls_for_exams + Version 21.54.6: Nov 09, 2021 Code refactoring in notifications. (322164 lines) Version 21.54.5: Nov 09, 2021 Queries moved from API module to database modules. (322185 lines) Version 21.54.4: Nov 09, 2021 Queries moved from API module to database modules. (322222 lines) Version 21.54.3: Nov 08, 2021 Queries moved from API module to database modules. (322095 lines) diff --git a/swad_enrolment.c b/swad_enrolment.c index e565b528..e8ddbe8b 100644 --- a/swad_enrolment.c +++ b/swad_enrolment.c @@ -457,8 +457,7 @@ void Enr_ReqAcceptRegisterInCrs (void) Err_WrongRoleExit (); break; } - Ntf_DB_MarkNotifAsSeen (NotifyEvent,-1L,Gbl.Hierarchy.Crs.CrsCod, - Gbl.Usrs.Me.UsrDat.UsrCod); + Ntf_DB_MarkNotifsInCrsAsSeenByMe (NotifyEvent); } /*****************************************************************************/ @@ -2342,9 +2341,7 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected) HTM_TR_End (); /***** Mark possible notification as seen *****/ - Ntf_DB_MarkNotifAsSeen (Ntf_EVENT_ENROLMENT_REQUEST, - ReqCod,Gbl.Hierarchy.Crs.CrsCod, - Gbl.Usrs.Me.UsrDat.UsrCod); + Ntf_DB_MarkNotifAsSeenByMe (Ntf_EVENT_ENROLMENT_REQUEST,ReqCod); } else // User does not exists or user already belongs to course ==> remove pair from crs_requests table Enr_RemUsrEnrolmentRequestInCrs (UsrDat.UsrCod,Crs.CrsCod); diff --git a/swad_follow.c b/swad_follow.c index 3f06facd..1c0260e5 100644 --- a/swad_follow.c +++ b/swad_follow.c @@ -564,15 +564,12 @@ static void Fol_ListFollowersUsr (struct UsrData *UsrDat) unsigned NumUsrs; unsigned NumUsr; struct UsrData FollowerUsrDat; - bool ItsMe; /***** Show user's profile *****/ if (Prf_ShowUserProfile (UsrDat)) { /***** Get list of followers *****/ - NumUsrs = Fol_DB_GetListFollowers (UsrDat->UsrCod,&mysql_res); - - if (NumUsrs) + if ((NumUsrs = Fol_DB_GetListFollowers (UsrDat->UsrCod,&mysql_res))) { /***** Initialize structure with user's data *****/ Usr_UsrDataConstructor (&FollowerUsrDat); @@ -582,24 +579,26 @@ static void Fol_ListFollowersUsr (struct UsrData *UsrDat) NULL,NULL, NULL,Box_NOT_CLOSABLE,2); - for (NumUsr = 0; - NumUsr < NumUsrs; - NumUsr++) - { - /***** Get user's code *****/ - FollowerUsrDat.UsrCod = DB_GetNextCode (mysql_res); + for (NumUsr = 0; + NumUsr < NumUsrs; + NumUsr++) + { + /***** Get user's code *****/ + FollowerUsrDat.UsrCod = DB_GetNextCode (mysql_res); - /***** Show user *****/ - if ((NumUsr % Fol_NUM_COLUMNS_FOLLOW) == 0) - HTM_TR_Begin (NULL); - if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&FollowerUsrDat, - Usr_DONT_GET_PREFS, - Usr_DONT_GET_ROLE_IN_CURRENT_CRS)) - Fol_ShowFollowedOrFollower (&FollowerUsrDat); - if ((NumUsr % Fol_NUM_COLUMNS_FOLLOW) == (Fol_NUM_COLUMNS_FOLLOW-1) || - NumUsr == NumUsrs - 1) - HTM_TR_End (); - } + /***** Show user *****/ + if ((NumUsr % Fol_NUM_COLUMNS_FOLLOW) == 0) + HTM_TR_Begin (NULL); + + if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&FollowerUsrDat, + Usr_DONT_GET_PREFS, + Usr_DONT_GET_ROLE_IN_CURRENT_CRS)) + Fol_ShowFollowedOrFollower (&FollowerUsrDat); + + if ((NumUsr % Fol_NUM_COLUMNS_FOLLOW) == (Fol_NUM_COLUMNS_FOLLOW-1) || + NumUsr == NumUsrs - 1) + HTM_TR_End (); + } /***** End table and box *****/ Box_BoxTableEnd (); @@ -612,11 +611,8 @@ static void Fol_ListFollowersUsr (struct UsrData *UsrDat) DB_FreeMySQLResult (&mysql_res); /***** If it's me, mark possible notification as seen *****/ - ItsMe = Usr_ItsMe (UsrDat->UsrCod); - if (ItsMe) - Ntf_DB_MarkNotifAsSeen (Ntf_EVENT_FOLLOWER, - -1L,-1L, - Gbl.Usrs.Me.UsrDat.UsrCod); + if (Usr_ItsMe (UsrDat->UsrCod)) + Ntf_DB_MarkNotifsAsSeen (Ntf_EVENT_FOLLOWER); } else Ale_ShowAlertUserNotFoundOrYouDoNotHavePermission (); diff --git a/swad_forum.c b/swad_forum.c index 4cc16a39..ae446a24 100644 --- a/swad_forum.c +++ b/swad_forum.c @@ -781,17 +781,15 @@ static void For_ShowPostsOfAThread (struct For_Forums *Forums, { case For_FORUM_COURSE_TCHS: case For_FORUM_COURSE_USRS: - Ntf_DB_MarkNotifAsSeen (Ntf_EVENT_FORUM_POST_COURSE, - Forums->PstCod,Gbl.Hierarchy.Crs.CrsCod, - Gbl.Usrs.Me.UsrDat.UsrCod); + Ntf_DB_MarkNotifAsSeenByMe (Ntf_EVENT_FORUM_POST_COURSE, + Forums->PstCod); break; default: break; } if (Thread.NumMyPosts) - Ntf_DB_MarkNotifAsSeen (Ntf_EVENT_FORUM_REPLY, - Forums->PstCod,-1L, - Gbl.Usrs.Me.UsrDat.UsrCod); + Ntf_DB_MarkNotifAsSeenByMe (Ntf_EVENT_FORUM_REPLY, + Forums->PstCod); } /***** End table *****/ diff --git a/swad_message.c b/swad_message.c index c3818e0d..54acc461 100644 --- a/swad_message.c +++ b/swad_message.c @@ -1211,9 +1211,7 @@ void Msg_ExpRecMsg (void) Msg_DB_ExpandRcvMsg (Messages.ExpandedMsgCod); /***** Mark possible notification as seen *****/ - Ntf_DB_MarkNotifAsSeen (Ntf_EVENT_MESSAGE, - Messages.ExpandedMsgCod,-1L, - Gbl.Usrs.Me.UsrDat.UsrCod); + Ntf_DB_MarkNotifAsSeenByMe (Ntf_EVENT_MESSAGE,Messages.ExpandedMsgCod); /***** Show again the messages *****/ Msg_ShowRecMsgs (); diff --git a/swad_notice.c b/swad_notice.c index 5f86b04a..becd7c91 100644 --- a/swad_notice.c +++ b/swad_notice.c @@ -431,9 +431,7 @@ void Not_ShowNotices (Not_Listing_t TypeNoticesListing,long HighlightNotCod) DB_FreeMySQLResult (&mysql_res); /***** Mark possible notification as seen *****/ - Ntf_DB_MarkNotifAsSeen (Ntf_EVENT_NOTICE, - -1L,Gbl.Hierarchy.Crs.CrsCod, - Gbl.Usrs.Me.UsrDat.UsrCod); + Ntf_DB_MarkNotifsInCrsAsSeenByMe (Ntf_EVENT_NOTICE); } /*****************************************************************************/ diff --git a/swad_notification_database.c b/swad_notification_database.c index 6791c409..9e1d894e 100644 --- a/swad_notification_database.c +++ b/swad_notification_database.c @@ -122,49 +122,60 @@ void Ntf_DB_MarkPendingNtfsAsSent (long ToUsrCod) } /*****************************************************************************/ -/********************** Set possible notification as seen ********************/ +/**************** Set one possible notification as seen by me ****************/ /*****************************************************************************/ -void Ntf_DB_MarkNotifAsSeen (Ntf_NotifyEvent_t NotifyEvent,long Cod,long CrsCod,long ToUsrCod) +void Ntf_DB_MarkNotifAsSeenByMe (Ntf_NotifyEvent_t NotifyEvent,long Cod) { + /***** Trivial check: if no code specified, nothing to do *****/ + if (Cod <= 0) // If the user code is specified + return; + /***** Set notification as seen by me *****/ - if (ToUsrCod > 0) // If the user code is specified - { - if (Cod > 0) // Set only one notification - // for the user as seen - DB_QueryUPDATE ("can not set notification(s) as seen", - "UPDATE ntf_notifications" - " SET Status=(Status | %u)" - " WHERE ToUsrCod=%ld" - " AND NotifyEvent=%u" - " AND Cod=%ld", - (unsigned) Ntf_STATUS_BIT_READ, - ToUsrCod, - (unsigned) NotifyEvent, - Cod); - else if (CrsCod > 0) // Set all notifications of this type - // in the current course for the user as seen - DB_QueryUPDATE ("can not set notification(s) as seen", - "UPDATE ntf_notifications" - " SET Status=(Status | %u)" - " WHERE ToUsrCod=%ld" - " AND NotifyEvent=%u" - " AND CrsCod=%ld", - (unsigned) Ntf_STATUS_BIT_READ, - ToUsrCod, - (unsigned) NotifyEvent, - Gbl.Hierarchy.Crs.CrsCod); - else // Set all notifications of this type - // for the user as seen - DB_QueryUPDATE ("can not set notification(s) as seen", - "UPDATE ntf_notifications" - " SET Status=(Status | %u)" - " WHERE ToUsrCod=%ld" - " AND NotifyEvent=%u", - (unsigned) Ntf_STATUS_BIT_READ, - ToUsrCod, - (unsigned) NotifyEvent); - } + DB_QueryUPDATE ("can not set notification(s) as seen", + "UPDATE ntf_notifications" + " SET Status=(Status | %u)" + " WHERE ToUsrCod=%ld" + " AND NotifyEvent=%u" + " AND Cod=%ld", + (unsigned) Ntf_STATUS_BIT_READ, + Gbl.Usrs.Me.UsrDat.UsrCod, + (unsigned) NotifyEvent, + Cod); + } + +/*****************************************************************************/ +/** Set all notifications of this type in the current course as seen by me ***/ +/*****************************************************************************/ + +void Ntf_DB_MarkNotifsInCrsAsSeenByMe (Ntf_NotifyEvent_t NotifyEvent) + { + DB_QueryUPDATE ("can not set notification(s) as seen", + "UPDATE ntf_notifications" + " SET Status=(Status | %u)" + " WHERE ToUsrCod=%ld" + " AND NotifyEvent=%u" + " AND CrsCod=%ld", + (unsigned) Ntf_STATUS_BIT_READ, + Gbl.Usrs.Me.UsrDat.UsrCod, + (unsigned) NotifyEvent, + Gbl.Hierarchy.Crs.CrsCod); + } + +/*****************************************************************************/ +/************* Set all notifications of this type as seen by me **************/ +/*****************************************************************************/ + +void Ntf_DB_MarkNotifsAsSeen (Ntf_NotifyEvent_t NotifyEvent) + { + DB_QueryUPDATE ("can not set notification(s) as seen", + "UPDATE ntf_notifications" + " SET Status=(Status | %u)" + " WHERE ToUsrCod=%ld" + " AND NotifyEvent=%u", + (unsigned) Ntf_STATUS_BIT_READ, + Gbl.Usrs.Me.UsrDat.UsrCod, + (unsigned) NotifyEvent); } /*****************************************************************************/ diff --git a/swad_notification_database.h b/swad_notification_database.h index 0431598b..826be77c 100644 --- a/swad_notification_database.h +++ b/swad_notification_database.h @@ -48,7 +48,9 @@ void Ntf_DB_StoreNotifyEventToUsr (Ntf_NotifyEvent_t NotifyEvent, void Ntf_DB_UpdateMyLastAccessToNotifications (void); void Ntf_DB_MarkAllMyNotifAsSeen (void); void Ntf_DB_MarkPendingNtfsAsSent (long ToUsrCod); -void Ntf_DB_MarkNotifAsSeen (Ntf_NotifyEvent_t NotifyEvent,long Cod,long CrsCod,long ToUsrCod); +void Ntf_DB_MarkNotifAsSeenByMe (Ntf_NotifyEvent_t NotifyEvent,long Cod); +void Ntf_DB_MarkNotifsInCrsAsSeenByMe (Ntf_NotifyEvent_t NotifyEvent); +void Ntf_DB_MarkNotifsAsSeen (Ntf_NotifyEvent_t NotifyEvent); void Ntf_DB_MarkNotifToOneUsrAsRemoved (Ntf_NotifyEvent_t NotifyEvent,long Cod,long ToUsrCod); void Ntf_DB_MarkNotifInCrsAsRemoved (long ToUsrCod,long CrsCod); void Ntf_DB_MarkNotifAsRemoved (Ntf_NotifyEvent_t NotifyEvent,long Cod); diff --git a/swad_profile.c b/swad_profile.c index ba58c7e7..2459baa6 100644 --- a/swad_profile.c +++ b/swad_profile.c @@ -280,9 +280,7 @@ void Prf_GetUsrDatAndShowUserProfile (void) /***** If it's not me, mark possible notification as seen *****/ if (!Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod)) // Not me - Ntf_DB_MarkNotifAsSeen (Ntf_EVENT_FOLLOWER, - Gbl.Usrs.Other.UsrDat.UsrCod,-1L, - Gbl.Usrs.Me.UsrDat.UsrCod); + Ntf_DB_MarkNotifAsSeenByMe (Ntf_EVENT_FOLLOWER,Gbl.Usrs.Other.UsrDat.UsrCod); } /*****************************************************************************/ diff --git a/swad_survey.c b/swad_survey.c index ae7b6899..d66e3078 100644 --- a/swad_survey.c +++ b/swad_survey.c @@ -682,7 +682,7 @@ static void Svy_ShowOneSurvey (struct Svy_Surveys *Surveys, Str_InsertLinks (Txt,Cns_MAX_BYTES_TEXT,60); // Insert links HTM_DIV_Begin ("class=\"PAR %s\"",Svy.Status.Visible ? "DAT" : "DAT_LIGHT"); - HTM_Txt (Txt); + HTM_Txt (Txt); HTM_DIV_End (); HTM_TD_End (); @@ -702,14 +702,12 @@ static void Svy_ShowOneSurvey (struct Svy_Surveys *Surveys, /***** Mark possible notification as seen *****/ if (Svy.Scope == HieLvl_CRS) // Only course surveys are notified - Ntf_DB_MarkNotifAsSeen (Ntf_EVENT_SURVEY, - SvyCod,Svy.Cod, - Gbl.Usrs.Me.UsrDat.UsrCod); + Ntf_DB_MarkNotifAsSeenByMe (Ntf_EVENT_SURVEY,Svy.Cod); if (ShowOnlyThisSvyComplete) { - /***** End table *****/ - HTM_TABLE_End (); + /***** End table *****/ + HTM_TABLE_End (); /***** End box *****/ Box_BoxEnd (); diff --git a/swad_timeline_notification.c b/swad_timeline_notification.c index 75c3952b..7056f38f 100644 --- a/swad_timeline_notification.c +++ b/swad_timeline_notification.c @@ -217,8 +217,8 @@ void Tml_Ntf_GetNotifPublication (char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1], void Tml_Ntf_MarkMyNotifAsSeen (void) { - Ntf_DB_MarkNotifAsSeen (Ntf_EVENT_TL_COMMENT,-1L,-1L,Gbl.Usrs.Me.UsrDat.UsrCod); - Ntf_DB_MarkNotifAsSeen (Ntf_EVENT_TL_FAV ,-1L,-1L,Gbl.Usrs.Me.UsrDat.UsrCod); - Ntf_DB_MarkNotifAsSeen (Ntf_EVENT_TL_SHARE ,-1L,-1L,Gbl.Usrs.Me.UsrDat.UsrCod); - Ntf_DB_MarkNotifAsSeen (Ntf_EVENT_TL_MENTION,-1L,-1L,Gbl.Usrs.Me.UsrDat.UsrCod); + Ntf_DB_MarkNotifsAsSeen (Ntf_EVENT_TL_COMMENT); + Ntf_DB_MarkNotifsAsSeen (Ntf_EVENT_TL_FAV ); + Ntf_DB_MarkNotifsAsSeen (Ntf_EVENT_TL_SHARE ); + Ntf_DB_MarkNotifsAsSeen (Ntf_EVENT_TL_MENTION); }