Version 20.37: Mar 01, 2021 Code refactoring and more error messages in timeline.

This commit is contained in:
acanas 2021-03-01 22:31:56 +01:00
parent 13aabae16b
commit a700a3512a
6 changed files with 458 additions and 282 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.36.49 (2021-03-01)"
#define Log_PLATFORM_VERSION "SWAD 20.37 (2021-03-01)"
#define CSS_FILE "swad20.33.9.css"
#define JS_FILE "swad20.6.2.js"
/*
Version 20.37: Mar 01, 2021 Code refactoring and more error messages in timeline. (305681 lines)
Version 20.36.49: Mar 01, 2021 Cleaning unused header files in timeline modules. (305544 lines)
Version 20.36.48: Mar 01, 2021 Query moved to module swad_timeline_database. (305553 lines)
Version 20.36.47: Mar 01, 2021 Query moved to module swad_timeline_database. (305543 lines)

View File

@ -476,13 +476,18 @@ static void TL_Com_CheckAndWriteComment (const struct TL_Timeline *Timeline,
| | Favs |Remove| > buttons |
|________|___________________________|______| / /
*/
if (Com->PubCod > 0 &&
Com->NotCod > 0 &&
Com->UsrCod > 0)
/***** Trivial check: codes *****/
if (Com->PubCod <= 0 ||
Com->NotCod <= 0 ||
Com->UsrCod <= 0)
{
Ale_ShowAlert (Ale_ERROR,"Error in comment.");
return;
}
/***** Write comment *****/
TL_Com_WriteComment (Timeline,Com);
else
Ale_ShowAlert (Ale_ERROR,"Error in comment.");
}
/*****************************************************************************/
@ -696,8 +701,13 @@ static long TL_Com_ReceiveComment (void)
Not.NotCod = TL_Not_GetParamNotCod ();
TL_Not_GetDataOfNoteByCod (&Not);
if (Not.NotCod > 0)
/***** Trivial check: note code *****/
if (Not.NotCod <= 0)
{
Ale_ShowAlert (Ale_WARNING,Txt_The_original_post_no_longer_exists);
return -1L;
}
/***** Get the content of the comment *****/
Par_GetParAndChangeFormat ("Txt",Content.Txt,Cns_MAX_BYTES_LONG_TEXT,
Str_TO_RIGOROUS_HTML,true);
@ -737,9 +747,6 @@ static long TL_Com_ReceiveComment (void)
/***** Free image *****/
Med_MediaDestructor (&Content.Media);
}
else
Ale_ShowAlert (Ale_WARNING,Txt_The_original_post_no_longer_exists);
return Not.NotCod;
}
@ -794,17 +801,29 @@ static void TL_Com_RequestRemovalComment (struct TL_Timeline *Timeline)
extern const char *Txt_Do_you_really_want_to_remove_the_following_comment;
struct TL_Com_Comment Com;
/***** Initialize image *****/
/***** Initialize media *****/
Med_MediaConstructor (&Com.Content.Media);
/***** Get data of comment *****/
Com.PubCod = TL_Pub_GetParamPubCod ();
TL_Com_GetDataOfCommByCod (&Com);
if (Com.PubCod > 0)
/***** Trivial check 1: publication code *****/
if (Com.PubCod <= 0)
{
if (Usr_ItsMe (Com.UsrCod)) // I am the author of this comment
Med_MediaDestructor (&Com.Content.Media);
Ale_ShowAlert (Ale_WARNING,Txt_The_comment_no_longer_exists);
return;
}
/***** Trivial check 2: only if I am the author of this comment *****/
if (!Usr_ItsMe (Com.UsrCod))
{
Med_MediaDestructor (&Com.Content.Media);
Ale_ShowAlert (Ale_ERROR,"You are not the author.");
return;
}
/***** Show question and button to remove comment *****/
/* Begin alert */
TL_Frm_BeginAlertRemove (Txt_Do_you_really_want_to_remove_the_following_comment);
@ -827,12 +846,8 @@ static void TL_Com_RequestRemovalComment (struct TL_Timeline *Timeline)
Timeline->PubCod = Com.PubCod; // Publication to be removed
TL_Frm_EndAlertRemove (Timeline,TL_Frm_REM_COMM,
TL_Com_PutParamsRemoveComment);
}
}
else
Ale_ShowAlert (Ale_WARNING,Txt_The_comment_no_longer_exists);
/***** Free image *****/
/***** Free media *****/
Med_MediaDestructor (&Com.Content.Media);
}
@ -902,34 +917,42 @@ static void TL_Com_RemoveComment (void)
extern const char *Txt_Comment_removed;
struct TL_Com_Comment Com;
/***** Initialize image *****/
/***** Initialize media *****/
Med_MediaConstructor (&Com.Content.Media);
/***** Get data of comment *****/
Com.PubCod = TL_Pub_GetParamPubCod ();
TL_Com_GetDataOfCommByCod (&Com);
if (Com.PubCod > 0)
/***** Trivial check 1: publication code *****/
if (Com.PubCod <= 0)
{
if (Usr_ItsMe (Com.UsrCod)) // I am the author of this comment
Med_MediaDestructor (&Com.Content.Media);
Ale_ShowAlert (Ale_WARNING,Txt_The_comment_no_longer_exists);
return;
}
/***** Trivial check 2: only if I am the author of this comment *****/
if (!Usr_ItsMe (Com.UsrCod))
{
Med_MediaDestructor (&Com.Content.Media);
Ale_ShowAlert (Ale_ERROR,"You are not the author.");
return;
}
/***** Remove media associated to comment
and delete comment from database *****/
TL_Com_RemoveCommentMediaAndDBEntries (Com.PubCod);
/***** Free media *****/
Med_MediaDestructor (&Com.Content.Media);
/***** Reset fields of comment *****/
TL_Com_ResetComment (&Com);
/***** Message of success *****/
Ale_ShowAlert (Ale_SUCCESS,Txt_Comment_removed);
}
}
else
Ale_ShowAlert (Ale_WARNING,Txt_The_comment_no_longer_exists);
/***** Free image *****/
Med_MediaDestructor (&Com.Content.Media);
}
/*****************************************************************************/
/*************** Remove comment media and database entries *******************/
@ -964,8 +987,14 @@ void TL_Com_GetDataOfCommByCod (struct TL_Com_Comment *Com)
MYSQL_RES *mysql_res;
MYSQL_ROW row;
if (Com->PubCod > 0)
/***** Trivial check: publication code should be > 0 *****/
if (Com->PubCod <= 0)
{
/***** Reset fields of comment *****/
TL_Com_ResetComment (Com);
return;
}
/***** Get data of comment from database *****/
if (TL_DB_GetDataOfCommByCod (Com->PubCod,&mysql_res))
{
@ -980,10 +1009,6 @@ void TL_Com_GetDataOfCommByCod (struct TL_Com_Comment *Com)
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
else
/***** Reset fields of comment *****/
TL_Com_ResetComment (Com);
}
/*****************************************************************************/
/********************** Get data of comment from row *************************/

