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

This commit is contained in:
acanas 2021-03-02 13:45:56 +01:00
parent 7557901463
commit 3aab36a11b
12 changed files with 76 additions and 130 deletions

View File

@ -753,7 +753,7 @@ int swad__createAccount (struct soap *soap,
createAccountOut->wsKey[0] = '\0'; createAccountOut->wsKey[0] = '\0';
/***** Get plugin code *****/ /***** Get plugin code *****/
if ((ReturnCode = API_GetPlgCodFromAppKey (soap,(const char *) appKey)) != SOAP_OK) if ((ReturnCode = API_GetPlgCodFromAppKey (soap,appKey)) != SOAP_OK)
return ReturnCode; return ReturnCode;
/***** Check parameters used to create the new account *****/ /***** Check parameters used to create the new account *****/
@ -896,8 +896,7 @@ int swad__loginByUserPasswordKey (struct soap *soap,
loginByUserPasswordKeyOut->userRole = 0; // unknown loginByUserPasswordKeyOut->userRole = 0; // unknown
/***** Get plugin code *****/ /***** Get plugin code *****/
if ((ReturnCode = API_GetPlgCodFromAppKey (soap, if ((ReturnCode = API_GetPlgCodFromAppKey (soap,appKey)) != SOAP_OK)
(const char *) appKey)) != SOAP_OK)
return ReturnCode; return ReturnCode;
/***** Check if user's email, @nickname or ID are valid *****/ /***** Check if user's email, @nickname or ID are valid *****/
@ -1070,8 +1069,7 @@ int swad__loginBySessionKey (struct soap *soap,
loginBySessionKeyOut->courseName[0] = '\0'; loginBySessionKeyOut->courseName[0] = '\0';
/***** Get plugin code *****/ /***** Get plugin code *****/
if ((ReturnCode = API_GetPlgCodFromAppKey (soap, if ((ReturnCode = API_GetPlgCodFromAppKey (soap,appKey)) != SOAP_OK)
(const char *) appKey)) != SOAP_OK)
return ReturnCode; return ReturnCode;
/***** Check length of session identifier *****/ /***** Check length of session identifier *****/
@ -1254,8 +1252,7 @@ int swad__getNewPassword (struct soap *soap,
getNewPasswordOut->success = 0; // error getNewPasswordOut->success = 0; // error
/***** Get plugin code *****/ /***** Get plugin code *****/
if ((ReturnCode = API_GetPlgCodFromAppKey (soap, if ((ReturnCode = API_GetPlgCodFromAppKey (soap,appKey)) != SOAP_OK)
(const char *) appKey)) != SOAP_OK)
return ReturnCode; return ReturnCode;
/***** Check if user's email, @nickname or ID are valid *****/ /***** Check if user's email, @nickname or ID are valid *****/
@ -3365,7 +3362,7 @@ int swad__getNotifications (struct soap *soap,
getNotificationsOut->notificationsArray.__ptr[NumNotif].notifCode = (int) NtfCod; getNotificationsOut->notificationsArray.__ptr[NumNotif].notifCode = (int) NtfCod;
/* Get notification event type (row[1]) */ /* Get notification event type (row[1]) */
NotifyEvent = Ntf_GetNotifyEventFromStr ((const char *) row[1]); NotifyEvent = Ntf_GetNotifyEventFromStr (row[1]);
getNotificationsOut->notificationsArray.__ptr[NumNotif].eventType = getNotificationsOut->notificationsArray.__ptr[NumNotif].eventType =
soap_malloc (soap,Ntf_MAX_BYTES_NOTIFY_EVENT + 1); soap_malloc (soap,Ntf_MAX_BYTES_NOTIFY_EVENT + 1);
Str_Copy (getNotificationsOut->notificationsArray.__ptr[NumNotif].eventType, Str_Copy (getNotificationsOut->notificationsArray.__ptr[NumNotif].eventType,

View File

@ -87,7 +87,7 @@ void QR_PutLinkToPrintQRCode (Act_Action_t Action,
void QR_PutParamQRString (void *QRString) void QR_PutParamQRString (void *QRString)
{ {
Par_PutHiddenParamString (NULL,"QRString",(const char *) QRString); Par_PutHiddenParamString (NULL,"QRString",QRString);
} }
/*****************************************************************************/ /*****************************************************************************/

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: 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 TODO: Salvador Romero Cortés: @acanas opción para editar posts
*/ */
#define Log_PLATFORM_VERSION "SWAD 20.39.5 (2021-03-02)" #define Log_PLATFORM_VERSION "SWAD 20.39.6 (2021-03-02)"
#define CSS_FILE "swad20.33.9.css" #define CSS_FILE "swad20.33.9.css"
#define JS_FILE "swad20.6.2.js" #define JS_FILE "swad20.6.2.js"
/* /*
Version 20.39.6: Mar 02, 2021 Code refactoring in fav/share timeline notes. (305570 lines)
Version 20.39.5: Mar 02, 2021 Code refactoring in timeline notes and posts. (305620 lines) Version 20.39.5: Mar 02, 2021 Code refactoring in timeline notes and posts. (305620 lines)
Version 20.39.4: Mar 02, 2021 Code refactoring in timeline notes. (305614 lines) Version 20.39.4: Mar 02, 2021 Code refactoring in timeline notes. (305614 lines)
Version 20.39.3: Mar 02, 2021 Code refactoring in timeline favourites. (305601 lines) Version 20.39.3: Mar 02, 2021 Code refactoring in timeline favourites. (305601 lines)

View File

@ -405,7 +405,7 @@ void Ntf_ShowMyNotifications (void)
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
/* Get event type (row[0]) */ /* Get event type (row[0]) */
NotifyEvent = Ntf_GetNotifyEventFromStr ((const char *) row[0]); NotifyEvent = Ntf_GetNotifyEventFromStr (row[0]);
/* Get (from) user code (row[1]) */ /* Get (from) user code (row[1]) */
UsrDat.UsrCod = Str_ConvertStrCodToLongCod (row[1]); UsrDat.UsrCod = Str_ConvertStrCodToLongCod (row[1]);
@ -1653,7 +1653,7 @@ static void Ntf_SendPendingNotifByEMailToOneUsr (struct UsrData *ToUsrDat,unsign
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
/* Get event type (row[0]) */ /* Get event type (row[0]) */
NotifyEvent = Ntf_GetNotifyEventFromStr ((const char *) row[0]); NotifyEvent = Ntf_GetNotifyEventFromStr (row[0]);
/* Get origin user code (row[1]) */ /* Get origin user code (row[1]) */
FromUsrDat.UsrCod = Str_ConvertStrCodToLongCod (row[1]); FromUsrDat.UsrCod = Str_ConvertStrCodToLongCod (row[1]);

View File

@ -443,7 +443,7 @@ static void TL_ShowTimeline (struct TL_Timeline *Timeline,
if (GlobalTimeline) if (GlobalTimeline)
{ {
/* Link to view new publications via AJAX */ /* Link to view new publications via AJAX */
TL_Pub_PutLinkToViewNewPublications (); TL_Pub_PutLinkToViewNewPubs ();
/* Hidden list where insert /* Hidden list where insert
just received (not visible) publications via AJAX */ just received (not visible) publications via AJAX */
@ -486,7 +486,7 @@ static void TL_ShowTimeline (struct TL_Timeline *Timeline,
if (NumPubs == TL_Pub_MAX_REC_PUBS_TO_GET_AND_SHOW) if (NumPubs == TL_Pub_MAX_REC_PUBS_TO_GET_AND_SHOW)
{ {
/* Link to view old publications via AJAX */ /* Link to view old publications via AJAX */
TL_Pub_PutLinkToViewOldPublications (); TL_Pub_PutLinkToViewOldPubs ();
/* Hidden list where insert old publications via AJAX */ /* Hidden list where insert old publications via AJAX */
HTM_UL_Begin ("id=\"old_timeline_list\" class=\"TL_LIST\""); HTM_UL_Begin ("id=\"old_timeline_list\" class=\"TL_LIST\"");

View File

@ -143,37 +143,14 @@ void TL_Fav_UnfNoteGbl (void)
static void TL_Fav_FavNote (struct TL_Not_Note *Not) static void TL_Fav_FavNote (struct TL_Not_Note *Not)
{ {
extern const char *Txt_The_original_post_no_longer_exists;
long OriginalPubCod; long OriginalPubCod;
/***** Get data of note *****/ /***** Get data of note and do some checks *****/
Not->NotCod = TL_Not_GetParamNotCod (); if (!TL_Not_CheckICanFavShaNote (Not))
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; return;
}
/***** Trivial check 2: I must be logged *****/ /***** Trivial check: Have I faved this note? *****/
if (!Gbl.Usrs.Me.Logged) if (TL_DB_CheckIfFavedByUsr (TL_Fav_NOTE,Not->NotCod,Gbl.Usrs.Me.UsrDat.UsrCod))
{
Ale_ShowAlert (Ale_ERROR,"You are not logged.");
return;
}
/***** Trivial check 3: The author can not fav his/her own notes *****/
if (Usr_ItsMe (Not->UsrCod))
{
Ale_ShowAlert (Ale_ERROR,"You can not fav/unfav your own posts.");
return;
}
/***** Trivial check 4: Have I faved this note? *****/
if (TL_DB_CheckIfFavedByUsr (TL_Fav_NOTE,Not->NotCod,
Gbl.Usrs.Me.UsrDat.UsrCod))
// Don't show error message // Don't show error message
return; return;
@ -194,37 +171,14 @@ static void TL_Fav_FavNote (struct TL_Not_Note *Not)
static void TL_Fav_UnfNote (struct TL_Not_Note *Not) static void TL_Fav_UnfNote (struct TL_Not_Note *Not)
{ {
extern const char *Txt_The_original_post_no_longer_exists;
long OriginalPubCod; long OriginalPubCod;
/***** Get data of note *****/ /***** Get data of note and do some checks *****/
Not->NotCod = TL_Not_GetParamNotCod (); if (!TL_Not_CheckICanFavShaNote (Not))
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; return;
}
/***** Trivial check 2: I must be logged *****/ /***** Trivial check: Have I faved this note? *****/
if (!Gbl.Usrs.Me.Logged) if (!TL_DB_CheckIfFavedByUsr (TL_Fav_NOTE,Not->NotCod,Gbl.Usrs.Me.UsrDat.UsrCod))
{
Ale_ShowAlert (Ale_ERROR,"You are not logged.");
return;
}
/***** 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/unfav your own posts.");
return;
}
/***** Trivial check 4: Have I faved this note? *****/
if (!TL_DB_CheckIfFavedByUsr (TL_Fav_NOTE,Not->NotCod,
Gbl.Usrs.Me.UsrDat.UsrCod))
// Don't show error message // Don't show error message
return; return;

View File

@ -1337,7 +1337,7 @@ static void TL_Not_GetDataOfNoteFromRow (MYSQL_ROW row,struct TL_Not_Note *Not)
Not->NotCod = Str_ConvertStrCodToLongCod (row[0]); Not->NotCod = Str_ConvertStrCodToLongCod (row[0]);
/***** Get note type (row[1]) *****/ /***** Get note type (row[1]) *****/
Not->NoteType = TL_Not_GetNoteTypeFromStr ((const char *) row[1]); Not->NoteType = TL_Not_GetNoteTypeFromStr (row[1]);
/***** Get file/post... code (row[2]) *****/ /***** Get file/post... code (row[2]) *****/
Not->Cod = Str_ConvertStrCodToLongCod (row[2]); Not->Cod = Str_ConvertStrCodToLongCod (row[2]);
@ -1424,3 +1424,39 @@ void TL_Not_GetDataOfNoteByCod (struct TL_Not_Note *Not)
/***** Free structure that stores the query result *****/ /***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res); 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,4 +113,6 @@ void TL_Not_RemoveNoteGbl (void);
void TL_Not_GetDataOfNoteByCod (struct TL_Not_Note *Not); void TL_Not_GetDataOfNoteByCod (struct TL_Not_Note *Not);
bool TL_Not_CheckICanFavShaNote (struct TL_Not_Note *Not);
#endif #endif

View File

@ -121,7 +121,7 @@ void TL_Ntf_GetNotifPublication (char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1],
/***** Get summary and content from post from database *****/ /***** Get summary and content from post from database *****/
if (TL_DB_GetDataOfPubByCod (PubCod,&mysql_res) == 1) // Result should have a unique row if (TL_DB_GetDataOfPubByCod (PubCod,&mysql_res) == 1) // Result should have a unique row
/* Get data of publication from row */ /* Get data of publication from row */
TL_Pub_GetDataOfPublicationFromNextRow (mysql_res,&Pub); TL_Pub_GetDataOfPubFromNextRow (mysql_res,&Pub);
/***** Free structure that stores the query result *****/ /***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res); DB_FreeMySQLResult (&mysql_res);

View File

@ -313,7 +313,7 @@ static struct TL_Pub_Publication *TL_Pub_SelectTheMostRecentPub (const struct TL
Lay_NotEnoughMemoryExit (); Lay_NotEnoughMemoryExit ();
/* Get data of publication */ /* Get data of publication */
TL_Pub_GetDataOfPublicationFromNextRow (mysql_res,Pub); TL_Pub_GetDataOfPubFromNextRow (mysql_res,Pub);
Pub->Next = NULL; Pub->Next = NULL;
} }
else else
@ -402,7 +402,7 @@ TL_TopMessage_t TL_Pub_GetTopMessage (TL_Pub_PubType_t PubType)
/***************** Put link to view new publications in timeline *************/ /***************** Put link to view new publications in timeline *************/
/*****************************************************************************/ /*****************************************************************************/
void TL_Pub_PutLinkToViewNewPublications (void) void TL_Pub_PutLinkToViewNewPubs (void)
{ {
extern const char *The_ClassFormInBoxBold[The_NUM_THEMES]; extern const char *The_ClassFormInBoxBold[The_NUM_THEMES];
extern const char *Txt_See_new_activity; extern const char *Txt_See_new_activity;
@ -437,7 +437,7 @@ void TL_Pub_PutLinkToViewNewPublications (void)
/***************** Put link to view old publications in timeline *************/ /***************** Put link to view old publications in timeline *************/
/*****************************************************************************/ /*****************************************************************************/
void TL_Pub_PutLinkToViewOldPublications (void) void TL_Pub_PutLinkToViewOldPubs (void)
{ {
extern const char *The_ClassFormInBoxBold[The_NUM_THEMES]; extern const char *The_ClassFormInBoxBold[The_NUM_THEMES];
extern const char *Txt_See_more; extern const char *Txt_See_more;
@ -494,8 +494,8 @@ long TL_Pub_GetParamPubCod (void)
/***************** Get data of publication using its code ********************/ /***************** Get data of publication using its code ********************/
/*****************************************************************************/ /*****************************************************************************/
void TL_Pub_GetDataOfPublicationFromNextRow (MYSQL_RES *mysql_res, void TL_Pub_GetDataOfPubFromNextRow (MYSQL_RES *mysql_res,
struct TL_Pub_Publication *Pub) struct TL_Pub_Publication *Pub)
{ {
MYSQL_ROW row; MYSQL_ROW row;
@ -518,7 +518,7 @@ void TL_Pub_GetDataOfPublicationFromNextRow (MYSQL_RES *mysql_res,
Pub->PublisherCod = Str_ConvertStrCodToLongCod (row[2]); Pub->PublisherCod = Str_ConvertStrCodToLongCod (row[2]);
/***** Get type of publication (row[3]) *****/ /***** Get type of publication (row[3]) *****/
Pub->PubType = TL_Pub_GetPubTypeFromStr ((const char *) row[3]); Pub->PubType = TL_Pub_GetPubTypeFromStr (row[3]);
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -93,14 +93,14 @@ void TL_Pub_ShowOldPubsInTimeline (struct TL_Timeline *Timeline);
TL_TopMessage_t TL_Pub_GetTopMessage (TL_Pub_PubType_t PubType); TL_TopMessage_t TL_Pub_GetTopMessage (TL_Pub_PubType_t PubType);
void TL_Pub_PutLinkToViewNewPublications (void); void TL_Pub_PutLinkToViewNewPubs (void);
void TL_Pub_PutLinkToViewOldPublications (void); void TL_Pub_PutLinkToViewOldPubs (void);
void TL_Pub_PutHiddenParamPubCod (long PubCod); void TL_Pub_PutHiddenParamPubCod (long PubCod);
long TL_Pub_GetParamPubCod (void); long TL_Pub_GetParamPubCod (void);
void TL_Pub_GetDataOfPublicationFromNextRow (MYSQL_RES *mysql_res, void TL_Pub_GetDataOfPubFromNextRow (MYSQL_RES *mysql_res,
struct TL_Pub_Publication *Pub); struct TL_Pub_Publication *Pub);
void TL_Pub_PublishPubInTimeline (struct TL_Pub_Publication *Pub); void TL_Pub_PublishPubInTimeline (struct TL_Pub_Publication *Pub);

View File

@ -115,36 +115,14 @@ void TL_Sha_ShaNoteGbl (void)
static void TL_Sha_ShaNote (struct TL_Not_Note *Not) static void TL_Sha_ShaNote (struct TL_Not_Note *Not)
{ {
extern const char *Txt_The_original_post_no_longer_exists;
struct TL_Pub_Publication Pub; struct TL_Pub_Publication Pub;
long OriginalPubCod; long OriginalPubCod;
/***** Get data of note *****/ /***** Get data of note and do some checks *****/
Not->NotCod = TL_Not_GetParamNotCod (); if (!TL_Not_CheckICanFavShaNote (Not))
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; return;
}
/***** Trivial check 2: Am I logged? *****/ /***** Trivial check: Is note already shared by me? *****/
if (!Gbl.Usrs.Me.Logged)
{
Ale_ShowAlert (Ale_ERROR,"You are not logged.");
return;
}
/***** Trivial check 3: Am I the author? *****/
if (Usr_ItsMe (Not->UsrCod))
{
Ale_ShowAlert (Ale_ERROR,"You can not share/unshare your own posts.");
return;
}
/***** Trivial check 4: Is note already shared by me? *****/
if (TL_DB_CheckIfNoteIsSharedByUsr (Not->NotCod,Gbl.Usrs.Me.UsrDat.UsrCod)) if (TL_DB_CheckIfNoteIsSharedByUsr (Not->NotCod,Gbl.Usrs.Me.UsrDat.UsrCod))
// Don't show error message // Don't show error message
return; return;
@ -192,35 +170,13 @@ void TL_Sha_UnsNoteGbl (void)
static void TL_Sha_UnsNote (struct TL_Not_Note *Not) static void TL_Sha_UnsNote (struct TL_Not_Note *Not)
{ {
extern const char *Txt_The_original_post_no_longer_exists;
long OriginalPubCod; long OriginalPubCod;
/***** Get data of note *****/ /***** Get data of note and do some checks *****/
Not->NotCod = TL_Not_GetParamNotCod (); if (!TL_Not_CheckICanFavShaNote (Not))
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; return;
}
/***** Trivial check 2: Am I logged? *****/ /***** Trivial check: Is note already shared by me? *****/
if (!Gbl.Usrs.Me.Logged)
{
Ale_ShowAlert (Ale_ERROR,"You are not logged.");
return;
}
/***** Trivial check 3: Am I the author? *****/
if (Usr_ItsMe (Not->UsrCod))
{
Ale_ShowAlert (Ale_ERROR,"You can not share/unshare your own posts.");
return;
}
/***** Trivial check 4: Is note already shared by me? *****/
if (!TL_DB_CheckIfNoteIsSharedByUsr (Not->NotCod,Gbl.Usrs.Me.UsrDat.UsrCod)) if (!TL_DB_CheckIfNoteIsSharedByUsr (Not->NotCod,Gbl.Usrs.Me.UsrDat.UsrCod))
// Don't show error message // Don't show error message
return; return;