From f296981e431c7605c64a825fae5476b88d6dfaf9 Mon Sep 17 00:00:00 2001 From: acanas Date: Fri, 30 Apr 2021 00:12:54 +0200 Subject: [PATCH] Version 20.68.8: Apr 30, 2021 Code refactoring in timeline. --- swad_changelog.h | 3 ++- swad_timeline_note.c | 25 +++++++++++++------------ swad_timeline_notification.c | 2 +- swad_timeline_post.c | 2 +- swad_timeline_publication.c | 24 +++++++++++------------- swad_timeline_share.c | 14 +++++++------- swad_timeline_user.c | 10 ++++++---- 7 files changed, 41 insertions(+), 39 deletions(-) diff --git a/swad_changelog.h b/swad_changelog.h index cc7daae7..6f9e1d65 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -600,13 +600,14 @@ TODO: Salvador Romero Cort TODO: FIX BUG, URGENT! En las fechas como parámetro Dat_WriteParamsIniEndDates(), por ejemplo al cambiar el color de la gráfica de accesos por día y hora, no se respeta la zona horaria. */ -#define Log_PLATFORM_VERSION "SWAD 20.68.7 (2021-04-29)" +#define Log_PLATFORM_VERSION "SWAD 20.68.8 (2021-04-30)" #define CSS_FILE "swad20.45.css" #define JS_FILE "swad20.6.2.js" /* TODO: Rename CENTRE to CENTER in help wiki. TODO: Rename ASSESSMENT.Announcements to ASSESSMENT.Calls_for_exams + Version 20.68.8: Apr 30, 2021 Code refactoring in timeline. (309751 lines) Version 20.68.7: Apr 29, 2021 Code refactoring in timeline. (309749 lines) Version 20.68.6: Apr 29, 2021 Code refactoring in timeline. (309738 lines) Version 20.68.5: Apr 29, 2021 Fixed bug in matches. Reported by Jesús Garrido Alcázar. (309746 lines) diff --git a/swad_timeline_note.c b/swad_timeline_note.c index 925712ce..456f3dd8 100644 --- a/swad_timeline_note.c +++ b/swad_timeline_note.c @@ -848,8 +848,8 @@ static void Tml_Not_WriteFavShaRem (const struct Tml_Timeline *Timeline, " class=\"TL_SHA_NOT TL_SHA_NOT_WIDTH\"", Gbl.UniqueNameEncrypted,NumDiv); Tml_Usr_PutIconFavSha (Tml_Usr_SHA_UNS_NOTE, - Not->NotCod,Not->UsrCod,Not->NumShared, - Tml_Usr_SHOW_FEW_USRS); + Not->NotCod,Not->UsrCod,Not->NumShared, + Tml_Usr_SHOW_FEW_USRS); HTM_DIV_End (); /***** Foot column 3: icon to remove this note *****/ @@ -1045,8 +1045,8 @@ void Tml_Not_MarkNotesChildrenOfFolderAsUnavailable (const char *Path) return; } Tml_DB_MarkNotesChildrenOfFolderAsUnavailable (NoteType, - FileBrowser,Brw_GetCodForFiles (), - Path); + FileBrowser,Brw_GetCodForFiles (), + Path); break; default: break; @@ -1139,15 +1139,15 @@ static void Tml_Not_RequestRemovalNote (struct Tml_Timeline *Timeline) NULL,Box_CLOSABLE); HTM_DIV_Begin ("class=\"TL_WIDTH\""); Tml_Not_CheckAndWriteNoteWithTopMsg (Timeline,&Not, - Tml_TOP_MESSAGE_NONE, - -1L); + Tml_TOP_MESSAGE_NONE, + -1L); HTM_DIV_End (); Box_BoxEnd (); /* End alert */ Timeline->NotCod = Not.NotCod; // Note to be removed Tml_Frm_EndAlertRemove (Timeline,Tml_Frm_REM_NOTE, - Tml_Not_PutParamsRemoveNote); + Tml_Not_PutParamsRemoveNote); } /*****************************************************************************/ @@ -1213,6 +1213,7 @@ void Tml_Not_RemoveNoteGbl (void) static void Tml_Not_RemoveNote (void) { extern const char *Txt_The_post_no_longer_exists; + extern const char *Txt_You_dont_have_permission_to_perform_this_action; extern const char *Txt_TIMELINE_Post_removed; struct Tml_Not_Note Not; @@ -1230,7 +1231,7 @@ static void Tml_Not_RemoveNote (void) /***** Trivial check 2: Am I the author of this note *****/ if (!Usr_ItsMe (Not.UsrCod)) { - Ale_ShowAlert (Ale_ERROR,"You are not the author."); + Ale_ShowAlert (Ale_ERROR,Txt_You_dont_have_permission_to_perform_this_action); return; } @@ -1318,7 +1319,7 @@ static void Tml_Not_GetDataOfNoteFromRow (MYSQL_ROW row,struct Tml_Not_Note *Not row[3]: UsrCod row[4]: HieCod row[5]: Unavailable - row[5]: UNIX_TIMESTAMP(TimeNote) + row[6]: UNIX_TIMESTAMP(TimeNote) */ /***** Get code (row[0]) *****/ Not->NotCod = Str_ConvertStrCodToLongCod (row[0]); @@ -1342,11 +1343,11 @@ static void Tml_Not_GetDataOfNoteFromRow (MYSQL_ROW row,struct Tml_Not_Note *Not Not->DateTimeUTC = Dat_GetUNIXTimeFromStr (row[6]); /***** Get number of times this note has been shared *****/ - Not->NumShared = Tml_DB_GetNumSharers (Not->NotCod,Not->UsrCod); + Not->NumShared = Tml_DB_GetNumSharers (Not->NotCod,Not->UsrCod); /***** Get number of times this note has been favourited *****/ - Not->NumFavs = Tml_DB_GetNumFavers (Tml_Usr_FAV_UNF_NOTE, - Not->NotCod,Not->UsrCod); + Not->NumFavs = Tml_DB_GetNumFavers (Tml_Usr_FAV_UNF_NOTE, + Not->NotCod,Not->UsrCod); } /*****************************************************************************/ diff --git a/swad_timeline_notification.c b/swad_timeline_notification.c index cd0f70a4..da1f764d 100644 --- a/swad_timeline_notification.c +++ b/swad_timeline_notification.c @@ -117,7 +117,7 @@ void Tml_Ntf_GetNotifPublication (char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1], /***** Return nothing on error *****/ Pub.PubType = Tml_Pub_UNKNOWN; - SummaryStr[0] = '\0'; // Return nothing on error + SummaryStr[0] = '\0'; // Return nothing on error Content.Txt[0] = '\0'; /***** Get summary and content from post from database *****/ diff --git a/swad_timeline_post.c b/swad_timeline_post.c index e79eef69..98f29e54 100644 --- a/swad_timeline_post.c +++ b/swad_timeline_post.c @@ -140,7 +140,7 @@ static void Tml_Pst_ShowPostContent (struct Tml_Pst_Content *Content) /***** Show media *****/ Med_ShowMedia (&Content->Media,"TL_PST_MED_CONT TL_RIGHT_WIDTH", "TL_PST_MED TL_RIGHT_WIDTH"); - } + } /*****************************************************************************/ /********************** Form to write a new publication **********************/ diff --git a/swad_timeline_publication.c b/swad_timeline_publication.c index 30bf0c2c..a1f3c9f0 100644 --- a/swad_timeline_publication.c +++ b/swad_timeline_publication.c @@ -60,7 +60,7 @@ extern struct Globals Gbl; /*****************************************************************************/ static void Tml_Pub_InitializeRangeOfPubs (Tml_WhatToGet_t WhatToGet, - struct Tml_Pub_RangePubsToGet *RangePubsToGet); + struct Tml_Pub_RangePubsToGet *RangePubsToGet); static unsigned Tml_Pub_GetMaxPubsToGet (const struct Tml_Timeline *Timeline); @@ -165,7 +165,7 @@ void Tml_Pub_GetListPubsToShowInTimeline (struct Tml_Timeline *Timeline) Timeline->Pubs.Bottom = Pub; // Update pointer to bottom publication if (Pub == NULL) // Nothing got ==> abort loop - break; // Last publication + break; // Last publication /* Insert note in temporary tables with just retrieved notes. These tables will be used to not get notes already shown */ @@ -201,7 +201,7 @@ void Tml_Pub_GetListPubsToShowInTimeline (struct Tml_Timeline *Timeline) /*****************************************************************************/ static void Tml_Pub_InitializeRangeOfPubs (Tml_WhatToGet_t WhatToGet, - struct Tml_Pub_RangePubsToGet *RangePubsToGet) + struct Tml_Pub_RangePubsToGet *RangePubsToGet) { /* Initialize range of pubs: @@ -276,16 +276,14 @@ static void Tml_Pub_UpdateFirstLastPubCodesIntoSession (const struct Tml_Timelin Tml_DB_UpdateLastPubCodInSession (); break; case Tml_GET_ONLY_OLD_PUBS: // Get only old publications - // The oldest publication code retrieved and shown - FirstPubCod = Timeline->Pubs.Bottom ? Timeline->Pubs.Bottom->PubCod : - 0; - Tml_DB_UpdateFirstPubCodInSession (FirstPubCod); - break; case Tml_GET_RECENT_TIMELINE: // Get last publications // The oldest publication code retrieved and shown FirstPubCod = Timeline->Pubs.Bottom ? Timeline->Pubs.Bottom->PubCod : 0; - Tml_DB_UpdateFirstLastPubCodsInSession (FirstPubCod); + if (Timeline->WhatToGet == Tml_GET_ONLY_OLD_PUBS) + Tml_DB_UpdateFirstPubCodInSession (FirstPubCod); + else + Tml_DB_UpdateFirstLastPubCodsInSession (FirstPubCod); break; } } @@ -367,8 +365,8 @@ void Tml_Pub_InsertNewPubsInTimeline (struct Tml_Timeline *Timeline) /* Write note */ HTM_LI_Begin ("class=\"TL_WIDTH TL_SEP TL_NEW_PUB\""); Tml_Not_CheckAndWriteNoteWithTopMsg (Timeline,&Not, - Tml_Pub_GetTopMessage (Pub->PubType), - Pub->PublisherCod); + Tml_Pub_GetTopMessage (Pub->PubType), + Pub->PublisherCod); HTM_LI_End (); } } @@ -395,8 +393,8 @@ void Tml_Pub_ShowOldPubsInTimeline (struct Tml_Timeline *Timeline) /* Write note */ HTM_LI_Begin ("class=\"TL_WIDTH TL_SEP\""); Tml_Not_CheckAndWriteNoteWithTopMsg (Timeline,&Not, - Tml_Pub_GetTopMessage (Pub->PubType), - Pub->PublisherCod); + Tml_Pub_GetTopMessage (Pub->PubType), + Pub->PublisherCod); HTM_LI_End (); } } diff --git a/swad_timeline_share.c b/swad_timeline_share.c index 5d70d7d2..c6b395cd 100644 --- a/swad_timeline_share.c +++ b/swad_timeline_share.c @@ -81,8 +81,8 @@ void Tml_Sha_ShowAllSharersNoteGbl (void) /***** Write HTML inside DIV with form to share/unshare *****/ Tml_Usr_PutIconFavSha (Tml_Usr_SHA_UNS_NOTE, - Not.NotCod,Not.UsrCod,Not.NumShared, - Tml_Usr_SHOW_ALL_USRS); + Not.NotCod,Not.UsrCod,Not.NumShared, + Tml_Usr_SHOW_ALL_USRS); } /*****************************************************************************/ @@ -107,8 +107,8 @@ void Tml_Sha_ShaNoteGbl (void) /***** Write HTML inside DIV with form to unshare *****/ Tml_Usr_PutIconFavSha (Tml_Usr_SHA_UNS_NOTE, - Not.NotCod,Not.UsrCod,Not.NumShared, - Tml_Usr_SHOW_FEW_USRS); + Not.NotCod,Not.UsrCod,Not.NumShared, + Tml_Usr_SHOW_FEW_USRS); } static void Tml_Sha_ShaNote (struct Tml_Not_Note *Not) @@ -126,7 +126,7 @@ static void Tml_Sha_ShaNote (struct Tml_Not_Note *Not) /***** Trivial check: Is note already shared by me? *****/ if (Tml_Usr_CheckIfFavedSharedByUsr (Tml_Usr_SHA_UNS_NOTE,Not->NotCod, - Gbl.Usrs.Me.UsrDat.UsrCod)) + Gbl.Usrs.Me.UsrDat.UsrCod)) return; /***** Share (publish note in timeline) *****/ @@ -167,8 +167,8 @@ void Tml_Sha_UnsNoteGbl (void) /***** Write HTML inside DIV with form to share *****/ Tml_Usr_PutIconFavSha (Tml_Usr_SHA_UNS_NOTE, - Not.NotCod,Not.UsrCod,Not.NumShared, - Tml_Usr_SHOW_FEW_USRS); + Not.NotCod,Not.UsrCod,Not.NumShared, + Tml_Usr_SHOW_FEW_USRS); } static void Tml_Sha_UnsNote (struct Tml_Not_Note *Not) diff --git a/swad_timeline_user.c b/swad_timeline_user.c index 32d42bb8..b951f333 100644 --- a/swad_timeline_user.c +++ b/swad_timeline_user.c @@ -348,6 +348,7 @@ static void Tml_Usr_PutDisabledIconFavSha (Tml_Usr_FavSha_t FavSha, bool Tml_Usr_CheckIfICanFavSha (long Cod,long UsrCod) { extern const char *Txt_The_post_no_longer_exists; + extern const char *Txt_You_dont_have_permission_to_perform_this_action; /***** Trivial check 1: note/comment code should be > 0 *****/ if (Cod <= 0) @@ -360,8 +361,8 @@ bool Tml_Usr_CheckIfICanFavSha (long Cod,long UsrCod) I can not fav/share my own notes/comments *****/ if (!Gbl.Usrs.Me.Logged || Usr_ItsMe (UsrCod)) { - Err_NoPermissionExit (); - return false; // Not reached + Ale_ShowAlert (Ale_ERROR,Txt_You_dont_have_permission_to_perform_this_action); + return false; } return true; @@ -374,6 +375,7 @@ bool Tml_Usr_CheckIfICanFavSha (long Cod,long UsrCod) bool Tml_Usr_CheckIfICanRemove (long Cod,long UsrCod) { extern const char *Txt_The_post_no_longer_exists; + extern const char *Txt_You_dont_have_permission_to_perform_this_action; /***** Trivial check 1: note/comment code should be > 0 *****/ if (Cod <= 0) @@ -386,8 +388,8 @@ bool Tml_Usr_CheckIfICanRemove (long Cod,long UsrCod) I can only remove my own notes/comments *****/ if (!Gbl.Usrs.Me.Logged || !Usr_ItsMe (UsrCod)) { - Err_NoPermissionExit (); - return false; // Not reached + Ale_ShowAlert (Ale_ERROR,Txt_You_dont_have_permission_to_perform_this_action); + return false; } return true;