From 0cda171c2eb3cbd0b77477cd55cc3f0b55076352 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Ca=C3=B1as=20Vargas?= Date: Tue, 5 Jan 2016 21:30:10 +0100 Subject: [PATCH] Version 15.99 --- swad_changelog.h | 11 ++- swad_social.c | 216 +++++++++++++++++++++++++++++------------------ swad_text.c | 117 +++++++++++++++++++------ 3 files changed, 231 insertions(+), 113 deletions(-) diff --git a/swad_changelog.h b/swad_changelog.h index ac1996c04..b29cfa20d 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -113,18 +113,25 @@ // TODO: Forum SWAD should be always named "SWAD"? // TODO: Enable chat for guests? // TODO: Go to forum post (or at least to forum thread) from social timeline? - +// TODO: When a social publishing is removed, but it is shared, author should be warned about it +// TODO: Consider the possibility of remove all the publishing of a social note when the author removes it +/* +Escribir social note después de compartir, descompartir o eliminar como antes, completa arriba y siempre tras el mensaje, +excepto cuando se elimina del todo tras descompartir/eliminar, sólo en ese caso no pintar nada. +En definitiva, se estará pintando simplemente una copia arriba de lo que hay más abajo en el timeline. +*/ /*****************************************************************************/ /****************************** Public constants *****************************/ /*****************************************************************************/ -#define Log_PLATFORM_VERSION "SWAD 15.98 (2016-01-05)" +#define Log_PLATFORM_VERSION "SWAD 15.99 (2016-01-05)" #define CSS_FILE "swad15.97.css" #define JS_FILE "swad15.77.7.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.99: Jan 05, 2016 Changes in social timeline. (190892 lines) Version 15.98: Jan 05, 2016 If a social note is unavailable and is shared, put button to unshare. Several bugs in social timeline fixed. (190789 lines) Version 15.97.5: Jan 04, 2016 Button to remove a social note is not shown if author already removed the note (but it yet exists because another user shared it). (190763 lines) diff --git a/swad_social.c b/swad_social.c index 5b20bd12d..a3ecacbb6 100644 --- a/swad_social.c +++ b/swad_social.c @@ -135,8 +135,9 @@ static void Soc_ShowTimeline (const char *Query,Act_Action_t UpdateAction, const char *Title); static void Soc_GetDataOfSocialPublishingFromRow (MYSQL_ROW row,struct SocialPublishing *SocPub); static void Soc_WriteSocialNote (const struct SocialPublishing *SocPub, - struct SocialNote *SocNot, - bool WritingTimeline,bool LastInList); + const struct SocialNote *SocNot, + bool ShowAlone, + bool LastInList); static void Soc_WriteNoteDate (time_t TimeUTC); static void Soc_GetAndWriteSocialPost (long PstCod); static void Soc_PutFormGoToAction (const struct SocialNote *SocNot); @@ -148,11 +149,13 @@ static void Soc_PutLinkToWriteANewPost (Act_Action_t Action,void (*FuncParams) ( static void Soc_FormSocialPost (void); static void Soc_ReceiveSocialPost (void); -static void Soc_PutDisabledIconShare (void); -static void Soc_PutFormToShareSocialNote (long PubCod); +static void Soc_PutDisabledIconShare (unsigned NumShared); +static void Soc_PutFormToShareSocialNote (long NotCod); static void Soc_PutFormToUnshareSocialPublishing (long PubCod); static void Soc_PutFormToRemoveSocialPublishing (long PubCod); +static void Soc_PutHiddenParamNotCod (long NotCod); static void Soc_PutHiddenParamPubCod (long PubCod); +static long Soc_GetParamNotCod (void); static long Soc_GetParamPubCod (void); static void Soc_ShareSocialNote (void); @@ -167,7 +170,7 @@ static void Soc_CheckAndDeleteASocialNoteFromDB (struct SocialNote *SocNot); static bool Soc_CheckIfNoteIsPublishedInTimelineByUsr (long NotCod,long UsrCod); static unsigned long Soc_GetNumPubsOfANote (long NotCod); -static void Soc_GetNumTimesANoteHasBeenShared (struct SocialNote *SocNot); +static void Soc_UpdateNumTimesANoteHasBeenShared (struct SocialNote *SocNot); static void Soc_ShowUsrsWhoHaveSharedSocialNote (const struct SocialNote *SocNot); static void Soc_GetDataOfSocialPublishingByCod (struct SocialPublishing *SocPub); static void Soc_GetDataOfSocialNoteByCod (struct SocialNote *SocNot); @@ -316,7 +319,7 @@ static void Soc_ShowTimeline (const char *Query,Act_Action_t UpdateAction, Soc_GetDataOfSocialNoteByCod (&SocNot); /* Write social note */ - Soc_WriteSocialNote (&SocPub,&SocNot,true,NumPub == NumPublishings - 1); + Soc_WriteSocialNote (&SocPub,&SocNot,false,NumPub == NumPublishings - 1); } /***** End list *****/ @@ -357,12 +360,11 @@ static void Soc_GetDataOfSocialPublishingFromRow (MYSQL_ROW row,struct SocialPub /*****************************************************************************/ /***************************** Write social note *****************************/ /*****************************************************************************/ -// Pointer SocNot is not const because the field Unavailable... -// ...can be marked as true inside this function static void Soc_WriteSocialNote (const struct SocialPublishing *SocPub, - struct SocialNote *SocNot, - bool WritingTimeline,bool LastInList) + const struct SocialNote *SocNot, + bool ShowAlone, // Social note is shown alone, not in a list + bool LastInList) // Social note is shown in a list and it's the last one { extern const char *Txt_Forum; extern const char *Txt_Course; @@ -381,9 +383,15 @@ static void Soc_WriteSocialNote (const struct SocialPublishing *SocPub, char ForumName[512]; char SummaryStr[Cns_MAX_BYTES_TEXT+1]; + if (ShowAlone) + { + Lay_StartRoundFrame (Soc_WIDTH_TIMELINE,NULL); + fprintf (Gbl.F.Out,""); + Lay_EndRoundFrame (); + } } /*****************************************************************************/ @@ -1132,9 +1143,11 @@ static void Soc_ReceiveSocialPost (void) /*********************** Put disabled icon to share **************************/ /*****************************************************************************/ -static void Soc_PutDisabledIconShare (void) +static void Soc_PutDisabledIconShare (unsigned NumShared) { - extern const char *Txt_SOCIAL_PUBLISHING_Shared; + extern const char *Txt_SOCIAL_PUBLISHING_Shared_by_X_USERS; + + sprintf (Gbl.Title,Txt_SOCIAL_PUBLISHING_Shared_by_X_USERS,NumShared); /***** Disabled icon to share *****/ fprintf (Gbl.F.Out,"
" @@ -1143,15 +1156,14 @@ static void Soc_PutDisabledIconShare (void) " class=\"ICON20x20\" />" "
", Gbl.Prefs.IconsURL, - Txt_SOCIAL_PUBLISHING_Shared, - Txt_SOCIAL_PUBLISHING_Shared); + Gbl.Title,Gbl.Title); } /*****************************************************************************/ /************************* Form to share social note *************************/ /*****************************************************************************/ -static void Soc_PutFormToShareSocialNote (long PubCod) +static void Soc_PutFormToShareSocialNote (long NotCod) { extern const char *Txt_Share; @@ -1163,7 +1175,7 @@ static void Soc_PutFormToShareSocialNote (long PubCod) } else Act_FormStart (ActShaSocNotGbl); - Soc_PutHiddenParamPubCod (PubCod); + Soc_PutHiddenParamNotCod (NotCod); fprintf (Gbl.F.Out,"
" " 0) @@ -1200,8 +1212,7 @@ static void Soc_PutFormToUnshareSocialPublishing (long PubCod) " class=\"ICON20x20\" />" "
", Gbl.Prefs.IconsURL, - Txt_SOCIAL_PUBLISHING_Shared, - Txt_SOCIAL_PUBLISHING_Shared); + Txt_Unshare,Txt_Unshare); Act_FormEnd (); } @@ -1234,6 +1245,15 @@ static void Soc_PutFormToRemoveSocialPublishing (long PubCod) Act_FormEnd (); } +/*****************************************************************************/ +/************** Put parameter with the code of a social note *****************/ +/*****************************************************************************/ + +static void Soc_PutHiddenParamNotCod (long NotCod) + { + Par_PutHiddenParamLong ("NotCod",NotCod); + } + /*****************************************************************************/ /*********** Put parameter with the code of a social publishing **************/ /*****************************************************************************/ @@ -1243,6 +1263,23 @@ static void Soc_PutHiddenParamPubCod (long PubCod) Par_PutHiddenParamLong ("PubCod",PubCod); } +/*****************************************************************************/ +/************** Get parameter with the code of a social note *****************/ +/*****************************************************************************/ + +static long Soc_GetParamNotCod (void) + { + char LongStr[1+10+1]; // String that holds the social note code + long NotCod; + + /* Get social note code */ + Par_GetParToText ("NotCod",LongStr,1+10); + if (sscanf (LongStr,"%ld",&NotCod) != 1) + Lay_ShowErrorAndExit ("Wrong code of social note."); + + return NotCod; + } + /*****************************************************************************/ /*********** Get parameter with the code of a social publishing **************/ /*****************************************************************************/ @@ -1303,13 +1340,9 @@ static void Soc_ShareSocialNote (void) bool IHavePublishedThisNote; /***** Get the code of the social publishing to unshare *****/ - SocPub.PubCod = Soc_GetParamPubCod (); - - /***** Get data of social publishing *****/ - Soc_GetDataOfSocialPublishingByCod (&SocPub); + SocPub.NotCod = Soc_GetParamNotCod (); /***** Get data of social note *****/ - SocNot.NotCod = SocPub.NotCod; Soc_GetDataOfSocialNoteByCod (&SocNot); ICanShare = (Gbl.Usrs.Me.Logged && @@ -1320,21 +1353,20 @@ static void Soc_ShareSocialNote (void) IHavePublishedThisNote = Soc_CheckIfNoteIsPublishedInTimelineByUsr (SocNot.NotCod,Gbl.Usrs.Me.UsrDat.UsrCod); if (!IHavePublishedThisNote) { - /***** Show the social note to be shared *****/ - Lay_StartRoundFrame (Soc_WIDTH_TIMELINE,NULL); - fprintf (Gbl.F.Out,""); - Lay_EndRoundFrame (); - /***** Share (publish social note in timeline) *****/ SocPub.AuthorCod = SocNot.UsrCod; SocPub.PublisherCod = Gbl.Usrs.Me.UsrDat.UsrCod; SocPub.NotCod = SocNot.NotCod; Soc_PublishSocialNoteInTimeline (&SocPub); // Set SocPub.PubCod + /* Update number of times this social note is shared */ + Soc_UpdateNumTimesANoteHasBeenShared (&SocNot); + /***** Message of success *****/ Lay_ShowAlert (Lay_SUCCESS,Txt_SOCIAL_PUBLISHING_Shared); + + /***** Show the social note just shared *****/ + Soc_WriteSocialNote (&SocPub,&SocNot,true,true); } } } @@ -1379,6 +1411,7 @@ static void Soc_UnshareSocialPublishing (void) struct SocialPublishing SocPub; struct SocialNote SocNot; bool ICanUnshare; + unsigned NumRemainingPubs; /***** Get the code of the social publishing to unshare *****/ SocPub.PubCod = Soc_GetParamPubCod (); @@ -1394,18 +1427,25 @@ static void Soc_UnshareSocialPublishing (void) SocPub.AuthorCod != Gbl.Usrs.Me.UsrDat.UsrCod); // I have shared the note if (ICanUnshare) { - /***** Show the social note to be unshared *****/ - Lay_StartRoundFrame (Soc_WIDTH_TIMELINE,NULL); - fprintf (Gbl.F.Out,""); - Lay_EndRoundFrame (); - /***** Delete social publishing from database *****/ Soc_UnshareASocialPublishingFromDB (&SocNot); + /***** Count number of remaining publishings *****/ + NumRemainingPubs = Soc_GetNumPubsOfANote (SocNot.NotCod); + /***** Message of success *****/ Lay_ShowAlert (Lay_SUCCESS,Txt_SOCIAL_PUBLISHING_Unshared); + + /***** Show the social note corresponding to the publishing + just unshared if it yet exists *****/ + if (NumRemainingPubs) + { + /* Update number of times this social note is shared */ + Soc_UpdateNumTimesANoteHasBeenShared (&SocNot); + + /* Show social note */ + Soc_WriteSocialNote (&SocPub,&SocNot,true,true); + } } } @@ -1490,6 +1530,13 @@ static void Soc_RequestRemovalSocialPublishing (void) { if (Soc_CheckIfNoteIsPublishedInTimelineByUsr (SocNot.NotCod,SocNot.UsrCod)) { + /***** Show warning and social note *****/ + /* Warning message */ + Lay_ShowAlert (Lay_WARNING,Txt_Do_you_really_want_to_remove_the_following_comment); + + /* Show social note */ + Soc_WriteSocialNote (&SocPub,&SocNot,true,true); + /***** Form to ask for confirmation to remove this social post *****/ /* Start form */ if (Gbl.Usrs.Other.UsrDat.UsrCod > 0) @@ -1501,16 +1548,6 @@ static void Soc_RequestRemovalSocialPublishing (void) Act_FormStart (ActRemSocPubGbl); Soc_PutHiddenParamPubCod (SocPub.PubCod); - /* Warning message */ - Lay_ShowAlert (Lay_WARNING,Txt_Do_you_really_want_to_remove_the_following_comment); - - /* Show social note */ - Lay_StartRoundFrame (Soc_WIDTH_TIMELINE,NULL); - fprintf (Gbl.F.Out,""); - Lay_EndRoundFrame (); - /* End form */ Lay_PutRemoveButton (Txt_Remove); Act_FormEnd (); @@ -1554,10 +1591,12 @@ void Soc_RemoveSocialPubUsr (void) static void Soc_RemoveSocialPublishing (void) { + extern const char *Txt_SOCIAL_PUBLISHING_Removed_but_shared_by_others; extern const char *Txt_SOCIAL_PUBLISHING_Removed; struct SocialPublishing SocPub; struct SocialNote SocNot; bool ICanRemove; + unsigned NumRemainingPubs; /***** Get the code of the social publishing to remove *****/ SocPub.PubCod = Soc_GetParamPubCod (); @@ -1573,18 +1612,27 @@ static void Soc_RemoveSocialPublishing (void) SocPub.PublisherCod == Gbl.Usrs.Me.UsrDat.UsrCod); if (ICanRemove) { - /***** Show the social note to be removed *****/ - Lay_StartRoundFrame (Soc_WIDTH_TIMELINE,NULL); - fprintf (Gbl.F.Out,""); - Lay_EndRoundFrame (); - /***** Delete social publishing from database *****/ Soc_RemoveASocialPublishingFromDB (&SocPub,&SocNot); + /***** Count number of remaining publishings *****/ + NumRemainingPubs = Soc_GetNumPubsOfANote (SocNot.NotCod); + /***** Message of success *****/ - Lay_ShowAlert (Lay_SUCCESS,Txt_SOCIAL_PUBLISHING_Removed); + Lay_ShowAlert (Lay_SUCCESS, + NumRemainingPubs ? Txt_SOCIAL_PUBLISHING_Removed_but_shared_by_others : + Txt_SOCIAL_PUBLISHING_Removed); + + /***** Show the social note corresponding to the publishing + just removed if it yet exists *****/ + if (NumRemainingPubs) + { + /* Update number of times this social note is shared */ + Soc_UpdateNumTimesANoteHasBeenShared (&SocNot); + + /* Show social note */ + Soc_WriteSocialNote (&SocPub,&SocNot,true,true); + } } } @@ -1685,7 +1733,7 @@ static unsigned long Soc_GetNumPubsOfANote (long NotCod) /******** Get number of times a note code has been shared in timeline ********/ /*****************************************************************************/ -static void Soc_GetNumTimesANoteHasBeenShared (struct SocialNote *SocNot) +static void Soc_UpdateNumTimesANoteHasBeenShared (struct SocialNote *SocNot) { char Query[128]; @@ -1821,7 +1869,7 @@ static void Soc_GetDataOfSocialNoteByCod (struct SocialNote *SocNot) Soc_GetDataOfSocialNoteFromRow (row,SocNot); /***** Get number of times this social note has been shared *****/ - Soc_GetNumTimesANoteHasBeenShared (SocNot); + Soc_UpdateNumTimesANoteHasBeenShared (SocNot); } else /***** Reset fields of social note *****/ diff --git a/swad_text.c b/swad_text.c index 2e73943f4..37436e5fb 100644 --- a/swad_text.c +++ b/swad_text.c @@ -35575,65 +35575,107 @@ const char *Txt_SOCIAL_NOTE[Soc_NUM_SOCIAL_NOTES] = const char *Txt_SOCIAL_PUBLISHING_Removed = #if L==1 - "Eliminat"; + "Eliminat."; #elif L==2 - "Entfernt"; + "Entfernt."; #elif L==3 - "Removed"; + "Removed."; #elif L==4 - "Eliminado"; + "Eliminado."; #elif L==5 - "Supprimé"; + "Supprimé."; #elif L==6 - "Eliminado"; // Okoteve traducción + "Eliminado."; // Okoteve traducción #elif L==7 - "Rimosso"; + "Rimosso."; #elif L==8 - "Usuniete"; + "Usuniete."; #elif L==9 - "Removido"; + "Removido."; +#endif + +const char *Txt_SOCIAL_PUBLISHING_Removed_but_shared_by_others = +#if L==1 + "Eliminat però encara compartit per altres."; +#elif L==2 + "Entfernt, sondern von anderen geteilt."; +#elif L==3 + "Removed but shared by others."; +#elif L==4 + "Eliminado pero aún compartido por otros."; +#elif L==5 + "Supprimé, mais partagé par d'autres."; +#elif L==6 + "Eliminado pero aún compartido por otros."; // Okoteve traducción +#elif L==7 + "Rimosso ma condiviso da altri."; +#elif L==8 + "Usuniete ale podzielają inni."; +#elif L==9 + "Removido mas compartilhado por outros."; #endif const char *Txt_SOCIAL_PUBLISHING_Shared = #if L==1 - "Compartit"; + "Compartit."; #elif L==2 - "Geteilt"; + "Geteilt."; #elif L==3 - "Shared"; + "Shared."; #elif L==4 - "Compartido"; + "Compartido."; #elif L==5 - "Partagé"; + "Partagé."; #elif L==6 - "Compartido"; // Okoteve traducción + "Compartido."; // Okoteve traducción #elif L==7 - "Condiviso"; + "Condiviso."; #elif L==8 - "Dzielone"; + "Dzielone."; #elif L==9 - "Compartilhado"; + "Compartilhado."; +#endif + +const char *Txt_SOCIAL_PUBLISHING_Shared_by_X_USERS = // Warning: it is very important to include %u in the following sentences +#if L==1 + "Compartit per %u"; +#elif L==2 + "Von %u geteilt"; +#elif L==3 + "Shared by %u"; +#elif L==4 + "Compartido por %u"; +#elif L==5 + "Partagé par %u"; +#elif L==6 + "Compartido por %u"; // Okoteve traducción +#elif L==7 + "Condiviso da %u"; +#elif L==8 + "Udostępnione przez %u"; +#elif L==9 + "Compartilhado por %u"; #endif const char *Txt_SOCIAL_PUBLISHING_Unshared = // No longer shared #if L==1 - "No compartit"; + "No compartit."; #elif L==2 - "Kein geteilt"; + "Kein geteilt."; #elif L==3 - "Unshared"; + "Unshared."; #elif L==4 - "No compartido"; + "No compartido."; #elif L==5 - "Non partagé"; + "Non partagé."; #elif L==6 - "No compartido"; // Okoteve traducción + "No compartido."; // Okoteve traducción #elif L==7 - "Non condiviso"; + "Non condiviso."; #elif L==8 - "Niedzieloną"; + "Niedzieloną."; #elif L==9 - "Não compartilhado"; + "Não compartilhado."; #endif const char *Txt_Sort_degrees_by = @@ -46870,6 +46912,27 @@ const char *Txt_Unread_BR_msgs = "Não
lidas"; #endif +const char *Txt_Unshare = +#if L==1 + "Compartir"; +#elif L==2 + "Teilen"; +#elif L==3 + "Unshare"; +#elif L==4 + "Dejar de compartir"; +#elif L==5 + "Arrêter le partage"; +#elif L==6 + "Dejar de compartir"; // Okoteve traducción +#elif L==7 + "Interrompere la condivisione"; +#elif L==8 + "Zatrzymaj udostępnianie"; +#elif L==9 + "Descompartilhar"; +#endif + const char *Txt_Update = #if L==1 "Actualitzar";