View File

@ -70,7 +70,7 @@ extern struct Globals Gbl;
/***************************** Private prototypes ****************************/
/*****************************************************************************/
static long TL_DB_GetMedCodFromPub (long PubCod,const char *DBTable);
static long TL_DB_GetMedCod (const char *Table,const char *Field,long Cod);
/*****************************************************************************/
/********************* Get which users to show in timeline *******************/
@ -409,9 +409,9 @@ unsigned TL_DB_GetPostByCod (long PstCod,MYSQL_RES **mysql_res)
/***************** Get code of media associated to post **********************/
/*****************************************************************************/
long TL_DB_GetMedCodFromPost (long PubCod)
long TL_DB_GetMedCodFromPost (long PstCod)
{
return TL_DB_GetMedCodFromPub (PubCod,"tl_posts");
return TL_DB_GetMedCod ("tl_posts","PstCod",PstCod);
}
/*****************************************************************************/
@ -597,7 +597,7 @@ void TL_DB_InsertCommentContent (long PubCod,
long TL_DB_GetMedCodFromComment (long PubCod)
{
return TL_DB_GetMedCodFromPub (PubCod,"tl_comments");
return TL_DB_GetMedCod ("tl_comments","PubCod",PubCod);
}
/*****************************************************************************/
@ -680,7 +680,7 @@ void TL_DB_RemoveAllCommentsMadeBy (long UsrCod)
/*************** Get code of media associated to post/comment ****************/
/*****************************************************************************/
static long TL_DB_GetMedCodFromPub (long PubCod,const char *DBTable)
static long TL_DB_GetMedCod (const char *Table,const char *Field,long Cod)
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
@ -690,8 +690,8 @@ static long TL_DB_GetMedCodFromPub (long PubCod,const char *DBTable)
if (DB_QuerySELECT (&mysql_res,"can not get media code",
"SELECT MedCod" // row[0]
" FROM %s"
" WHERE PubCod=%ld",
DBTable,PubCod) == 1) // Result should have a unique row
" WHERE %s=%ld",
Table,Field,Cod) == 1) // Result should have a unique row
{
/* Get media code */
row = mysql_fetch_row (mysql_res);

View File

@ -160,19 +160,40 @@ void TL_Fav_PutIconToFavUnfNote (const 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;
/***** Get data of note *****/
Not->NotCod = TL_Not_GetParamNotCod ();
TL_Not_GetDataOfNoteByCod (Not);
if (Not->NotCod > 0)
/***** Trivial check 1: note code should be > 0 *****/
if (Not->NotCod <= 0)
{
if (Gbl.Usrs.Me.Logged && // I am logged...
!Usr_ItsMe (Not->UsrCod)) // ...but I am not the author
if (!TL_DB_CheckIfFavedByUsr (TL_Fav_NOTE,Not->NotCod,
Gbl.Usrs.Me.UsrDat.UsrCod)) // I have not yet favourited the note
Ale_ShowAlert (Ale_WARNING,Txt_The_original_post_no_longer_exists);
return;
}
/***** Trivial check 2: I must be logged *****/
if (!Gbl.Usrs.Me.Logged)
{
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
return;
/***** Mark note as favourite in database *****/
TL_DB_MarkAsFav (TL_Fav_NOTE,Not->NotCod);
@ -187,24 +208,43 @@ static void TL_Fav_FavNote (struct TL_Not_Note *Not)
TL_Ntf_CreateNotifToAuthor (Not->UsrCod,OriginalPubCod,
Ntf_EVENT_TIMELINE_FAV);
}
}
}
static void TL_Fav_UnfNote (struct TL_Not_Note *Not)
{
extern const char *Txt_The_original_post_no_longer_exists;
long OriginalPubCod;
/***** Get data of note *****/
Not->NotCod = TL_Not_GetParamNotCod ();
TL_Not_GetDataOfNoteByCod (Not);
if (Not->NotCod > 0)
if (Not->NumFavs &&
Gbl.Usrs.Me.Logged && // I am logged...
!Usr_ItsMe (Not->UsrCod)) // ...but I am not the author
if (TL_DB_CheckIfFavedByUsr (TL_Fav_NOTE,Not->NotCod,
Gbl.Usrs.Me.UsrDat.UsrCod)) // I have favourited the note
/***** Trivial check 1: note code should be > 0 *****/
if (Not->NotCod <= 0)
{
Ale_ShowAlert (Ale_WARNING,Txt_The_original_post_no_longer_exists);
return;
}
/***** Trivial check 2: I must be logged *****/
if (!Gbl.Usrs.Me.Logged)
{
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
return;
/***** Delete the mark as favourite from database *****/
TL_DB_UnmarkAsFav (TL_Fav_NOTE,Not->NotCod);
@ -217,7 +257,6 @@ static void TL_Fav_UnfNote (struct TL_Not_Note *Not)
if (OriginalPubCod > 0)
Ntf_MarkNotifAsRemoved (Ntf_EVENT_TIMELINE_FAV,OriginalPubCod);
}
}
/*****************************************************************************/
/********************* Mark/unmark a comment as favourite ********************/
@ -306,6 +345,8 @@ void TL_Fav_PutIconToFavUnfComment (const struct TL_Com_Comment *Com,
static void TL_Fav_FavComment (struct TL_Com_Comment *Com)
{
extern const char *Txt_The_comment_no_longer_exists;
/***** Initialize image *****/
Med_MediaConstructor (&Com->Content.Media);
@ -313,11 +354,39 @@ static void TL_Fav_FavComment (struct TL_Com_Comment *Com)
Com->PubCod = TL_Pub_GetParamPubCod ();
TL_Com_GetDataOfCommByCod (Com);
if (Com->PubCod > 0)
if (!Usr_ItsMe (Com->UsrCod)) // I am not the author
if (!TL_DB_CheckIfFavedByUsr (TL_Fav_COMM,Com->PubCod,
Gbl.Usrs.Me.UsrDat.UsrCod)) // I have not yet favourited the comment
/***** 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;
}
/***** 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;
}
/***** 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;
}
/***** Trivial check 4: Have I faved this comment? *****/
if (TL_DB_CheckIfFavedByUsr (TL_Fav_COMM,Com->PubCod,
Gbl.Usrs.Me.UsrDat.UsrCod))
{
Med_MediaDestructor (&Com->Content.Media);
// Don't show error message
return;
}
/***** Mark comment as favourite in database *****/
TL_DB_MarkAsFav (TL_Fav_COMM,Com->PubCod);
@ -329,7 +398,6 @@ static void TL_Fav_FavComment (struct TL_Com_Comment *Com)
for the author of the post *****/
TL_Ntf_CreateNotifToAuthor (Com->UsrCod,Com->PubCod,
Ntf_EVENT_TIMELINE_FAV);
}
/***** Free image *****/
Med_MediaDestructor (&Com->Content.Media);
@ -337,6 +405,8 @@ static void TL_Fav_FavComment (struct TL_Com_Comment *Com)
static void TL_Fav_UnfComment (struct TL_Com_Comment *Com)
{
extern const char *Txt_The_comment_no_longer_exists;
/***** Initialize image *****/
Med_MediaConstructor (&Com->Content.Media);
@ -344,12 +414,39 @@ static void TL_Fav_UnfComment (struct TL_Com_Comment *Com)
Com->PubCod = TL_Pub_GetParamPubCod ();
TL_Com_GetDataOfCommByCod (Com);
if (Com->PubCod > 0)
if (Com->NumFavs &&
!Usr_ItsMe (Com->UsrCod)) // I am not the author
if (TL_DB_CheckIfFavedByUsr (TL_Fav_COMM,Com->PubCod,
Gbl.Usrs.Me.UsrDat.UsrCod)) // I have favourited the comment
/***** 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;
}
/***** 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;
}
/***** Trivial check 3: The author can not fav its own notes *****/
if (Usr_ItsMe (Com->UsrCod))
{
Med_MediaDestructor (&Com->Content.Media);
Ale_ShowAlert (Ale_ERROR,"You can not fav/unfav your own comments.");
return;
}
/***** Trivial check 4: Have I faved this comment? *****/
if (!TL_DB_CheckIfFavedByUsr (TL_Fav_COMM,Com->PubCod,
Gbl.Usrs.Me.UsrDat.UsrCod))
{
Med_MediaDestructor (&Com->Content.Media);
// Don't show error message
return;
}
/***** Delete the mark as favourite from database *****/
TL_DB_UnmarkAsFav (TL_Fav_COMM,Com->PubCod);
@ -359,13 +456,11 @@ static void TL_Fav_UnfComment (struct TL_Com_Comment *Com)
/***** Mark possible notifications on this comment as removed *****/
Ntf_MarkNotifAsRemoved (Ntf_EVENT_TIMELINE_FAV,Com->PubCod);
}
/***** Free image *****/
Med_MediaDestructor (&Com->Content.Media);
}
/*****************************************************************************/
/****************** Put disabled icon to mark as favourite *******************/
/*****************************************************************************/

