diff --git a/swad_changelog.h b/swad_changelog.h index d693b46fc..59c33f41b 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.23 (2021-02-28)" +#define Log_PLATFORM_VERSION "SWAD 20.36.24 (2021-02-28)" #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.24: Feb 28, 2021 Functions moved to module swad_timeline_database. (305385 lines) Version 20.36.23: Feb 28, 2021 Function moved to module swad_timeline_database. (305387 lines) Version 20.36.22: Feb 28, 2021 Query moved to module swad_timeline_database. (305387 lines) Version 20.36.21: Feb 27, 2021 Function moved to module swad_timeline_database. (305376 lines) diff --git a/swad_follow.h b/swad_follow.h index 6d1556d19..f8f973691 100644 --- a/swad_follow.h +++ b/swad_follow.h @@ -81,5 +81,4 @@ void Fol_RemoveUsrFromUsrFollow (long UsrCod); void Fol_CreateTmpTableMeAndUsrsIFollow (void); void Fol_DropTmpTableMeAndUsrsIFollow (void); - #endif diff --git a/swad_timeline_comment.c b/swad_timeline_comment.c index cc432f1c9..1fcb19ec3 100644 --- a/swad_timeline_comment.c +++ b/swad_timeline_comment.c @@ -953,7 +953,7 @@ void TL_Com_RemoveCommentMediaAndDBEntries (long PubCod) TL_DB_RemoveCommentContent (PubCod); /***** Remove this comment publication *****/ - TL_DB_RemoveCommentPub (PubCod,Gbl.Usrs.Me.UsrDat.UsrCod); + TL_DB_RemoveCommentPub (PubCod); } /*****************************************************************************/ diff --git a/swad_timeline_database.c b/swad_timeline_database.c index d51602f1b..5dc1e82e4 100644 --- a/swad_timeline_database.c +++ b/swad_timeline_database.c @@ -26,6 +26,8 @@ /*****************************************************************************/ #include "swad_database.h" +#include "swad_follow.h" +#include "swad_global.h" #include "swad_timeline.h" #include "swad_timeline_database.h" #include "swad_timeline_publication.h" @@ -42,6 +44,8 @@ /************** External global variables from others modules ****************/ /*****************************************************************************/ +extern struct Globals Gbl; + /*****************************************************************************/ /************************* Private global variables **************************/ /*****************************************************************************/ @@ -172,7 +176,7 @@ void TL_DB_CreateTmpTableJustRetrievedNotes (void) " ENGINE=MEMORY"); } -void TL_DB_CreateTmpTableVisibleTimeline (char SessionId[Cns_BYTES_SESSION_ID + 1]) +void TL_DB_CreateTmpTableVisibleTimeline (void) { /***** Create temporary table with all notes visible in timeline *****/ DB_Query ("can not create temporary table", @@ -180,7 +184,7 @@ void TL_DB_CreateTmpTableVisibleTimeline (char SessionId[Cns_BYTES_SESSION_ID + "(NotCod BIGINT NOT NULL,UNIQUE INDEX(NotCod))" " ENGINE=MEMORY" " SELECT NotCod FROM tl_timelines WHERE SessionId='%s'", - SessionId); + Gbl.Session.Id); } /*****************************************************************************/ @@ -211,7 +215,7 @@ void TL_DB_InsertNoteInVisibleTimeline (long NotCod) /****** Add just retrieved notes to current timeline for this session ********/ /*****************************************************************************/ -void TL_DB_AddNotesJustRetrievedToVisibleTimelineOfSession (char SessionId[Cns_BYTES_SESSION_ID + 1]) +void TL_DB_AddNotesJustRetrievedToVisibleTimelineOfSession (void) { /* tl_timelines contains the distinct notes in timeline of each open session: mysql> SELECT SessionId,COUNT(*) FROM tl_timelines GROUP BY SessionId; @@ -235,7 +239,7 @@ mysql> SELECT SessionId,COUNT(*) FROM tl_timelines GROUP BY SessionId; "INSERT IGNORE INTO tl_timelines" " (SessionId,NotCod)" " SELECT '%s',NotCod FROM tl_tmp_just_retrieved_notes", - SessionId); + Gbl.Session.Id); } /*****************************************************************************/ @@ -272,13 +276,13 @@ void TL_DB_ClearOldTimelinesNotesFromDB (void) /***************** Clear timeline for a session in database ******************/ /*****************************************************************************/ -void TL_DB_ClearTimelineNotesOfSessionFromDB (char SessionId[Cns_BYTES_SESSION_ID + 1]) +void TL_DB_ClearTimelineNotesOfSessionFromDB (void) { /***** Remove timeline for a session *****/ DB_QueryDELETE ("can not remove timeline", "DELETE FROM tl_timelines" " WHERE SessionId='%s'", - SessionId); + Gbl.Session.Id); } /*****************************************************************************/ @@ -311,7 +315,7 @@ void TL_DB_RemoveNotePubs (long NotCod) /******************* Remove note publication from database *******************/ /*****************************************************************************/ -void TL_DB_RemoveNote (long NotCod,long PublisherCod) +void TL_DB_RemoveNote (long NotCod) { /***** Remove note *****/ DB_QueryDELETE ("can not remove a note", @@ -319,7 +323,7 @@ void TL_DB_RemoveNote (long NotCod,long PublisherCod) " WHERE NotCod=%ld" " AND UsrCod=%ld", // Extra check: author NotCod, - PublisherCod); + Gbl.Usrs.Me.UsrDat.UsrCod); } /*****************************************************************************/ @@ -549,7 +553,7 @@ void TL_DB_RemoveCommentContent (long PubCod) /***************** Remove comment publication from database ******************/ /*****************************************************************************/ -void TL_DB_RemoveCommentPub (long PubCod,long PublisherCod) +void TL_DB_RemoveCommentPub (long PubCod) { /***** Remove comment publication *****/ DB_QueryDELETE ("can not remove comment", @@ -558,7 +562,7 @@ void TL_DB_RemoveCommentPub (long PubCod,long PublisherCod) " AND PublisherCod=%ld" // Extra check: author " AND PubType=%u", // Extra check: it's a comment PubCod, - PublisherCod, + Gbl.Usrs.Me.UsrDat.UsrCod, (unsigned) TL_Pub_COMMENT_TO_NOTE); } @@ -590,6 +594,98 @@ static long TL_DB_GetMedCodFromPub (long PubCod,const char *DBTable) return MedCod; } +/*****************************************************************************/ +/******* Create temporary table and subquery with potential publishers *******/ +/*****************************************************************************/ + +void TL_DB_CreateSubQueryPublishers (const struct TL_Timeline *Timeline, + struct TL_Pub_SubQueries *SubQueries) + { + /***** Create temporary table and subquery with potential publishers *****/ + switch (Timeline->UsrOrGbl) + { + case TL_Usr_TIMELINE_USR: // Show the timeline of a user + SubQueries->TablePublishers = ""; + sprintf (SubQueries->Publishers,"tl_pubs.PublisherCod=%ld AND ", + Gbl.Usrs.Other.UsrDat.UsrCod); + break; + case TL_Usr_TIMELINE_GBL: // Show the global timeline + switch (Timeline->Who) + { + case Usr_WHO_ME: // Show my timeline + SubQueries->TablePublishers = ""; + snprintf (SubQueries->Publishers,sizeof (SubQueries->Publishers), + "tl_pubs.PublisherCod=%ld AND ", + Gbl.Usrs.Me.UsrDat.UsrCod); + break; + case Usr_WHO_FOLLOWED: // Show the timeline of the users I follow + Fol_CreateTmpTableMeAndUsrsIFollow (); + SubQueries->TablePublishers = ",fol_tmp_me_and_followed"; + Str_Copy (SubQueries->Publishers, + "tl_pubs.PublisherCod=fol_tmp_me_and_followed.UsrCod AND ", + sizeof (SubQueries->Publishers) - 1); + break; + case Usr_WHO_ALL: // Show the timeline of all users + SubQueries->TablePublishers = ""; + SubQueries->Publishers[0] = '\0'; + break; + default: + Lay_WrongWhoExit (); + break; + } + break; + } + } + +/*****************************************************************************/ +/********* Create subquery to get only notes not present in timeline *********/ +/*****************************************************************************/ + +void TL_DB_CreateSubQueryAlreadyExists (const struct TL_Timeline *Timeline, + struct TL_Pub_SubQueries *SubQueries) + { + switch (Timeline->WhatToGet) + { + case TL_GET_RECENT_TIMELINE: + case TL_GET_ONLY_NEW_PUBS: + Str_Copy (SubQueries->AlreadyExists, + " tl_pubs.NotCod NOT IN" + " (SELECT NotCod FROM tl_tmp_just_retrieved_notes)", // Avoid notes just retrieved + sizeof (SubQueries->AlreadyExists) - 1); + break; + case TL_GET_ONLY_OLD_PUBS: // Get only old publications + Str_Copy (SubQueries->AlreadyExists, + " tl_pubs.NotCod NOT IN" + " (SELECT NotCod FROM tl_tmp_visible_timeline)", // Avoid notes already shown + sizeof (SubQueries->AlreadyExists) - 1); + break; + } + } + +/*****************************************************************************/ +/***** Create subqueries with range of publications to get from tl_pubs ******/ +/*****************************************************************************/ + +void TL_DB_CreateSubQueryRangeBottom (const struct TL_Pub_RangePubsToGet *RangePubsToGet, + struct TL_Pub_SubQueries *SubQueries) + { + if (RangePubsToGet->Bottom > 0) + sprintf (SubQueries->RangeBottom,"tl_pubs.PubCod>%ld AND ", + RangePubsToGet->Bottom); + else + SubQueries->RangeBottom[0] = '\0'; + } + +void TL_DB_CreateSubQueryRangeTop (const struct TL_Pub_RangePubsToGet *RangePubsToGet, + struct TL_Pub_SubQueries *SubQueries) + { + if (RangePubsToGet->Top > 0) + sprintf (SubQueries->RangeTop,"tl_pubs.PubCod<%ld AND ", + RangePubsToGet->Top); + else + SubQueries->RangeTop[0] = '\0'; + } + /*****************************************************************************/ /******************** Select the most recent publication *********************/ /*****************************************************************************/ @@ -648,8 +744,7 @@ long TL_DB_GetNotCodFromPubCod (long PubCod) // "LastPubCod" // "FirstPubCod" -long TL_DB_GetPubCodFromSession (const char *FieldName, - const char SessionId[Cns_BYTES_SESSION_ID + 1]) +long TL_DB_GetPubCodFromSession (const char *FieldName) { MYSQL_RES *mysql_res; MYSQL_ROW row; @@ -659,7 +754,7 @@ long TL_DB_GetPubCodFromSession (const char *FieldName, if (DB_QuerySELECT (&mysql_res,"can not get publication code from session", "SELECT %s FROM sessions" " WHERE SessionId='%s'", - FieldName,SessionId) == 1) + FieldName,Gbl.Session.Id) == 1) { /***** Get last publication code *****/ row = mysql_fetch_row (mysql_res); @@ -711,22 +806,21 @@ long TL_DB_CreateNewPub (const struct TL_Pub_Publication *Pub) /************** Update first publication code stored in session **************/ /*****************************************************************************/ -void TL_DB_UpdateFirstPubCodInSession (long FirstPubCod, - const char SessionId[Cns_BYTES_SESSION_ID + 1]) +void TL_DB_UpdateFirstPubCodInSession (long FirstPubCod) { DB_QueryUPDATE ("can not update first publication code into session", "UPDATE sessions" " SET FirstPubCod=%ld" " WHERE SessionId='%s'", FirstPubCod, - SessionId); + Gbl.Session.Id); } /*****************************************************************************/ /*************** Update last publication code stored in session **************/ /*****************************************************************************/ -void TL_DB_UpdateLastPubCodInSession (const char SessionId[Cns_BYTES_SESSION_ID + 1]) +void TL_DB_UpdateLastPubCodInSession (void) { DB_QueryUPDATE ("can not update last publication code into session", "UPDATE sessions" @@ -734,15 +828,14 @@ void TL_DB_UpdateLastPubCodInSession (const char SessionId[Cns_BYTES_SESSION_ID "(SELECT IFNULL(MAX(PubCod),0)" " FROM tl_pubs)" // The most recent publication " WHERE SessionId='%s'", - SessionId); + Gbl.Session.Id); } /*****************************************************************************/ /********* Update first and last publication codes stored in session *********/ /*****************************************************************************/ -void TL_DB_UpdateFirstLastPubCodsInSession (long FirstPubCod, - const char SessionId[Cns_BYTES_SESSION_ID + 1]) +void TL_DB_UpdateFirstLastPubCodsInSession (long FirstPubCod) { DB_QueryUPDATE ("can not update first/last publication codes into session", "UPDATE sessions" @@ -752,5 +845,5 @@ void TL_DB_UpdateFirstLastPubCodsInSession (long FirstPubCod, " FROM tl_pubs)" // The most recent publication " WHERE SessionId='%s'", FirstPubCod, - SessionId); + Gbl.Session.Id); } diff --git a/swad_timeline_database.h b/swad_timeline_database.h index 483e028d1..949419147 100644 --- a/swad_timeline_database.h +++ b/swad_timeline_database.h @@ -56,17 +56,17 @@ void TL_DB_MarkNotesChildrenOfFolderAsUnavailable (TL_Not_NoteType_t NoteType, long Cod, const char *Path); void TL_DB_CreateTmpTableJustRetrievedNotes (void); -void TL_DB_CreateTmpTableVisibleTimeline (char SessionId[Cns_BYTES_SESSION_ID + 1]); +void TL_DB_CreateTmpTableVisibleTimeline (void); void TL_DB_InsertNoteInJustRetrievedNotes (long NotCod); void TL_DB_InsertNoteInVisibleTimeline (long NotCod); -void TL_DB_AddNotesJustRetrievedToVisibleTimelineOfSession (char SessionId[Cns_BYTES_SESSION_ID + 1]); +void TL_DB_AddNotesJustRetrievedToVisibleTimelineOfSession (void); void TL_DB_DropTmpTableJustRetrievedNotes (void); void TL_DB_DropTmpTableVisibleTimeline (void); void TL_DB_ClearOldTimelinesNotesFromDB (void); -void TL_DB_ClearTimelineNotesOfSessionFromDB (char SessionId[Cns_BYTES_SESSION_ID + 1]); +void TL_DB_ClearTimelineNotesOfSessionFromDB (void); void TL_DB_RemoveNoteFavs (long NotCod); void TL_DB_RemoveNotePubs (long NotCod); -void TL_DB_RemoveNote (long NotCod,long PublisherCod); +void TL_DB_RemoveNote (long NotCod); /* Posts */ unsigned TL_DB_GetPostByCod (long PstCod,MYSQL_RES **mysql_res); @@ -89,20 +89,25 @@ void TL_DB_InsertCommentContent (long PubCod, long TL_DB_GetMedCodFromComment (long PubCod); void TL_DB_RemoveCommentFavs (long PubCod); void TL_DB_RemoveCommentContent (long PubCod); -void TL_DB_RemoveCommentPub (long PubCod,long PublisherCod); +void TL_DB_RemoveCommentPub (long PubCod); /* Publications */ +void TL_DB_CreateSubQueryPublishers (const struct TL_Timeline *Timeline, + struct TL_Pub_SubQueries *SubQueries); +void TL_DB_CreateSubQueryAlreadyExists (const struct TL_Timeline *Timeline, + struct TL_Pub_SubQueries *SubQueries); +void TL_DB_CreateSubQueryRangeBottom (const struct TL_Pub_RangePubsToGet *RangePubsToGet, + struct TL_Pub_SubQueries *SubQueries); +void TL_DB_CreateSubQueryRangeTop (const struct TL_Pub_RangePubsToGet *RangePubsToGet, + struct TL_Pub_SubQueries *SubQueries); unsigned TL_DB_SelectTheMostRecentPub (const struct TL_Pub_SubQueries *SubQueries, MYSQL_RES **mysql_res); long TL_DB_GetNotCodFromPubCod (long PubCod); -long TL_DB_GetPubCodFromSession (const char *FieldName, - const char SessionId[Cns_BYTES_SESSION_ID + 1]); +long TL_DB_GetPubCodFromSession (const char *FieldName); unsigned long TL_DB_GetNumPubsUsr (long UsrCod); long TL_DB_CreateNewPub (const struct TL_Pub_Publication *Pub); -void TL_DB_UpdateFirstPubCodInSession (long FirstPubCod, - const char SessionId[Cns_BYTES_SESSION_ID + 1]); -void TL_DB_UpdateLastPubCodInSession (const char SessionId[Cns_BYTES_SESSION_ID + 1]); -void TL_DB_UpdateFirstLastPubCodsInSession (long FirstPubCod, - const char SessionId[Cns_BYTES_SESSION_ID + 1]); +void TL_DB_UpdateFirstPubCodInSession (long FirstPubCod); +void TL_DB_UpdateLastPubCodInSession (void); +void TL_DB_UpdateFirstLastPubCodsInSession (long FirstPubCod); #endif diff --git a/swad_timeline_note.c b/swad_timeline_note.c index 186c6b380..e2b758597 100644 --- a/swad_timeline_note.c +++ b/swad_timeline_note.c @@ -1247,7 +1247,7 @@ static void TL_Not_RemoveNoteMediaAndDBEntries (struct TL_Not_Note *Not) TL_DB_RemoveNotePubs (Not->NotCod); /***** Remove note *****/ - TL_DB_RemoveNote (Not->NotCod,Gbl.Usrs.Me.UsrDat.UsrCod); + TL_DB_RemoveNote (Not->NotCod); if (Not->NoteType == TL_NOTE_POST) /***** Remove post *****/ diff --git a/swad_timeline_publication.c b/swad_timeline_publication.c index 4c813b62e..76553b5f3 100644 --- a/swad_timeline_publication.c +++ b/swad_timeline_publication.c @@ -46,12 +46,6 @@ /************************* Private constants and types ***********************/ /*****************************************************************************/ -struct TL_Pub_RangePubsToGet - { - long Top; - long Bottom; - }; - /*****************************************************************************/ /************** External global variables from others modules ****************/ /*****************************************************************************/ @@ -68,15 +62,6 @@ extern struct Globals Gbl; static unsigned TL_Pub_GetMaxPubsToGet (const struct TL_Timeline *Timeline); -static void TL_Pub_CreateSubQueryPublishers (const struct TL_Timeline *Timeline, - struct TL_Pub_SubQueries *SubQueries); -static void TL_Pub_CreateSubQueryAlreadyExists (const struct TL_Timeline *Timeline, - struct TL_Pub_SubQueries *SubQueries); -static void TL_Pub_CreateSubQueryRangeBottom (const struct TL_Pub_RangePubsToGet *RangePubsToGet, - struct TL_Pub_SubQueries *SubQueries); -static void TL_Pub_CreateSubQueryRangeTop (const struct TL_Pub_RangePubsToGet *RangePubsToGet, - struct TL_Pub_SubQueries *SubQueries); - static void TL_Pub_UpdateFirstLastPubCodesIntoSession (const struct TL_Timeline *Timeline); static struct TL_Pub_Publication *TL_Pub_SelectTheMostRecentPub (const struct TL_Pub_SubQueries *SubQueries); @@ -97,7 +82,7 @@ void TL_Pub_GetListPubsToShowInTimeline (struct TL_Timeline *Timeline) /***** Clear timeline for this session in database *****/ if (Timeline->WhatToGet == TL_GET_RECENT_TIMELINE) - TL_DB_ClearTimelineNotesOfSessionFromDB (Gbl.Session.Id); + TL_DB_ClearTimelineNotesOfSessionFromDB (); /***** Create temporary tables *****/ /* Create temporary table with notes just retrieved */ @@ -105,14 +90,14 @@ void TL_Pub_GetListPubsToShowInTimeline (struct TL_Timeline *Timeline) /* Create temporary table with all notes visible in timeline */ if (Timeline->WhatToGet == TL_GET_ONLY_OLD_PUBS) - TL_DB_CreateTmpTableVisibleTimeline (Gbl.Session.Id); + TL_DB_CreateTmpTableVisibleTimeline (); /***** Create subqueries *****/ /* Create subquery with potential publishers */ - TL_Pub_CreateSubQueryPublishers (Timeline,&SubQueries); + TL_DB_CreateSubQueryPublishers (Timeline,&SubQueries); /* Create subquery to get only notes not present in timeline */ - TL_Pub_CreateSubQueryAlreadyExists (Timeline,&SubQueries); + TL_DB_CreateSubQueryAlreadyExists (Timeline,&SubQueries); /***** Get the publications in timeline *****/ /* Initialize range of pubs: @@ -138,13 +123,13 @@ void TL_Pub_GetListPubsToShowInTimeline (struct TL_Timeline *Timeline) // newer than LastPubCod /* This query is made via AJAX automatically from time to time */ RangePubsToGet.Top = 0; // +Infinite - RangePubsToGet.Bottom = TL_DB_GetPubCodFromSession ("LastPubCod",Gbl.Session.Id); + RangePubsToGet.Bottom = TL_DB_GetPubCodFromSession ("LastPubCod"); break; case TL_GET_ONLY_OLD_PUBS: // Get some limited publications // older than FirstPubCod /* This query is made via AJAX when I click in link to get old publications */ - RangePubsToGet.Top = TL_DB_GetPubCodFromSession ("FirstPubCod",Gbl.Session.Id); + RangePubsToGet.Top = TL_DB_GetPubCodFromSession ("FirstPubCod"); RangePubsToGet.Bottom = 0; // -Infinite break; case TL_GET_RECENT_TIMELINE: // Get some limited recent publications @@ -157,7 +142,7 @@ void TL_Pub_GetListPubsToShowInTimeline (struct TL_Timeline *Timeline) } /* Create subquery with bottom range of publications to get from tl_pubs. Bottom pub. code remains unchanged in all iterations of the next loop. */ - TL_Pub_CreateSubQueryRangeBottom (&RangePubsToGet,&SubQueries); + TL_DB_CreateSubQueryRangeBottom (&RangePubsToGet,&SubQueries); /* With the current approach, we select one by one the publications and notes in a loop. In each iteration, @@ -199,7 +184,7 @@ void TL_Pub_GetListPubsToShowInTimeline (struct TL_Timeline *Timeline) { /* Create subquery with top range of publications to get from tl_pubs In each iteration of this loop, top publication code is changed to a lower value */ - TL_Pub_CreateSubQueryRangeTop (&RangePubsToGet,&SubQueries); + TL_DB_CreateSubQueryRangeTop (&RangePubsToGet,&SubQueries); /* Select the most recent publication from tl_pubs */ Pub = TL_Pub_SelectTheMostRecentPub (&SubQueries); @@ -229,7 +214,7 @@ void TL_Pub_GetListPubsToShowInTimeline (struct TL_Timeline *Timeline) TL_Pub_UpdateFirstLastPubCodesIntoSession (Timeline); /***** Add notes just retrieved to visible timeline for this session *****/ - TL_DB_AddNotesJustRetrievedToVisibleTimelineOfSession (Gbl.Session.Id); + TL_DB_AddNotesJustRetrievedToVisibleTimelineOfSession (); /***** Drop temporary tables *****/ /* Drop temporary tables with notes already retrieved */ @@ -259,98 +244,6 @@ static unsigned TL_Pub_GetMaxPubsToGet (const struct TL_Timeline *Timeline) return MaxPubsToGet[Timeline->WhatToGet]; } -/*****************************************************************************/ -/******* Create temporary table and subquery with potential publishers *******/ -/*****************************************************************************/ - -static void TL_Pub_CreateSubQueryPublishers (const struct TL_Timeline *Timeline, - struct TL_Pub_SubQueries *SubQueries) - { - /***** Create temporary table and subquery with potential publishers *****/ - switch (Timeline->UsrOrGbl) - { - case TL_Usr_TIMELINE_USR: // Show the timeline of a user - SubQueries->TablePublishers = ""; - sprintf (SubQueries->Publishers,"tl_pubs.PublisherCod=%ld AND ", - Gbl.Usrs.Other.UsrDat.UsrCod); - break; - case TL_Usr_TIMELINE_GBL: // Show the global timeline - switch (Timeline->Who) - { - case Usr_WHO_ME: // Show my timeline - SubQueries->TablePublishers = ""; - snprintf (SubQueries->Publishers,sizeof (SubQueries->Publishers), - "tl_pubs.PublisherCod=%ld AND ", - Gbl.Usrs.Me.UsrDat.UsrCod); - break; - case Usr_WHO_FOLLOWED: // Show the timeline of the users I follow - Fol_CreateTmpTableMeAndUsrsIFollow (); - SubQueries->TablePublishers = ",fol_tmp_me_and_followed"; - Str_Copy (SubQueries->Publishers, - "tl_pubs.PublisherCod=fol_tmp_me_and_followed.UsrCod AND ", - sizeof (SubQueries->Publishers) - 1); - break; - case Usr_WHO_ALL: // Show the timeline of all users - SubQueries->TablePublishers = ""; - SubQueries->Publishers[0] = '\0'; - break; - default: - Lay_WrongWhoExit (); - break; - } - break; - } - } - -/*****************************************************************************/ -/********* Create subquery to get only notes not present in timeline *********/ -/*****************************************************************************/ - -static void TL_Pub_CreateSubQueryAlreadyExists (const struct TL_Timeline *Timeline, - struct TL_Pub_SubQueries *SubQueries) - { - switch (Timeline->WhatToGet) - { - case TL_GET_RECENT_TIMELINE: - case TL_GET_ONLY_NEW_PUBS: - Str_Copy (SubQueries->AlreadyExists, - " tl_pubs.NotCod NOT IN" - " (SELECT NotCod FROM tl_tmp_just_retrieved_notes)", // Avoid notes just retrieved - sizeof (SubQueries->AlreadyExists) - 1); - break; - case TL_GET_ONLY_OLD_PUBS: // Get only old publications - Str_Copy (SubQueries->AlreadyExists, - " tl_pubs.NotCod NOT IN" - " (SELECT NotCod FROM tl_tmp_visible_timeline)", // Avoid notes already shown - sizeof (SubQueries->AlreadyExists) - 1); - break; - } - } - -/*****************************************************************************/ -/***** Create subqueries with range of publications to get from tl_pubs ******/ -/*****************************************************************************/ - -static void TL_Pub_CreateSubQueryRangeBottom (const struct TL_Pub_RangePubsToGet *RangePubsToGet, - struct TL_Pub_SubQueries *SubQueries) - { - if (RangePubsToGet->Bottom > 0) - sprintf (SubQueries->RangeBottom,"tl_pubs.PubCod>%ld AND ", - RangePubsToGet->Bottom); - else - SubQueries->RangeBottom[0] = '\0'; - } - -static void TL_Pub_CreateSubQueryRangeTop (const struct TL_Pub_RangePubsToGet *RangePubsToGet, - struct TL_Pub_SubQueries *SubQueries) - { - if (RangePubsToGet->Top > 0) - sprintf (SubQueries->RangeTop,"tl_pubs.PubCod<%ld AND ", - RangePubsToGet->Top); - else - SubQueries->RangeTop[0] = '\0'; - } - /*****************************************************************************/ /************* Update first (oldest) and last (more recent) ***************/ /************* publication codes into session for next refresh ***************/ @@ -363,19 +256,19 @@ static void TL_Pub_UpdateFirstLastPubCodesIntoSession (const struct TL_Timeline switch (Timeline->WhatToGet) { case TL_GET_ONLY_NEW_PUBS: // Get only new publications - TL_DB_UpdateLastPubCodInSession (Gbl.Session.Id); + TL_DB_UpdateLastPubCodInSession (); break; case TL_GET_ONLY_OLD_PUBS: // Get only old publications // The oldest publication code retrieved and shown FirstPubCod = Timeline->Pubs.Bottom ? Timeline->Pubs.Bottom->PubCod : 0; - TL_DB_UpdateFirstPubCodInSession (FirstPubCod,Gbl.Session.Id); + TL_DB_UpdateFirstPubCodInSession (FirstPubCod); break; case TL_GET_RECENT_TIMELINE: // Get last publications // The oldest publication code retrieved and shown FirstPubCod = Timeline->Pubs.Bottom ? Timeline->Pubs.Bottom->PubCod : 0; - TL_DB_UpdateFirstLastPubCodsInSession (FirstPubCod,Gbl.Session.Id); + TL_DB_UpdateFirstLastPubCodsInSession (FirstPubCod); break; } } diff --git a/swad_timeline_publication.h b/swad_timeline_publication.h index 78268aca7..c4d27accd 100644 --- a/swad_timeline_publication.h +++ b/swad_timeline_publication.h @@ -65,6 +65,12 @@ struct TL_Pub_Publication struct TL_Pub_Publication *Next; // Used for chained list }; +struct TL_Pub_RangePubsToGet + { + long Top; + long Bottom; + }; + #define TL_Pub_MAX_BYTES_SUBQUERY (128 - 1) struct TL_Pub_SubQueries {