mirror of
https://github.com/flarum/framework.git
synced 2025-01-19 18:12:59 +08:00
Track user "last seen" time and display whether they are online or not
according to their preferences
This commit is contained in:
parent
359f44552e
commit
38ebb15334
|
@ -70,7 +70,12 @@ export default Ember.Component.extend(HasItemLists, {
|
|||
}
|
||||
|
||||
items.pushObjectWithTag(Ember.Component.extend({
|
||||
layout: Ember.Handlebars.compile('{{fa-icon "circle"}} Online')
|
||||
tagName: 'li',
|
||||
classNames: ['user-last-seen'],
|
||||
classNameBindings: ['hidden', 'user.online:online'],
|
||||
layout: Ember.Handlebars.compile('{{#if user.online}}{{fa-icon "circle"}} Online{{else}}{{fa-icon "clock-o"}} {{human-time user.lastSeenTime}}{{/if}}'),
|
||||
user: this.get('user'),
|
||||
hidden: Ember.computed.not('user.lastSeenTime')
|
||||
}), 'lastActiveTime');
|
||||
|
||||
items.pushObjectWithTag(Ember.Component.extend({
|
||||
|
|
|
@ -18,6 +18,9 @@ export default DS.Model.extend(HasItemLists, {
|
|||
|
||||
joinTime: DS.attr('date'),
|
||||
lastSeenTime: DS.attr('date'),
|
||||
online: Ember.computed('lastSeenTime', function() {
|
||||
return this.get('lastSeenTime') > moment().subtract(5, 'minutes').toDate();
|
||||
}),
|
||||
readTime: DS.attr('date'),
|
||||
unreadNotificationsCount: DS.attr('number'),
|
||||
|
||||
|
|
|
@ -104,6 +104,14 @@
|
|||
font-size: 14px;
|
||||
}
|
||||
}
|
||||
& .user-last-seen {
|
||||
& .fa {
|
||||
font-size: 14px;
|
||||
}
|
||||
&.online .fa {
|
||||
font-size: 12px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.user-activity .loading-indicator {
|
||||
|
|
|
@ -21,7 +21,10 @@ class LoginWithHeader
|
|||
if (starts_with($header, $this->prefix) &&
|
||||
($token = substr($header, strlen($this->prefix))) &&
|
||||
($accessToken = AccessToken::where('id', $token)->first())) {
|
||||
$this->actor->setUser($accessToken->user);
|
||||
$this->actor->setUser($user = $accessToken->user);
|
||||
|
||||
$user->last_seen_time = time();
|
||||
$user->save();
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
|
|
|
@ -25,13 +25,18 @@ class UserSerializer extends UserBasicSerializer
|
|||
$attributes += [
|
||||
'bioHtml' => $user->bioHtml,
|
||||
'joinTime' => $user->join_time ? $user->join_time->toRFC3339String() : null,
|
||||
'lastSeenTime' => $user->last_seen_time ? $user->last_seen_time->toRFC3339String() : null,
|
||||
'discussionsCount' => (int) $user->discussions_count,
|
||||
'commentsCount' => (int) $user->comments_count,
|
||||
'canEdit' => $canEdit,
|
||||
'canDelete' => $user->can($actorUser, 'delete'),
|
||||
];
|
||||
|
||||
if ($user->preference('discloseOnline')) {
|
||||
$attributes += [
|
||||
'lastSeenTime' => $user->last_seen_time ? $user->last_seen_time->toRFC3339String() : null
|
||||
];
|
||||
}
|
||||
|
||||
if ($canEdit) {
|
||||
$attributes += [
|
||||
'bio' => $user->bio,
|
||||
|
|
Loading…
Reference in New Issue
Block a user