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.
|
2023-03-10 17:21:04 +01:00
|
|
|
|
Copyright (C) 1999-2023 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"
|
2021-10-01 09:11:58 +02:00
|
|
|
|
#include "swad_notification_database.h"
|
2023-03-10 17:21:04 +01:00
|
|
|
|
#include "swad_parameter_code.h"
|
2021-02-08 18:33:16 +01:00
|
|
|
|
#include "swad_timeline.h"
|
2021-02-27 17:23:22 +01:00
|
|
|
|
#include "swad_timeline_database.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"
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/************** External global variables from others modules ****************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
extern struct Globals Gbl;
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/***************************** Private prototypes ****************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2021-12-31 14:51:44 +01:00
|
|
|
|
static void TmlSha_ShaNote (struct TmlNot_Note *Not);
|
|
|
|
|
static void TmlSha_UnsNote (struct TmlNot_Note *Not);
|
2021-02-08 18:33:16 +01:00
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2021-03-03 10:48:23 +01:00
|
|
|
|
/****************************** Show all sharers *****************************/
|
2021-02-08 18:33:16 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2021-12-31 14:51:44 +01:00
|
|
|
|
void TmlSha_ShowAllSharersNoteUsr (void)
|
2021-02-08 18:33:16 +01:00
|
|
|
|
{
|
|
|
|
|
/***** Get user whom profile is displayed *****/
|
2023-03-10 00:13:55 +01:00
|
|
|
|
Usr_GetParOtherUsrCodEncryptedAndGetUsrData ();
|
2021-02-08 18:33:16 +01:00
|
|
|
|
|
|
|
|
|
/***** Show all sharers *****/
|
2021-12-31 14:51:44 +01:00
|
|
|
|
TmlSha_ShowAllSharersNoteGbl ();
|
2021-02-08 18:33:16 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-12-31 14:51:44 +01:00
|
|
|
|
void TmlSha_ShowAllSharersNoteGbl (void)
|
2021-02-08 18:33:16 +01:00
|
|
|
|
{
|
2021-12-31 14:51:44 +01:00
|
|
|
|
struct TmlNot_Note Not;
|
2021-02-08 18:33:16 +01:00
|
|
|
|
|
|
|
|
|
/***** Get data of note *****/
|
2023-03-10 17:21:04 +01:00
|
|
|
|
Not.NotCod = ParCod_GetAndCheckPar (ParCod_Not);
|
2023-03-23 09:35:20 +01:00
|
|
|
|
TmlNot_GetNoteDataByCod (&Not);
|
2021-02-08 18:33:16 +01:00
|
|
|
|
|
|
|
|
|
/***** Write HTML inside DIV with form to share/unshare *****/
|
2021-12-31 14:51:44 +01:00
|
|
|
|
TmlUsr_PutIconFavSha (TmlUsr_SHA_UNS_NOTE,
|
2022-06-30 11:53:24 +02:00
|
|
|
|
Not.NotCod,Not.UsrCod,Not.NumShared,
|
|
|
|
|
TmlUsr_SHOW_ALL_USRS);
|
2021-02-08 18:33:16 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-03-03 10:48:23 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/******************************** Share a note *******************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2021-12-31 14:51:44 +01:00
|
|
|
|
void TmlSha_ShaNoteUsr (void)
|
2021-02-08 18:33:16 +01:00
|
|
|
|
{
|
|
|
|
|
/***** Get user whom profile is displayed *****/
|
2023-03-10 00:13:55 +01:00
|
|
|
|
Usr_GetParOtherUsrCodEncryptedAndGetUsrData ();
|
2021-02-08 18:33:16 +01:00
|
|
|
|
|
|
|
|
|
/***** Share note *****/
|
2021-12-31 14:51:44 +01:00
|
|
|
|
TmlSha_ShaNoteGbl ();
|
2021-02-08 18:33:16 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-12-31 14:51:44 +01:00
|
|
|
|
void TmlSha_ShaNoteGbl (void)
|
2021-02-08 18:33:16 +01:00
|
|
|
|
{
|
2021-12-31 14:51:44 +01:00
|
|
|
|
struct TmlNot_Note Not;
|
2021-02-08 18:33:16 +01:00
|
|
|
|
|
|
|
|
|
/***** Share note *****/
|
2021-12-31 14:51:44 +01:00
|
|
|
|
TmlSha_ShaNote (&Not);
|
2021-02-08 18:33:16 +01:00
|
|
|
|
|
|
|
|
|
/***** Write HTML inside DIV with form to unshare *****/
|
2021-12-31 14:51:44 +01:00
|
|
|
|
TmlUsr_PutIconFavSha (TmlUsr_SHA_UNS_NOTE,
|
2022-06-30 11:53:24 +02:00
|
|
|
|
Not.NotCod,Not.UsrCod,Not.NumShared,
|
|
|
|
|
TmlUsr_SHOW_FEW_USRS);
|
2021-02-08 18:33:16 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-12-31 14:51:44 +01:00
|
|
|
|
static void TmlSha_ShaNote (struct TmlNot_Note *Not)
|
2021-02-08 18:33:16 +01:00
|
|
|
|
{
|
2021-12-31 14:51:44 +01:00
|
|
|
|
struct TmlPub_Publication Pub;
|
2021-02-08 18:33:16 +01:00
|
|
|
|
long OriginalPubCod;
|
|
|
|
|
|
2021-03-02 20:36:20 +01:00
|
|
|
|
/***** Get data of note *****/
|
2023-03-10 17:21:04 +01:00
|
|
|
|
Not->NotCod = ParCod_GetAndCheckPar (ParCod_Not);
|
2023-03-23 09:35:20 +01:00
|
|
|
|
TmlNot_GetNoteDataByCod (Not);
|
2021-03-02 20:36:20 +01:00
|
|
|
|
|
|
|
|
|
/***** Do some checks *****/
|
2021-12-31 14:51:44 +01:00
|
|
|
|
if (!TmlUsr_CheckIfICanFavSha (Not->NotCod,Not->UsrCod))
|
2021-03-01 22:31:56 +01:00
|
|
|
|
return;
|
|
|
|
|
|
2021-03-02 13:45:56 +01:00
|
|
|
|
/***** Trivial check: Is note already shared by me? *****/
|
2021-12-31 14:51:44 +01:00
|
|
|
|
if (TmlUsr_CheckIfFavedSharedByUsr (TmlUsr_SHA_UNS_NOTE,Not->NotCod,
|
2021-04-30 00:12:54 +02:00
|
|
|
|
Gbl.Usrs.Me.UsrDat.UsrCod))
|
2021-03-01 22:31:56 +01:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
/***** Share (publish note in timeline) *****/
|
|
|
|
|
Pub.NotCod = Not->NotCod;
|
|
|
|
|
Pub.PublisherCod = Gbl.Usrs.Me.UsrDat.UsrCod;
|
2021-12-31 14:51:44 +01:00
|
|
|
|
Pub.Type = TmlPub_SHARED_NOTE;
|
|
|
|
|
TmlPub_PublishPubInTimeline (&Pub); // Set Pub.PubCod
|
2021-03-01 22:31:56 +01:00
|
|
|
|
|
|
|
|
|
/***** Update number of times this note is shared *****/
|
2021-03-04 17:47:08 +01:00
|
|
|
|
Not->NumShared = Tml_DB_GetNumSharers (Not->NotCod,Not->UsrCod);
|
2021-03-01 22:31:56 +01:00
|
|
|
|
|
|
|
|
|
/***** Create notification about shared post
|
|
|
|
|
for the author of the post *****/
|
2021-11-21 01:22:59 +01:00
|
|
|
|
if ((OriginalPubCod = Tml_DB_GetPubCodOfOriginalNote (Not->NotCod)) > 0)
|
2021-12-31 14:51:44 +01:00
|
|
|
|
TmlNtf_CreateNotifToAuthor (Not->UsrCod,OriginalPubCod,Ntf_EVENT_TML_SHARE);
|
2021-02-08 18:33:16 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/******************** Unshare a previously shared note ***********************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2021-12-31 14:51:44 +01:00
|
|
|
|
void TmlSha_UnsNoteUsr (void)
|
2021-02-08 18:33:16 +01:00
|
|
|
|
{
|
|
|
|
|
/***** Get user whom profile is displayed *****/
|
2023-03-10 00:13:55 +01:00
|
|
|
|
Usr_GetParOtherUsrCodEncryptedAndGetUsrData ();
|
2021-02-08 18:33:16 +01:00
|
|
|
|
|
|
|
|
|
/***** Unshare note *****/
|
2021-12-31 14:51:44 +01:00
|
|
|
|
TmlSha_UnsNoteGbl ();
|
2021-02-08 18:33:16 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-12-31 14:51:44 +01:00
|
|
|
|
void TmlSha_UnsNoteGbl (void)
|
2021-02-08 18:33:16 +01:00
|
|
|
|
{
|
2021-12-31 14:51:44 +01:00
|
|
|
|
struct TmlNot_Note Not;
|
2021-02-08 18:33:16 +01:00
|
|
|
|
|
|
|
|
|
/***** Unshare note *****/
|
2021-12-31 14:51:44 +01:00
|
|
|
|
TmlSha_UnsNote (&Not);
|
2021-02-08 18:33:16 +01:00
|
|
|
|
|
|
|
|
|
/***** Write HTML inside DIV with form to share *****/
|
2021-12-31 14:51:44 +01:00
|
|
|
|
TmlUsr_PutIconFavSha (TmlUsr_SHA_UNS_NOTE,
|
2022-06-30 11:53:24 +02:00
|
|
|
|
Not.NotCod,Not.UsrCod,Not.NumShared,
|
|
|
|
|
TmlUsr_SHOW_FEW_USRS);
|
2021-02-08 18:33:16 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-12-31 14:51:44 +01:00
|
|
|
|
static void TmlSha_UnsNote (struct TmlNot_Note *Not)
|
2021-02-08 18:33:16 +01:00
|
|
|
|
{
|
|
|
|
|
long OriginalPubCod;
|
|
|
|
|
|
2021-03-02 20:36:20 +01:00
|
|
|
|
/***** Get data of note *****/
|
2023-03-10 17:21:04 +01:00
|
|
|
|
Not->NotCod = ParCod_GetAndCheckPar (ParCod_Not);
|
2023-03-23 09:35:20 +01:00
|
|
|
|
TmlNot_GetNoteDataByCod (Not);
|
2021-03-01 22:31:56 +01:00
|
|
|
|
|
2021-03-02 20:36:20 +01:00
|
|
|
|
/***** Do some checks *****/
|
2021-12-31 14:51:44 +01:00
|
|
|
|
if (!TmlUsr_CheckIfICanFavSha (Not->NotCod,Not->UsrCod))
|
2021-03-01 22:31:56 +01:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
/***** Delete publication from database *****/
|
2021-03-04 17:47:08 +01:00
|
|
|
|
Tml_DB_RemoveSharedPub (Not->NotCod);
|
2021-03-01 22:31:56 +01:00
|
|
|
|
|
|
|
|
|
/***** Update number of times this note is shared *****/
|
2021-03-04 17:47:08 +01:00
|
|
|
|
Not->NumShared = Tml_DB_GetNumSharers (Not->NotCod,Not->UsrCod);
|
2021-03-01 22:31:56 +01:00
|
|
|
|
|
|
|
|
|
/***** Mark possible notifications on this note as removed *****/
|
2021-11-21 01:22:59 +01:00
|
|
|
|
if ((OriginalPubCod = Tml_DB_GetPubCodOfOriginalNote (Not->NotCod)) > 0)
|
2021-11-12 01:12:15 +01:00
|
|
|
|
Ntf_DB_MarkNotifAsRemoved (Ntf_EVENT_TML_SHARE,OriginalPubCod);
|
2021-02-08 18:33:16 +01:00
|
|
|
|
}
|