Skip to content

Commit

Permalink
Refactor preferences & subscriptions
Browse files Browse the repository at this point in the history
- Simplify preferences bit shifting
- Use constants for subscriptions
  • Loading branch information
luchaos committed Mar 2, 2023
1 parent 9c5d7ae commit 5a734b9
Show file tree
Hide file tree
Showing 14 changed files with 129 additions and 382 deletions.
3 changes: 2 additions & 1 deletion app_legacy/Helpers/database/forum.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use LegacyApp\Community\Enums\ArticleType;
use LegacyApp\Community\Enums\SubscriptionSubjectType;
use LegacyApp\Site\Enums\Permissions;
use RA\UserPreference;

function getForumList($categoryID = 0): ?array
{
Expand Down Expand Up @@ -354,7 +355,7 @@ function notifyUsersAboutForumActivity($topicID, $topicTitle, $author, $commentI
$subscribers = getSubscribersOf(
SubscriptionSubjectType::ForumTopic,
$topicID,
1 << 3,
UserPreference::EmailOn_ForumReply,
"
SELECT DISTINCT ua.*
FROM
Expand Down
2 changes: 1 addition & 1 deletion app_legacy/Helpers/database/message.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function CreateNewMessage($author, $destUser, $messageTitle, $messagePayloadIn):
$websitePrefs = $userDetails['websitePrefs'];
$destEmail = $userDetails['EmailAddress'];

if (BitSet($websitePrefs, UserPreference::EmailOn_PrivateMessage)) {
if (isBitSet($websitePrefs, UserPreference::EmailOn_PrivateMessage)) {
sendPrivateMessageEmail($destUser, $destEmail, $messageTitle, $messagePayload, $author);
}
}
Expand Down
299 changes: 0 additions & 299 deletions app_legacy/Helpers/database/subscription.php

This file was deleted.

1 change: 0 additions & 1 deletion app_legacy/Helpers/database/user-activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,6 @@ function addArticleComment($user, $articleType, $articleID, $commentPayload, $on
return false;
}

// Inform Subscribers of this comment:
if (is_array($articleID)) {
foreach ($articleID as $id) {
informAllSubscribersAboutActivity($articleType, $id, $user, $onBehalfOfUser);
Expand Down
2 changes: 1 addition & 1 deletion app_legacy/Helpers/database/user-relationship.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function changeFriendStatus(string $user, string $friend, int $newStatus): strin
case UserRelationship::Following:
// attempt to notify the target of the new follower
if (getAccountDetails($friend, $friendData)) {
if ($newRelationship && BitSet($friendData['websitePrefs'], UserPreference::EmailOn_Followed)) {
if ($newRelationship && isBitSet($friendData['websitePrefs'], UserPreference::EmailOn_Followed)) {
// notify the new friend of the request
sendFriendEmail($friend, $friendData['EmailAddress'], 0, $user);
}
Expand Down
3 changes: 2 additions & 1 deletion app_legacy/Helpers/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
require_once __DIR__ . '/database/set-request.php';
require_once __DIR__ . '/database/site-award.php';
require_once __DIR__ . '/database/static.php';
require_once __DIR__ . '/database/subscription.php';
require_once __DIR__ . '/database/ticket.php';
require_once __DIR__ . '/database/user.php';
require_once __DIR__ . '/database/user-account-deletion.php';
Expand All @@ -30,7 +29,9 @@
require_once __DIR__ . '/database/user-email-verify.php';
require_once __DIR__ . '/database/user-password-reset.php';
require_once __DIR__ . '/database/user-permission.php';
require_once __DIR__ . '/database/user-preference.php';
require_once __DIR__ . '/database/user-relationship.php';
require_once __DIR__ . '/database/user-subscription.php';

require_once __DIR__ . '/render/achievement.php';
require_once __DIR__ . '/render/avatar.php';
Expand Down
4 changes: 2 additions & 2 deletions app_legacy/Helpers/util/bit.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

function BitSet($value, $flagBit): bool
function isBitSet(int|string $value, int $index): bool
{
return ($value & (1 << $flagBit)) !== 0;
return ((int) $value & (1 << $index)) !== 0;
}
14 changes: 7 additions & 7 deletions app_legacy/Helpers/util/mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ function informAllSubscribersAboutActivity($articleType, $articleID, $activityAu
switch ($articleType) {
case ArticleType::Game:
$gameData = getGameData($articleID);
$subscribers = getSubscribersOfGameWall($articleID);
$subscribers = getSubscribersOfGame($articleID);
$articleTitle = $gameData['Title'] . ' (' . $gameData['ConsoleName'] . ')';
break;

Expand All @@ -225,12 +225,12 @@ function informAllSubscribersAboutActivity($articleType, $articleID, $activityAu
case ArticleType::News: // News
break;

case ArticleType::Activity: // Activity (feed)
$activityData = getActivityMetadata($articleID);
$subscribers = getSubscribersOfFeedActivity($articleID, $activityData['User']);
$subjectAuthor = $activityData['User'];
$articleTitle = $activityData['User'];
break;
// case ArticleType::Activity: // Activity (feed)
// $activityData = getActivityMetadata($articleID);
// $subscribers = getSubscribersOfFeedActivity($articleID, $activityData['User']);
// $subjectAuthor = $activityData['User'];
// $articleTitle = $activityData['User'];
// break;

case ArticleType::Leaderboard: // Leaderboard
break;
Expand Down
Loading

0 comments on commit 5a734b9

Please sign in to comment.