diff --git a/swad_changelog.h b/swad_changelog.h index 3bedf491..012a9854 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -122,13 +122,16 @@ /****************************** Public constants *****************************/ /*****************************************************************************/ -#define Log_PLATFORM_VERSION "SWAD 15.110.6 (2016-01-12)" +#define Log_PLATFORM_VERSION "SWAD 15.110.8 (2016-01-12)" #define CSS_FILE "swad15.110.2.css" #define JS_FILE "swad15.107.2.js" // Number of lines (includes comments but not blank lines) has been got with the following command: // nl swad*.c swad*.h css/swad*.css py/swad*.py js/swad*.js soap/swad*.h sql/swad*.sql | tail -1 /* + Version 15.110.8: Jan 12, 2016 Insert social notes in current social timeline in database. + Show old social notes only if they are not already shown in timeline. (192354 lines) + Version 15.110.7: Jan 12, 2016 Remove unused old social timelines in database. (192320 lines) Version 15.110.6: Jan 12, 2016 Social timeline for this session in database is cleared when timeline is reloaded. (192303 lines) Version 15.110.5: Jan 12, 2016 New database table used to store social notes already present in every timeline. (192288 lines) 1 change necessary in database: diff --git a/swad_session.c b/swad_session.c index ce7305ab..6723c42b 100644 --- a/swad_session.c +++ b/swad_session.c @@ -34,6 +34,7 @@ #include "swad_database.h" #include "swad_global.h" #include "swad_parameter.h" +#include "swad_social.h" /*****************************************************************************/ /**************************** Internal constants *****************************/ @@ -49,6 +50,8 @@ extern struct Globals Gbl; /***************************** Internal prototypes ***************************/ /*****************************************************************************/ +static void Ses_RemoveSessionFromDB (void); + static bool Ses_CheckIfHiddenParIsAlreadyInDB (Act_Action_t Action,const char *ParamName); /*****************************************************************************/ @@ -214,7 +217,7 @@ void Ses_UpdateSessionLastRefreshInDB (void) /********************** Remove session from the database *********************/ /*****************************************************************************/ -void Ses_RemoveSessionFromDB (void) +static void Ses_RemoveSessionFromDB (void) { char Query[512]; @@ -222,6 +225,10 @@ void Ses_RemoveSessionFromDB (void) sprintf (Query,"DELETE FROM sessions WHERE SessionId='%s'", Gbl.Session.Id); DB_QueryDELETE (Query,"can not remove a session"); + + /***** Clear old unused social timelines in database *****/ + // This is necessary to prevent the table growing and growing + Soc_ClearOldTimelinesDB (); } /*****************************************************************************/ diff --git a/swad_session.h b/swad_session.h index d55745b7..e4575fb8 100644 --- a/swad_session.h +++ b/swad_session.h @@ -49,7 +49,6 @@ void Ses_CloseSession (void); void Ses_InsertSessionInDB (void); void Ses_UpdateSessionDataInDB (void); void Ses_UpdateSessionLastRefreshInDB (void); -void Ses_RemoveSessionFromDB (void); void Ses_RemoveExpiredSessions (void); bool Ses_GetSessionData (void); void Ses_InsertHiddenParInDB (Act_Action_t Action,const char *ParamName,const char *ParamValue); diff --git a/swad_social.c b/swad_social.c index 4d3008c0..59413c68 100644 --- a/swad_social.c +++ b/swad_social.c @@ -277,6 +277,7 @@ static void Soc_ResetSocialComment (struct SocialComment *SocCom); static void Soc_SetUniqueId (char UniqueId[Soc_MAX_LENGTH_ID]); static void Soc_ClearTimelineForThisSession (void); +static bool Soc_StoreSocialNoteInTimeline (long NotCod); /*****************************************************************************/ /*********** Show social activity (timeline) of a selected user **************/ @@ -519,8 +520,9 @@ static void Soc_ShowTimeline (const char *Query,const char *Title) unsigned long NumPub; struct SocialPublishing SocPub; struct SocialNote SocNot; + bool AlreadyWasInTimeline; - /***** Clear timeline for this session in database *****/ + /***** Clear social timeline for this session in database *****/ Soc_ClearTimelineForThisSession (); /***** Get publishings from database *****/ @@ -557,9 +559,13 @@ static void Soc_ShowTimeline (const char *Query,const char *Title) SocNot.NotCod = SocPub.NotCod; Soc_GetDataOfSocialNoteByCod (&SocNot); + /* Add this social note to timeline */ + AlreadyWasInTimeline = Soc_StoreSocialNoteInTimeline (SocNot.NotCod); + /* Write social note */ - fprintf (Gbl.F.Out,"
  • PubCod %ld:
  • ",SocPub.PubCod); - Soc_WriteSocialNote (&SocNot,&SocPub,false,true); + if (!AlreadyWasInTimeline) + // fprintf (Gbl.F.Out,"
  • PubCod %ld:
  • ",SocPub.PubCod); + Soc_WriteSocialNote (&SocNot,&SocPub,false,true); } fprintf (Gbl.F.Out,""); @@ -613,8 +619,12 @@ static void Soc_ShowNewPubsInTimeline (const char *Query) SocNot.NotCod = SocPub.NotCod; Soc_GetDataOfSocialNoteByCod (&SocNot); + /* Add this social note to timeline */ + Soc_StoreSocialNoteInTimeline (SocNot.NotCod); + /* Write social note */ - fprintf (Gbl.F.Out,"
  • PubCod %ld:
  • ",SocPub.PubCod); + // New publishings are written even if the note was already un timeline + // fprintf (Gbl.F.Out,"
  • PubCod %ld:
  • ",SocPub.PubCod); Soc_WriteSocialNote (&SocNot,&SocPub,false,true); } @@ -635,6 +645,7 @@ static void Soc_ShowOldPubsInTimeline (const char *Query) unsigned long NumPub; struct SocialPublishing SocPub; struct SocialNote SocNot; + bool AlreadyWasInTimeline; /***** Get old publishings timeline from database *****/ NumPubsGot = DB_QuerySELECT (Query,&mysql_res,"can not get timeline"); @@ -654,9 +665,13 @@ static void Soc_ShowOldPubsInTimeline (const char *Query) SocNot.NotCod = SocPub.NotCod; Soc_GetDataOfSocialNoteByCod (&SocNot); + /* Add this social note to timeline */ + AlreadyWasInTimeline = Soc_StoreSocialNoteInTimeline (SocNot.NotCod); + /* Write social note */ - fprintf (Gbl.F.Out,"
  • PubCod %ld:
  • ",SocPub.PubCod); - Soc_WriteSocialNote (&SocNot,&SocPub,false,true); + if (!AlreadyWasInTimeline) + // fprintf (Gbl.F.Out,"
  • PubCod %ld:
  • ",SocPub.PubCod); + Soc_WriteSocialNote (&SocNot,&SocPub,false,true); } /***** Store first publishing code into session *****/ @@ -777,13 +792,18 @@ static void Soc_WriteSocialNote (const struct SocialNote *SocNot, /***** Write sharer if distinct to author *****/ if (!ShowNoteAlone && SocPub) - if (SocPub->PubType == Soc_PUB_SHARED_NOTE) - // && SocPub->PublisherCod != SocNot->UsrCod) + { + if (SocPub->PubType == Soc_PUB_SHARED_NOTE || + SocPub->PubType == Soc_PUB_COMMENT_TO_NOTE) { fprintf (Gbl.F.Out,"
    "); - fprintf (Gbl.F.Out,"Fulanito compartió."); // TODO: Need translation!!! + if (SocPub->PubType == Soc_PUB_SHARED_NOTE) + fprintf (Gbl.F.Out,"Fulanito ha compartido:"); // TODO: Need translation!!! + else + fprintf (Gbl.F.Out,"Fulanito ha comentado:"); // TODO: Need translation!!! fprintf (Gbl.F.Out,"
    "); } + } /***** Left: write author's photo *****/ fprintf (Gbl.F.Out,"
    "); @@ -1650,7 +1670,7 @@ static void Soc_WriteCommentsInSocialNote (long NotCod, Soc_GetDataOfSocialCommentFromRow (row,&SocCom); /* Write social comment */ - fprintf (Gbl.F.Out,"
  • PubCod %ld:
  • ",SocCom.ComCod); + // fprintf (Gbl.F.Out,"
  • PubCod %ld:
  • ",SocCom.ComCod); Soc_WriteSocialComment (&SocCom,false); } @@ -2983,16 +3003,49 @@ static void Soc_SetUniqueId (char UniqueId[Soc_MAX_LENGTH_ID]) ++CountForThisExecution); } +/*****************************************************************************/ +/**************** Clear unused old social timelines in database **************/ +/*****************************************************************************/ + +void Soc_ClearOldTimelinesDB (void) + { + char Query[256]; + + /***** Remove social timelines for expired sessions *****/ + sprintf (Query,"DELETE LOW_PRIORITY FROM social_timelines" + " WHERE SessionId NOT IN (SELECT SessionId FROM sessions)"); + DB_QueryDELETE (Query,"can not remove old social timelines"); + } + /*****************************************************************************/ /************* Clear social timeline for this session in database ************/ /*****************************************************************************/ static void Soc_ClearTimelineForThisSession (void) { - char Query[128]; + char Query[128+Ses_LENGTH_SESSION_ID]; /***** Remove social timeline for this session *****/ sprintf (Query,"DELETE FROM social_timelines WHERE SessionId='%s'", Gbl.Session.Id); DB_QueryDELETE (Query,"can not remove social timeline"); } + +/*****************************************************************************/ +/*** Check if this social note is present in timeline. If not ==> add it *****/ +/*****************************************************************************/ +// Returns true if social note already was in timeline before inserting it + +static bool Soc_StoreSocialNoteInTimeline (long NotCod) + { + char Query[128+Ses_LENGTH_SESSION_ID]; + bool AlreadyWasInTimeline; + + sprintf (Query,"INSERT IGNORE INTO social_timelines" + " (SessionId,NotCod) VALUES ('%s','%ld')", + Gbl.Session.Id,NotCod); + DB_QueryREPLACE (Query,"can not insert social note in timeline"); + AlreadyWasInTimeline = (mysql_affected_rows (&Gbl.mysql) == 0); + + return AlreadyWasInTimeline; + } diff --git a/swad_social.h b/swad_social.h index 3a1ca6d1..08c86678 100644 --- a/swad_social.h +++ b/swad_social.h @@ -125,4 +125,6 @@ void Soc_RemoveSocialComUsr (void); void Soc_RemoveUsrSocialContent (long UsrCod); +void Soc_ClearOldTimelinesDB (void); + #endif