Merge pull request #13668 from annando/issue-8542

Issue 8542: User option to display the event list/birthday notification
This commit is contained in:
Hypolite Petovan
2023-11-25 10:26:34 -05:00
committed by GitHub
9 changed files with 182 additions and 169 deletions
+30 -31
View File
@@ -22,6 +22,7 @@
namespace Friendica\Model;
use Friendica\App;
use Friendica\App\Mode;
use Friendica\Content\Text\BBCode;
use Friendica\Content\Widget\ContactBlock;
use Friendica\Core\Cache\Enum\Duration;
@@ -506,30 +507,40 @@ class Profile
return $o;
}
/**
* Check if the event list should be displayed
*
* @param integer $uid
* @param Mode $mode
* @return boolean
*/
public static function shouldDisplayEventList(int $uid, Mode $mode): bool
{
if (empty($uid) || $mode->isMobile()) {
return false;
}
if (!DI::pConfig()->get($uid, 'system', 'display_eventlist', true)) {
return false;
}
return !DI::config()->get('theme', 'hide_eventlist');
}
/**
* Returns the upcoming birthdays of contacts of the current user as HTML content
* @param int $uid User Id
*
* @return string The upcoming birthdays (HTML)
* @throws HTTPException\InternalServerErrorException
* @throws HTTPException\ServiceUnavailableException
* @throws \ImagickException
*/
public static function getBirthdays(): string
public static function getBirthdays(int $uid): string
{
if (!DI::userSession()->getLocalUserId() || DI::mode()->isMobile() || DI::mode()->isMobile()) {
return '';
}
/*
* $mobile_detect = new Mobile_Detect();
* $is_mobile = $mobile_detect->isMobile() || $mobile_detect->isTablet();
* if ($is_mobile)
* return $o;
*/
$bd_short = DI::l10n()->t('F d');
$cacheKey = 'get_birthdays:' . DI::userSession()->getLocalUserId();
$cacheKey = 'get_birthdays:' . $uid;
$events = DI::cache()->get($cacheKey);
if (is_null($events)) {
$result = DBA::p(
@@ -546,7 +557,7 @@ class Profile
ORDER BY `start`",
Contact::SHARING,
Contact::FRIEND,
DI::userSession()->getLocalUserId(),
$uid,
DateTimeFormat::utc('now + 6 days'),
DateTimeFormat::utcNow()
);
@@ -610,30 +621,18 @@ class Profile
/**
* Renders HTML for event reminder (e.g. contact birthdays
* @param int $uid User Id
* @param int $pcid Public Contact Id
*
* @return string Rendered HTML
*/
public static function getEventsReminderHTML(): string
public static function getEventsReminderHTML(int $uid, int $pcid): string
{
$a = DI::app();
$o = '';
if (!DI::userSession()->getLocalUserId() || DI::mode()->isMobile() || DI::mode()->isMobile()) {
return $o;
}
/*
* $mobile_detect = new Mobile_Detect();
* $is_mobile = $mobile_detect->isMobile() || $mobile_detect->isTablet();
* if ($is_mobile)
* return $o;
*/
$bd_format = DI::l10n()->t('g A l F d'); // 8 AM Friday January 18
$classtoday = '';
$condition = ["`uid` = ? AND `type` != 'birthday' AND `start` < ? AND `start` >= ?",
DI::userSession()->getLocalUserId(), DateTimeFormat::utc('now + 7 days'), DateTimeFormat::utc('now - 1 days')];
$uid, DateTimeFormat::utc('now + 7 days'), DateTimeFormat::utc('now - 1 days')];
$s = DBA::select('event', [], $condition, ['order' => ['start']]);
$r = [];
@@ -643,7 +642,7 @@ class Profile
$total = 0;
while ($rr = DBA::fetch($s)) {
$condition = ['parent-uri' => $rr['uri'], 'uid' => $rr['uid'], 'author-id' => DI::userSession()->getPublicContactId(),
$condition = ['parent-uri' => $rr['uri'], 'uid' => $rr['uid'], 'author-id' => $pcid,
'vid' => [Verb::getID(Activity::ATTEND), Verb::getID(Activity::ATTENDMAYBE)],
'visible' => true, 'deleted' => false];
if (!Post::exists($condition)) {
+3 -3
View File
@@ -231,9 +231,9 @@ class Network extends Timeline
} else {
$this->systemMessages->addNotice($this->l10n->t('Invalid contact.'));
}
} elseif (!$this->config->get('theme', 'hide_eventlist')) {
$o .= Profile::getBirthdays();
$o .= Profile::getEventsReminderHTML();
} elseif (Profile::shouldDisplayEventList($this->session->getLocalUserId(), $this->mode)) {
$o .= Profile::getBirthdays($this->session->getLocalUserId());
$o .= Profile::getEventsReminderHTML($this->session->getLocalUserId(), $this->session->getPublicContactId());
}
try {
+3 -3
View File
@@ -220,9 +220,9 @@ class Conversations extends BaseProfile
$last_updated_array[$last_updated_key] = time();
$this->session->set('last_updated', $last_updated_array);
if ($is_owner && !$this->config->get('theme', 'hide_eventlist')) {
$o .= ProfileModel::getBirthdays();
$o .= ProfileModel::getEventsReminderHTML();
if ($is_owner && ProfileModel::shouldDisplayEventList($this->session->getLocalUserId(), $this->mode)) {
$o .= ProfileModel::getBirthdays($this->session->getLocalUserId());
$o .= ProfileModel::getEventsReminderHTML($this->session->getLocalUserId(), $this->session->getPublicContactId());
}
if ($is_owner) {
+4
View File
@@ -108,6 +108,7 @@ class Display extends BaseSettings
$display_resharer = (bool)$request['display_resharer'];
$stay_local = (bool)$request['stay_local'];
$show_page_drop = (bool)$request['show_page_drop'];
$display_eventlist = (bool)$request['display_eventlist'];
$preview_mode = (int)$request['preview_mode'];
$browser_update = (int)$request['browser_update'];
if ($browser_update != -1) {
@@ -158,6 +159,7 @@ class Display extends BaseSettings
$this->pConfig->set($uid, 'system', 'display_resharer' , $display_resharer);
$this->pConfig->set($uid, 'system', 'stay_local' , $stay_local);
$this->pConfig->set($uid, 'system', 'show_page_drop' , $show_page_drop);
$this->pConfig->set($uid, 'system', 'display_eventlist' , $display_eventlist);
$this->pConfig->set($uid, 'system', 'preview_mode' , $preview_mode);
$this->pConfig->set($uid, 'system', 'network_timelines' , $network_timelines);
@@ -251,6 +253,7 @@ class Display extends BaseSettings
$display_resharer = $this->pConfig->get($uid, 'system', 'display_resharer', false);
$stay_local = $this->pConfig->get($uid, 'system', 'stay_local', false);
$show_page_drop = $this->pConfig->get($uid, 'system', 'show_page_drop', true);
$display_eventlist = $this->pConfig->get($uid, 'system', 'display_eventlist', true);
$preview_mode = $this->pConfig->get($uid, 'system', 'preview_mode', BBCode::PREVIEW_LARGE);
$preview_modes = [
@@ -329,6 +332,7 @@ class Display extends BaseSettings
'$display_resharer' => ['display_resharer' , $this->t('Display the resharer'), $display_resharer, $this->t('Display the first resharer as icon and text on a reshared item.')],
'$stay_local' => ['stay_local' , $this->t('Stay local'), $stay_local, $this->t("Don't go to a remote system when following a contact link.")],
'$show_page_drop' => ['show_page_drop' , $this->t('Show the post deletion checkbox'), $show_page_drop, $this->t("Display the checkbox for the post deletion on the network page.")],
'$display_eventlist' => ['display_eventlist' , $this->t('DIsplay the event list'), $display_eventlist, $this->t("Display the birthday reminder and event list on the network page.")],
'$preview_mode' => ['preview_mode' , $this->t('Link preview mode'), $preview_mode, $this->t('Appearance of the link preview that is added to each post with a link.'), $preview_modes, false],
'$timeline_label' => $this->t('Label'),
+3 -3
View File
@@ -104,9 +104,9 @@ class Profile extends BaseModule
$last_updated_array[$last_updated_key] = time();
DI::session()->set('last_updated', $last_updated_array);
if ($is_owner && !$a->getProfileOwner() && !DI::config()->get('theme', 'hide_eventlist')) {
$o .= ProfileModel::getBirthdays();
$o .= ProfileModel::getEventsReminderHTML();
if ($is_owner && !$a->getProfileOwner() && ProfileModel::shouldDisplayEventList(DI::userSession()->getLocalUserId(), DI::mode())) {
$o .= ProfileModel::getBirthdays(DI::userSession()->getLocalUserId());
$o .= ProfileModel::getEventsReminderHTML(DI::userSession()->getLocalUserId(), DI::userSession()->getPublicContactId());
}
if ($is_owner) {
@@ -47,7 +47,7 @@ class Configuration extends BaseDataTransferObject
StatusesConfig $statuses,
MediaAttachmentsConfig $media_attachments,
Polls $polls,
Accounts $accounts,
Accounts $accounts
) {
$this->accounts = $accounts;
$this->statuses = $statuses;