From d5428a11c9960a3151479a73014d30c8a8640808 Mon Sep 17 00:00:00 2001 From: acanas Date: Sat, 27 Feb 2021 16:30:41 +0100 Subject: [PATCH] Version 20.36.13: Feb 27, 2021 Functions moved to module swad_timeline_database. --- swad_changelog.h | 3 +- swad_timeline_database.c | 58 +++++++++++++++++++++++++++++++++++ swad_timeline_database.h | 2 ++ swad_timeline_favourite.c | 5 ++-- swad_timeline_note.c | 60 +------------------------------------ swad_timeline_note.h | 4 --- swad_timeline_publication.c | 3 +- swad_timeline_share.c | 4 +-- 8 files changed, 70 insertions(+), 69 deletions(-) diff --git a/swad_changelog.h b/swad_changelog.h index a99f5abb..ce7cb752 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -553,7 +553,7 @@ enscript -2 --landscape --color --file-align=2 --highlight --line-numbers -o - * En OpenSWAD: ps2pdf source.ps destination.pdf */ -#define Log_PLATFORM_VERSION "SWAD 20.36.12 (2021-02-07)" +#define Log_PLATFORM_VERSION "SWAD 20.36.13 (2021-02-27)" #define CSS_FILE "swad20.33.9.css" #define JS_FILE "swad20.6.2.js" /* @@ -601,6 +601,7 @@ 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 + Version 20.36.13: Feb 27, 2021 Functions moved to module swad_timeline_database. (305285 lines) Version 20.36.12: Feb 27, 2021 Queries moved to module swad_timeline_database. (305282 lines) Version 20.36.11: Feb 27, 2021 Query moved to module swad_timeline_database. (305246 lines) Version 20.36.10: Feb 27, 2021 Query moved to module swad_timeline_database. (305243 lines) diff --git a/swad_timeline_database.c b/swad_timeline_database.c index a66fcade..cad1d0fa 100644 --- a/swad_timeline_database.c +++ b/swad_timeline_database.c @@ -130,6 +130,64 @@ void TL_DB_InsertNoteInVisibleTimeline (long NotCod) NotCod); } +/*****************************************************************************/ +/****** Add just retrieved notes to current timeline for this session ********/ +/*****************************************************************************/ + +void TL_DB_AddNotesJustRetrievedToVisibleTimelineOfSession (char SessionId[Cns_BYTES_SESSION_ID + 1]) + { + /* tl_timelines contains the distinct notes in timeline of each open session: +mysql> SELECT SessionId,COUNT(*) FROM tl_timelines GROUP BY SessionId; ++---------------------------------------------+----------+ +| SessionId | COUNT(*) | ++---------------------------------------------+----------+ +| u-X-R3gKki7eKMXrNCP8bGhwOAZuVngRy7FNGZFMKzI | 52 | --> 52 distinct notes +| u1CoqL1YWl3_hR4wk4bI7vhnc-uRcCmIDyKYAgBB6kk | 10 | +| u8xqamzkorHfY4BvYRMXjNhzHvQyigZUZemO0YiMn48 | 10 | +| u_n2V_L3KrFjnd4SqZk0gxMFwZHRuWZ8_EIVTU9sdpI | 10 | +| V6pGe1kGGS_uO5i__waqXKnuDkPYaDZHNAYr-Zv-GJQ | 2 | +| vqDRz-iiM8v10Dl8ThwqIqmDRIklz8szJaqflwXZucs | 10 | +| w11juqKPx6lg-f_pL2ZBYqlagU1mEepSvvk9L3gDGac | 10 | --> 10 distinct notes +| wLg4e8KQljCcVuFWIkJjNeti89kAiwOZ3iyXdzm_eDk | 10 | +| wnU85YrwJHhZGWIZhd7LQfQTPrclIWHfMF3DcB-Rcgw | 4 | +| wRzRJFnHfzW61fZYnvMIaMRlkuWUeEyqXVQ6JeWA32k | 11 | ++---------------------------------------------+----------+ +10 rows in set (0,01 sec) + */ + DB_QueryINSERT ("can not insert notes in timeline", + "INSERT IGNORE INTO tl_timelines" + " (SessionId,NotCod)" + " SELECT '%s',NotCod FROM tl_tmp_just_retrieved_notes", + SessionId); + } + +/*****************************************************************************/ +/*************** Get code of publication of the original note ****************/ +/*****************************************************************************/ + +long TL_DB_GetPubCodOfOriginalNote (long NotCod) + { + MYSQL_RES *mysql_res; + MYSQL_ROW row; + long OriginalPubCod = -1L; // Default value + + /***** Get code of publication of the original note *****/ + if (DB_QuerySELECT (&mysql_res,"can not get code of publication", + "SELECT PubCod FROM tl_pubs" + " WHERE NotCod=%ld AND PubType=%u", + NotCod,(unsigned) TL_Pub_ORIGINAL_NOTE) == 1) // Result should have a unique row + { + /* Get code of publication (row[0]) */ + row = mysql_fetch_row (mysql_res); + OriginalPubCod = Str_ConvertStrCodToLongCod (row[0]); + } + + /***** Free structure that stores the query result *****/ + DB_FreeMySQLResult (&mysql_res); + + return OriginalPubCod; + } + /*****************************************************************************/ /*************************** Remove favs for a note **************************/ /*****************************************************************************/ diff --git a/swad_timeline_database.h b/swad_timeline_database.h index 4b21ffce..c751cc98 100644 --- a/swad_timeline_database.h +++ b/swad_timeline_database.h @@ -54,6 +54,8 @@ void TL_DB_MarkNotesChildrenOfFolderAsUnavailable (TL_Not_NoteType_t NoteType, const char *Path); void TL_DB_InsertNoteInJustRetrievedNotes (long NotCod); void TL_DB_InsertNoteInVisibleTimeline (long NotCod); +void TL_DB_AddNotesJustRetrievedToVisibleTimelineOfSession (char SessionId[Cns_BYTES_SESSION_ID + 1]); +long TL_DB_GetPubCodOfOriginalNote (long NotCod); void TL_DB_RemoveNoteFavs (long NotCod); void TL_DB_RemoveNotePubs (long NotCod); void TL_DB_RemoveNote (long NotCod,long PublisherCod); diff --git a/swad_timeline_favourite.c b/swad_timeline_favourite.c index 27c052de..5e421873 100644 --- a/swad_timeline_favourite.c +++ b/swad_timeline_favourite.c @@ -28,6 +28,7 @@ #include "swad_database.h" #include "swad_global.h" #include "swad_timeline.h" +#include "swad_timeline_database.h" #include "swad_timeline_favourite.h" #include "swad_timeline_form.h" #include "swad_timeline_notification.h" @@ -187,7 +188,7 @@ static void TL_Fav_FavNote (struct TL_Not_Note *Not) /***** Create notification about favourite post for the author of the post *****/ - OriginalPubCod = TL_Not_GetPubCodOfOriginalNote (Not->NotCod); + OriginalPubCod = TL_DB_GetPubCodOfOriginalNote (Not->NotCod); if (OriginalPubCod > 0) TL_Ntf_CreateNotifToAuthor (Not->UsrCod,OriginalPubCod, Ntf_EVENT_TIMELINE_FAV); @@ -221,7 +222,7 @@ static void TL_Fav_UnfNote (struct TL_Not_Note *Not) TL_Fav_GetNumTimesANoteHasBeenFav (Not); /***** Mark possible notifications on this note as removed *****/ - OriginalPubCod = TL_Not_GetPubCodOfOriginalNote (Not->NotCod); + OriginalPubCod = TL_DB_GetPubCodOfOriginalNote (Not->NotCod); if (OriginalPubCod > 0) Ntf_MarkNotifAsRemoved (Ntf_EVENT_TIMELINE_FAV,OriginalPubCod); } diff --git a/swad_timeline_note.c b/swad_timeline_note.c index 28c7b435..bd01c806 100644 --- a/swad_timeline_note.c +++ b/swad_timeline_note.c @@ -1233,7 +1233,7 @@ static void TL_Not_RemoveNoteMediaAndDBEntries (struct TL_Not_Note *Not) /***** Mark possible notifications on the publications of this note as removed *****/ - PubCod = TL_Not_GetPubCodOfOriginalNote (Not->NotCod); + PubCod = TL_DB_GetPubCodOfOriginalNote (Not->NotCod); if (PubCod > 0) { Ntf_MarkNotifAsRemoved (Ntf_EVENT_TIMELINE_FAV ,PubCod); @@ -1329,64 +1329,6 @@ static void TL_Not_ResetNote (struct TL_Not_Note *Not) Not->NumShared = 0; } -/*****************************************************************************/ -/*************** Get code of publication of the original note ****************/ -/*****************************************************************************/ - -long TL_Not_GetPubCodOfOriginalNote (long NotCod) - { - MYSQL_RES *mysql_res; - MYSQL_ROW row; - long OriginalPubCod = -1L; - - /***** Get code of publication of the original note *****/ - if (DB_QuerySELECT (&mysql_res,"can not get code of publication", - "SELECT PubCod FROM tl_pubs" - " WHERE NotCod=%ld AND PubType=%u", - NotCod,(unsigned) TL_Pub_ORIGINAL_NOTE) == 1) // Result should have a unique row - { - /* Get code of publication (row[0]) */ - row = mysql_fetch_row (mysql_res); - OriginalPubCod = Str_ConvertStrCodToLongCod (row[0]); - } - - /***** Free structure that stores the query result *****/ - DB_FreeMySQLResult (&mysql_res); - - return OriginalPubCod; - } - -/*****************************************************************************/ -/****** Add just retrieved notes to current timeline for this session ********/ -/*****************************************************************************/ - -void TL_Not_AddNotesJustRetrievedToVisibleTimelineThisSession (void) - { - /* tl_timelines contains the distinct notes in timeline of each open session: -mysql> SELECT SessionId,COUNT(*) FROM tl_timelines GROUP BY SessionId; -+---------------------------------------------+----------+ -| SessionId | COUNT(*) | -+---------------------------------------------+----------+ -| u-X-R3gKki7eKMXrNCP8bGhwOAZuVngRy7FNGZFMKzI | 52 | --> 52 distinct notes -| u1CoqL1YWl3_hR4wk4bI7vhnc-uRcCmIDyKYAgBB6kk | 10 | -| u8xqamzkorHfY4BvYRMXjNhzHvQyigZUZemO0YiMn48 | 10 | -| u_n2V_L3KrFjnd4SqZk0gxMFwZHRuWZ8_EIVTU9sdpI | 10 | -| V6pGe1kGGS_uO5i__waqXKnuDkPYaDZHNAYr-Zv-GJQ | 2 | -| vqDRz-iiM8v10Dl8ThwqIqmDRIklz8szJaqflwXZucs | 10 | -| w11juqKPx6lg-f_pL2ZBYqlagU1mEepSvvk9L3gDGac | 10 | --> 10 distinct notes -| wLg4e8KQljCcVuFWIkJjNeti89kAiwOZ3iyXdzm_eDk | 10 | -| wnU85YrwJHhZGWIZhd7LQfQTPrclIWHfMF3DcB-Rcgw | 4 | -| wRzRJFnHfzW61fZYnvMIaMRlkuWUeEyqXVQ6JeWA32k | 11 | -+---------------------------------------------+----------+ -10 rows in set (0,01 sec) - */ - DB_QueryINSERT ("can not insert notes in timeline", - "INSERT IGNORE INTO tl_timelines" - " (SessionId,NotCod)" - " SELECT '%s',NotCod FROM tl_tmp_just_retrieved_notes", - Gbl.Session.Id); - } - /*****************************************************************************/ /******************** Get data of note using its code ************************/ /*****************************************************************************/ diff --git a/swad_timeline_note.h b/swad_timeline_note.h index 28c18b1e..681a5326 100644 --- a/swad_timeline_note.h +++ b/swad_timeline_note.h @@ -110,10 +110,6 @@ void TL_Not_RequestRemNoteGbl (void); void TL_Not_RemoveNoteUsr (void); void TL_Not_RemoveNoteGbl (void); -long TL_Not_GetPubCodOfOriginalNote (long NotCod); - -void TL_Not_AddNotesJustRetrievedToVisibleTimelineThisSession (void); - void TL_Not_GetDataOfNoteByCod (struct TL_Not_Note *Not); void TL_Not_ClearOldTimelinesNotesFromDB (void); diff --git a/swad_timeline_publication.c b/swad_timeline_publication.c index 62d2d488..5b59ed5e 100644 --- a/swad_timeline_publication.c +++ b/swad_timeline_publication.c @@ -33,6 +33,7 @@ #include "swad_global.h" #include "swad_profile.h" #include "swad_timeline.h" +#include "swad_timeline_database.h" #include "swad_timeline_favourite.h" #include "swad_timeline_note.h" #include "swad_timeline_publication.h" @@ -236,7 +237,7 @@ void TL_Pub_GetListPubsToShowInTimeline (struct TL_Timeline *Timeline) TL_Pub_UpdateFirstLastPubCodesIntoSession (Timeline); /***** Add notes just retrieved to visible timeline for this session *****/ - TL_Not_AddNotesJustRetrievedToVisibleTimelineThisSession (); + TL_DB_AddNotesJustRetrievedToVisibleTimelineOfSession (Gbl.Session.Id); /***** Drop temporary tables *****/ TL_Pub_DropTemporaryTables (Timeline); diff --git a/swad_timeline_share.c b/swad_timeline_share.c index 80ebf637..883901ce 100644 --- a/swad_timeline_share.c +++ b/swad_timeline_share.c @@ -140,7 +140,7 @@ static void TL_Sha_ShaNote (struct TL_Not_Note *Not) /**** Create notification about shared post for the author of the post ***/ - OriginalPubCod = TL_Not_GetPubCodOfOriginalNote (Not->NotCod); + OriginalPubCod = TL_DB_GetPubCodOfOriginalNote (Not->NotCod); if (OriginalPubCod > 0) TL_Ntf_CreateNotifToAuthor (Not->UsrCod,OriginalPubCod, Ntf_EVENT_TIMELINE_SHARE); @@ -200,7 +200,7 @@ static void TL_Sha_UnsNote (struct TL_Not_Note *Not) TL_Sha_UpdateNumTimesANoteHasBeenShared (Not); /***** Mark possible notifications on this note as removed *****/ - OriginalPubCod = TL_Not_GetPubCodOfOriginalNote (Not->NotCod); + OriginalPubCod = TL_DB_GetPubCodOfOriginalNote (Not->NotCod); if (OriginalPubCod > 0) Ntf_MarkNotifAsRemoved (Ntf_EVENT_TIMELINE_SHARE,OriginalPubCod); }