Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/Data/UserData.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Data;

use App\Models\Role;
use App\Models\User;
use App\Platform\Enums\PlayerPreferredMode;
use App\Support\Media\UserAvatarUrl;
Expand Down Expand Up @@ -36,6 +37,7 @@ public function __construct(
public Lazy|bool $isGone = false,
public Lazy|bool $isMuted = false,
public Lazy|bool $isNew = false,
public Lazy|bool $isTeamAccount = false,
public Lazy|bool|null $isUserWallActive = null,
public Lazy|Carbon|null $lastActivityAt = null,
public Lazy|int|null $legacyPermissions = null,
Expand Down Expand Up @@ -94,6 +96,7 @@ public static function fromUser(User $user): self
isGone: Lazy::create(fn () => $user->is_gone),
isMuted: Lazy::create(fn () => $user->isMuted()),
isNew: Lazy::create(fn () => $user->isNew()),
isTeamAccount: Lazy::create(fn () => $user->hasRole(Role::TEAM_ACCOUNT)),
isUserWallActive: Lazy::create(fn () => $user->is_user_wall_active),
lastActivityAt: Lazy::create(fn () => $user->last_activity_at),
legacyPermissions: Lazy::create(fn () => (int) $user->getAttribute('Permissions')),
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/Api/SearchApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ private function searchUsers(string $keyword, ?int $page = null, ?int $perPage =
$filteredUsers = $users->filter(fn ($user) => $user->email_verified_at !== null);

$results = $filteredUsers->map(function ($user) {
return UserData::fromUser($user)->include('lastActivityAt', 'points', 'pointsSoftcore', 'roles');
return UserData::fromUser($user)->include('isTeamAccount', 'lastActivityAt', 'points', 'pointsSoftcore');
});

return $this->buildSearchResponse($results, 0.5, $this->buildPaginationMeta($paginator));
Expand All @@ -245,7 +245,7 @@ private function searchUsers(string $keyword, ?int $page = null, ?int $perPage =
->take(self::MAX_RESULTS_PER_SCOPE);

$results = $filteredUsers->map(function ($user) {
return UserData::fromUser($user)->include('lastActivityAt', 'points', 'pointsSoftcore', 'roles');
return UserData::fromUser($user)->include('isTeamAccount', 'lastActivityAt', 'points', 'pointsSoftcore');
});

// Calculate average relevance for section ordering.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ describe('Component: UserResultDisplay', () => {

const user = createUser({
lastActivityAt: '2024-01-15T10:00:00Z', // !! 2 hours ago
roles: ['team-account'],
isTeamAccount: true,
});

render(<UserResultDisplay user={user} />);
Expand All @@ -139,7 +139,7 @@ describe('Component: UserResultDisplay', () => {

const user = createUser({
lastActivityAt: '2024-01-15T11:57:00Z', // !! 3 minutes ago
roles: ['team-account'],
isTeamAccount: true,
});

render(<UserResultDisplay user={user} />);
Expand All @@ -152,7 +152,7 @@ describe('Component: UserResultDisplay', () => {
// ARRANGE
const user = createUser({
lastActivityAt: undefined,
roles: ['team-account'],
isTeamAccount: true,
});

render(<UserResultDisplay user={user} />);
Expand All @@ -162,14 +162,14 @@ describe('Component: UserResultDisplay', () => {
expect(screen.queryByTestId('active-indicator')).not.toBeInTheDocument();
});

it('given the user has no roles defined and has last activity, still shows the last seen label', () => {
it('given the user has no team account flag and has last activity, still shows the last seen label', () => {
// ARRANGE
const mockCurrentTime = dayjs.utc('2024-01-15T12:00:00Z').toDate();
vi.setSystemTime(mockCurrentTime);

const user = createUser({
lastActivityAt: '2024-01-15T10:00:00Z',
roles: undefined,
isTeamAccount: undefined,
});

render(<UserResultDisplay user={user} />);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,15 @@ import dayjs from 'dayjs';
import type { FC } from 'react';
import { useTranslation } from 'react-i18next';

import { UserRole } from '@/common/utils/generatedAppConstants';
import { useDiffForHumans } from '@/common/utils/l10n/useDiffForHumans';

interface UserResultDisplayProps {
user: App.Data.User;
}

export const UserResultDisplay: FC<UserResultDisplayProps> = ({ user }) => {
const isTeamAccount = user.roles?.includes(UserRole.TEAM_ACCOUNT) ?? false;

const isActive =
!isTeamAccount && user.lastActivityAt
!user.isTeamAccount && user.lastActivityAt
? Math.abs(dayjs(user.lastActivityAt).diff(dayjs(), 'minute')) <= 5
: false;

Expand All @@ -34,7 +31,7 @@ export const UserResultDisplay: FC<UserResultDisplayProps> = ({ user }) => {
<div className="font-medium text-link">{user.displayName}</div>

<div className="flex items-center gap-4 text-xs text-neutral-400 light:text-neutral-600">
{user.lastActivityAt && !isTeamAccount ? (
{user.lastActivityAt && !user.isTeamAccount ? (
<LastSeenLabel userLastActivityAt={user.lastActivityAt} />
) : null}
</div>
Expand Down
1 change: 1 addition & 0 deletions resources/js/types/generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ isEmailVerified?: boolean;
isGone?: boolean;
isMuted?: boolean;
isNew?: boolean;
isTeamAccount?: boolean;
isUserWallActive?: boolean | null;
lastActivityAt?: string | null;
legacyPermissions?: number | null;
Expand Down