Version 20.39.11: Mar 02, 2021 Code refactoring in fav/share timeline.

This commit is contained in:
acanas 2021-03-02 20:36:20 +01:00
parent 60be159d57
commit a83e87d750
10 changed files with 84 additions and 142 deletions

View File

@ -598,10 +598,11 @@ 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
*/
#define Log_PLATFORM_VERSION "SWAD 20.39.10 (2021-03-02)"
#define Log_PLATFORM_VERSION "SWAD 20.39.11 (2021-03-02)"
#define CSS_FILE "swad20.33.9.css"
#define JS_FILE "swad20.6.2.js"
/*
Version 20.39.11: Mar 02, 2021 Code refactoring in fav/share timeline. (305525 lines)
Version 20.39.10: Mar 02, 2021 Code refactoring in timeline. (305576 lines)
Version 20.39.9: Mar 02, 2021 Code refactoring in timeline. (305580 lines)
Version 20.39.8: Mar 02, 2021 Code refactoring in timeline. (305573 lines)

View File

@ -46594,27 +46594,6 @@ const char *Txt_The_centre_X_has_been_renamed_as_Y = // Warning: it is very impo
"O centro <strong>%s</strong> foi renomeado como <strong>%s</strong>.";
#endif
const char *Txt_The_comment_no_longer_exists =
#if L==1 // ca
"El comentari ja no existeix.";
#elif L==2 // de
"Der Kommentar nicht mehr existiert.";
#elif L==3 // en
"The comment no longer exists.";
#elif L==4 // es
"El comentario ya no existe.";
#elif L==5 // fr
"Le commentaire a disparu.";
#elif L==6 // gn
"El comentario ya no existe."; // Okoteve traducción
#elif L==7 // it
"Il commento non esiste pi&ugrave;.";
#elif L==8 // pl
"Komentarz ju&zdot; nie istnieje.";
#elif L==9 // pt
"O coment&aacute;rio n&atilde;o existe mais.";
#endif
const char *Txt_The_configuration_of_the_projects_has_been_updated =
#if L==1 // ca
"La configuraci&oacute; dels projectes s'ha actualitzat.";
@ -49660,25 +49639,25 @@ const char *Txt_The_photo_no_longer_exists =
"La foto n&atilde;o existe mais.";
#endif
const char *Txt_The_original_post_no_longer_exists =
const char *Txt_The_post_no_longer_exists =
#if L==1 // ca
"La publicaci&oacute; original ja no existeix.";
"La publicaci&oacute; ja no existeix.";
#elif L==2 // de
"Der urspr&uuml;ngliche Post nicht mehr existiert.";
"Der Post nicht mehr existiert.";
#elif L==3 // en
"The original post no longer exists.";
"The post no longer exists.";
#elif L==4 // es
"La publicaci&oacute;n original ya no existe.";
"La publicaci&oacute;n ya no existe.";
#elif L==5 // fr
"Le post original a disparu.";
"Le post a disparu.";
#elif L==6 // gn
"La publicaci&oacute;n original ya no existe."; // Okoteve traducción
"La publicaci&oacute;n ya no existe."; // Okoteve traducción
#elif L==7 // it
"La pubblicazione originale non esiste pi&ugrave;.";
"La pubblicazione non esiste pi&ugrave;.";
#elif L==8 // pl
"Oryginalna publikacja ju&zdot; nie istnieje.";
"Publikacja ju&zdot; nie istnieje.";
#elif L==9 // pt
"A publica&ccedil;&atilde;o original n&atilde;o existe mais.";
"A publica&ccedil;&atilde;o n&atilde;o existe mais.";
#endif
const char *Txt_The_password_can_not_consist_only_of_digits =

View File

@ -726,7 +726,7 @@ void TL_Com_ReceiveCommGbl (void)
static long TL_Com_ReceiveComm (void)
{
extern const char *Txt_The_original_post_no_longer_exists;
extern const char *Txt_The_post_no_longer_exists;
struct TL_Pst_PostContent Content;
struct TL_Not_Note Not;
struct TL_Pub_Publication Pub;
@ -738,7 +738,7 @@ static long TL_Com_ReceiveComm (void)
/***** Trivial check: note code *****/
if (Not.NotCod <= 0)
{
Ale_ShowAlert (Ale_WARNING,Txt_The_original_post_no_longer_exists);
Ale_ShowAlert (Ale_WARNING,Txt_The_post_no_longer_exists);
return -1L;
}
@ -831,7 +831,7 @@ void TL_Com_RequestRemComGbl (void)
static void TL_Com_RequestRemovalComm (struct TL_Timeline *Timeline)
{
extern const char *Txt_The_comment_no_longer_exists;
extern const char *Txt_The_post_no_longer_exists;
extern const char *Txt_Do_you_really_want_to_remove_the_following_comment;
struct TL_Com_Comment Com;
@ -846,7 +846,7 @@ static void TL_Com_RequestRemovalComm (struct TL_Timeline *Timeline)
if (Com.PubCod <= 0)
{
Med_MediaDestructor (&Com.Content.Media);
Ale_ShowAlert (Ale_WARNING,Txt_The_comment_no_longer_exists);
Ale_ShowAlert (Ale_WARNING,Txt_The_post_no_longer_exists);
return;
}
@ -950,7 +950,7 @@ void TL_Com_RemoveComGbl (void)
static void TL_Com_RemoveComm (void)
{
extern const char *Txt_The_comment_no_longer_exists;
extern const char *Txt_The_post_no_longer_exists;
extern const char *Txt_Comment_removed;
struct TL_Com_Comment Com;
@ -965,7 +965,7 @@ static void TL_Com_RemoveComm (void)
if (Com.PubCod <= 0)
{
Med_MediaDestructor (&Com.Content.Media);
Ale_ShowAlert (Ale_WARNING,Txt_The_comment_no_longer_exists);
Ale_ShowAlert (Ale_WARNING,Txt_The_post_no_longer_exists);
return;
}
@ -1094,42 +1094,3 @@ static void TL_Com_ResetComm (struct TL_Com_Comment *Com)
Com->Content.Txt[0] = '\0';
Com->NumFavs = 0;
}
/*****************************************************************************/
/******************* Check if I can fav/share a comment **********************/
/*****************************************************************************/
bool TL_Com_CheckICanFavShaComm (struct TL_Com_Comment *Com)
{
extern const char *Txt_The_comment_no_longer_exists;
/***** Get data of comment *****/
Com->PubCod = TL_Pub_GetParamPubCod ();
TL_Com_GetDataOfCommByCod (Com);
/***** Trivial check 1: publication code should be > 0 *****/
if (Com->PubCod <= 0)
{
Med_MediaDestructor (&Com->Content.Media);
Ale_ShowAlert (Ale_WARNING,Txt_The_comment_no_longer_exists);
return false;
}
/***** Trivial check 2: I must be logged *****/
if (!Gbl.Usrs.Me.Logged)
{
Med_MediaDestructor (&Com->Content.Media);
Ale_ShowAlert (Ale_ERROR,"You are not logged.");
return false;
}
/***** Trivial check 3: The author can not fav his/her own comments *****/
if (Usr_ItsMe (Com->UsrCod))
{
Med_MediaDestructor (&Com->Content.Media);
Ale_ShowAlert (Ale_ERROR,"You can not fav/unfav your own comments.");
return false;
}
return true;
}

View File

@ -77,6 +77,4 @@ void TL_Com_RemoveCommMediaAndDBEntries (long PubCod);
void TL_Com_GetDataOfCommByCod (struct TL_Com_Comment *Com);
bool TL_Com_CheckICanFavShaComm (struct TL_Com_Comment *Com);
#endif

View File

@ -145,13 +145,16 @@ static void TL_Fav_FavNote (struct TL_Not_Note *Not)
{
long OriginalPubCod;
/***** Get data of note and do some checks *****/
if (!TL_Not_CheckICanFavShaNote (Not))
/***** Get data of note *****/
Not->NotCod = TL_Not_GetParamNotCod ();
TL_Not_GetDataOfNoteByCod (Not);
/***** Do some checks *****/
if (!TL_Usr_CheckICanFavSha (Not->NotCod,Not->UsrCod))
return;
/***** Trivial check: Have I faved this note? *****/
if (TL_DB_CheckIfFavedByUsr (TL_Fav_NOTE,Not->NotCod,Gbl.Usrs.Me.UsrDat.UsrCod))
// Don't show error message
return;
/***** Mark note as favourite in database *****/
@ -173,13 +176,16 @@ static void TL_Fav_UnfNote (struct TL_Not_Note *Not)
{
long OriginalPubCod;
/***** Get data of note and do some checks *****/
if (!TL_Not_CheckICanFavShaNote (Not))
/***** Get data of note *****/
Not->NotCod = TL_Not_GetParamNotCod ();
TL_Not_GetDataOfNoteByCod (Not);
/***** Do some checks *****/
if (!TL_Usr_CheckICanFavSha (Not->NotCod,Not->UsrCod))
return;
/***** Trivial check: Have I faved this note? *****/
if (!TL_DB_CheckIfFavedByUsr (TL_Fav_NOTE,Not->NotCod,Gbl.Usrs.Me.UsrDat.UsrCod))
// Don't show error message
return;
/***** Delete the mark as favourite from database *****/
@ -270,8 +276,12 @@ static void TL_Fav_FavComm (struct TL_Com_Comment *Com)
/***** Initialize image *****/
Med_MediaConstructor (&Com->Content.Media);
/***** Get data of comment and do some checks *****/
if (!TL_Com_CheckICanFavShaComm (Com))
/***** Get data of comment *****/
Com->PubCod = TL_Pub_GetParamPubCod ();
TL_Com_GetDataOfCommByCod (Com);
/***** Do some checks *****/
if (!TL_Usr_CheckICanFavSha (Com->PubCod,Com->UsrCod))
{
Med_MediaDestructor (&Com->Content.Media);
return;
@ -282,7 +292,6 @@ static void TL_Fav_FavComm (struct TL_Com_Comment *Com)
Gbl.Usrs.Me.UsrDat.UsrCod))
{
Med_MediaDestructor (&Com->Content.Media);
// Don't show error message
return;
}
@ -307,8 +316,12 @@ static void TL_Fav_UnfComm (struct TL_Com_Comment *Com)
/***** Initialize image *****/
Med_MediaConstructor (&Com->Content.Media);
/***** Get data of comment and do some checks *****/
if (!TL_Com_CheckICanFavShaComm (Com))
/***** Get data of comment *****/
Com->PubCod = TL_Pub_GetParamPubCod ();
TL_Com_GetDataOfCommByCod (Com);
/***** Do some checks *****/
if (!TL_Usr_CheckICanFavSha (Com->PubCod,Com->UsrCod))
{
Med_MediaDestructor (&Com->Content.Media);
return;
@ -319,7 +332,6 @@ static void TL_Fav_UnfComm (struct TL_Com_Comment *Com)
Gbl.Usrs.Me.UsrDat.UsrCod))
{
Med_MediaDestructor (&Com->Content.Media);
// Don't show error message
return;
}

View File

@ -1118,7 +1118,7 @@ void TL_Not_RequestRemNoteGbl (void)
static void TL_Not_RequestRemovalNote (struct TL_Timeline *Timeline)
{
extern const char *Txt_The_original_post_no_longer_exists;
extern const char *Txt_The_post_no_longer_exists;
extern const char *Txt_Do_you_really_want_to_remove_the_following_post;
struct TL_Not_Note Not;
@ -1129,7 +1129,7 @@ static void TL_Not_RequestRemovalNote (struct TL_Timeline *Timeline)
/***** Trivial check 1: note code should be > 0 *****/
if (Not.NotCod <= 0)
{
Ale_ShowAlert (Ale_WARNING,Txt_The_original_post_no_longer_exists);
Ale_ShowAlert (Ale_WARNING,Txt_The_post_no_longer_exists);
return;
}
@ -1223,7 +1223,7 @@ void TL_Not_RemoveNoteGbl (void)
static void TL_Not_RemoveNote (void)
{
extern const char *Txt_The_original_post_no_longer_exists;
extern const char *Txt_The_post_no_longer_exists;
extern const char *Txt_TIMELINE_Post_removed;
struct TL_Not_Note Not;
@ -1234,7 +1234,7 @@ static void TL_Not_RemoveNote (void)
/***** Trivial check 1: note code should be > 0 *****/
if (Not.NotCod <= 0)
{
Ale_ShowAlert (Ale_WARNING,Txt_The_original_post_no_longer_exists);
Ale_ShowAlert (Ale_WARNING,Txt_The_post_no_longer_exists);
return;
}
@ -1424,39 +1424,3 @@ void TL_Not_GetDataOfNoteByCod (struct TL_Not_Note *Not)
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
/*****************************************************************************/
/******************** Check if I can fav/share a note ************************/
/*****************************************************************************/
bool TL_Not_CheckICanFavShaNote (struct TL_Not_Note *Not)
{
extern const char *Txt_The_original_post_no_longer_exists;
/***** Get data of note *****/
Not->NotCod = TL_Not_GetParamNotCod ();
TL_Not_GetDataOfNoteByCod (Not);
/***** Trivial check 1: note code should be > 0 *****/
if (Not->NotCod <= 0)
{
Ale_ShowAlert (Ale_WARNING,Txt_The_original_post_no_longer_exists);
return false;
}
/***** Trivial check 2: I must be logged *****/
if (!Gbl.Usrs.Me.Logged)
{
Ale_ShowAlert (Ale_ERROR,"You are not logged.");
return false;
}
/***** Trivial check 3: The author can not unfav his/her own notes *****/
if (Usr_ItsMe (Not->UsrCod))
{
Ale_ShowAlert (Ale_ERROR,"You can not fav/share your own posts.");
return false;
}
return true;
}

View File

@ -113,6 +113,4 @@ void TL_Not_RemoveNoteGbl (void);
void TL_Not_GetDataOfNoteByCod (struct TL_Not_Note *Not);
bool TL_Not_CheckICanFavShaNote (struct TL_Not_Note *Not);
#endif

View File

@ -118,13 +118,16 @@ static void TL_Sha_ShaNote (struct TL_Not_Note *Not)
struct TL_Pub_Publication Pub;
long OriginalPubCod;
/***** Get data of note and do some checks *****/
if (!TL_Not_CheckICanFavShaNote (Not))
/***** Get data of note *****/
Not->NotCod = TL_Not_GetParamNotCod ();
TL_Not_GetDataOfNoteByCod (Not);
/***** Do some checks *****/
if (!TL_Usr_CheckICanFavSha (Not->NotCod,Not->UsrCod))
return;
/***** Trivial check: Is note already shared by me? *****/
if (TL_DB_CheckIfNoteIsSharedByUsr (Not->NotCod,Gbl.Usrs.Me.UsrDat.UsrCod))
// Don't show error message
return;
/***** Share (publish note in timeline) *****/
@ -172,13 +175,12 @@ static void TL_Sha_UnsNote (struct TL_Not_Note *Not)
{
long OriginalPubCod;
/***** Get data of note and do some checks *****/
if (!TL_Not_CheckICanFavShaNote (Not))
return;
/***** Get data of note *****/
Not->NotCod = TL_Not_GetParamNotCod ();
TL_Not_GetDataOfNoteByCod (Not);
/***** Trivial check: Is note already shared by me? *****/
if (!TL_DB_CheckIfNoteIsSharedByUsr (Not->NotCod,Gbl.Usrs.Me.UsrDat.UsrCod))
// Don't show error message
/***** Do some checks *****/
if (!TL_Usr_CheckICanFavSha (Not->NotCod,Not->UsrCod))
return;
/***** Delete publication from database *****/

View File

@ -162,3 +162,29 @@ void TL_Usr_ShowSharersOrFavers (MYSQL_RES **mysql_res,
/***** Free memory used for user's data *****/
Usr_UsrDataDestructor (&UsrDat);
}
/*****************************************************************************/
/***************** Check if I can fav/share a note/comment *******************/
/*****************************************************************************/
bool TL_Usr_CheckICanFavSha (long Cod,long UsrCod)
{
extern const char *Txt_The_post_no_longer_exists;
/***** Trivial check 1: note/comment code should be > 0 *****/
if (Cod <= 0)
{
Ale_ShowAlert (Ale_WARNING,Txt_The_post_no_longer_exists);
return false;
}
/***** Trivial check 2: I must be logged
I can not fav/share my own notes/comments *****/
if (!Gbl.Usrs.Me.Logged || Usr_ItsMe (UsrCod))
{
Lay_NoPermissionExit ();
return false; // Not reached
}
return true;
}

View File

@ -64,5 +64,6 @@ void TL_Usr_RemoveUsrContent (long UsrCod);
void TL_Usr_ShowNumSharersOrFavers (unsigned NumUsrs);
void TL_Usr_ShowSharersOrFavers (MYSQL_RES **mysql_res,
unsigned NumUsrs,unsigned NumFirstUsrs);
bool TL_Usr_CheckICanFavSha (long Cod,long UsrCod);
#endif