View File

@ -218,10 +218,15 @@ void TL_Not_CheckAndWriteNoteWithTopMsg (const struct TL_Timeline *Timeline,
| Form to write new comment | | |
|__________________________________| / /
*/
if (Not->NotCod > 0 &&
Not->UsrCod > 0 &&
Not->NoteType != TL_NOTE_UNKNOWN)
/***** Trivial check: codes *****/
if (Not->NotCod <= 0 ||
Not->UsrCod <= 0 ||
Not->NoteType == TL_NOTE_UNKNOWN)
{
Ale_ShowAlert (Ale_ERROR,"Error in note.");
return;
}
/***** Write sharer/commenter if distinct to author *****/
if (TopMessage != TL_TOP_MESSAGE_NONE)
TL_Not_WriteTopMessage (TopMessage,PublisherCod);
@ -229,9 +234,6 @@ void TL_Not_CheckAndWriteNoteWithTopMsg (const struct TL_Timeline *Timeline,
/***** Write note *****/
TL_Not_WriteNote (Timeline,Not);
}
else
Ale_ShowAlert (Ale_ERROR,"Error in note.");
}
/*****************************************************************************/
/*************** Write sharer/commenter if distinct to author ****************/
@ -1074,10 +1076,20 @@ static void TL_Not_RequestRemovalNote (struct TL_Timeline *Timeline)
Not.NotCod = TL_Not_GetParamNotCod ();
TL_Not_GetDataOfNoteByCod (&Not);
if (Not.NotCod > 0)
/***** Trivial check 1: note code should be > 0 *****/
if (Not.NotCod <= 0)
{
if (Usr_ItsMe (Not.UsrCod)) // I am the author of this note
Ale_ShowAlert (Ale_WARNING,Txt_The_original_post_no_longer_exists);
return;
}
/***** Trivial check 2: Am I the author of this note *****/
if (!Usr_ItsMe (Not.UsrCod))
{
Ale_ShowAlert (Ale_ERROR,"You are not the author.");
return;
}
/***** Show question and button to remove note *****/
/* Begin alert */
TL_Frm_BeginAlertRemove (Txt_Do_you_really_want_to_remove_the_following_post);
@ -1098,10 +1110,6 @@ static void TL_Not_RequestRemovalNote (struct TL_Timeline *Timeline)
TL_Frm_EndAlertRemove (Timeline,TL_Frm_REM_NOTE,
TL_Not_PutParamsRemoveNote);
}
}
else
Ale_ShowAlert (Ale_WARNING,Txt_The_original_post_no_longer_exists);
}
/*****************************************************************************/
/********************* Put parameters to remove a note ***********************/
@ -1173,10 +1181,20 @@ static void TL_Not_RemoveNote (void)
Not.NotCod = TL_Not_GetParamNotCod ();
TL_Not_GetDataOfNoteByCod (&Not);
if (Not.NotCod > 0)
/***** Trivial check 1: note code should be > 0 *****/
if (Not.NotCod <= 0)
{
if (Usr_ItsMe (Not.UsrCod)) // I am the author of this note
Ale_ShowAlert (Ale_WARNING,Txt_The_original_post_no_longer_exists);
return;
}
/***** Trivial check 2: Am I the author of this note *****/
if (!Usr_ItsMe (Not.UsrCod))
{
Ale_ShowAlert (Ale_ERROR,"You are not the author.");
return;
}
/***** Delete note from database *****/
TL_Not_RemoveNoteMediaAndDBEntries (&Not);
@ -1186,10 +1204,6 @@ static void TL_Not_RemoveNote (void)
/***** Message of success *****/
Ale_ShowAlert (Ale_SUCCESS,Txt_TIMELINE_Post_removed);
}
}
else
Ale_ShowAlert (Ale_WARNING,Txt_The_original_post_no_longer_exists);
}
/*****************************************************************************/
/*********************** Remove a note from database *************************/
@ -1338,8 +1352,14 @@ void TL_Not_GetDataOfNoteByCod (struct TL_Not_Note *Not)
MYSQL_RES *mysql_res;
MYSQL_ROW row;
if (Not->NotCod > 0)
/***** Trivial check: note code should be > 0 *****/
if (Not->NotCod <= 0)
{
/***** Reset fields of note *****/
TL_Not_ResetNote (Not);
return;
}
/***** Get data of note from database *****/
if (TL_DB_GetDataOfNoteByCod (Not->NotCod,&mysql_res))
{
@ -1354,7 +1374,3 @@ void TL_Not_GetDataOfNoteByCod (struct TL_Not_Note *Not)
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
else
/***** Reset fields of note *****/
TL_Not_ResetNote (Not);
}

