From 195f593f9565b4451fa953eeaf6dbee580a828c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Ca=C3=B1as=20Vargas?= Date: Tue, 24 Mar 2015 00:01:40 +0100 Subject: [PATCH] Version 14.100 --- sql/cambios.sql | 22 +++++++++++++++++++ swad_changelog.h | 8 +++++-- swad_follow.c | 41 ++++++++++++++++++++++++++++++++++- swad_follow.h | 4 ++++ swad_notification.c | 22 +++++++++++++++++++ swad_notification.h | 5 ++++- swad_text.c | 52 +++++++++++++++++++++++++++++++++++++++++++++ swad_user.c | 3 ++- 8 files changed, 152 insertions(+), 5 deletions(-) diff --git a/sql/cambios.sql b/sql/cambios.sql index 54b3ce50..69019e49 100644 --- a/sql/cambios.sql +++ b/sql/cambios.sql @@ -10551,3 +10551,25 @@ CREATE TABLE IF NOT EXISTS usr_follow (FollowerCod INT NOT NULL,FollowedCod NIT CREATE INDEX UsrCod ON file_view (UsrCod); SELECT FollowedCod,COUNT(FollowerCod) AS N FROM usr_follow GROUP BY FollowedCod ORDER BY N DESC,FollowedCod LIMIT 100; + + +----- 2015-03-23, swad14.100 +/* +UPDATE notif SET NotifyEvent=13 WHERE NotifyEvent=12; +UPDATE notif SET NotifyEvent=12 WHERE NotifyEvent=11; +UPDATE notif SET NotifyEvent=11 WHERE NotifyEvent=10; +UPDATE notif SET NotifyEvent=10 WHERE NotifyEvent=9; +UPDATE notif SET NotifyEvent=9 WHERE NotifyEvent=8; + +UPDATE sta_notif SET NotifyEvent=13 WHERE NotifyEvent=12; +UPDATE sta_notif SET NotifyEvent=12 WHERE NotifyEvent=11; +UPDATE sta_notif SET NotifyEvent=11 WHERE NotifyEvent=10; +UPDATE sta_notif SET NotifyEvent=10 WHERE NotifyEvent=9; +UPDATE sta_notif SET NotifyEvent=9 WHERE NotifyEvent=8; + +UPDATE usr_data SET NotifNtfEvents=(((NotifNtfEvents & ~0xFF) << 1) | (NotifNtfEvents & 0xFF) | 0x100); +UPDATE usr_data SET EmailNtfEvent =(((EmailNtfEvent & ~0xFF) << 1) | (EmailNtfEvent & 0xFF)); +*/ +UPDATE usr_data SET NotifNtfEvents=(NotifNtfEvents | 0x2000); + + diff --git a/swad_changelog.h b/swad_changelog.h index d1a08355..cd318657 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -103,14 +103,18 @@ /****************************** Public constants *****************************/ /*****************************************************************************/ -#define Log_PLATFORM_VERSION "SWAD 14.99.2 (2015/03/23)" +#define Log_PLATFORM_VERSION "SWAD 14.100 (2015/03/23)" // 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 /* + Version 14.100: Mar 23, 2015 Notification when a user gets a new follower. (183723 lines) + 1 change necessary in database: +UPDATE usr_data SET NotifNtfEvents=(NotifNtfEvents | 0x2000) WHERE NotifNtfEvents<>0; + Version 14.99.2: Mar 23, 2015 Ranking attending to number of followers. (183614 lines) Version 14.99.1: Mar 21, 2015 Change in file_view to accelerate queries. (183521 lines) - 1 change necessary in Makefile: + 1 change necessary in database: CREATE INDEX UsrCod ON file_view (UsrCod); Version 14.99: Mar 21, 2015 Icons instead of text in user's profile. diff --git a/swad_follow.c b/swad_follow.c index c09978d7..55a5528e 100644 --- a/swad_follow.c +++ b/swad_follow.c @@ -26,11 +26,13 @@ /*****************************************************************************/ #include // For sprintf +#include // For string functions #include "swad_bool.h" #include "swad_database.h" #include "swad_follow.h" #include "swad_global.h" +#include "swad_notification.h" #include "swad_profile.h" #include "swad_user.h" @@ -291,7 +293,12 @@ void Fol_ListFollowers (void) struct UsrData UsrDat; /***** Get user to view user he/she follows *****/ - if (Usr_GetParamOtherUsrCodEncryptedAndGetUsrData ()) + Usr_GetParamOtherUsrCodEncrypted (); + if (Gbl.Usrs.Other.UsrDat.UsrCod <= 0) // If user not specified, view my profile + Gbl.Usrs.Other.UsrDat.UsrCod = Gbl.Usrs.Me.UsrDat.UsrCod; + + /***** Check if user exists and get his data *****/ + if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&Gbl.Usrs.Other.UsrDat)) { /***** Show user's profile *****/ if (Prf_ShowUserProfile ()) @@ -339,6 +346,11 @@ void Fol_ListFollowers (void) /***** Free structure that stores the query result *****/ DB_FreeMySQLResult (&mysql_res); + + /***** If it's me, mark possible notification as seen *****/ + if (Gbl.Usrs.Other.UsrDat.UsrCod == Gbl.Usrs.Me.UsrDat.UsrCod) + Ntf_SetNotifAsSeen (Ntf_EVENT_FOLLOWER,-1L, + Gbl.Usrs.Me.UsrDat.UsrCod); } else Lay_ShowAlert (Lay_WARNING,Txt_User_not_found_or_you_do_not_have_permission_); @@ -435,6 +447,8 @@ void Fol_FollowUsr (void) { extern const char *Txt_User_not_found_or_you_do_not_have_permission_; char Query[256]; + bool CreateNotif; + bool NotifyByEmail; bool Error; /***** Get user to be followed *****/ @@ -453,6 +467,18 @@ void Fol_FollowUsr (void) Gbl.Usrs.Me.UsrDat.UsrCod, Gbl.Usrs.Other.UsrDat.UsrCod); DB_QueryREPLACE (Query,"can not follow user"); + + /***** This follow must be notified by e-mail? *****/ + CreateNotif = (Gbl.Usrs.Other.UsrDat.Prefs.NotifNtfEvents & (1 << Ntf_EVENT_FOLLOWER)); + NotifyByEmail = CreateNotif && + (Gbl.Usrs.Other.UsrDat.Prefs.EmailNtfEvents & (1 << Ntf_EVENT_FOLLOWER)); + + /***** Create notification for this followed. + If this followed wants to receive notifications by e-mail, activate the sending of a notification *****/ + if (CreateNotif) + Ntf_StoreNotifyEventToOneUser (Ntf_EVENT_FOLLOWER,&Gbl.Usrs.Other.UsrDat,-1L, + (Ntf_Status_t) (NotifyByEmail ? Ntf_STATUS_BIT_EMAIL : + 0)); } /***** Show user's profile again *****/ @@ -578,3 +604,16 @@ void Fol_GetAndShowRankingFollowers (void) } Prf_ShowRankingFigure (Query); } + +/*****************************************************************************/ +/********************* Get notification of a new follower ********************/ +/*****************************************************************************/ +// This function may be called inside a web service, so don't report error + +void Fol_GetNotifFollower (char *SummaryStr,char **ContentStr) + { + SummaryStr[0] = '\0'; + + if ((*ContentStr = (char *) malloc (1))) + strcpy (*ContentStr,""); + } diff --git a/swad_follow.h b/swad_follow.h index 5be6aa82..5b55f3bb 100644 --- a/swad_follow.h +++ b/swad_follow.h @@ -27,6 +27,8 @@ /********************************** Headers **********************************/ /*****************************************************************************/ +#include // For malloc + #include "swad_user.h" /*****************************************************************************/ @@ -51,4 +53,6 @@ void Fol_UnfollowUsr (void); void Fol_GetAndShowRankingFollowers (void); +void Fol_GetNotifFollower (char *SummaryStr,char **ContentStr); + #endif diff --git a/swad_notification.c b/swad_notification.c index c6ef3fa2..cb4a3db3 100644 --- a/swad_notification.c +++ b/swad_notification.c @@ -37,6 +37,7 @@ #include "swad_database.h" #include "swad_enrollment.h" #include "swad_exam.h" +#include "swad_follow.h" #include "swad_global.h" #include "swad_mark.h" #include "swad_notice.h" @@ -78,6 +79,9 @@ const char *Ntf_WSNotifyEvents[Ntf_NUM_NOTIFY_EVENTS] = /* Statistics tab */ "survey", + + /* Profile tab */ + "follower", }; static const Act_Action_t Ntf_DefaultActions[Ntf_NUM_NOTIFY_EVENTS] = @@ -105,6 +109,9 @@ static const Act_Action_t Ntf_DefaultActions[Ntf_NUM_NOTIFY_EVENTS] = /* Statistics tab */ ActSeeAllSvy, // Ntf_EVENT_SURVEY + + /* Profile tab */ + ActSeeFlr, // Ntf_EVENT_FOLLOWER }; /*****************************************************************************/ @@ -137,6 +144,9 @@ static const char *Ntf_ParamNotifMeAboutNotifyEvents[Ntf_NUM_NOTIFY_EVENTS] = /* Statistics tab */ "NotifyNtfEventSurvey", + + /* Profile tab */ + "NotifyNtfEventFollower", }; // Email me about notification events @@ -165,6 +175,9 @@ static const char *Ntf_ParamEmailMeAboutNotifyEvents[Ntf_NUM_NOTIFY_EVENTS] = /* Statistics tab */ "EmailNtfEventSurvey", + + /* Profile tab */ + "EmailNtfEventFollower", }; // Icons for notification events @@ -193,6 +206,9 @@ static const char *Ntf_Icons[Ntf_NUM_NOTIFY_EVENTS] = /* Statistics tab */ "survey", // Ntf_EVENT_SURVEY + + /* Profile tab */ + "follow", // Ntf_EVENT_FOLLOWER }; /*****************************************************************************/ @@ -750,6 +766,9 @@ void Ntf_GetNotifSummaryAndContent (char *SummaryStr,char **ContentStr,Ntf_Notif case Ntf_EVENT_SURVEY: Svy_GetNotifSurvey (SummaryStr,ContentStr,Cod,MaxChars,GetContent); break; + case Ntf_EVENT_FOLLOWER: + Fol_GetNotifFollower (SummaryStr,ContentStr); + break; } //if (Gbl.WebService.IsWebService) @@ -1135,6 +1154,8 @@ unsigned Ntf_StoreNotifyEventsToAllUsrs (Ntf_NotifyEvent_t NotifyEvent,long Cod) Cod,Cod,Gbl.Usrs.Me.UsrDat.UsrCod, Cod,Gbl.Usrs.Me.UsrDat.UsrCod); break; + case Ntf_EVENT_FOLLOWER: // This function should not be called in this case + return 0; } if ((NumRows = DB_QuerySELECT (Query,&mysql_res,"can not get users to be notified"))) // Users found @@ -1421,6 +1442,7 @@ static void Ntf_SendPendingNotifByEMailToOneUsr (struct UsrData *ToUsrDat,unsign switch (NotifyEvent) { case Ntf_EVENT_UNKNOWN: + case Ntf_EVENT_FOLLOWER: break; case Ntf_EVENT_DOCUMENT_FILE: case Ntf_EVENT_SHARED_FILE: diff --git a/swad_notification.h b/swad_notification.h index 2fb63fa1..d3a23459 100644 --- a/swad_notification.h +++ b/swad_notification.h @@ -37,7 +37,7 @@ /******************************** Public types *******************************/ /*****************************************************************************/ -#define Ntf_NUM_NOTIFY_EVENTS 13 +#define Ntf_NUM_NOTIFY_EVENTS 14 // If the numbers assigned to each event type change, // it is necessary to change old numbers to new ones in database tables notif and sta_notif typedef enum @@ -66,6 +66,9 @@ typedef enum /* Statistics tab */ Ntf_EVENT_SURVEY = 12, + /* Profile tab */ + Ntf_EVENT_FOLLOWER = 13, + } Ntf_NotifyEvent_t; typedef enum diff --git a/swad_text.c b/swad_text.c index 1f93c972..aefa866f 100644 --- a/swad_text.c +++ b/swad_text.c @@ -681,6 +681,18 @@ const char *Txt_NOTIFY_EVENTS_SINGULAR_NO_HTML[Ntf_NUM_NOTIFY_EVENTS][Txt_NUM_LA "Nowe badania", "Novo inquérito", }, + { + // Ntf_EVENT_FOLLOWER + "Nou seguidor", + "Neue Anhänger", + "New follower", + "Nuevo seguidor", + "Nouveau suiveur", + "Nuevo seguidor", // Okoteve traducción + "Nuovo follower", + "Nowy obserwują", + "Novo seguidor", + }, }; const char *Txt_NOTIFY_EVENTS_There_is_a_new_event_NO_HTML[Txt_NUM_LANGUAGES] = // Warning: it is very important to include %s in the following sentences @@ -24818,6 +24830,26 @@ const char *Txt_NOTIFY_EVENTS_PLURAL[Ntf_NUM_NOTIFY_EVENTS] = "Nowe badania" #elif L==8 "Novos inquéritos" +#endif + , +#if L==0 // Ntf_EVENT_FOLLOWER + "Nous seguidors" +#elif L==1 + "Neue Anhänger" +#elif L==2 + "New followers" +#elif L==3 + "Nuevos seguidores" +#elif L==4 + "Nouveaux suiveurs" +#elif L==5 + "Nuevos seguidores" // Okoteve traducción +#elif L==6 + "Nuovi followers" +#elif L==7 + "Nowe obserwują" +#elif L==8 + "Novos seguidores" #endif }; @@ -25081,6 +25113,26 @@ const char *Txt_NOTIFY_EVENTS_SINGULAR[Ntf_NUM_NOTIFY_EVENTS] = "Badania" #elif L==8 "Inquérito" +#endif + , +#if L==0 // Ntf_EVENT_FOLLOWER + "Seguidor" +#elif L==1 + "Anhänger" +#elif L==2 + "Follower" +#elif L==3 + "Seguidor" +#elif L==4 + "Suiveur" +#elif L==5 + "Seguidor" // Okoteve traducción +#elif L==6 + "Follower" +#elif L==7 + "Obserwują" +#elif L==8 + "Seguidor" #endif }; diff --git a/swad_user.c b/swad_user.c index 6e7126fc..83fb5ff0 100644 --- a/swad_user.c +++ b/swad_user.c @@ -507,10 +507,11 @@ void Usr_GetUsrDataFromUsrCod (struct UsrData *UsrDat) else UsrDat->Prefs.SideCols = Cfg_DEFAULT_COLUMNS; - /* Get on which events I want to be notified by e-mail */ + /* Get on which events I want to be notified inside the platform */ if (sscanf (row[29],"%u",&UsrDat->Prefs.NotifNtfEvents) != 1) UsrDat->Prefs.NotifNtfEvents = (unsigned) -1; // 0xFF..FF + /* Get on which events I want to be notified by e-mail */ if (sscanf (row[30],"%u",&UsrDat->Prefs.EmailNtfEvents) != 1) UsrDat->Prefs.EmailNtfEvents = 0; if (UsrDat->Prefs.EmailNtfEvents >= (1 << Ntf_NUM_NOTIFY_EVENTS)) // Maximum binary value for NotifyEvents is 000...0011...11