Fix #161: online status bug

This commit is contained in:
Celestora 2021-11-04 13:45:30 +02:00
parent e5ea1cd351
commit c0c35c3872
5 changed files with 17 additions and 20 deletions

View file

@ -568,6 +568,11 @@ class User extends RowModel
return !is_null($this->getBanReason());
}
function isOnline(): bool
{
return time() - $this->getRecord()->online <= 300;
}
function prefersNotToSeeRating(): bool
{
return !((bool) $this->getRecord()->show_rating);

View file

@ -30,18 +30,14 @@ final class UserPresenter extends OpenVKPresenter
if(parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH) !== "/" . $user->getShortCode())
$this->redirect("/" . $user->getShortCode(), static::REDIRECT_TEMPORARY_PRESISTENT);
$then = date_create("@" . $user->getOnline()->timestamp());
$now = date_create();
$diff = date_diff($now, $then);
$this->template->albums = (new Albums)->getUserAlbums($user);
$this->template->albumsCount = (new Albums)->getUserAlbumsCount($user);
$this->template->videos = (new Videos)->getByUser($user, 1, 2);
$this->template->videosCount = (new Videos)->getUserVideosCount($user);
$this->template->notes = (new Notes)->getUserNotes($user, 1, 4);
$this->template->notesCount = (new Notes)->getUserNotesCount($user);
$this->template->user = $user;
$this->template->diff = $diff;
}
}

View file

@ -34,10 +34,10 @@
<!-- DEBUG: ONLINE REPORT: static {$user->getOnline()->timestamp()}s adjusted {$user->getOnline()->timestamp() + 2505600}s real {time()}s -->
<div n:if="$user->getOnline()->timestamp() + 2505600 > time()" style="float:right;">
{if $diff->i <= 5}
<span><b>{_online}</b></span>
{if $user->isOnline()}
<span><b>{_online}</b></span>
{else}
<span>{_was_online} {$user->getOnline()}</span>
<span>{_was_online} {$user->getOnline()}</span>
{/if}
</div>
<div n:if="$user->onlineStatus() == 2" style="float:right;">

View file

@ -7,12 +7,10 @@
<img
src="{$author->getAvatarURL()}"
width="{ifset $compact}25{else}50{/ifset}" />
{if !$post->isPostedOnBehalfOfGroup() && !$compact}
<span n:if="$author->getOnline()->timestamp() + 2505600 > time()" class="post-online">
{if $diff->i <= 5}
{_online}
{/if}
</span>
{if !$post->isPostedOnBehalfOfGroup() && !$compact}
<span n:if="$author->isOnline()" class="post-online">
{_online}
</span>
{/if}
</td>
<td width="100%" valign="top">

View file

@ -7,13 +7,11 @@
<img
src="{$author->getAvatarURL()}"
width="50" />
{if !$post->isPostedOnBehalfOfGroup() && !$compact}
<span n:if="$author->getOnline()->timestamp() + 2505600 > time()" class="post-online">
{if $diff->i <= 5}
{_online}
{if !$post->isPostedOnBehalfOfGroup() && !$compact}
<span n:if="$author->isOnline()" class="post-online">
{_online}
</span>
{/if}
</span>
{/if}
</td>
<td width="100%" valign="top">
<div class="post-author">