Version 21.54.6: Nov 09, 2021 Code refactoring in notifications.

This commit is contained in:
acanas 2021-11-09 10:26:27 +01:00
parent 387244eed4
commit bf6028913d
14 changed files with 112 additions and 127 deletions

View File

@ -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);
}
/*****************************************************************************/

View File

@ -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;

View File

@ -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);
}
/*****************************************************************************/

View File

@ -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)

View File

@ -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);

View File

@ -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 ();

View File

@ -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 *****/

View File

@ -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 ();

View File

@ -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);
}
/*****************************************************************************/

View File

@ -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);
}
/*****************************************************************************/

View File

@ -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);

View File

@ -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);
}
/*****************************************************************************/

View File

@ -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 ();

View File

@ -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);
}