diff --git a/swad_API.c b/swad_API.c index b981d3ac..6c2f28a9 100644 --- a/swad_API.c +++ b/swad_API.c @@ -753,7 +753,7 @@ int swad__createAccount (struct soap *soap, createAccountOut->wsKey[0] = '\0'; /***** Get plugin code *****/ - if ((ReturnCode = API_GetPlgCodFromAppKey (soap,(const char *) appKey)) != SOAP_OK) + if ((ReturnCode = API_GetPlgCodFromAppKey (soap,appKey)) != SOAP_OK) return ReturnCode; /***** Check parameters used to create the new account *****/ @@ -896,8 +896,7 @@ int swad__loginByUserPasswordKey (struct soap *soap, loginByUserPasswordKeyOut->userRole = 0; // unknown /***** Get plugin code *****/ - if ((ReturnCode = API_GetPlgCodFromAppKey (soap, - (const char *) appKey)) != SOAP_OK) + if ((ReturnCode = API_GetPlgCodFromAppKey (soap,appKey)) != SOAP_OK) return ReturnCode; /***** Check if user's email, @nickname or ID are valid *****/ @@ -1070,8 +1069,7 @@ int swad__loginBySessionKey (struct soap *soap, loginBySessionKeyOut->courseName[0] = '\0'; /***** Get plugin code *****/ - if ((ReturnCode = API_GetPlgCodFromAppKey (soap, - (const char *) appKey)) != SOAP_OK) + if ((ReturnCode = API_GetPlgCodFromAppKey (soap,appKey)) != SOAP_OK) return ReturnCode; /***** Check length of session identifier *****/ @@ -1254,8 +1252,7 @@ int swad__getNewPassword (struct soap *soap, getNewPasswordOut->success = 0; // error /***** Get plugin code *****/ - if ((ReturnCode = API_GetPlgCodFromAppKey (soap, - (const char *) appKey)) != SOAP_OK) + if ((ReturnCode = API_GetPlgCodFromAppKey (soap,appKey)) != SOAP_OK) return ReturnCode; /***** Check if user's email, @nickname or ID are valid *****/ @@ -3365,7 +3362,7 @@ int swad__getNotifications (struct soap *soap, getNotificationsOut->notificationsArray.__ptr[NumNotif].notifCode = (int) NtfCod; /* Get notification event type (row[1]) */ - NotifyEvent = Ntf_GetNotifyEventFromStr ((const char *) row[1]); + NotifyEvent = Ntf_GetNotifyEventFromStr (row[1]); getNotificationsOut->notificationsArray.__ptr[NumNotif].eventType = soap_malloc (soap,Ntf_MAX_BYTES_NOTIFY_EVENT + 1); Str_Copy (getNotificationsOut->notificationsArray.__ptr[NumNotif].eventType, diff --git a/swad_QR.c b/swad_QR.c index 2020a3bd..4e075019 100644 --- a/swad_QR.c +++ b/swad_QR.c @@ -87,7 +87,7 @@ void QR_PutLinkToPrintQRCode (Act_Action_t Action, void QR_PutParamQRString (void *QRString) { - Par_PutHiddenParamString (NULL,"QRString",(const char *) QRString); + Par_PutHiddenParamString (NULL,"QRString",QRString); } /*****************************************************************************/ diff --git a/swad_changelog.h b/swad_changelog.h index 970bf115..09f8b6d4 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -598,10 +598,11 @@ TODO: DNI de un estudiante sale err TODO: BUG: Cuando un tipo de grupo sólo tiene un grupo, inscribirse es voluntario, el estudiante sólo puede pertenecer a un grupo, y se inscribe en él, debería poder desapuntarse. Ahora no puede. TODO: Salvador Romero Cortés: @acanas opción para editar posts */ -#define Log_PLATFORM_VERSION "SWAD 20.39.5 (2021-03-02)" +#define Log_PLATFORM_VERSION "SWAD 20.39.6 (2021-03-02)" #define CSS_FILE "swad20.33.9.css" #define JS_FILE "swad20.6.2.js" /* + Version 20.39.6: Mar 02, 2021 Code refactoring in fav/share timeline notes. (305570 lines) Version 20.39.5: Mar 02, 2021 Code refactoring in timeline notes and posts. (305620 lines) Version 20.39.4: Mar 02, 2021 Code refactoring in timeline notes. (305614 lines) Version 20.39.3: Mar 02, 2021 Code refactoring in timeline favourites. (305601 lines) diff --git a/swad_notification.c b/swad_notification.c index 46b0b6fb..f8299e66 100644 --- a/swad_notification.c +++ b/swad_notification.c @@ -405,7 +405,7 @@ void Ntf_ShowMyNotifications (void) row = mysql_fetch_row (mysql_res); /* Get event type (row[0]) */ - NotifyEvent = Ntf_GetNotifyEventFromStr ((const char *) row[0]); + NotifyEvent = Ntf_GetNotifyEventFromStr (row[0]); /* Get (from) user code (row[1]) */ UsrDat.UsrCod = Str_ConvertStrCodToLongCod (row[1]); @@ -1653,7 +1653,7 @@ static void Ntf_SendPendingNotifByEMailToOneUsr (struct UsrData *ToUsrDat,unsign row = mysql_fetch_row (mysql_res); /* Get event type (row[0]) */ - NotifyEvent = Ntf_GetNotifyEventFromStr ((const char *) row[0]); + NotifyEvent = Ntf_GetNotifyEventFromStr (row[0]); /* Get origin user code (row[1]) */ FromUsrDat.UsrCod = Str_ConvertStrCodToLongCod (row[1]); diff --git a/swad_timeline.c b/swad_timeline.c index 1237d8f4..03cec306 100644 --- a/swad_timeline.c +++ b/swad_timeline.c @@ -443,7 +443,7 @@ static void TL_ShowTimeline (struct TL_Timeline *Timeline, if (GlobalTimeline) { /* Link to view new publications via AJAX */ - TL_Pub_PutLinkToViewNewPublications (); + TL_Pub_PutLinkToViewNewPubs (); /* Hidden list where insert just received (not visible) publications via AJAX */ @@ -486,7 +486,7 @@ static void TL_ShowTimeline (struct TL_Timeline *Timeline, if (NumPubs == TL_Pub_MAX_REC_PUBS_TO_GET_AND_SHOW) { /* Link to view old publications via AJAX */ - TL_Pub_PutLinkToViewOldPublications (); + TL_Pub_PutLinkToViewOldPubs (); /* Hidden list where insert old publications via AJAX */ HTM_UL_Begin ("id=\"old_timeline_list\" class=\"TL_LIST\""); diff --git a/swad_timeline_favourite.c b/swad_timeline_favourite.c index a3979605..491fddef 100644 --- a/swad_timeline_favourite.c +++ b/swad_timeline_favourite.c @@ -143,37 +143,14 @@ void TL_Fav_UnfNoteGbl (void) static void TL_Fav_FavNote (struct TL_Not_Note *Not) { - extern const char *Txt_The_original_post_no_longer_exists; long OriginalPubCod; - /***** Get data of note *****/ - Not->NotCod = TL_Not_GetParamNotCod (); - TL_Not_GetDataOfNoteByCod (Not); - - /***** Trivial check 1: note code should be > 0 *****/ - if (Not->NotCod <= 0) - { - Ale_ShowAlert (Ale_WARNING,Txt_The_original_post_no_longer_exists); + /***** Get data of note and do some checks *****/ + if (!TL_Not_CheckICanFavShaNote (Not)) return; - } - /***** Trivial check 2: I must be logged *****/ - if (!Gbl.Usrs.Me.Logged) - { - Ale_ShowAlert (Ale_ERROR,"You are not logged."); - return; - } - - /***** Trivial check 3: The author can not fav his/her own notes *****/ - if (Usr_ItsMe (Not->UsrCod)) - { - Ale_ShowAlert (Ale_ERROR,"You can not fav/unfav your own posts."); - return; - } - - /***** Trivial check 4: Have I faved this note? *****/ - if (TL_DB_CheckIfFavedByUsr (TL_Fav_NOTE,Not->NotCod, - Gbl.Usrs.Me.UsrDat.UsrCod)) + /***** Trivial check: Have I faved this note? *****/ + if (TL_DB_CheckIfFavedByUsr (TL_Fav_NOTE,Not->NotCod,Gbl.Usrs.Me.UsrDat.UsrCod)) // Don't show error message return; @@ -194,37 +171,14 @@ static void TL_Fav_FavNote (struct TL_Not_Note *Not) static void TL_Fav_UnfNote (struct TL_Not_Note *Not) { - extern const char *Txt_The_original_post_no_longer_exists; long OriginalPubCod; - /***** Get data of note *****/ - Not->NotCod = TL_Not_GetParamNotCod (); - TL_Not_GetDataOfNoteByCod (Not); - - /***** Trivial check 1: note code should be > 0 *****/ - if (Not->NotCod <= 0) - { - Ale_ShowAlert (Ale_WARNING,Txt_The_original_post_no_longer_exists); + /***** Get data of note and do some checks *****/ + if (!TL_Not_CheckICanFavShaNote (Not)) return; - } - /***** Trivial check 2: I must be logged *****/ - if (!Gbl.Usrs.Me.Logged) - { - Ale_ShowAlert (Ale_ERROR,"You are not logged."); - return; - } - - /***** Trivial check 3: The author can not unfav his/her own notes *****/ - if (Usr_ItsMe (Not->UsrCod)) - { - Ale_ShowAlert (Ale_ERROR,"You can not fav/unfav your own posts."); - return; - } - - /***** Trivial check 4: Have I faved this note? *****/ - if (!TL_DB_CheckIfFavedByUsr (TL_Fav_NOTE,Not->NotCod, - Gbl.Usrs.Me.UsrDat.UsrCod)) + /***** Trivial check: Have I faved this note? *****/ + if (!TL_DB_CheckIfFavedByUsr (TL_Fav_NOTE,Not->NotCod,Gbl.Usrs.Me.UsrDat.UsrCod)) // Don't show error message return; diff --git a/swad_timeline_note.c b/swad_timeline_note.c index e60ba951..0cae1d83 100644 --- a/swad_timeline_note.c +++ b/swad_timeline_note.c @@ -1337,7 +1337,7 @@ static void TL_Not_GetDataOfNoteFromRow (MYSQL_ROW row,struct TL_Not_Note *Not) Not->NotCod = Str_ConvertStrCodToLongCod (row[0]); /***** Get note type (row[1]) *****/ - Not->NoteType = TL_Not_GetNoteTypeFromStr ((const char *) row[1]); + Not->NoteType = TL_Not_GetNoteTypeFromStr (row[1]); /***** Get file/post... code (row[2]) *****/ Not->Cod = Str_ConvertStrCodToLongCod (row[2]); @@ -1424,3 +1424,39 @@ void TL_Not_GetDataOfNoteByCod (struct TL_Not_Note *Not) /***** Free structure that stores the query result *****/ DB_FreeMySQLResult (&mysql_res); } + +/*****************************************************************************/ +/******************** Check if I can fav/share a note ************************/ +/*****************************************************************************/ + +bool TL_Not_CheckICanFavShaNote (struct TL_Not_Note *Not) + { + extern const char *Txt_The_original_post_no_longer_exists; + + /***** Get data of note *****/ + Not->NotCod = TL_Not_GetParamNotCod (); + TL_Not_GetDataOfNoteByCod (Not); + + /***** Trivial check 1: note code should be > 0 *****/ + if (Not->NotCod <= 0) + { + Ale_ShowAlert (Ale_WARNING,Txt_The_original_post_no_longer_exists); + return false; + } + + /***** Trivial check 2: I must be logged *****/ + if (!Gbl.Usrs.Me.Logged) + { + Ale_ShowAlert (Ale_ERROR,"You are not logged."); + return false; + } + + /***** Trivial check 3: The author can not unfav his/her own notes *****/ + if (Usr_ItsMe (Not->UsrCod)) + { + Ale_ShowAlert (Ale_ERROR,"You can not fav/share your own posts."); + return false; + } + + return true; + } diff --git a/swad_timeline_note.h b/swad_timeline_note.h index 2a6ee453..d1232310 100644 --- a/swad_timeline_note.h +++ b/swad_timeline_note.h @@ -113,4 +113,6 @@ void TL_Not_RemoveNoteGbl (void); void TL_Not_GetDataOfNoteByCod (struct TL_Not_Note *Not); +bool TL_Not_CheckICanFavShaNote (struct TL_Not_Note *Not); + #endif diff --git a/swad_timeline_notification.c b/swad_timeline_notification.c index 56dbd9ed..1dee9391 100644 --- a/swad_timeline_notification.c +++ b/swad_timeline_notification.c @@ -121,7 +121,7 @@ void TL_Ntf_GetNotifPublication (char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1], /***** Get summary and content from post from database *****/ if (TL_DB_GetDataOfPubByCod (PubCod,&mysql_res) == 1) // Result should have a unique row /* Get data of publication from row */ - TL_Pub_GetDataOfPublicationFromNextRow (mysql_res,&Pub); + TL_Pub_GetDataOfPubFromNextRow (mysql_res,&Pub); /***** Free structure that stores the query result *****/ DB_FreeMySQLResult (&mysql_res); diff --git a/swad_timeline_publication.c b/swad_timeline_publication.c index 63bbe597..cbbca7f1 100644 --- a/swad_timeline_publication.c +++ b/swad_timeline_publication.c @@ -313,7 +313,7 @@ static struct TL_Pub_Publication *TL_Pub_SelectTheMostRecentPub (const struct TL Lay_NotEnoughMemoryExit (); /* Get data of publication */ - TL_Pub_GetDataOfPublicationFromNextRow (mysql_res,Pub); + TL_Pub_GetDataOfPubFromNextRow (mysql_res,Pub); Pub->Next = NULL; } else @@ -402,7 +402,7 @@ TL_TopMessage_t TL_Pub_GetTopMessage (TL_Pub_PubType_t PubType) /***************** Put link to view new publications in timeline *************/ /*****************************************************************************/ -void TL_Pub_PutLinkToViewNewPublications (void) +void TL_Pub_PutLinkToViewNewPubs (void) { extern const char *The_ClassFormInBoxBold[The_NUM_THEMES]; extern const char *Txt_See_new_activity; @@ -437,7 +437,7 @@ void TL_Pub_PutLinkToViewNewPublications (void) /***************** Put link to view old publications in timeline *************/ /*****************************************************************************/ -void TL_Pub_PutLinkToViewOldPublications (void) +void TL_Pub_PutLinkToViewOldPubs (void) { extern const char *The_ClassFormInBoxBold[The_NUM_THEMES]; extern const char *Txt_See_more; @@ -494,8 +494,8 @@ long TL_Pub_GetParamPubCod (void) /***************** Get data of publication using its code ********************/ /*****************************************************************************/ -void TL_Pub_GetDataOfPublicationFromNextRow (MYSQL_RES *mysql_res, - struct TL_Pub_Publication *Pub) +void TL_Pub_GetDataOfPubFromNextRow (MYSQL_RES *mysql_res, + struct TL_Pub_Publication *Pub) { MYSQL_ROW row; @@ -518,7 +518,7 @@ void TL_Pub_GetDataOfPublicationFromNextRow (MYSQL_RES *mysql_res, Pub->PublisherCod = Str_ConvertStrCodToLongCod (row[2]); /***** Get type of publication (row[3]) *****/ - Pub->PubType = TL_Pub_GetPubTypeFromStr ((const char *) row[3]); + Pub->PubType = TL_Pub_GetPubTypeFromStr (row[3]); } /*****************************************************************************/ diff --git a/swad_timeline_publication.h b/swad_timeline_publication.h index c4d27acc..08ebc987 100644 --- a/swad_timeline_publication.h +++ b/swad_timeline_publication.h @@ -93,14 +93,14 @@ void TL_Pub_ShowOldPubsInTimeline (struct TL_Timeline *Timeline); TL_TopMessage_t TL_Pub_GetTopMessage (TL_Pub_PubType_t PubType); -void TL_Pub_PutLinkToViewNewPublications (void); -void TL_Pub_PutLinkToViewOldPublications (void); +void TL_Pub_PutLinkToViewNewPubs (void); +void TL_Pub_PutLinkToViewOldPubs (void); void TL_Pub_PutHiddenParamPubCod (long PubCod); long TL_Pub_GetParamPubCod (void); -void TL_Pub_GetDataOfPublicationFromNextRow (MYSQL_RES *mysql_res, - struct TL_Pub_Publication *Pub); +void TL_Pub_GetDataOfPubFromNextRow (MYSQL_RES *mysql_res, + struct TL_Pub_Publication *Pub); void TL_Pub_PublishPubInTimeline (struct TL_Pub_Publication *Pub); diff --git a/swad_timeline_share.c b/swad_timeline_share.c index f4cbd905..858aeabc 100644 --- a/swad_timeline_share.c +++ b/swad_timeline_share.c @@ -115,36 +115,14 @@ void TL_Sha_ShaNoteGbl (void) static void TL_Sha_ShaNote (struct TL_Not_Note *Not) { - extern const char *Txt_The_original_post_no_longer_exists; struct TL_Pub_Publication Pub; long OriginalPubCod; - /***** Get data of note *****/ - Not->NotCod = TL_Not_GetParamNotCod (); - TL_Not_GetDataOfNoteByCod (Not); - - /***** Trivial check 1: note code should be > 0 *****/ - if (Not->NotCod <= 0) - { - Ale_ShowAlert (Ale_WARNING,Txt_The_original_post_no_longer_exists); + /***** Get data of note and do some checks *****/ + if (!TL_Not_CheckICanFavShaNote (Not)) return; - } - /***** Trivial check 2: Am I logged? *****/ - if (!Gbl.Usrs.Me.Logged) - { - Ale_ShowAlert (Ale_ERROR,"You are not logged."); - return; - } - - /***** Trivial check 3: Am I the author? *****/ - if (Usr_ItsMe (Not->UsrCod)) - { - Ale_ShowAlert (Ale_ERROR,"You can not share/unshare your own posts."); - return; - } - - /***** Trivial check 4: Is note already shared by me? *****/ + /***** Trivial check: Is note already shared by me? *****/ if (TL_DB_CheckIfNoteIsSharedByUsr (Not->NotCod,Gbl.Usrs.Me.UsrDat.UsrCod)) // Don't show error message return; @@ -192,35 +170,13 @@ void TL_Sha_UnsNoteGbl (void) static void TL_Sha_UnsNote (struct TL_Not_Note *Not) { - extern const char *Txt_The_original_post_no_longer_exists; long OriginalPubCod; - /***** Get data of note *****/ - Not->NotCod = TL_Not_GetParamNotCod (); - TL_Not_GetDataOfNoteByCod (Not); - - /***** Trivial check 1: note code should be > 0 *****/ - if (Not->NotCod <= 0) - { - Ale_ShowAlert (Ale_WARNING,Txt_The_original_post_no_longer_exists); + /***** Get data of note and do some checks *****/ + if (!TL_Not_CheckICanFavShaNote (Not)) return; - } - /***** Trivial check 2: Am I logged? *****/ - if (!Gbl.Usrs.Me.Logged) - { - Ale_ShowAlert (Ale_ERROR,"You are not logged."); - return; - } - - /***** Trivial check 3: Am I the author? *****/ - if (Usr_ItsMe (Not->UsrCod)) - { - Ale_ShowAlert (Ale_ERROR,"You can not share/unshare your own posts."); - return; - } - - /***** Trivial check 4: Is note already shared by me? *****/ + /***** Trivial check: Is note already shared by me? *****/ if (!TL_DB_CheckIfNoteIsSharedByUsr (Not->NotCod,Gbl.Usrs.Me.UsrDat.UsrCod)) // Don't show error message return;