mirror of
https://github.com/acanas/swad-core.git
synced 2024-06-17 05:55:43 +02:00
Version20.15
This commit is contained in:
parent
480b34f738
commit
43ee77df40
|
@ -553,7 +553,7 @@ enscript -2 --landscape --color --file-align=2 --highlight --line-numbers -o - *
|
||||||
En OpenSWAD:
|
En OpenSWAD:
|
||||||
ps2pdf source.ps destination.pdf
|
ps2pdf source.ps destination.pdf
|
||||||
*/
|
*/
|
||||||
#define Log_PLATFORM_VERSION "SWAD 20.14.3 (2021-02-08)"
|
#define Log_PLATFORM_VERSION "SWAD 20.15 (2021-02-08)"
|
||||||
#define CSS_FILE "swad20.8.css"
|
#define CSS_FILE "swad20.8.css"
|
||||||
#define JS_FILE "swad20.6.2.js"
|
#define JS_FILE "swad20.6.2.js"
|
||||||
/*
|
/*
|
||||||
|
@ -600,6 +600,8 @@ 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: 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.
|
||||||
|
|
||||||
|
Version 20.15: Feb 08, 2021 Code refactoring in timeline. (305118 lines)
|
||||||
|
Version 20.14.4: Feb 08, 2021 Code refactoring in timeline. (305096 lines)
|
||||||
Version 20.14.3: Feb 08, 2021 Code refactoring related to parameter who (which users). (305057 lines)
|
Version 20.14.3: Feb 08, 2021 Code refactoring related to parameter who (which users). (305057 lines)
|
||||||
Version 20.14.2: Feb 08, 2021 Code refactoring in timeline. (305044 lines)
|
Version 20.14.2: Feb 08, 2021 Code refactoring in timeline. (305044 lines)
|
||||||
Version 20.14.1: Feb 08, 2021 Code refactoring in timeline. (305072 lines)
|
Version 20.14.1: Feb 08, 2021 Code refactoring in timeline. (305072 lines)
|
||||||
|
|
358
swad_timeline.c
358
swad_timeline.c
|
@ -65,22 +65,7 @@
|
||||||
|
|
||||||
#define TL_MAX_CHARS_IN_POST 1000 // Maximum number of characters in a post
|
#define TL_MAX_CHARS_IN_POST 1000 // Maximum number of characters in a post
|
||||||
|
|
||||||
typedef enum
|
#define TL_MAX_BYTES_SUBQUERY (128 - 1)
|
||||||
{
|
|
||||||
TL_TIMELINE_USR, // Show the timeline of a user
|
|
||||||
TL_TIMELINE_GBL, // Show the timeline of the users follwed by me
|
|
||||||
} TL_TimelineUsrOrGbl_t;
|
|
||||||
|
|
||||||
#define TL_NUM_WHAT_TO_GET_FROM_TIMELINE 3
|
|
||||||
typedef enum
|
|
||||||
{
|
|
||||||
TL_GET_ONLY_NEW_PUBS, // New publications are retrieved via AJAX
|
|
||||||
// automatically from time to time
|
|
||||||
TL_GET_RECENT_TIMELINE, // Recent timeline is shown when the user clicks on action menu,...
|
|
||||||
// or after editing timeline
|
|
||||||
TL_GET_ONLY_OLD_PUBS, // Old publications are retrieved via AJAX
|
|
||||||
// when the user clicks on link at bottom of timeline
|
|
||||||
} TL_WhatToGetFromTimeline_t;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Timeline images will be saved with:
|
Timeline images will be saved with:
|
||||||
|
@ -179,17 +164,22 @@ static void TL_ShowTimelineGblHighlightingNot (struct TL_Timeline *Timeline,
|
||||||
static void TL_ShowTimelineUsrHighlightingNot (struct TL_Timeline *Timeline,
|
static void TL_ShowTimelineUsrHighlightingNot (struct TL_Timeline *Timeline,
|
||||||
long NotCod);
|
long NotCod);
|
||||||
|
|
||||||
static void TL_GetAndShowOldTimeline (struct TL_Timeline *Timeline,
|
static void TL_GetAndShowOldTimeline (struct TL_Timeline *Timeline);
|
||||||
TL_TimelineUsrOrGbl_t TimelineUsrOrGbl);
|
|
||||||
|
|
||||||
static void TL_BuildQueryToGetTimeline (struct TL_Timeline *Timeline,
|
static void TL_BuildQueryToGetTimeline (struct TL_Timeline *Timeline,
|
||||||
char **Query,
|
char **Query);
|
||||||
TL_TimelineUsrOrGbl_t TimelineUsrOrGbl,
|
|
||||||
TL_WhatToGetFromTimeline_t WhatToGetFromTimeline);
|
|
||||||
static long TL_GetPubCodFromSession (const char *FieldName);
|
static long TL_GetPubCodFromSession (const char *FieldName);
|
||||||
static void TL_UpdateLastPubCodIntoSession (void);
|
static void TL_UpdateLastPubCodIntoSession (void);
|
||||||
static void TL_UpdateFirstPubCodIntoSession (long FirstPubCod);
|
static void TL_UpdateFirstPubCodIntoSession (long FirstPubCod);
|
||||||
static void TL_DropTemporaryTablesUsedToQueryTimeline (void);
|
static void TL_CreateTmpTablePubCodes (void);
|
||||||
|
static void TL_CreateTmpTableNotCodes (void);
|
||||||
|
static void TL_CreateTmpTableCurrentTimeline (void);
|
||||||
|
static void TL_CreateTmpTablePublishers (void);
|
||||||
|
static void TL_DropTmpTablesUsedToQueryTimeline (void);
|
||||||
|
static void TL_CreateSubQueryPublishers (const struct TL_Timeline *Timeline,
|
||||||
|
char SubQueryPublishers[TL_MAX_BYTES_SUBQUERY + 1]);
|
||||||
|
static void TL_CreateSubQueryAlreadyExists (const struct TL_Timeline *Timeline,
|
||||||
|
char SubQueryAlreadyExists[TL_MAX_BYTES_SUBQUERY + 1]);
|
||||||
|
|
||||||
static void TL_ShowTimeline (struct TL_Timeline *Timeline,
|
static void TL_ShowTimeline (struct TL_Timeline *Timeline,
|
||||||
char *Query,
|
char *Query,
|
||||||
|
@ -324,7 +314,9 @@ static void TL_InitTimelineGbl (struct TL_Timeline *Timeline)
|
||||||
|
|
||||||
void TL_ResetTimeline (struct TL_Timeline *Timeline)
|
void TL_ResetTimeline (struct TL_Timeline *Timeline)
|
||||||
{
|
{
|
||||||
Timeline->Who = TL_DEFAULT_WHO;
|
Timeline->UsrOrGbl = TL_TIMELINE_GBL;
|
||||||
|
Timeline->Who = TL_DEFAULT_WHO;
|
||||||
|
Timeline->WhatToGet = TL_GET_RECENT_TIMELINE;
|
||||||
Timeline->NotCod = -1L;
|
Timeline->NotCod = -1L;
|
||||||
Timeline->PubCod = -1L;
|
Timeline->PubCod = -1L;
|
||||||
}
|
}
|
||||||
|
@ -449,15 +441,15 @@ static void TL_ShowTimelineGblHighlightingNot (struct TL_Timeline *Timeline,
|
||||||
char *Query = NULL;
|
char *Query = NULL;
|
||||||
|
|
||||||
/***** Build query to get timeline *****/
|
/***** Build query to get timeline *****/
|
||||||
TL_BuildQueryToGetTimeline (Timeline,&Query,
|
Timeline->UsrOrGbl = TL_TIMELINE_GBL;
|
||||||
TL_TIMELINE_GBL,
|
Timeline->WhatToGet = TL_GET_RECENT_TIMELINE;
|
||||||
TL_GET_RECENT_TIMELINE);
|
TL_BuildQueryToGetTimeline (Timeline,&Query);
|
||||||
|
|
||||||
/***** Show timeline *****/
|
/***** Show timeline *****/
|
||||||
TL_ShowTimeline (Timeline,Query,Txt_Timeline,NotCod);
|
TL_ShowTimeline (Timeline,Query,Txt_Timeline,NotCod);
|
||||||
|
|
||||||
/***** Drop temporary tables *****/
|
/***** Drop temporary tables *****/
|
||||||
TL_DropTemporaryTablesUsedToQueryTimeline ();
|
TL_DropTmpTablesUsedToQueryTimeline ();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
@ -480,9 +472,9 @@ static void TL_ShowTimelineUsrHighlightingNot (struct TL_Timeline *Timeline,
|
||||||
char *Query = NULL;
|
char *Query = NULL;
|
||||||
|
|
||||||
/***** Build query to show timeline with publications of a unique user *****/
|
/***** Build query to show timeline with publications of a unique user *****/
|
||||||
TL_BuildQueryToGetTimeline (Timeline,&Query,
|
Timeline->UsrOrGbl = TL_TIMELINE_USR;
|
||||||
TL_TIMELINE_USR,
|
Timeline->WhatToGet = TL_GET_RECENT_TIMELINE;
|
||||||
TL_GET_RECENT_TIMELINE);
|
TL_BuildQueryToGetTimeline (Timeline,&Query);
|
||||||
|
|
||||||
/***** Show timeline *****/
|
/***** Show timeline *****/
|
||||||
TL_ShowTimeline (Timeline,
|
TL_ShowTimeline (Timeline,
|
||||||
|
@ -492,7 +484,7 @@ static void TL_ShowTimelineUsrHighlightingNot (struct TL_Timeline *Timeline,
|
||||||
Str_FreeString ();
|
Str_FreeString ();
|
||||||
|
|
||||||
/***** Drop temporary tables *****/
|
/***** Drop temporary tables *****/
|
||||||
TL_DropTemporaryTablesUsedToQueryTimeline ();
|
TL_DropTmpTablesUsedToQueryTimeline ();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
@ -513,15 +505,15 @@ void TL_RefreshNewTimelineGbl (void)
|
||||||
Timeline.Who = TL_GetGlobalWho ();
|
Timeline.Who = TL_GetGlobalWho ();
|
||||||
|
|
||||||
/***** Build query to get timeline *****/
|
/***** Build query to get timeline *****/
|
||||||
TL_BuildQueryToGetTimeline (&Timeline,&Query,
|
Timeline.UsrOrGbl = TL_TIMELINE_GBL;
|
||||||
TL_TIMELINE_GBL,
|
Timeline.WhatToGet = TL_GET_ONLY_NEW_PUBS;
|
||||||
TL_GET_ONLY_NEW_PUBS);
|
TL_BuildQueryToGetTimeline (&Timeline,&Query);
|
||||||
|
|
||||||
/***** Show new timeline *****/
|
/***** Show new timeline *****/
|
||||||
TL_InsertNewPubsInTimeline (&Timeline,Query);
|
TL_InsertNewPubsInTimeline (&Timeline,Query);
|
||||||
|
|
||||||
/***** Drop temporary tables *****/
|
/***** Drop temporary tables *****/
|
||||||
TL_DropTemporaryTablesUsedToQueryTimeline ();
|
TL_DropTmpTablesUsedToQueryTimeline ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -540,7 +532,9 @@ void TL_RefreshOldTimelineGbl (void)
|
||||||
Timeline.Who = TL_GetGlobalWho ();
|
Timeline.Who = TL_GetGlobalWho ();
|
||||||
|
|
||||||
/***** Show old publications *****/
|
/***** Show old publications *****/
|
||||||
TL_GetAndShowOldTimeline (&Timeline,TL_TIMELINE_GBL);
|
Timeline.UsrOrGbl = TL_TIMELINE_GBL;
|
||||||
|
Timeline.WhatToGet = TL_GET_ONLY_OLD_PUBS;
|
||||||
|
TL_GetAndShowOldTimeline (&Timeline);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TL_RefreshOldTimelineUsr (void)
|
void TL_RefreshOldTimelineUsr (void)
|
||||||
|
@ -554,7 +548,9 @@ void TL_RefreshOldTimelineUsr (void)
|
||||||
TL_ResetTimeline (&Timeline);
|
TL_ResetTimeline (&Timeline);
|
||||||
|
|
||||||
/***** If user exists, show old publications *****/
|
/***** If user exists, show old publications *****/
|
||||||
TL_GetAndShowOldTimeline (&Timeline,TL_TIMELINE_USR);
|
Timeline.UsrOrGbl = TL_TIMELINE_USR;
|
||||||
|
Timeline.WhatToGet = TL_GET_ONLY_OLD_PUBS;
|
||||||
|
TL_GetAndShowOldTimeline (&Timeline);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -562,21 +558,18 @@ void TL_RefreshOldTimelineUsr (void)
|
||||||
/**************** Get and show old publications in timeline ******************/
|
/**************** Get and show old publications in timeline ******************/
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
static void TL_GetAndShowOldTimeline (struct TL_Timeline *Timeline,
|
static void TL_GetAndShowOldTimeline (struct TL_Timeline *Timeline)
|
||||||
TL_TimelineUsrOrGbl_t TimelineUsrOrGbl)
|
|
||||||
{
|
{
|
||||||
char *Query = NULL;
|
char *Query = NULL;
|
||||||
|
|
||||||
/***** Build query to get timeline *****/
|
/***** Build query to get timeline *****/
|
||||||
TL_BuildQueryToGetTimeline (Timeline,&Query,
|
TL_BuildQueryToGetTimeline (Timeline,&Query);
|
||||||
TimelineUsrOrGbl,
|
|
||||||
TL_GET_ONLY_OLD_PUBS);
|
|
||||||
|
|
||||||
/***** Show old timeline *****/
|
/***** Show old timeline *****/
|
||||||
TL_ShowOldPubsInTimeline (Timeline,Query);
|
TL_ShowOldPubsInTimeline (Timeline,Query);
|
||||||
|
|
||||||
/***** Drop temporary tables *****/
|
/***** Drop temporary tables *****/
|
||||||
TL_DropTemporaryTablesUsedToQueryTimeline ();
|
TL_DropTmpTablesUsedToQueryTimeline ();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
@ -596,17 +589,13 @@ void TL_MarkMyNotifAsSeen (void)
|
||||||
/************************ Build query to get timeline ************************/
|
/************************ Build query to get timeline ************************/
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
#define TL_MAX_BYTES_SUBQUERY_ALREADY_EXISTS (256 - 1)
|
|
||||||
|
|
||||||
static void TL_BuildQueryToGetTimeline (struct TL_Timeline *Timeline,
|
static void TL_BuildQueryToGetTimeline (struct TL_Timeline *Timeline,
|
||||||
char **Query,
|
char **Query)
|
||||||
TL_TimelineUsrOrGbl_t TimelineUsrOrGbl,
|
|
||||||
TL_WhatToGetFromTimeline_t WhatToGetFromTimeline)
|
|
||||||
{
|
{
|
||||||
char SubQueryPublishers[128];
|
char SubQueryPublishers[TL_MAX_BYTES_SUBQUERY + 1];
|
||||||
char SubQueryRangeBottom[128];
|
char SubQueryRangeBottom[TL_MAX_BYTES_SUBQUERY + 1];
|
||||||
char SubQueryRangeTop[128];
|
char SubQueryRangeTop[TL_MAX_BYTES_SUBQUERY + 1];
|
||||||
char SubQueryAlreadyExists[TL_MAX_BYTES_SUBQUERY_ALREADY_EXISTS + 1];
|
char SubQueryAlreadyExists[TL_MAX_BYTES_SUBQUERY + 1];
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
long Top;
|
long Top;
|
||||||
|
@ -618,7 +607,7 @@ static void TL_BuildQueryToGetTimeline (struct TL_Timeline *Timeline,
|
||||||
unsigned NumPub;
|
unsigned NumPub;
|
||||||
long PubCod;
|
long PubCod;
|
||||||
long NotCod;
|
long NotCod;
|
||||||
static const unsigned MaxPubsToGet[TL_NUM_WHAT_TO_GET_FROM_TIMELINE] =
|
static const unsigned MaxPubsToGet[TL_NUM_WHAT_TO_GET] =
|
||||||
{
|
{
|
||||||
[TL_GET_ONLY_NEW_PUBS ] = TL_MAX_NEW_PUBS_TO_GET_AND_SHOW,
|
[TL_GET_ONLY_NEW_PUBS ] = TL_MAX_NEW_PUBS_TO_GET_AND_SHOW,
|
||||||
[TL_GET_RECENT_TIMELINE] = TL_MAX_REC_PUBS_TO_GET_AND_SHOW,
|
[TL_GET_RECENT_TIMELINE] = TL_MAX_REC_PUBS_TO_GET_AND_SHOW,
|
||||||
|
@ -626,107 +615,22 @@ static void TL_BuildQueryToGetTimeline (struct TL_Timeline *Timeline,
|
||||||
};
|
};
|
||||||
|
|
||||||
/***** Clear timeline for this session in database *****/
|
/***** Clear timeline for this session in database *****/
|
||||||
if (WhatToGetFromTimeline == TL_GET_RECENT_TIMELINE)
|
if (Timeline->WhatToGet == TL_GET_RECENT_TIMELINE)
|
||||||
TL_ClearTimelineThisSession ();
|
TL_ClearTimelineThisSession ();
|
||||||
|
|
||||||
/***** Drop temporary tables *****/
|
/***** Drop temporary tables *****/
|
||||||
TL_DropTemporaryTablesUsedToQueryTimeline ();
|
TL_DropTmpTablesUsedToQueryTimeline ();
|
||||||
|
|
||||||
/***** Create temporary table with publication codes *****/
|
/***** Create some temporary tables *****/
|
||||||
DB_Query ("can not create temporary table",
|
TL_CreateTmpTablePubCodes ();
|
||||||
"CREATE TEMPORARY TABLE tl_pub_codes "
|
TL_CreateTmpTableNotCodes ();
|
||||||
"(PubCod BIGINT NOT NULL,UNIQUE INDEX(PubCod)) ENGINE=MEMORY");
|
TL_CreateTmpTableCurrentTimeline ();
|
||||||
|
|
||||||
/***** Create temporary table with notes got in this execution *****/
|
|
||||||
DB_Query ("can not create temporary table",
|
|
||||||
"CREATE TEMPORARY TABLE tl_not_codes "
|
|
||||||
"(NotCod BIGINT NOT NULL,INDEX(NotCod)) ENGINE=MEMORY");
|
|
||||||
|
|
||||||
/***** Create temporary table with notes already present in timeline for this session *****/
|
|
||||||
DB_Query ("can not create temporary table",
|
|
||||||
"CREATE TEMPORARY TABLE tl_current_timeline "
|
|
||||||
"(NotCod BIGINT NOT NULL,INDEX(NotCod)) ENGINE=MEMORY"
|
|
||||||
" SELECT NotCod FROM tl_timelines WHERE SessionId='%s'",
|
|
||||||
Gbl.Session.Id);
|
|
||||||
|
|
||||||
/***** Create temporary table and subquery with potential publishers *****/
|
/***** Create temporary table and subquery with potential publishers *****/
|
||||||
switch (TimelineUsrOrGbl)
|
TL_CreateSubQueryPublishers (Timeline,SubQueryPublishers);
|
||||||
{
|
|
||||||
case TL_TIMELINE_USR: // Show the timeline of a user
|
|
||||||
sprintf (SubQueryPublishers,"PublisherCod=%ld AND ",
|
|
||||||
Gbl.Usrs.Other.UsrDat.UsrCod);
|
|
||||||
break;
|
|
||||||
case TL_TIMELINE_GBL: // Show the global timeline
|
|
||||||
switch (Timeline->Who)
|
|
||||||
{
|
|
||||||
case Usr_WHO_ME: // Show my timeline
|
|
||||||
sprintf (SubQueryPublishers,"PublisherCod=%ld AND ",
|
|
||||||
Gbl.Usrs.Me.UsrDat.UsrCod);
|
|
||||||
break;
|
|
||||||
case Usr_WHO_FOLLOWED: // Show the timeline of the users I follow
|
|
||||||
DB_Query ("can not create temporary table",
|
|
||||||
"CREATE TEMPORARY TABLE tl_publishers "
|
|
||||||
"(UsrCod INT NOT NULL,UNIQUE INDEX(UsrCod)) ENGINE=MEMORY"
|
|
||||||
" SELECT %ld AS UsrCod"
|
|
||||||
" UNION"
|
|
||||||
" SELECT FollowedCod AS UsrCod"
|
|
||||||
" FROM usr_follow WHERE FollowerCod=%ld",
|
|
||||||
Gbl.Usrs.Me.UsrDat.UsrCod,
|
|
||||||
Gbl.Usrs.Me.UsrDat.UsrCod);
|
|
||||||
|
|
||||||
sprintf (SubQueryPublishers,
|
|
||||||
"tl_pubs.PublisherCod=tl_publishers.UsrCod AND ");
|
|
||||||
break;
|
|
||||||
case Usr_WHO_ALL: // Show the timeline of all users
|
|
||||||
SubQueryPublishers[0] = '\0';
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
Lay_WrongWhoExit ();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
/***** Create subquery to get only notes not present in timeline *****/
|
/***** Create subquery to get only notes not present in timeline *****/
|
||||||
switch (TimelineUsrOrGbl)
|
TL_CreateSubQueryAlreadyExists (Timeline,SubQueryAlreadyExists);
|
||||||
{
|
|
||||||
case TL_TIMELINE_USR: // Show the timeline of a user
|
|
||||||
switch (WhatToGetFromTimeline)
|
|
||||||
{
|
|
||||||
case TL_GET_ONLY_NEW_PUBS:
|
|
||||||
case TL_GET_RECENT_TIMELINE:
|
|
||||||
Str_Copy (SubQueryAlreadyExists,
|
|
||||||
" NotCod NOT IN"
|
|
||||||
" (SELECT NotCod FROM tl_not_codes)",
|
|
||||||
TL_MAX_BYTES_SUBQUERY_ALREADY_EXISTS);
|
|
||||||
break;
|
|
||||||
case TL_GET_ONLY_OLD_PUBS:
|
|
||||||
Str_Copy (SubQueryAlreadyExists,
|
|
||||||
" NotCod NOT IN"
|
|
||||||
" (SELECT NotCod FROM tl_current_timeline)",
|
|
||||||
TL_MAX_BYTES_SUBQUERY_ALREADY_EXISTS);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case TL_TIMELINE_GBL: // Show the timeline of the users I follow
|
|
||||||
switch (WhatToGetFromTimeline)
|
|
||||||
{
|
|
||||||
case TL_GET_ONLY_NEW_PUBS:
|
|
||||||
case TL_GET_RECENT_TIMELINE:
|
|
||||||
Str_Copy (SubQueryAlreadyExists,
|
|
||||||
" tl_pubs.NotCod NOT IN"
|
|
||||||
" (SELECT NotCod FROM tl_not_codes)",
|
|
||||||
TL_MAX_BYTES_SUBQUERY_ALREADY_EXISTS);
|
|
||||||
break;
|
|
||||||
case TL_GET_ONLY_OLD_PUBS:
|
|
||||||
Str_Copy (SubQueryAlreadyExists,
|
|
||||||
" tl_pubs.NotCod NOT IN"
|
|
||||||
" (SELECT NotCod FROM tl_current_timeline)",
|
|
||||||
TL_MAX_BYTES_SUBQUERY_ALREADY_EXISTS);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
/***** Get the publications in timeline *****/
|
/***** Get the publications in timeline *****/
|
||||||
/* Initialize range of pubs:
|
/* Initialize range of pubs:
|
||||||
|
@ -748,7 +652,7 @@ static void TL_BuildQueryToGetTimeline (struct TL_Timeline *Timeline,
|
||||||
*/
|
*/
|
||||||
RangePubsToGet.Top = 0; // +Infinite
|
RangePubsToGet.Top = 0; // +Infinite
|
||||||
RangePubsToGet.Bottom = 0; // -Infinite
|
RangePubsToGet.Bottom = 0; // -Infinite
|
||||||
switch (WhatToGetFromTimeline)
|
switch (Timeline->WhatToGet)
|
||||||
{
|
{
|
||||||
case TL_GET_ONLY_NEW_PUBS: // Get the publications (without limit) newer than LastPubCod
|
case TL_GET_ONLY_NEW_PUBS: // Get the publications (without limit) newer than LastPubCod
|
||||||
/* This query is made via AJAX automatically from time to time */
|
/* This query is made via AJAX automatically from time to time */
|
||||||
|
@ -783,12 +687,12 @@ static void TL_BuildQueryToGetTimeline (struct TL_Timeline *Timeline,
|
||||||
*/
|
*/
|
||||||
|
|
||||||
for (NumPub = 0;
|
for (NumPub = 0;
|
||||||
NumPub < MaxPubsToGet[WhatToGetFromTimeline];
|
NumPub < MaxPubsToGet[Timeline->WhatToGet];
|
||||||
NumPub++)
|
NumPub++)
|
||||||
{
|
{
|
||||||
/* Create subqueries with range of publications to get from tl_pubs */
|
/* Create subqueries with range of publications to get from tl_pubs */
|
||||||
if (RangePubsToGet.Bottom > 0)
|
if (RangePubsToGet.Bottom > 0)
|
||||||
switch (TimelineUsrOrGbl)
|
switch (Timeline->UsrOrGbl)
|
||||||
{
|
{
|
||||||
case TL_TIMELINE_USR: // Show the timeline of a user
|
case TL_TIMELINE_USR: // Show the timeline of a user
|
||||||
sprintf (SubQueryRangeBottom,"PubCod>%ld AND ",
|
sprintf (SubQueryRangeBottom,"PubCod>%ld AND ",
|
||||||
|
@ -816,7 +720,7 @@ static void TL_BuildQueryToGetTimeline (struct TL_Timeline *Timeline,
|
||||||
SubQueryRangeBottom[0] = '\0';
|
SubQueryRangeBottom[0] = '\0';
|
||||||
|
|
||||||
if (RangePubsToGet.Top > 0)
|
if (RangePubsToGet.Top > 0)
|
||||||
switch (TimelineUsrOrGbl)
|
switch (Timeline->UsrOrGbl)
|
||||||
{
|
{
|
||||||
case TL_TIMELINE_USR: // Show the timeline of a user
|
case TL_TIMELINE_USR: // Show the timeline of a user
|
||||||
sprintf (SubQueryRangeTop,"PubCod<%ld AND ",
|
sprintf (SubQueryRangeTop,"PubCod<%ld AND ",
|
||||||
|
@ -845,7 +749,7 @@ static void TL_BuildQueryToGetTimeline (struct TL_Timeline *Timeline,
|
||||||
|
|
||||||
/* Select the most recent publication from tl_pubs */
|
/* Select the most recent publication from tl_pubs */
|
||||||
NumPubs = 0; // Initialized to avoid warning
|
NumPubs = 0; // Initialized to avoid warning
|
||||||
switch (TimelineUsrOrGbl)
|
switch (Timeline->UsrOrGbl)
|
||||||
{
|
{
|
||||||
case TL_TIMELINE_USR: // Show the timeline of a user
|
case TL_TIMELINE_USR: // Show the timeline of a user
|
||||||
NumPubs =
|
NumPubs =
|
||||||
|
@ -1015,22 +919,164 @@ static void TL_UpdateFirstPubCodIntoSession (long FirstPubCod)
|
||||||
{
|
{
|
||||||
/***** Update last publication code *****/
|
/***** Update last publication code *****/
|
||||||
DB_QueryUPDATE ("can not update first publication code into session",
|
DB_QueryUPDATE ("can not update first publication code into session",
|
||||||
"UPDATE sessions SET FirstPubCod=%ld WHERE SessionId='%s'",
|
"UPDATE sessions"
|
||||||
FirstPubCod,Gbl.Session.Id);
|
" SET FirstPubCod=%ld"
|
||||||
|
" WHERE SessionId='%s'",
|
||||||
|
FirstPubCod,
|
||||||
|
Gbl.Session.Id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/************* Create temporary tables used to query timeline ****************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
static void TL_CreateTmpTablePubCodes (void)
|
||||||
|
{
|
||||||
|
/***** Create temporary table with publication codes *****/
|
||||||
|
DB_Query ("can not create temporary table",
|
||||||
|
"CREATE TEMPORARY TABLE tl_pub_codes "
|
||||||
|
"(PubCod BIGINT NOT NULL,"
|
||||||
|
"UNIQUE INDEX(PubCod))"
|
||||||
|
" ENGINE=MEMORY");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void TL_CreateTmpTableNotCodes (void)
|
||||||
|
{
|
||||||
|
/***** Create temporary table with notes got in this execution *****/
|
||||||
|
DB_Query ("can not create temporary table",
|
||||||
|
"CREATE TEMPORARY TABLE tl_not_codes "
|
||||||
|
"(NotCod BIGINT NOT NULL,"
|
||||||
|
"INDEX(NotCod))"
|
||||||
|
" ENGINE=MEMORY");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void TL_CreateTmpTableCurrentTimeline (void)
|
||||||
|
{
|
||||||
|
/***** Create temporary table with notes
|
||||||
|
already present in timeline for this session *****/
|
||||||
|
DB_Query ("can not create temporary table",
|
||||||
|
"CREATE TEMPORARY TABLE tl_current_timeline "
|
||||||
|
"(NotCod BIGINT NOT NULL,"
|
||||||
|
"INDEX(NotCod))"
|
||||||
|
" ENGINE=MEMORY"
|
||||||
|
" SELECT NotCod FROM tl_timelines WHERE SessionId='%s'",
|
||||||
|
Gbl.Session.Id);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void TL_CreateTmpTablePublishers (void)
|
||||||
|
{
|
||||||
|
/***** Create temporary table with me and the users I follow *****/
|
||||||
|
DB_Query ("can not create temporary table",
|
||||||
|
"CREATE TEMPORARY TABLE tl_publishers "
|
||||||
|
"(UsrCod INT NOT NULL,"
|
||||||
|
"UNIQUE INDEX(UsrCod))"
|
||||||
|
" ENGINE=MEMORY"
|
||||||
|
" SELECT %ld AS UsrCod" // Me
|
||||||
|
" UNION"
|
||||||
|
" SELECT FollowedCod AS UsrCod" // Users I follow
|
||||||
|
" FROM usr_follow"
|
||||||
|
" WHERE FollowerCod=%ld",
|
||||||
|
Gbl.Usrs.Me.UsrDat.UsrCod,
|
||||||
|
Gbl.Usrs.Me.UsrDat.UsrCod);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/*************** Drop temporary tables used to query timeline ****************/
|
/*************** Drop temporary tables used to query timeline ****************/
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
static void TL_DropTemporaryTablesUsedToQueryTimeline (void)
|
static void TL_DropTmpTablesUsedToQueryTimeline (void)
|
||||||
{
|
{
|
||||||
DB_Query ("can not remove temporary tables",
|
DB_Query ("can not remove temporary tables",
|
||||||
"DROP TEMPORARY TABLE IF EXISTS "
|
"DROP TEMPORARY TABLE IF EXISTS "
|
||||||
"tl_pub_codes,"
|
"tl_pub_codes,"
|
||||||
"tl_not_codes,"
|
"tl_not_codes,"
|
||||||
"tl_publishers,"
|
"tl_current_timeline,"
|
||||||
"tl_current_timeline");
|
"tl_publishers");
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/******* Create temporary table and subquery with potential publishers *******/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
static void TL_CreateSubQueryPublishers (const struct TL_Timeline *Timeline,
|
||||||
|
char SubQueryPublishers[TL_MAX_BYTES_SUBQUERY + 1])
|
||||||
|
{
|
||||||
|
/***** Create temporary table and subquery with potential publishers *****/
|
||||||
|
switch (Timeline->UsrOrGbl)
|
||||||
|
{
|
||||||
|
case TL_TIMELINE_USR: // Show the timeline of a user
|
||||||
|
sprintf (SubQueryPublishers,"PublisherCod=%ld AND ",
|
||||||
|
Gbl.Usrs.Other.UsrDat.UsrCod);
|
||||||
|
break;
|
||||||
|
case TL_TIMELINE_GBL: // Show the global timeline
|
||||||
|
switch (Timeline->Who)
|
||||||
|
{
|
||||||
|
case Usr_WHO_ME: // Show my timeline
|
||||||
|
sprintf (SubQueryPublishers,"PublisherCod=%ld AND ",
|
||||||
|
Gbl.Usrs.Me.UsrDat.UsrCod);
|
||||||
|
break;
|
||||||
|
case Usr_WHO_FOLLOWED: // Show the timeline of the users I follow
|
||||||
|
TL_CreateTmpTablePublishers ();
|
||||||
|
sprintf (SubQueryPublishers,
|
||||||
|
"tl_pubs.PublisherCod=tl_publishers.UsrCod AND ");
|
||||||
|
break;
|
||||||
|
case Usr_WHO_ALL: // Show the timeline of all users
|
||||||
|
SubQueryPublishers[0] = '\0';
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
Lay_WrongWhoExit ();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/********* Create subquery to get only notes not present in timeline *********/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
static void TL_CreateSubQueryAlreadyExists (const struct TL_Timeline *Timeline,
|
||||||
|
char SubQueryAlreadyExists[TL_MAX_BYTES_SUBQUERY + 1])
|
||||||
|
{
|
||||||
|
switch (Timeline->UsrOrGbl)
|
||||||
|
{
|
||||||
|
case TL_TIMELINE_USR: // Show the timeline of a user
|
||||||
|
switch (Timeline->WhatToGet)
|
||||||
|
{
|
||||||
|
case TL_GET_ONLY_NEW_PUBS:
|
||||||
|
case TL_GET_RECENT_TIMELINE:
|
||||||
|
Str_Copy (SubQueryAlreadyExists,
|
||||||
|
" NotCod NOT IN"
|
||||||
|
" (SELECT NotCod FROM tl_not_codes)",
|
||||||
|
TL_MAX_BYTES_SUBQUERY);
|
||||||
|
break;
|
||||||
|
case TL_GET_ONLY_OLD_PUBS:
|
||||||
|
Str_Copy (SubQueryAlreadyExists,
|
||||||
|
" NotCod NOT IN"
|
||||||
|
" (SELECT NotCod FROM tl_current_timeline)",
|
||||||
|
TL_MAX_BYTES_SUBQUERY);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TL_TIMELINE_GBL: // Show the timeline of the users I follow
|
||||||
|
switch (Timeline->WhatToGet)
|
||||||
|
{
|
||||||
|
case TL_GET_ONLY_NEW_PUBS:
|
||||||
|
case TL_GET_RECENT_TIMELINE:
|
||||||
|
Str_Copy (SubQueryAlreadyExists,
|
||||||
|
" tl_pubs.NotCod NOT IN"
|
||||||
|
" (SELECT NotCod FROM tl_not_codes)",
|
||||||
|
TL_MAX_BYTES_SUBQUERY);
|
||||||
|
break;
|
||||||
|
case TL_GET_ONLY_OLD_PUBS:
|
||||||
|
Str_Copy (SubQueryAlreadyExists,
|
||||||
|
" tl_pubs.NotCod NOT IN"
|
||||||
|
" (SELECT NotCod FROM tl_current_timeline)",
|
||||||
|
TL_MAX_BYTES_SUBQUERY);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
|
@ -84,9 +84,28 @@ typedef enum
|
||||||
TL_TOP_MESSAGE_MENTIONED = 6,
|
TL_TOP_MESSAGE_MENTIONED = 6,
|
||||||
} TL_TopMessage_t;
|
} TL_TopMessage_t;
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
TL_TIMELINE_USR, // Show the timeline of a user
|
||||||
|
TL_TIMELINE_GBL, // Show the timeline of the users follwed by me
|
||||||
|
} TL_UsrOrGbl_t;
|
||||||
|
|
||||||
|
#define TL_NUM_WHAT_TO_GET 3
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
TL_GET_ONLY_NEW_PUBS, // New publications are retrieved via AJAX
|
||||||
|
// automatically from time to time
|
||||||
|
TL_GET_RECENT_TIMELINE, // Recent timeline is shown when the user clicks on action menu,...
|
||||||
|
// or after editing timeline
|
||||||
|
TL_GET_ONLY_OLD_PUBS, // Old publications are retrieved via AJAX
|
||||||
|
// when the user clicks on link at bottom of timeline
|
||||||
|
} TL_WhatToGet_t;
|
||||||
|
|
||||||
struct TL_Timeline
|
struct TL_Timeline
|
||||||
{
|
{
|
||||||
|
TL_UsrOrGbl_t UsrOrGbl;
|
||||||
Usr_Who_t Who;
|
Usr_Who_t Who;
|
||||||
|
TL_WhatToGet_t WhatToGet;
|
||||||
long NotCod; // Used as parameter about social note to be edited, removed...
|
long NotCod; // Used as parameter about social note to be edited, removed...
|
||||||
long PubCod; // Used as parameter about social publishing to be edited, removed...
|
long PubCod; // Used as parameter about social publishing to be edited, removed...
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue
Block a user