diff --git a/Makefile b/Makefile index 3bc7a30c9..85173bb48 100644 --- a/Makefile +++ b/Makefile @@ -63,7 +63,7 @@ OBJS = swad_account.o swad_action.o swad_agenda.o swad_alert.o \ swad_test_import.o swad_test_print.o swad_test_visibility.o \ swad_theme.o swad_timeline.o swad_timeline_comment.o \ swad_timeline_favourite.o swad_timeline_note.o \ - swad_timeline_publication.o swad_timeline_share.o \ + swad_timeline_publication.o swad_timeline_share.o swad_timeline_who.o \ swad_timetable.o \ swad_user.o \ swad_xml.o \ diff --git a/swad_action.c b/swad_action.c index c17c4bef4..2bdde5f3c 100644 --- a/swad_action.c +++ b/swad_action.c @@ -98,6 +98,7 @@ #include "swad_timeline_comment.h" #include "swad_timeline_favourite.h" #include "swad_timeline_share.h" +#include "swad_timeline_who.h" #include "swad_timetable.h" #include "swad_zip.h" @@ -126,7 +127,7 @@ const struct Act_Actions Act_Actions[Act_NUM_ACTIONS] = // TabStr ****************************************************************** [ActFrmLogIn ] = {1521, 0,TabStr,ActFrmLogIn , 0,0x001,0x001,0x001,0x001,0x001,0x001,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Usr_WriteLandingPage ,"power-off" }, [ActReqSch ] = { 627, 1,TabStr,ActReqSch ,0x3F8,0x3C7,0x3C7,0x3C7,0x3C7,0x3C7,0x3C7,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Sch_ReqSysSearch ,"search" }, - [ActSeeTmlGbl ] = {1490, 2,TabStr,ActSeeTmlGbl ,0x3F8,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,Act_CONT_NORM,Act_BRW_1ST_TAB,TL_GetParamWho ,TL_ShowTimelineGbl ,"comment-dots" }, + [ActSeeTmlGbl ] = {1490, 2,TabStr,ActSeeTmlGbl ,0x3F8,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,Act_CONT_NORM,Act_BRW_1ST_TAB,TL_Who_GetParamWho ,TL_ShowTimelineGbl ,"comment-dots" }, [ActSeeSocPrf ] = {1520, 3,TabStr,ActSeeSocPrf ,0x3F8,0x3C7,0x3C7,0x3C7,0x3C7,0x3C7,0x3C7,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Prf_SeeSocialProfiles ,"user-circle" }, [ActSeeCal ] = {1622, 4,TabStr,ActSeeCal ,0x3F8,0x3C7,0x3C7,0x3C7,0x3C7,0x3C7,0x3C7,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Cal_ShowCalendar ,"calendar" }, [ActSeeNtf ] = { 990, 5,TabStr,ActSeeNtf ,0x3F8,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Ntf_ShowMyNotifications ,"bell" }, @@ -141,10 +142,10 @@ const struct Act_Actions Act_Actions[Act_NUM_ACTIONS] = [ActSch ] = { 628,-1,TabUnk,ActReqSch ,0x3F8,0x3C7,0x3C7,0x3C7,0x3C7,0x3C7,0x3C7,Act_CONT_NORM,Act_BRW_1ST_TAB,Sch_GetParamsSearch ,Sch_SysSearch ,NULL}, - [ActRefNewTL_PubGbl ] = {1509,-1,TabUnk,ActSeeTmlGbl ,0x3F8,0x3C7,0x3C7,0x3C7,0x3C7,0x3C7,0x3C7,Act_CONT_NORM,Act_AJAX_RFRESH,TL_GetParamWho ,TL_RefreshNewTimelineGbl ,NULL}, - [ActRefOldTL_PubGbl ] = {1510,-1,TabUnk,ActSeeTmlGbl ,0x3F8,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,Act_CONT_NORM,Act_AJAX_NORMAL,TL_GetParamWho ,TL_RefreshOldTimelineGbl ,NULL}, - [ActRcvTL_PstGbl ] = {1492,-1,TabUnk,ActSeeTmlGbl ,0x3F8,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,Act_CONT_DATA,Act_BRW_1ST_TAB,TL_GetParamWho ,TL_ReceivePostGbl ,NULL}, - [ActRcvTL_ComGbl ] = {1503,-1,TabUnk,ActSeeTmlGbl ,0x3F8,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,Act_CONT_DATA,Act_BRW_1ST_TAB,TL_GetParamWho ,TL_Com_ReceiveCommentGbl ,NULL}, + [ActRefNewTL_PubGbl ] = {1509,-1,TabUnk,ActSeeTmlGbl ,0x3F8,0x3C7,0x3C7,0x3C7,0x3C7,0x3C7,0x3C7,Act_CONT_NORM,Act_AJAX_RFRESH,TL_Who_GetParamWho ,TL_RefreshNewTimelineGbl ,NULL}, + [ActRefOldTL_PubGbl ] = {1510,-1,TabUnk,ActSeeTmlGbl ,0x3F8,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,Act_CONT_NORM,Act_AJAX_NORMAL,TL_Who_GetParamWho ,TL_RefreshOldTimelineGbl ,NULL}, + [ActRcvTL_PstGbl ] = {1492,-1,TabUnk,ActSeeTmlGbl ,0x3F8,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,Act_CONT_DATA,Act_BRW_1ST_TAB,TL_Who_GetParamWho ,TL_ReceivePostGbl ,NULL}, + [ActRcvTL_ComGbl ] = {1503,-1,TabUnk,ActSeeTmlGbl ,0x3F8,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,Act_CONT_DATA,Act_BRW_1ST_TAB,TL_Who_GetParamWho ,TL_Com_ReceiveCommentGbl ,NULL}, [ActShoHidTL_ComGbl ] = {1806,-1,TabUnk,ActSeeTmlGbl ,0x3F8,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,Act_CONT_NORM,Act_AJAX_NORMAL,NULL ,TL_Com_ShowHiddenCommentsGbl ,NULL}, [ActAllShaTL_NotGbl ] = {1766,-1,TabUnk,ActSeeTmlGbl ,0x3F8,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,Act_CONT_NORM,Act_AJAX_NORMAL,NULL ,TL_Sha_ShowAllSharersNoteGbl ,NULL}, [ActAllFavTL_NotGbl ] = {1767,-1,TabUnk,ActSeeTmlGbl ,0x3F8,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,Act_CONT_NORM,Act_AJAX_NORMAL,NULL ,TL_Fav_ShowAllFaversNoteGbl ,NULL}, @@ -155,10 +156,10 @@ const struct Act_Actions Act_Actions[Act_NUM_ACTIONS] = [ActUnfTL_NotGbl ] = {1513,-1,TabUnk,ActSeeTmlGbl ,0x3F8,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,Act_CONT_NORM,Act_AJAX_NORMAL,NULL ,TL_Fav_UnfNoteGbl ,NULL}, [ActFavTL_ComGbl ] = {1516,-1,TabUnk,ActSeeTmlGbl ,0x3F8,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,Act_CONT_NORM,Act_AJAX_NORMAL,NULL ,TL_Fav_FavCommentGbl ,NULL}, [ActUnfTL_ComGbl ] = {1517,-1,TabUnk,ActSeeTmlGbl ,0x3F8,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,Act_CONT_NORM,Act_AJAX_NORMAL,NULL ,TL_Fav_UnfCommentGbl ,NULL}, - [ActReqRemTL_PubGbl ] = {1494,-1,TabUnk,ActSeeTmlGbl ,0x3F8,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,Act_CONT_NORM,Act_BRW_1ST_TAB,TL_GetParamWho ,TL_Not_RequestRemNoteGbl ,NULL}, - [ActRemTL_PubGbl ] = {1493,-1,TabUnk,ActSeeTmlGbl ,0x3F8,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,Act_CONT_NORM,Act_BRW_1ST_TAB,TL_GetParamWho ,TL_Not_RemoveNoteGbl ,NULL}, - [ActReqRemTL_ComGbl ] = {1505,-1,TabUnk,ActSeeTmlGbl ,0x3F8,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,Act_CONT_NORM,Act_BRW_1ST_TAB,TL_GetParamWho ,TL_Com_RequestRemComGbl ,NULL}, - [ActRemTL_ComGbl ] = {1507,-1,TabUnk,ActSeeTmlGbl ,0x3F8,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,Act_CONT_NORM,Act_BRW_1ST_TAB,TL_GetParamWho ,TL_Com_RemoveComGbl ,NULL}, + [ActReqRemTL_PubGbl ] = {1494,-1,TabUnk,ActSeeTmlGbl ,0x3F8,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,Act_CONT_NORM,Act_BRW_1ST_TAB,TL_Who_GetParamWho ,TL_Not_RequestRemNoteGbl ,NULL}, + [ActRemTL_PubGbl ] = {1493,-1,TabUnk,ActSeeTmlGbl ,0x3F8,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,Act_CONT_NORM,Act_BRW_1ST_TAB,TL_Who_GetParamWho ,TL_Not_RemoveNoteGbl ,NULL}, + [ActReqRemTL_ComGbl ] = {1505,-1,TabUnk,ActSeeTmlGbl ,0x3F8,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,Act_CONT_NORM,Act_BRW_1ST_TAB,TL_Who_GetParamWho ,TL_Com_RequestRemComGbl ,NULL}, + [ActRemTL_ComGbl ] = {1507,-1,TabUnk,ActSeeTmlGbl ,0x3F8,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,Act_CONT_NORM,Act_BRW_1ST_TAB,TL_Who_GetParamWho ,TL_Com_RemoveComGbl ,NULL}, [ActReqOthPubPrf ] = {1401,-1,TabUnk,ActSeeSocPrf ,0x3F8,0x3C7,0x3C7,0x3C7,0x3C7,0x3C7,0x3C7,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Prf_RequestUserProfile ,NULL}, diff --git a/swad_changelog.h b/swad_changelog.h index aff1e7950..44d9e8f14 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -553,7 +553,7 @@ enscript -2 --landscape --color --file-align=2 --highlight --line-numbers -o - * En OpenSWAD: ps2pdf source.ps destination.pdf */ -#define Log_PLATFORM_VERSION "SWAD 20.25 (2021-02-11)" +#define Log_PLATFORM_VERSION "SWAD 20.26 (2021-02-11)" #define CSS_FILE "swad20.8.css" #define JS_FILE "swad20.6.2.js" /* @@ -601,6 +601,7 @@ 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 + Version 20.26: Feb 11, 2021 New module swad_timeline_who. (305540 lines) Version 20.25: Feb 11, 2021 New module swad_timeline_publication. (305440 lines) Version 20.24: Feb 11, 2021 Code refactoring in timeline. New linked list to hold publications. (305354 lines) Version 20.23: Feb 11, 2021 New modules swad_timeline_comment and swad_timeline_note. (305319 lines) diff --git a/swad_layout.c b/swad_layout.c index bca9a7dc1..66395008c 100644 --- a/swad_layout.c +++ b/swad_layout.c @@ -61,6 +61,7 @@ #include "swad_tab.h" #include "swad_theme.h" #include "swad_timeline.h" +#include "swad_timeline_who.h" /*****************************************************************************/ /************** External global variables from others modules ****************/ @@ -889,7 +890,7 @@ static void Lay_WriteScriptParamsAJAX (void) "var RefreshParamWho = \"Who=%u\";\n", Act_GetActCod (ActRefNewTL_PubGbl), Act_GetActCod (ActRefOldTL_PubGbl), - (unsigned) TL_GetGlobalWho ()); // Global variable got in a priori function + (unsigned) TL_Who_GetGlobalWho ()); // Global variable got in a priori function break; /* Parameters related with user timeline refreshing */ case ActSeeOthPubPrf: diff --git a/swad_timeline.c b/swad_timeline.c index 280839905..685a6dbb6 100644 --- a/swad_timeline.c +++ b/swad_timeline.c @@ -49,6 +49,7 @@ #include "swad_timeline_note.h" #include "swad_timeline_publication.h" #include "swad_timeline_share.h" +#include "swad_timeline_who.h" /*****************************************************************************/ /****************************** Public constants *****************************/ @@ -182,14 +183,6 @@ static void TL_ShowTimeline (struct TL_Timeline *Timeline, const char *Title,long NotCodToHighlight); static void TL_PutIconsTimeline (__attribute__((unused)) void *Args); -static void TL_PutFormWho (struct TL_Timeline *Timeline); -static Usr_Who_t TL_GetWhoFromDB (void); -static void TL_SetGlobalWho (Usr_Who_t Who); - -static void TL_SaveWhoInDB (struct TL_Timeline *Timeline); - -static void TL_ShowWarningYouDontFollowAnyUser (void); - static void TL_PutFormToWriteNewPost (struct TL_Timeline *Timeline); static long TL_ReceivePost (void); @@ -207,7 +200,7 @@ void TL_InitTimelineGbl (struct TL_Timeline *Timeline) TL_MarkMyNotifAsSeen (); /***** Get which users *****/ - Timeline->Who = TL_GetGlobalWho (); + Timeline->Who = TL_Who_GetGlobalWho (); } /*****************************************************************************/ @@ -237,7 +230,7 @@ void TL_ShowTimelineGbl (void) TL_InitTimelineGbl (&Timeline); /***** Save which users in database *****/ - TL_SaveWhoInDB (&Timeline); + TL_Who_SaveWhoInDB (&Timeline); /***** Show highlighted note and global timeline *****/ TL_ShowNoteAndTimelineGbl (&Timeline); @@ -342,7 +335,7 @@ void TL_RefreshNewTimelineGbl (void) TL_ResetTimeline (&Timeline); /***** Get which users *****/ - Timeline.Who = TL_GetGlobalWho (); + Timeline.Who = TL_Who_GetGlobalWho (); /***** Get list of pubications to show in timeline *****/ Timeline.UsrOrGbl = TL_TIMELINE_GBL; @@ -369,7 +362,7 @@ void TL_RefreshOldTimelineGbl (void) TL_ResetTimeline (&Timeline); /***** Get which users *****/ - Timeline.Who = TL_GetGlobalWho (); + Timeline.Who = TL_Who_GetGlobalWho (); /***** Show old publications *****/ Timeline.UsrOrGbl = TL_TIMELINE_GBL; @@ -472,7 +465,7 @@ static void TL_ShowTimeline (struct TL_Timeline *Timeline, /***** Put form to select users whom public activity is displayed *****/ if (GlobalTimeline) - TL_PutFormWho (Timeline); + TL_Who_PutFormWho (Timeline); /***** Form to write a new post *****/ if (GlobalTimeline || ItsMe) @@ -559,155 +552,6 @@ void TL_FormStart (const struct TL_Timeline *Timeline, } } -/*****************************************************************************/ -/******** Show form to select users whom public activity is displayed ********/ -/*****************************************************************************/ - -static void TL_PutFormWho (struct TL_Timeline *Timeline) - { - Usr_Who_t Who; - unsigned Mask = 1 << Usr_WHO_ME | - 1 << Usr_WHO_FOLLOWED | - 1 << Usr_WHO_ALL; - - /***** Setting selector for which users *****/ - Set_StartSettingsHead (); - Set_StartOneSettingSelector (); - for (Who = (Usr_Who_t) 0; - Who <= (Usr_Who_t) (Usr_NUM_WHO - 1); - Who++) - if (Mask & (1 << Who)) - { - HTM_DIV_Begin ("class=\"%s\"", - Who == Timeline->Who ? "PREF_ON" : - "PREF_OFF"); - Frm_StartForm (ActSeeTmlGbl); - Par_PutHiddenParamUnsigned (NULL,"Who",(unsigned) Who); - Usr_PutWhoIcon (Who); - Frm_EndForm (); - HTM_DIV_End (); - } - Set_EndOneSettingSelector (); - Set_EndSettingsHead (); - - /***** Show warning if I do not follow anyone *****/ - if (Timeline->Who == Usr_WHO_FOLLOWED) - TL_ShowWarningYouDontFollowAnyUser (); - } - -/*****************************************************************************/ -/********* Get parameter with which users to view in global timeline *********/ -/*****************************************************************************/ - -void TL_GetParamWho (void) - { - Usr_Who_t Who; - - /***** Get which users I want to see *****/ - Who = Usr_GetHiddenParamWho (); - - /***** If parameter Who is not present, get it from database *****/ - if (Who == Usr_WHO_UNKNOWN) - Who = TL_GetWhoFromDB (); - - /***** If parameter Who is unknown, set it to default *****/ - if (Who == Usr_WHO_UNKNOWN) - Who = TL_DEFAULT_WHO; - - /***** Set global variable *****/ - TL_SetGlobalWho (Who); - } - -/*****************************************************************************/ -/********* Get which users to view in global timeline from database **********/ -/*****************************************************************************/ - -static Usr_Who_t TL_GetWhoFromDB (void) - { - MYSQL_RES *mysql_res; - MYSQL_ROW row; - unsigned UnsignedNum; - Usr_Who_t Who = Usr_WHO_UNKNOWN; - - /***** Get which users from database *****/ - if (DB_QuerySELECT (&mysql_res,"can not get timeline users from user's last data", - "SELECT TimelineUsrs" // row[0] - " FROM usr_last WHERE UsrCod=%ld", - Gbl.Usrs.Me.UsrDat.UsrCod) == 1) - { - row = mysql_fetch_row (mysql_res); - - /* Get who */ - if (sscanf (row[0],"%u",&UnsignedNum) == 1) - if (UnsignedNum < Usr_NUM_WHO) - Who = (Usr_Who_t) UnsignedNum; - } - - /***** Free structure that stores the query result *****/ - DB_FreeMySQLResult (&mysql_res); - - return Who; - } - -/*****************************************************************************/ -/******** Save which users to view in global timeline into database **********/ -/*****************************************************************************/ - -static void TL_SaveWhoInDB (struct TL_Timeline *Timeline) - { - if (Gbl.Usrs.Me.Logged) - { - if (Timeline->Who == Usr_WHO_UNKNOWN) - Timeline->Who = TL_DEFAULT_WHO; - - /***** Update which users in database *****/ - // Who is stored in usr_last for next time I log in - DB_QueryUPDATE ("can not update timeline users in user's last data", - "UPDATE usr_last SET TimelineUsrs=%u" - " WHERE UsrCod=%ld", - (unsigned) Timeline->Who, - Gbl.Usrs.Me.UsrDat.UsrCod); - } - } - -/*****************************************************************************/ -/**** Set/get global variable with which users to view in global timeline ****/ -/*****************************************************************************/ - -static void TL_SetGlobalWho (Usr_Who_t Who) - { - TL_GlobalWho = Who; - } - -Usr_Who_t TL_GetGlobalWho (void) - { - return TL_GlobalWho; - } - -/*****************************************************************************/ -/********* Get parameter with which users to view in global timeline *********/ -/*****************************************************************************/ - -static void TL_ShowWarningYouDontFollowAnyUser (void) - { - extern const char *Txt_You_dont_follow_any_user; - unsigned NumFollowing; - unsigned NumFollowers; - - /***** Check if I follow someone *****/ - Fol_GetNumFollow (Gbl.Usrs.Me.UsrDat.UsrCod,&NumFollowing,&NumFollowers); - if (!NumFollowing) - { - /***** Show warning if I do not follow anyone *****/ - Ale_ShowAlert (Ale_WARNING,Txt_You_dont_follow_any_user); - - /***** Contextual menu *****/ - Mnu_ContextMenuBegin (); - Fol_PutLinkWhoToFollow (); // Users to follow - Mnu_ContextMenuEnd (); - } - } - /*****************************************************************************/ /*************** Write sharer/commenter if distinct to author ****************/ /*****************************************************************************/ diff --git a/swad_timeline.h b/swad_timeline.h index f8ecf7b3b..c39acaf92 100644 --- a/swad_timeline.h +++ b/swad_timeline.h @@ -153,9 +153,6 @@ void TL_FormStart (const struct TL_Timeline *Timeline, Act_Action_t ActionGbl, Act_Action_t ActionUsr); -void TL_GetParamWho (void); -Usr_Who_t TL_GetGlobalWho (void); - void TL_WriteTopMessage (TL_TopMessage_t TopMessage,long PublisherCod); void TL_WriteDateTime (time_t TimeUTC); diff --git a/swad_timeline_who.c b/swad_timeline_who.c new file mode 100644 index 000000000..8f39ccd69 --- /dev/null +++ b/swad_timeline_who.c @@ -0,0 +1,232 @@ +// swad_timeline_who.c: select users whom timeline is displayed + +/* + 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. + Copyright (C) 1999-2021 Antonio Cañas Vargas + + 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 . +*/ +/*****************************************************************************/ +/*********************************** Headers *********************************/ +/*****************************************************************************/ + +#define _GNU_SOURCE // For asprintf +#include // For PATH_MAX +#include // For asprintf +#include // For malloc and free +#include // For string functions +#include // For time_t + +#include "swad_database.h" +#include "swad_exam_announcement.h" +#include "swad_figure.h" +#include "swad_follow.h" +#include "swad_form.h" +#include "swad_forum.h" +#include "swad_global.h" +#include "swad_message.h" +#include "swad_notice.h" +#include "swad_photo.h" +#include "swad_profile.h" +#include "swad_setting.h" +#include "swad_timeline.h" +#include "swad_timeline_favourite.h" +#include "swad_timeline_note.h" +#include "swad_timeline_publication.h" +#include "swad_timeline_share.h" + +/*****************************************************************************/ +/****************************** Public constants *****************************/ +/*****************************************************************************/ + +/*****************************************************************************/ +/************************* Private constants and types ***********************/ +/*****************************************************************************/ + +/*****************************************************************************/ +/************** External global variables from others modules ****************/ +/*****************************************************************************/ + +extern struct Globals Gbl; + +/*****************************************************************************/ +/************************* Private global variables **************************/ +/*****************************************************************************/ + +Usr_Who_t TL_GlobalWho; + +#define TL_DEFAULT_WHO Usr_WHO_FOLLOWED + +/*****************************************************************************/ +/***************************** Private prototypes ****************************/ +/*****************************************************************************/ + +static Usr_Who_t TL_Who_GetWhoFromDB (void); + +static void TL_Who_SetGlobalWho (Usr_Who_t Who); + +static void TL_Who_ShowWarningYouDontFollowAnyUser (void); + +/*****************************************************************************/ +/******** Show form to select users whom public activity is displayed ********/ +/*****************************************************************************/ + +void TL_Who_PutFormWho (struct TL_Timeline *Timeline) + { + Usr_Who_t Who; + unsigned Mask = 1 << Usr_WHO_ME | + 1 << Usr_WHO_FOLLOWED | + 1 << Usr_WHO_ALL; + + /***** Setting selector for which users *****/ + Set_StartSettingsHead (); + Set_StartOneSettingSelector (); + for (Who = (Usr_Who_t) 0; + Who <= (Usr_Who_t) (Usr_NUM_WHO - 1); + Who++) + if (Mask & (1 << Who)) + { + HTM_DIV_Begin ("class=\"%s\"", + Who == Timeline->Who ? "PREF_ON" : + "PREF_OFF"); + Frm_StartForm (ActSeeTmlGbl); + Par_PutHiddenParamUnsigned (NULL,"Who",(unsigned) Who); + Usr_PutWhoIcon (Who); + Frm_EndForm (); + HTM_DIV_End (); + } + Set_EndOneSettingSelector (); + Set_EndSettingsHead (); + + /***** Show warning if I do not follow anyone *****/ + if (Timeline->Who == Usr_WHO_FOLLOWED) + TL_Who_ShowWarningYouDontFollowAnyUser (); + } + +/*****************************************************************************/ +/********* Get parameter with which users to view in global timeline *********/ +/*****************************************************************************/ + +void TL_Who_GetParamWho (void) + { + Usr_Who_t Who; + + /***** Get which users I want to see *****/ + Who = Usr_GetHiddenParamWho (); + + /***** If parameter Who is not present, get it from database *****/ + if (Who == Usr_WHO_UNKNOWN) + Who = TL_Who_GetWhoFromDB (); + + /***** If parameter Who is unknown, set it to default *****/ + if (Who == Usr_WHO_UNKNOWN) + Who = TL_DEFAULT_WHO; + + /***** Set global variable *****/ + TL_Who_SetGlobalWho (Who); + } + +/*****************************************************************************/ +/********* Get which users to view in global timeline from database **********/ +/*****************************************************************************/ + +static Usr_Who_t TL_Who_GetWhoFromDB (void) + { + MYSQL_RES *mysql_res; + MYSQL_ROW row; + unsigned UnsignedNum; + Usr_Who_t Who = Usr_WHO_UNKNOWN; + + /***** Get which users from database *****/ + if (DB_QuerySELECT (&mysql_res,"can not get timeline users from user's last data", + "SELECT TimelineUsrs" // row[0] + " FROM usr_last WHERE UsrCod=%ld", + Gbl.Usrs.Me.UsrDat.UsrCod) == 1) + { + row = mysql_fetch_row (mysql_res); + + /* Get who */ + if (sscanf (row[0],"%u",&UnsignedNum) == 1) + if (UnsignedNum < Usr_NUM_WHO) + Who = (Usr_Who_t) UnsignedNum; + } + + /***** Free structure that stores the query result *****/ + DB_FreeMySQLResult (&mysql_res); + + return Who; + } + +/*****************************************************************************/ +/******** Save which users to view in global timeline into database **********/ +/*****************************************************************************/ + +void TL_Who_SaveWhoInDB (struct TL_Timeline *Timeline) + { + if (Gbl.Usrs.Me.Logged) + { + if (Timeline->Who == Usr_WHO_UNKNOWN) + Timeline->Who = TL_DEFAULT_WHO; + + /***** Update which users in database *****/ + // Who is stored in usr_last for next time I log in + DB_QueryUPDATE ("can not update timeline users in user's last data", + "UPDATE usr_last SET TimelineUsrs=%u" + " WHERE UsrCod=%ld", + (unsigned) Timeline->Who, + Gbl.Usrs.Me.UsrDat.UsrCod); + } + } + +/*****************************************************************************/ +/**** Set/get global variable with which users to view in global timeline ****/ +/*****************************************************************************/ + +static void TL_Who_SetGlobalWho (Usr_Who_t Who) + { + TL_GlobalWho = Who; + } + +Usr_Who_t TL_Who_GetGlobalWho (void) + { + return TL_GlobalWho; + } + +/*****************************************************************************/ +/********* Get parameter with which users to view in global timeline *********/ +/*****************************************************************************/ + +static void TL_Who_ShowWarningYouDontFollowAnyUser (void) + { + extern const char *Txt_You_dont_follow_any_user; + unsigned NumFollowing; + unsigned NumFollowers; + + /***** Check if I follow someone *****/ + Fol_GetNumFollow (Gbl.Usrs.Me.UsrDat.UsrCod,&NumFollowing,&NumFollowers); + if (!NumFollowing) + { + /***** Show warning if I do not follow anyone *****/ + Ale_ShowAlert (Ale_WARNING,Txt_You_dont_follow_any_user); + + /***** Contextual menu *****/ + Mnu_ContextMenuBegin (); + Fol_PutLinkWhoToFollow (); // Users to follow + Mnu_ContextMenuEnd (); + } + } diff --git a/swad_timeline_who.h b/swad_timeline_who.h new file mode 100644 index 000000000..89b68e0e0 --- /dev/null +++ b/swad_timeline_who.h @@ -0,0 +1,52 @@ +// swad_timeline_who.c: select users whom timeline is displayed + +#ifndef _SWAD_TL_WHO +#define _SWAD_TL_WHO +/* + SWAD (Shared Workspace At a Distance in Spanish), + is a web platform developed at the University of Granada (Spain), + and used to support university teaching. + + This file is part of SWAD core. + Copyright (C) 1999-2021 Antonio Cañas Vargas + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public 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 . +*/ +/*****************************************************************************/ +/********************************** Headers **********************************/ +/*****************************************************************************/ + +#include "swad_user.h" + +/*****************************************************************************/ +/****************************** Public constants *****************************/ +/*****************************************************************************/ + +/*****************************************************************************/ +/******************************** Public types *******************************/ +/*****************************************************************************/ + +/*****************************************************************************/ +/****************************** Public prototypes ****************************/ +/*****************************************************************************/ + +void TL_Who_PutFormWho (struct TL_Timeline *Timeline); + +void TL_Who_GetParamWho (void); + +void TL_Who_SaveWhoInDB (struct TL_Timeline *Timeline); + +Usr_Who_t TL_Who_GetGlobalWho (void); + +#endif