swad-core/swad_timeline_share.c

195 lines
6.8 KiB
C
Raw Normal View History

2021-02-08 18:33:16 +01:00
// swad_timeline_share.c: social timeline shared
/*
SWAD (Shared Workspace At a Distance),
is a web platform developed at the University of Granada (Spain),
and used to support university teaching.
This file is part of SWAD core.
2021-02-09 12:43:45 +01:00
Copyright (C) 1999-2021 Antonio Ca<EFBFBD>as Vargas
2021-02-08 18:33:16 +01:00
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General 3 License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*****************************************************************************/
/*********************************** Headers *********************************/
/*****************************************************************************/
#include "swad_database.h"
#include "swad_global.h"
#include "swad_timeline.h"
#include "swad_timeline_database.h"
#include "swad_timeline_form.h"
2021-02-11 17:45:16 +01:00
#include "swad_timeline_notification.h"
2021-02-11 13:10:08 +01:00
#include "swad_timeline_publication.h"
2021-02-08 18:33:16 +01:00
#include "swad_timeline_share.h"
/*****************************************************************************/
/****************************** Public constants *****************************/
/*****************************************************************************/
/*****************************************************************************/
/************************* Private constants and types ***********************/
/*****************************************************************************/
/*****************************************************************************/
/************** External global variables from others modules ****************/
/*****************************************************************************/
extern struct Globals Gbl;
/*****************************************************************************/
/************************* Private global variables **************************/
/*****************************************************************************/
/*****************************************************************************/
/***************************** Private prototypes ****************************/
/*****************************************************************************/
2021-02-11 00:58:53 +01:00
static void TL_Sha_ShaNote (struct TL_Not_Note *Not);
static void TL_Sha_UnsNote (struct TL_Not_Note *Not);
2021-02-08 18:33:16 +01:00
/*****************************************************************************/
/******************************** Share a note *******************************/
/*****************************************************************************/
void TL_Sha_ShowAllSharersNoteUsr (void)
{
/***** Get user whom profile is displayed *****/
Usr_GetParamOtherUsrCodEncryptedAndGetUsrData ();
/***** Show all sharers *****/
TL_Sha_ShowAllSharersNoteGbl ();
}
void TL_Sha_ShowAllSharersNoteGbl (void)
{
2021-02-11 00:58:53 +01:00
struct TL_Not_Note Not;
2021-02-08 18:33:16 +01:00
/***** Get data of note *****/
2021-02-11 00:58:53 +01:00
Not.NotCod = TL_Not_GetParamNotCod ();
TL_Not_GetDataOfNoteByCod (&Not);
2021-02-08 18:33:16 +01:00
/***** Write HTML inside DIV with form to share/unshare *****/
TL_Usr_PutIconFavSha (TL_Usr_SHA_UNS_NOTE,
Not.NotCod,Not.UsrCod,Not.NumShared,
TL_Usr_SHOW_ALL_USRS);
2021-02-08 18:33:16 +01:00
}
void TL_Sha_ShaNoteUsr (void)
{
/***** Get user whom profile is displayed *****/
Usr_GetParamOtherUsrCodEncryptedAndGetUsrData ();
/***** Share note *****/
TL_Sha_ShaNoteGbl ();
}
void TL_Sha_ShaNoteGbl (void)
{
2021-02-11 00:58:53 +01:00
struct TL_Not_Note Not;
2021-02-08 18:33:16 +01:00
/***** Share note *****/
2021-02-10 19:53:57 +01:00
TL_Sha_ShaNote (&Not);
2021-02-08 18:33:16 +01:00
/***** Write HTML inside DIV with form to unshare *****/
TL_Usr_PutIconFavSha (TL_Usr_SHA_UNS_NOTE,
Not.NotCod,Not.UsrCod,Not.NumShared,
TL_Usr_SHOW_FEW_USRS);
2021-02-08 18:33:16 +01:00
}
2021-02-11 00:58:53 +01:00
static void TL_Sha_ShaNote (struct TL_Not_Note *Not)
2021-02-08 18:33:16 +01:00
{
2021-02-11 13:10:08 +01:00
struct TL_Pub_Publication Pub;
2021-02-08 18:33:16 +01:00
long OriginalPubCod;
/***** 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_Usr_CheckIfFavedSharedByUsr (TL_Usr_SHA_UNS_NOTE,Not->NotCod,
Gbl.Usrs.Me.UsrDat.UsrCod))
return;
/***** Share (publish note in timeline) *****/
Pub.NotCod = Not->NotCod;
Pub.PublisherCod = Gbl.Usrs.Me.UsrDat.UsrCod;
Pub.PubType = TL_Pub_SHARED_NOTE;
TL_Pub_PublishPubInTimeline (&Pub); // Set Pub.PubCod
/***** Update number of times this note is shared *****/
Not->NumShared = TL_DB_GetNumSharers (Not->NotCod,Not->UsrCod);
/***** Create notification about shared post
for the author of the post *****/
OriginalPubCod = TL_DB_GetPubCodOfOriginalNote (Not->NotCod);
if (OriginalPubCod > 0)
TL_Ntf_CreateNotifToAuthor (Not->UsrCod,OriginalPubCod,
Ntf_EVENT_TIMELINE_SHARE);
2021-02-08 18:33:16 +01:00
}
/*****************************************************************************/
/******************** Unshare a previously shared note ***********************/
/*****************************************************************************/
void TL_Sha_UnsNoteUsr (void)
{
/***** Get user whom profile is displayed *****/
Usr_GetParamOtherUsrCodEncryptedAndGetUsrData ();
/***** Unshare note *****/
TL_Sha_UnsNoteGbl ();
}
void TL_Sha_UnsNoteGbl (void)
{
2021-02-11 00:58:53 +01:00
struct TL_Not_Note Not;
2021-02-08 18:33:16 +01:00
/***** Unshare note *****/
2021-02-10 19:53:57 +01:00
TL_Sha_UnsNote (&Not);
2021-02-08 18:33:16 +01:00
/***** Write HTML inside DIV with form to share *****/
TL_Usr_PutIconFavSha (TL_Usr_SHA_UNS_NOTE,
Not.NotCod,Not.UsrCod,Not.NumShared,
TL_Usr_SHOW_FEW_USRS);
2021-02-08 18:33:16 +01:00
}
2021-02-11 00:58:53 +01:00
static void TL_Sha_UnsNote (struct TL_Not_Note *Not)
2021-02-08 18:33:16 +01:00
{
long OriginalPubCod;
/***** 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;
/***** Delete publication from database *****/
TL_DB_RemoveSharedPub (Not->NotCod);
/***** Update number of times this note is shared *****/
Not->NumShared = TL_DB_GetNumSharers (Not->NotCod,Not->UsrCod);
/***** Mark possible notifications on this note as removed *****/
OriginalPubCod = TL_DB_GetPubCodOfOriginalNote (Not->NotCod);
if (OriginalPubCod > 0)
Ntf_MarkNotifAsRemoved (Ntf_EVENT_TIMELINE_SHARE,OriginalPubCod);
2021-02-08 18:33:16 +01:00
}