Version 15.125

This commit is contained in:
Antonio Cañas Vargas 2016-01-24 13:46:57 +01:00
parent 83995fea4e
commit fc51cdb747
2 changed files with 261 additions and 250 deletions

View File

@ -120,20 +120,23 @@
// TODO: Change ComCod to PubCod in social_comments and social_comments_fav // TODO: Change ComCod to PubCod in social_comments and social_comments_fav
// TODO: When receiving a new post, create first the publishing, then the post // TODO: When receiving a new post, create first the publishing, then the post
// TODO: Change PstCod to PubCod in social_posts, removing AUTO_INCREMENT // TODO: Change PstCod to PubCod in social_posts, removing AUTO_INCREMENT
// TODO: View highlighted social note when clicking in timeline notification
// TODO: Mark timeline notifications as removed when post/comment are removed or fav/share are undone // TODO: Mark timeline notifications as removed when post/comment are removed or fav/share are undone
/*****************************************************************************/ /*****************************************************************************/
/****************************** Public constants *****************************/ /****************************** Public constants *****************************/
/*****************************************************************************/ /*****************************************************************************/
#define Log_PLATFORM_VERSION "SWAD 15.124.3 (2016-01-24)" #define Log_PLATFORM_VERSION "SWAD 15.125 (2016-01-24)"
#define CSS_FILE "swad15.121.7.css" #define CSS_FILE "swad15.121.7.css"
#define JS_FILE "swad15.121.7.js" #define JS_FILE "swad15.121.7.js"
// Number of lines (includes comments but not blank lines) has been got with the following command: // 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 // nl swad*.c swad*.h css/swad*.css py/swad*.py js/swad*.js soap/swad*.h sql/swad*.sql | tail -1
/* /*
Version 15.124.3: Jan 24, 2016 Mark timeline notifications as seen after viewing social timeline. (? lines) Version 15.125: Jan 24, 2016 Mark notification about shared social note as removed after unsharing.
Code refactoring in social timeline. (194563 lines)
Version 15.124.3: Jan 24, 2016 Mark timeline notifications as seen after viewing social timeline. (194554 lines)
Version 15.124.2: Jan 23, 2016 Changed numeration of notifications in database. (194546 lines) Version 15.124.2: Jan 23, 2016 Changed numeration of notifications in database. (194546 lines)
14 changes necessary in database: 14 changes necessary in database:
UPDATE notif SET NotifyEvent=17 WHERE NotifyEvent=9; UPDATE notif SET NotifyEvent=17 WHERE NotifyEvent=9;

View File

@ -309,9 +309,9 @@ static void Soc_RequestRemovalSocialComment (void);
static void Soc_RemoveSocialComment (void); static void Soc_RemoveSocialComment (void);
static void Soc_RemoveASocialCommentFromDB (struct SocialComment *SocCom); static void Soc_RemoveASocialCommentFromDB (struct SocialComment *SocCom);
static bool Soc_CheckIfNoteIsPublishedInTimelineByUsr (long NotCod,long UsrCod); static bool Soc_CheckIfNoteIsSharedByUsr (long NotCod,long UsrCod);
static bool Soc_CheckIfNoteIsFavouritedByUsr (long NotCod,long UsrCod); static bool Soc_CheckIfNoteIsFavedByUsr (long NotCod,long UsrCod);
static bool Soc_CheckIfCommIsFavouritedByUsr (long ComCod,long UsrCod); static bool Soc_CheckIfCommIsFavedByUsr (long ComCod,long UsrCod);
static unsigned Soc_UpdateNumTimesANoteHasBeenShared (struct SocialNote *SocNot); static unsigned Soc_UpdateNumTimesANoteHasBeenShared (struct SocialNote *SocNot);
static unsigned Soc_GetNumTimesANoteHasBeenFav (struct SocialNote *SocNot); static unsigned Soc_GetNumTimesANoteHasBeenFav (struct SocialNote *SocNot);
@ -1057,8 +1057,8 @@ static void Soc_WriteSocialNote (const struct SocialNote *SocNot,
extern const char *Txt_Institution; extern const char *Txt_Institution;
struct UsrData UsrDat; struct UsrData UsrDat;
bool IAmTheAuthor = false; bool IAmTheAuthor = false;
bool IAmAPublisherOfThisSocNot = false; bool IAmASharerOfThisSocNot = false;
bool IAmAFavouriterOfThisSocNot = false; bool IAmAFaverOfThisSocNot = false;
struct Institution Ins; struct Institution Ins;
struct Centre Ctr; struct Centre Ctr;
struct Degree Deg; struct Degree Deg;
@ -1114,10 +1114,13 @@ static void Soc_WriteSocialNote (const struct SocialNote *SocNot,
if (Gbl.Usrs.Me.Logged) if (Gbl.Usrs.Me.Logged)
{ {
IAmTheAuthor = (UsrDat.UsrCod == Gbl.Usrs.Me.UsrDat.UsrCod); IAmTheAuthor = (UsrDat.UsrCod == Gbl.Usrs.Me.UsrDat.UsrCod);
IAmAPublisherOfThisSocNot = Soc_CheckIfNoteIsPublishedInTimelineByUsr (SocNot->NotCod, if (!IAmTheAuthor)
Gbl.Usrs.Me.UsrDat.UsrCod); {
IAmAFavouriterOfThisSocNot = Soc_CheckIfNoteIsFavouritedByUsr (SocNot->NotCod, IAmASharerOfThisSocNot = Soc_CheckIfNoteIsSharedByUsr (SocNot->NotCod,
Gbl.Usrs.Me.UsrDat.UsrCod); Gbl.Usrs.Me.UsrDat.UsrCod);
IAmAFaverOfThisSocNot = Soc_CheckIfNoteIsFavedByUsr (SocNot->NotCod,
Gbl.Usrs.Me.UsrDat.UsrCod);
}
} }
/***** Left: write author's photo *****/ /***** Left: write author's photo *****/
@ -1271,7 +1274,7 @@ static void Soc_WriteSocialNote (const struct SocialNote *SocNot,
/* Put icon to mark this social note as favourite */ /* Put icon to mark this social note as favourite */
if (IAmTheAuthor) // I am the author if (IAmTheAuthor) // I am the author
Soc_PutDisabledIconFav (SocNot->NumFavs); Soc_PutDisabledIconFav (SocNot->NumFavs);
else if (IAmAFavouriterOfThisSocNot) // I have favourited this social note else if (IAmAFaverOfThisSocNot) // I have favourited this social note
/* Put icon to unfav this publishing */ /* Put icon to unfav this publishing */
Soc_PutFormToUnfavSocialNote (SocNot->NotCod); Soc_PutFormToUnfavSocialNote (SocNot->NotCod);
else // I am not the author and I am not a sharer else // I am not the author and I am not a sharer
@ -1289,8 +1292,8 @@ static void Soc_WriteSocialNote (const struct SocialNote *SocNot,
/* Put icons to share/unshare */ /* Put icons to share/unshare */
if (IAmTheAuthor) // I am the author if (IAmTheAuthor) // I am the author
Soc_PutDisabledIconShare (SocNot->NumShared); Soc_PutDisabledIconShare (SocNot->NumShared);
else if (IAmAPublisherOfThisSocNot) // I am a sharer of this social note, else if (IAmASharerOfThisSocNot) // I am a sharer of this social note,
// but not the author ==> I have shared this social note // but not the author ==> I have shared this social note
/* Put icon to unshare this publishing */ /* Put icon to unshare this publishing */
Soc_PutFormToUnshareSocialNote (SocNot->NotCod); Soc_PutFormToUnshareSocialNote (SocNot->NotCod);
else // I am not the author and I am not a sharer else // I am not the author and I am not a sharer
@ -2199,7 +2202,7 @@ static void Soc_WriteSocialComment (struct SocialComment *SocCom,
extern const char *Txt_Institution; extern const char *Txt_Institution;
struct UsrData UsrDat; struct UsrData UsrDat;
bool IAmTheAuthor; bool IAmTheAuthor;
bool IAmAFavouriterOfThisSocCom; bool IAmAFaverOfThisSocCom = false;
bool ShowPhoto = false; bool ShowPhoto = false;
char PhotoURL[PATH_MAX+1]; char PhotoURL[PATH_MAX+1];
@ -2234,8 +2237,9 @@ static void Soc_WriteSocialComment (struct SocialComment *SocCom,
Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&UsrDat); Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&UsrDat);
IAmTheAuthor = (Gbl.Usrs.Me.Logged && IAmTheAuthor = (Gbl.Usrs.Me.Logged &&
UsrDat.UsrCod == Gbl.Usrs.Me.UsrDat.UsrCod); UsrDat.UsrCod == Gbl.Usrs.Me.UsrDat.UsrCod);
IAmAFavouriterOfThisSocCom = Soc_CheckIfCommIsFavouritedByUsr (SocCom->ComCod, if (!IAmTheAuthor)
Gbl.Usrs.Me.UsrDat.UsrCod); IAmAFaverOfThisSocCom = Soc_CheckIfCommIsFavedByUsr (SocCom->ComCod,
Gbl.Usrs.Me.UsrDat.UsrCod);
/***** Left: write author's photo *****/ /***** Left: write author's photo *****/
fprintf (Gbl.F.Out,"<div class=\"SOCIAL_COMMENT_PHOTO\">"); fprintf (Gbl.F.Out,"<div class=\"SOCIAL_COMMENT_PHOTO\">");
@ -2262,7 +2266,7 @@ static void Soc_WriteSocialComment (struct SocialComment *SocCom,
/* Put icon to mark this social comment as favourite */ /* Put icon to mark this social comment as favourite */
if (IAmTheAuthor) // I am the author if (IAmTheAuthor) // I am the author
Soc_PutDisabledIconFav (SocCom->NumFavs); Soc_PutDisabledIconFav (SocCom->NumFavs);
else if (IAmAFavouriterOfThisSocCom) // I have favourited this social note else if (IAmAFaverOfThisSocCom) // I have favourited this social note
/* Put icon to unfav this publishing */ /* Put icon to unfav this publishing */
Soc_PutFormToUnfavSocialComment (SocCom->ComCod); Soc_PutFormToUnfavSocialComment (SocCom->ComCod);
else // I am not the author and I am not a favouriter else // I am not the author and I am not a favouriter
@ -2784,9 +2788,6 @@ static long Soc_ShareSocialNote (void)
extern const char *Txt_The_original_post_no_longer_exists; extern const char *Txt_The_original_post_no_longer_exists;
struct SocialNote SocNot; struct SocialNote SocNot;
struct SocialPublishing SocPub; struct SocialPublishing SocPub;
bool IAmTheAuthor;
bool IAmAPublisherOfThisSocNot;
bool ICanShare;
/***** Get the code of the social note to share *****/ /***** Get the code of the social note to share *****/
SocNot.NotCod = Soc_GetParamNotCod (); SocNot.NotCod = Soc_GetParamNotCod ();
@ -2796,26 +2797,20 @@ static long Soc_ShareSocialNote (void)
if (SocNot.NotCod > 0) if (SocNot.NotCod > 0)
{ {
IAmTheAuthor = (SocNot.UsrCod == Gbl.Usrs.Me.UsrDat.UsrCod); if (Gbl.Usrs.Me.Logged &&
if (IAmTheAuthor) SocNot.UsrCod != Gbl.Usrs.Me.UsrDat.UsrCod) // I am not the author
IAmAPublisherOfThisSocNot = true; if (!Soc_CheckIfNoteIsSharedByUsr (SocNot.NotCod,
else Gbl.Usrs.Me.UsrDat.UsrCod)) // Not yet shared by me
IAmAPublisherOfThisSocNot = Soc_CheckIfNoteIsPublishedInTimelineByUsr (SocNot.NotCod, {
Gbl.Usrs.Me.UsrDat.UsrCod); /***** Share (publish social note in timeline) *****/
ICanShare = (Gbl.Usrs.Me.Logged && SocPub.NotCod = SocNot.NotCod;
!IAmTheAuthor && // I am not the author SocPub.PublisherCod = Gbl.Usrs.Me.UsrDat.UsrCod;
!IAmAPublisherOfThisSocNot); // I have not shared the note SocPub.PubType = Soc_PUB_SHARED_NOTE;
if (ICanShare) Soc_PublishSocialNoteInTimeline (&SocPub); // Set SocPub.PubCod
{
/***** Share (publish social note in timeline) *****/
SocPub.NotCod = SocNot.NotCod;
SocPub.PublisherCod = Gbl.Usrs.Me.UsrDat.UsrCod;
SocPub.PubType = Soc_PUB_SHARED_NOTE;
Soc_PublishSocialNoteInTimeline (&SocPub); // Set SocPub.PubCod
/* Update number of times this social note is shared */ /* Update number of times this social note is shared */
SocNot.NumShared = Soc_UpdateNumTimesANoteHasBeenShared (&SocNot); SocNot.NumShared = Soc_UpdateNumTimesANoteHasBeenShared (&SocNot);
} }
} }
else else
Lay_ShowAlert (Lay_WARNING,Txt_The_original_post_no_longer_exists); Lay_ShowAlert (Lay_WARNING,Txt_The_original_post_no_longer_exists);
@ -2868,9 +2863,6 @@ static long Soc_FavSocialNote (void)
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
struct SocialNote SocNot; struct SocialNote SocNot;
bool IAmTheAuthor;
bool IAmAFavouriterOfThisSocNot;
bool ICanFav;
long PubCod; long PubCod;
/***** Get the code of the social note to mark as favourite *****/ /***** Get the code of the social note to mark as favourite *****/
@ -2881,47 +2873,44 @@ static long Soc_FavSocialNote (void)
if (SocNot.NotCod > 0) if (SocNot.NotCod > 0)
{ {
IAmTheAuthor = (SocNot.UsrCod == Gbl.Usrs.Me.UsrDat.UsrCod); if (Gbl.Usrs.Me.Logged &&
IAmAFavouriterOfThisSocNot = Soc_CheckIfNoteIsFavouritedByUsr (SocNot.NotCod, SocNot.UsrCod != Gbl.Usrs.Me.UsrDat.UsrCod) // I am not the author
Gbl.Usrs.Me.UsrDat.UsrCod); if (!Soc_CheckIfNoteIsFavedByUsr (SocNot.NotCod,
ICanFav = (Gbl.Usrs.Me.Logged && Gbl.Usrs.Me.UsrDat.UsrCod)) // I have not yet favourited the note
!IAmTheAuthor && // I am not the author
!IAmAFavouriterOfThisSocNot); // I have not favourited the note
if (ICanFav)
{
/***** Mark as favourite in database *****/
sprintf (Query,"INSERT IGNORE INTO social_notes_fav"
" (NotCod,UsrCod,TimeFav) VALUES ('%ld','%ld',NOW())",
SocNot.NotCod,
Gbl.Usrs.Me.UsrDat.UsrCod);
DB_QueryINSERT (Query,"can not favourite social note");
/* Update number of times this social note is favourited */
SocNot.NumFavs = Soc_GetNumTimesANoteHasBeenFav (&SocNot);
/**** Create notification about favourite post
for the author of the post ***/
sprintf (Query,"SELECT PubCod FROM social_pubs"
" WHERE NotCod='%ld' AND PubType='%u'",
SocNot.NotCod,(unsigned) Soc_PUB_ORIGINAL_NOTE);
if (DB_QuerySELECT (Query,&mysql_res,"can not get publishing") == 1)
{ {
row = mysql_fetch_row (mysql_res); /***** Mark as favourite in database *****/
sprintf (Query,"INSERT IGNORE INTO social_notes_fav"
" (NotCod,UsrCod,TimeFav) VALUES ('%ld','%ld',NOW())",
SocNot.NotCod,
Gbl.Usrs.Me.UsrDat.UsrCod);
DB_QueryINSERT (Query,"can not favourite social note");
/* Get code of social publishing (row[0]) */ /* Update number of times this social note is favourited */
PubCod = Str_ConvertStrCodToLongCod (row[0]); SocNot.NumFavs = Soc_GetNumTimesANoteHasBeenFav (&SocNot);
Soc_CreateFavNotifToAuthor (SocNot.UsrCod,PubCod); /**** Create notification about favourite post
for the author of the post ***/
sprintf (Query,"SELECT PubCod FROM social_pubs"
" WHERE NotCod='%ld' AND PubType='%u'",
SocNot.NotCod,(unsigned) Soc_PUB_ORIGINAL_NOTE);
if (DB_QuerySELECT (Query,&mysql_res,"can not get publishing") == 1)
{
row = mysql_fetch_row (mysql_res);
/* Get code of social publishing (row[0]) */
PubCod = Str_ConvertStrCodToLongCod (row[0]);
Soc_CreateFavNotifToAuthor (SocNot.UsrCod,PubCod);
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
/***** Show the social note just favourited *****/
Soc_WriteSocialNote (&SocNot,
Soc_TOP_MESSAGE_FAV,Gbl.Usrs.Me.UsrDat.UsrCod,
true,true);
} }
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
/***** Show the social note just favourited *****/
Soc_WriteSocialNote (&SocNot,
Soc_TOP_MESSAGE_FAV,Gbl.Usrs.Me.UsrDat.UsrCod,
true,true);
}
} }
else else
Lay_ShowAlert (Lay_WARNING,Txt_The_original_post_no_longer_exists); Lay_ShowAlert (Lay_WARNING,Txt_The_original_post_no_longer_exists);
@ -2971,9 +2960,6 @@ static long Soc_FavSocialComment (void)
{ {
extern const char *Txt_The_comment_no_longer_exists; extern const char *Txt_The_comment_no_longer_exists;
struct SocialComment SocCom; struct SocialComment SocCom;
bool IAmTheAuthor;
bool IAmAFavouriterOfThisSocCom;
bool ICanFav;
char Query[256]; char Query[256];
/***** Get the code of the social note to mark as favourite *****/ /***** Get the code of the social note to mark as favourite *****/
@ -2982,36 +2968,32 @@ static long Soc_FavSocialComment (void)
/***** Get data of social note *****/ /***** Get data of social note *****/
Soc_GetDataOfSocialComByCod (&SocCom); Soc_GetDataOfSocialComByCod (&SocCom);
if (SocCom.ComCod > 0 && if (SocCom.ComCod > 0)
SocCom.NotCod > 0) // Extra check
{ {
IAmTheAuthor = (SocCom.UsrCod == Gbl.Usrs.Me.UsrDat.UsrCod); if (Gbl.Usrs.Me.Logged &&
IAmAFavouriterOfThisSocCom = Soc_CheckIfCommIsFavouritedByUsr (SocCom.ComCod, SocCom.UsrCod != Gbl.Usrs.Me.UsrDat.UsrCod) // I am not the author
Gbl.Usrs.Me.UsrDat.UsrCod); if (!Soc_CheckIfCommIsFavedByUsr (SocCom.ComCod,
ICanFav = (Gbl.Usrs.Me.Logged && Gbl.Usrs.Me.UsrDat.UsrCod)) // I have not yet favourited the comment
!IAmTheAuthor && // I am not the author {
!IAmAFavouriterOfThisSocCom); // I have not favourited the comment /***** Mark as favourite in database *****/
if (ICanFav) sprintf (Query,"INSERT IGNORE INTO social_comments_fav"
{ " (ComCod,UsrCod,TimeFav) VALUES ('%ld','%ld',NOW())",
/***** Mark as favourite in database *****/ SocCom.ComCod,
sprintf (Query,"INSERT IGNORE INTO social_comments_fav" Gbl.Usrs.Me.UsrDat.UsrCod);
" (ComCod,UsrCod,TimeFav) VALUES ('%ld','%ld',NOW())", DB_QueryINSERT (Query,"can not favourite social comment");
SocCom.ComCod,
Gbl.Usrs.Me.UsrDat.UsrCod);
DB_QueryINSERT (Query,"can not favourite social comment");
/* Update number of times this social comment is favourited */ /* Update number of times this social comment is favourited */
SocCom.NumFavs = Soc_GetNumTimesACommHasBeenFav (&SocCom); SocCom.NumFavs = Soc_GetNumTimesACommHasBeenFav (&SocCom);
/**** Create notification about favourite post /**** Create notification about favourite post
for the author of the post ***/ for the author of the post ***/
Soc_CreateFavNotifToAuthor (SocCom.UsrCod,SocCom.ComCod); Soc_CreateFavNotifToAuthor (SocCom.UsrCod,SocCom.ComCod);
/***** Show the social comment just favourited *****/ /***** Show the social comment just favourited *****/
Soc_WriteSocialComment (&SocCom, Soc_WriteSocialComment (&SocCom,
Soc_TOP_MESSAGE_FAV,Gbl.Usrs.Me.UsrDat.UsrCod, Soc_TOP_MESSAGE_FAV,Gbl.Usrs.Me.UsrDat.UsrCod,
true); true);
} }
} }
else else
Lay_ShowAlert (Lay_WARNING,Txt_The_comment_no_longer_exists); Lay_ShowAlert (Lay_WARNING,Txt_The_comment_no_longer_exists);
@ -3093,46 +3075,68 @@ void Soc_UnshareSocialNoteUsr (void)
static long Soc_UnshareSocialNote (void) static long Soc_UnshareSocialNote (void)
{ {
struct SocialNote SocNot; extern const char *Txt_The_original_post_no_longer_exists;
bool IAmTheAuthor;
bool IAmAPublisherOfThisSocNot;
bool ICanUnshare;
char Query[256]; char Query[256];
MYSQL_RES *mysql_res;
MYSQL_ROW row;
struct SocialNote SocNot;
long PubCod;
/***** Get data of social note *****/ /***** Get data of social note *****/
SocNot.NotCod = Soc_GetParamNotCod (); SocNot.NotCod = Soc_GetParamNotCod ();
Soc_GetDataOfSocialNotByCod (&SocNot); Soc_GetDataOfSocialNotByCod (&SocNot);
IAmTheAuthor = (SocNot.UsrCod == Gbl.Usrs.Me.UsrDat.UsrCod); if (SocNot.NotCod > 0)
if (IAmTheAuthor)
IAmAPublisherOfThisSocNot = true;
else
IAmAPublisherOfThisSocNot = Soc_CheckIfNoteIsPublishedInTimelineByUsr (SocNot.NotCod,
Gbl.Usrs.Me.UsrDat.UsrCod);
ICanUnshare = (Gbl.Usrs.Me.Logged &&
!IAmTheAuthor && // I am not the author
IAmAPublisherOfThisSocNot); // I have shared the note
if (ICanUnshare)
{ {
/***** Delete social publishing from database *****/ if (SocNot.NumShared &&
sprintf (Query,"DELETE FROM social_pubs" Gbl.Usrs.Me.Logged &&
" WHERE NotCod='%ld'" SocNot.UsrCod != Gbl.Usrs.Me.UsrDat.UsrCod) // I am not the author
" AND PublisherCod='%ld'" // I have share this note if (Soc_CheckIfNoteIsSharedByUsr (SocNot.NotCod,
" AND PubType='%u'", // It's a shared note Gbl.Usrs.Me.UsrDat.UsrCod)) // I am a sharer
SocNot.NotCod, {
Gbl.Usrs.Me.UsrDat.UsrCod, /***** Get code of social publishing from database *****/
(unsigned) Soc_PUB_SHARED_NOTE); sprintf (Query,"SELECT PubCod FROM social_pubs"
DB_QueryDELETE (Query,"can not remove a social publishing"); " WHERE NotCod='%ld'"
" AND PublisherCod='%ld'" // I have share this note
" AND PubType='%u'", // It's a shared note
SocNot.NotCod,
Gbl.Usrs.Me.UsrDat.UsrCod,
(unsigned) Soc_PUB_SHARED_NOTE);
if (DB_QuerySELECT (Query,&mysql_res,"can not get code of social publishing") == 1) // Result should have a unique row
{
/* Get code of social publishing (row[0]) */
row = mysql_fetch_row (mysql_res);
PubCod = Str_ConvertStrCodToLongCod (row[0]);
}
else
PubCod = -1L;
/***** Update number of times this social note is shared *****/ /* Free structure that stores the query result */
SocNot.NumShared = Soc_UpdateNumTimesANoteHasBeenShared (&SocNot); DB_FreeMySQLResult (&mysql_res);
/***** Show the social note corresponding if (PubCod > 0)
to the publishing just unshared *****/ {
Soc_WriteSocialNote (&SocNot, /***** Delete social publishing from database *****/
Soc_TOP_MESSAGE_UNSHARED,Gbl.Usrs.Me.UsrDat.UsrCod, sprintf (Query,"DELETE FROM social_pubs WHERE PubCod='%ld'",
true,true); PubCod);
DB_QueryDELETE (Query,"can not remove a social publishing");
/***** Mark possible notification as removed *****/
Ntf_MarkNotifAsRemoved (Ntf_EVENT_TIMELINE_SHARE,PubCod);
}
/***** Update number of times this social note is shared *****/
SocNot.NumShared = Soc_UpdateNumTimesANoteHasBeenShared (&SocNot);
/***** Show the social note corresponding
to the publishing just unshared *****/
Soc_WriteSocialNote (&SocNot,
Soc_TOP_MESSAGE_UNSHARED,Gbl.Usrs.Me.UsrDat.UsrCod,
true,true);
}
} }
else
Lay_ShowAlert (Lay_WARNING,Txt_The_original_post_no_longer_exists);
return SocNot.NotCod; return SocNot.NotCod;
} }
@ -3177,39 +3181,40 @@ void Soc_UnfavSocialNoteUsr (void)
static long Soc_UnfavSocialNote (void) static long Soc_UnfavSocialNote (void)
{ {
extern const char *Txt_The_original_post_no_longer_exists;
struct SocialNote SocNot; struct SocialNote SocNot;
bool IAmTheAuthor;
bool IAmAFavouriterOfThisSocNot;
bool ICanUnfav;
char Query[256]; char Query[256];
/***** Get data of social note *****/ /***** Get data of social note *****/
SocNot.NotCod = Soc_GetParamNotCod (); SocNot.NotCod = Soc_GetParamNotCod ();
Soc_GetDataOfSocialNotByCod (&SocNot); Soc_GetDataOfSocialNotByCod (&SocNot);
IAmTheAuthor = (SocNot.UsrCod == Gbl.Usrs.Me.UsrDat.UsrCod); if (SocNot.NotCod > 0)
IAmAFavouriterOfThisSocNot = Soc_CheckIfNoteIsFavouritedByUsr (SocNot.NotCod,
Gbl.Usrs.Me.UsrDat.UsrCod);
ICanUnfav = (Gbl.Usrs.Me.Logged &&
!IAmTheAuthor && // I am not the author
IAmAFavouriterOfThisSocNot); // I have favourited the note
if (ICanUnfav)
{ {
/***** Delete the mark as favourite from database *****/ if (SocNot.NumFavs &&
sprintf (Query,"DELETE FROM social_notes_fav" Gbl.Usrs.Me.Logged &&
" WHERE NotCod='%ld' AND UsrCod='%ld'", SocNot.UsrCod != Gbl.Usrs.Me.UsrDat.UsrCod) // I am not the author
SocNot.NotCod, if (Soc_CheckIfNoteIsFavedByUsr (SocNot.NotCod,
Gbl.Usrs.Me.UsrDat.UsrCod); Gbl.Usrs.Me.UsrDat.UsrCod)) // I have favourited the note
DB_QueryDELETE (Query,"can not unfavourite social note"); {
/***** Delete the mark as favourite from database *****/
sprintf (Query,"DELETE FROM social_notes_fav"
" WHERE NotCod='%ld' AND UsrCod='%ld'",
SocNot.NotCod,
Gbl.Usrs.Me.UsrDat.UsrCod);
DB_QueryDELETE (Query,"can not unfavourite social note");
/***** Update number of times this social note is favourited *****/ /***** Update number of times this social note is favourited *****/
SocNot.NumFavs = Soc_GetNumTimesANoteHasBeenFav (&SocNot); SocNot.NumFavs = Soc_GetNumTimesANoteHasBeenFav (&SocNot);
/***** Show the social note just unfavourited *****/ /***** Show the social note just unfavourited *****/
Soc_WriteSocialNote (&SocNot, Soc_WriteSocialNote (&SocNot,
Soc_TOP_MESSAGE_UNFAV,Gbl.Usrs.Me.UsrDat.UsrCod, Soc_TOP_MESSAGE_UNFAV,Gbl.Usrs.Me.UsrDat.UsrCod,
true,true); true,true);
}
} }
else
Lay_ShowAlert (Lay_WARNING,Txt_The_original_post_no_longer_exists);
return SocNot.NotCod; return SocNot.NotCod;
} }
@ -3254,39 +3259,40 @@ void Soc_UnfavSocialCommentUsr (void)
static long Soc_UnfavSocialComment (void) static long Soc_UnfavSocialComment (void)
{ {
extern const char *Txt_The_comment_no_longer_exists;
struct SocialComment SocCom; struct SocialComment SocCom;
bool IAmTheAuthor;
bool IAmAFavouriterOfThisSocCom;
bool ICanUnfav;
char Query[256]; char Query[256];
/***** Get data of social comment *****/ /***** Get data of social comment *****/
SocCom.ComCod = Soc_GetParamComCod (); SocCom.ComCod = Soc_GetParamComCod ();
Soc_GetDataOfSocialComByCod (&SocCom); Soc_GetDataOfSocialComByCod (&SocCom);
IAmTheAuthor = (SocCom.UsrCod == Gbl.Usrs.Me.UsrDat.UsrCod); if (SocCom.ComCod > 0)
IAmAFavouriterOfThisSocCom = Soc_CheckIfCommIsFavouritedByUsr (SocCom.ComCod,
Gbl.Usrs.Me.UsrDat.UsrCod);
ICanUnfav = (Gbl.Usrs.Me.Logged &&
!IAmTheAuthor && // I am not the author
IAmAFavouriterOfThisSocCom); // I have favourited the comment
if (ICanUnfav)
{ {
/***** Delete the mark as favourite from database *****/ if (SocCom.NumFavs &&
sprintf (Query,"DELETE FROM social_comments_fav" Gbl.Usrs.Me.Logged &&
" WHERE ComCod='%ld' AND UsrCod='%ld'", SocCom.UsrCod != Gbl.Usrs.Me.UsrDat.UsrCod) // I am not the author
SocCom.ComCod, if (Soc_CheckIfCommIsFavedByUsr (SocCom.ComCod,
Gbl.Usrs.Me.UsrDat.UsrCod); Gbl.Usrs.Me.UsrDat.UsrCod)) // I have favourited the comment
DB_QueryDELETE (Query,"can not unfavourite social comment"); {
/***** Delete the mark as favourite from database *****/
sprintf (Query,"DELETE FROM social_comments_fav"
" WHERE ComCod='%ld' AND UsrCod='%ld'",
SocCom.ComCod,
Gbl.Usrs.Me.UsrDat.UsrCod);
DB_QueryDELETE (Query,"can not unfavourite social comment");
/***** Update number of times this social comment is favourited *****/ /***** Update number of times this social comment is favourited *****/
SocCom.NumFavs = Soc_GetNumTimesACommHasBeenFav (&SocCom); SocCom.NumFavs = Soc_GetNumTimesACommHasBeenFav (&SocCom);
/***** Show the social comment just unfavourited *****/ /***** Show the social comment just unfavourited *****/
Soc_WriteSocialComment (&SocCom, Soc_WriteSocialComment (&SocCom,
Soc_TOP_MESSAGE_UNFAV,Gbl.Usrs.Me.UsrDat.UsrCod, Soc_TOP_MESSAGE_UNFAV,Gbl.Usrs.Me.UsrDat.UsrCod,
true); true);
}
} }
else
Lay_ShowAlert (Lay_WARNING,Txt_The_comment_no_longer_exists);
return SocCom.NotCod; return SocCom.NotCod;
} }
@ -3327,20 +3333,19 @@ void Soc_RequestRemSocialNoteUsr (void)
static void Soc_RequestRemovalSocialNote (void) static void Soc_RequestRemovalSocialNote (void)
{ {
extern const char *Txt_The_original_post_no_longer_exists;
extern const char *Txt_Do_you_really_want_to_remove_the_following_post; extern const char *Txt_Do_you_really_want_to_remove_the_following_post;
extern const char *Txt_Remove; extern const char *Txt_Remove;
struct SocialNote SocNot; struct SocialNote SocNot;
bool ICanRemove;
/***** Get data of social note *****/ /***** Get data of social note *****/
SocNot.NotCod = Soc_GetParamNotCod (); SocNot.NotCod = Soc_GetParamNotCod ();
Soc_GetDataOfSocialNotByCod (&SocNot); Soc_GetDataOfSocialNotByCod (&SocNot);
ICanRemove = (Gbl.Usrs.Me.Logged && if (SocNot.NotCod > 0)
SocNot.UsrCod == Gbl.Usrs.Me.UsrDat.UsrCod); // I am the author of this note
if (ICanRemove)
{ {
if (Soc_CheckIfNoteIsPublishedInTimelineByUsr (SocNot.NotCod,SocNot.UsrCod)) if (Gbl.Usrs.Me.Logged &&
SocNot.UsrCod == Gbl.Usrs.Me.UsrDat.UsrCod) // I am the author of this note
{ {
/***** Show warning and social note *****/ /***** Show warning and social note *****/
/* Warning message */ /* Warning message */
@ -3348,8 +3353,8 @@ static void Soc_RequestRemovalSocialNote (void)
/* Show social note */ /* Show social note */
Soc_WriteSocialNote (&SocNot, Soc_WriteSocialNote (&SocNot,
Soc_TOP_MESSAGE_NONE,-1L, Soc_TOP_MESSAGE_NONE,-1L,
false,true); false,true);
/***** Form to ask for confirmation to remove this social post *****/ /***** Form to ask for confirmation to remove this social post *****/
/* Start form */ /* Start form */
@ -3367,6 +3372,8 @@ static void Soc_RequestRemovalSocialNote (void)
Act_FormEnd (); Act_FormEnd ();
} }
} }
else
Lay_ShowAlert (Lay_WARNING,Txt_The_original_post_no_longer_exists);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -3405,24 +3412,28 @@ void Soc_RemoveSocialNoteUsr (void)
static void Soc_RemoveSocialNote (void) static void Soc_RemoveSocialNote (void)
{ {
extern const char *Txt_The_original_post_no_longer_exists;
extern const char *Txt_Post_removed; extern const char *Txt_Post_removed;
struct SocialNote SocNot; struct SocialNote SocNot;
bool ICanRemove;
/***** Get data of social note *****/ /***** Get data of social note *****/
SocNot.NotCod = Soc_GetParamNotCod (); SocNot.NotCod = Soc_GetParamNotCod ();
Soc_GetDataOfSocialNotByCod (&SocNot); Soc_GetDataOfSocialNotByCod (&SocNot);
ICanRemove = (Gbl.Usrs.Me.Logged && if (SocNot.NotCod > 0)
SocNot.UsrCod == Gbl.Usrs.Me.UsrDat.UsrCod); // I am the author of this note
if (ICanRemove)
{ {
/***** Delete social publishing from database *****/ if (Gbl.Usrs.Me.Logged &&
Soc_RemoveASocialNoteFromDB (&SocNot); SocNot.UsrCod == Gbl.Usrs.Me.UsrDat.UsrCod) // I am the author of this note
{
/***** Delete social publishing from database *****/
Soc_RemoveASocialNoteFromDB (&SocNot);
/***** Message of success *****/ /***** Message of success *****/
Lay_ShowAlert (Lay_SUCCESS,Txt_Post_removed); Lay_ShowAlert (Lay_SUCCESS,Txt_Post_removed);
}
} }
else
Lay_ShowAlert (Lay_WARNING,Txt_The_original_post_no_longer_exists);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -3519,10 +3530,10 @@ void Soc_RequestRemSocialComUsr (void)
static void Soc_RequestRemovalSocialComment (void) static void Soc_RequestRemovalSocialComment (void)
{ {
extern const char *Txt_The_comment_no_longer_exists;
extern const char *Txt_Do_you_really_want_to_remove_the_following_comment; extern const char *Txt_Do_you_really_want_to_remove_the_following_comment;
extern const char *Txt_Remove; extern const char *Txt_Remove;
struct SocialComment SocCom; struct SocialComment SocCom;
bool ICanRemove;
/***** Get the code of the social comment to remove *****/ /***** Get the code of the social comment to remove *****/
SocCom.ComCod = Soc_GetParamComCod (); SocCom.ComCod = Soc_GetParamComCod ();
@ -3530,34 +3541,38 @@ static void Soc_RequestRemovalSocialComment (void)
/***** Get data of social comment *****/ /***** Get data of social comment *****/
Soc_GetDataOfSocialComByCod (&SocCom); Soc_GetDataOfSocialComByCod (&SocCom);
ICanRemove = (Gbl.Usrs.Me.Logged && if (SocCom.ComCod > 0)
SocCom.UsrCod == Gbl.Usrs.Me.UsrDat.UsrCod);
if (ICanRemove)
{ {
/***** Show warning and social comment *****/ if (Gbl.Usrs.Me.Logged &&
/* Warning message */ SocCom.UsrCod == Gbl.Usrs.Me.UsrDat.UsrCod) // I am the author of this comment
Lay_ShowAlert (Lay_WARNING,Txt_Do_you_really_want_to_remove_the_following_comment);
/* Show social comment */
Soc_WriteSocialComment (&SocCom,
Soc_TOP_MESSAGE_NONE,-1L,
true);
/***** Form to ask for confirmation to remove this social comment *****/
/* Start form */
if (Gbl.Usrs.Other.UsrDat.UsrCod > 0)
{ {
Act_FormStartAnchor (ActRemSocComUsr,"timeline"); /***** Show warning and social comment *****/
Usr_PutParamOtherUsrCodEncrypted (); /* Warning message */
} Lay_ShowAlert (Lay_WARNING,Txt_Do_you_really_want_to_remove_the_following_comment);
else
Act_FormStart (ActRemSocComGbl);
Soc_PutHiddenParamComCod (SocCom.ComCod);
/* End form */ /* Show social comment */
Lay_PutRemoveButton (Txt_Remove); Soc_WriteSocialComment (&SocCom,
Act_FormEnd (); Soc_TOP_MESSAGE_NONE,-1L,
true);
/***** Form to ask for confirmation to remove this social comment *****/
/* Start form */
if (Gbl.Usrs.Other.UsrDat.UsrCod > 0)
{
Act_FormStartAnchor (ActRemSocComUsr,"timeline");
Usr_PutParamOtherUsrCodEncrypted ();
}
else
Act_FormStart (ActRemSocComGbl);
Soc_PutHiddenParamComCod (SocCom.ComCod);
/* End form */
Lay_PutRemoveButton (Txt_Remove);
Act_FormEnd ();
}
} }
else
Lay_ShowAlert (Lay_WARNING,Txt_The_comment_no_longer_exists);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -3596,10 +3611,9 @@ void Soc_RemoveSocialComUsr (void)
static void Soc_RemoveSocialComment (void) static void Soc_RemoveSocialComment (void)
{ {
extern const char *Txt_The_comment_no_longer_exists;
extern const char *Txt_Comment_removed; extern const char *Txt_Comment_removed;
struct SocialComment SocCom; struct SocialComment SocCom;
struct SocialNote SocNot;
bool ICanRemove;
/***** Get the code of the social comment to remove *****/ /***** Get the code of the social comment to remove *****/
SocCom.ComCod = Soc_GetParamComCod (); SocCom.ComCod = Soc_GetParamComCod ();
@ -3607,20 +3621,20 @@ static void Soc_RemoveSocialComment (void)
/***** Get data of social comment *****/ /***** Get data of social comment *****/
Soc_GetDataOfSocialComByCod (&SocCom); Soc_GetDataOfSocialComByCod (&SocCom);
/***** Get data of social note *****/ if (SocCom.ComCod > 0)
SocNot.NotCod = SocCom.NotCod;
Soc_GetDataOfSocialNotByCod (&SocNot);
ICanRemove = (Gbl.Usrs.Me.Logged &&
SocCom.UsrCod == Gbl.Usrs.Me.UsrDat.UsrCod);
if (ICanRemove)
{ {
/***** Delete social comment from database *****/ if (Gbl.Usrs.Me.Logged &&
Soc_RemoveASocialCommentFromDB (&SocCom); SocCom.UsrCod == Gbl.Usrs.Me.UsrDat.UsrCod) // I am the author of this comment
{
/***** Delete social comment from database *****/
Soc_RemoveASocialCommentFromDB (&SocCom);
/***** Message of success *****/ /***** Message of success *****/
Lay_ShowAlert (Lay_SUCCESS,Txt_Comment_removed); Lay_ShowAlert (Lay_SUCCESS,Txt_Comment_removed);
}
} }
else
Lay_ShowAlert (Lay_WARNING,Txt_The_comment_no_longer_exists);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -3748,14 +3762,12 @@ void Soc_RemoveUsrSocialContent (long UsrCod)
DB_QueryDELETE (Query,"can not remove social publishings"); DB_QueryDELETE (Query,"can not remove social publishings");
/***** Remove all the social publishings of the user *****/ /***** Remove all the social publishings of the user *****/
sprintf (Query,"DELETE FROM social_pubs" sprintf (Query,"DELETE FROM social_pubs WHERE PublisherCod='%ld'",
" WHERE PublisherCod='%ld'",
UsrCod); UsrCod);
DB_QueryDELETE (Query,"can not remove social publishings"); DB_QueryDELETE (Query,"can not remove social publishings");
/***** Remove all the social notes of the user *****/ /***** Remove all the social notes of the user *****/
sprintf (Query,"DELETE FROM social_notes" sprintf (Query,"DELETE FROM social_notes WHERE UsrCod='%ld'",
" WHERE UsrCod='%ld'",
UsrCod); UsrCod);
DB_QueryDELETE (Query,"can not remove social notes"); DB_QueryDELETE (Query,"can not remove social notes");
} }
@ -3764,25 +3776,21 @@ void Soc_RemoveUsrSocialContent (long UsrCod)
/**************** Check if a user has published a social note ****************/ /**************** Check if a user has published a social note ****************/
/*****************************************************************************/ /*****************************************************************************/
static bool Soc_CheckIfNoteIsPublishedInTimelineByUsr (long NotCod,long UsrCod) static bool Soc_CheckIfNoteIsSharedByUsr (long NotCod,long UsrCod)
{ {
char Query[256]; char Query[256];
sprintf (Query,"SELECT COUNT(*) FROM social_pubs" sprintf (Query,"SELECT COUNT(*) FROM social_pubs"
" WHERE NotCod='%ld'" " WHERE NotCod='%ld' AND PublisherCod='%ld' AND PubType='%u'",
" AND PublisherCod='%ld'" NotCod,UsrCod,(unsigned) Soc_PUB_SHARED_NOTE);
" AND PubType IN ('%u','%u')", return (DB_QueryCOUNT (Query,"can not check if a user has shared a social note") != 0);
NotCod,UsrCod,
(unsigned) Soc_PUB_ORIGINAL_NOTE,
(unsigned) Soc_PUB_SHARED_NOTE);
return (DB_QueryCOUNT (Query,"can not check if a user has published a social note") != 0);
} }
/*****************************************************************************/ /*****************************************************************************/
/*************** Check if a user has favourited a social note ****************/ /*************** Check if a user has favourited a social note ****************/
/*****************************************************************************/ /*****************************************************************************/
static bool Soc_CheckIfNoteIsFavouritedByUsr (long NotCod,long UsrCod) static bool Soc_CheckIfNoteIsFavedByUsr (long NotCod,long UsrCod)
{ {
char Query[256]; char Query[256];
@ -3796,7 +3804,7 @@ static bool Soc_CheckIfNoteIsFavouritedByUsr (long NotCod,long UsrCod)
/************* Check if a user has favourited a social comment ***************/ /************* Check if a user has favourited a social comment ***************/
/*****************************************************************************/ /*****************************************************************************/
static bool Soc_CheckIfCommIsFavouritedByUsr (long ComCod,long UsrCod) static bool Soc_CheckIfCommIsFavedByUsr (long ComCod,long UsrCod)
{ {
char Query[256]; char Query[256];