View File

@ -115,6 +115,7 @@ void TL_Sha_ShaNoteGbl (void)
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;
long OriginalPubCod;
@ -122,12 +123,32 @@ static void TL_Sha_ShaNote (struct TL_Not_Note *Not)
Not->NotCod = TL_Not_GetParamNotCod ();
TL_Not_GetDataOfNoteByCod (Not);
if (Not->NotCod > 0)
if (Gbl.Usrs.Me.Logged && // I am logged...
!Usr_ItsMe (Not->UsrCod)) // ...but I am not the author
if (!TL_DB_CheckIfNoteIsSharedByUsr (Not->NotCod,
Gbl.Usrs.Me.UsrDat.UsrCod)) // Not yet shared by me
/***** Trivial check 1: note code should be > 0 *****/
if (Not->NotCod <= 0)
{
Ale_ShowAlert (Ale_WARNING,Txt_The_original_post_no_longer_exists);
return;
}
/***** Trivial check 2: Am I logged? *****/
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))
// Don't show error message
return;
/***** Share (publish note in timeline) *****/
Pub.NotCod = Not->NotCod;
Pub.PublisherCod = Gbl.Usrs.Me.UsrDat.UsrCod;
@ -144,7 +165,6 @@ static void TL_Sha_ShaNote (struct TL_Not_Note *Not)
TL_Ntf_CreateNotifToAuthor (Not->UsrCod,OriginalPubCod,
Ntf_EVENT_TIMELINE_SHARE);
}
}
/*****************************************************************************/
/******************** Unshare a previously shared note ***********************/
@ -172,19 +192,39 @@ void TL_Sha_UnsNoteGbl (void)
static void TL_Sha_UnsNote (struct TL_Not_Note *Not)
{
extern const char *Txt_The_original_post_no_longer_exists;
long OriginalPubCod;
/***** Get data of note *****/
Not->NotCod = TL_Not_GetParamNotCod ();
TL_Not_GetDataOfNoteByCod (Not);
if (Not->NotCod > 0)
if (Not->NumShared &&
Gbl.Usrs.Me.Logged && // I am logged...
!Usr_ItsMe (Not->UsrCod)) // ...but I am not the author
if (TL_DB_CheckIfNoteIsSharedByUsr (Not->NotCod,
Gbl.Usrs.Me.UsrDat.UsrCod)) // I am a sharer
/***** Trivial check 1: note code should be > 0 *****/
if (Not->NotCod <= 0)
{
Ale_ShowAlert (Ale_WARNING,Txt_The_original_post_no_longer_exists);
return;
}
/***** Trivial check 2: Am I logged? *****/
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))
// Don't show error message
return;
/***** Delete publication from database *****/
TL_DB_RemoveSharedPub (Not->NotCod);
@ -196,7 +236,6 @@ static void TL_Sha_UnsNote (struct TL_Not_Note *Not)
if (OriginalPubCod > 0)
Ntf_MarkNotifAsRemoved (Ntf_EVENT_TIMELINE_SHARE,OriginalPubCod);
}
}
void TL_Sha_PutIconToShaUnsNote (const struct TL_Not_Note *Not,
TL_Usr_HowManyUsrs_t HowManyUsrs)