Browse Source

Set a priority of XEP-0319: Last User Interaction in Presence over XEP-0203: Delayed Delivery

- Refactor the prepareDate and prepareTime functions
pull/1323/head
Timothée Jaussoin 1 year ago
parent
commit
401b6aad1d
  1. 2
      CHANGELOG.md
  2. 13
      app/Presence.php
  3. 12
      app/helpers/DateHelper.php
  4. 2
      app/widgets/Account/_account_fingerprints.tpl
  5. 2
      app/widgets/AdminReported/_adminreported_reported.tpl
  6. 2
      app/widgets/AdminSessions/adminsessions.tpl
  7. 8
      app/widgets/Chat/Chat.php
  8. 4
      app/widgets/Chat/_chat_empty.tpl
  9. 2
      app/widgets/Chat/_chat_header.tpl
  10. 2
      app/widgets/ChatActions/_chatactions_message.tpl
  11. 6
      app/widgets/Chats/_chats_item.tpl
  12. 2
      app/widgets/CommunitiesServer/_communitiesserver_ticket.tpl
  13. 2
      app/widgets/CommunityData/_communitydata_card.tpl
  14. 6
      app/widgets/ContactActions/_contactactions_drawer.tpl
  15. 2
      app/widgets/ContactActions/_contactactions_drawer_fingerprints.tpl
  16. 4
      app/widgets/ContactData/_contactdata.tpl
  17. 6
      app/widgets/ContactData/_contactdata_card.tpl
  18. 2
      app/widgets/Location/_location_toggle.tpl
  19. 4
      app/widgets/NotificationConfig/_notificationconfig_push.tpl
  20. 2
      app/widgets/Notifications/_notifications.tpl
  21. 4
      app/widgets/Post/_post.tpl
  22. 4
      app/widgets/Post/_post_card.tpl
  23. 6
      app/widgets/Post/_post_comments.tpl
  24. 2
      app/widgets/Post/_post_reply.tpl
  25. 4
      app/widgets/Post/_post_ticket.tpl
  26. 2
      app/widgets/RoomsUtils/_rooms_presences_list.tpl
  27. 2
      app/widgets/Search/_search_roster.tpl

2
CHANGELOG.md

@ -4,6 +4,8 @@ Movim Changelog
v0.24.2 (master)
---------------------------
* Fix #1317 Handle properly the from attribute from MAM messages
* Set a priority of XEP-0319: Last User Interaction in Presence over XEP-0203: Delayed Delivery
* Refactor the prepareDate and prepareTime functions
v0.24.1
---------------------------

13
app/Presence.php

@ -41,19 +41,22 @@ class Presence extends Model
return $this->hasOne('App\Contact', 'id', 'jid');
}
public function getSeenAttribute()
public function getSeenAttribute(): ?string
{
if ($this->value == 1) return;
if ($this->value == 1) return null;
if ($this->resource == '' && $this->delay) {
// XEP-0319
if ($this->idle) {
return $this->idle;
}
// ...supersedes XEP-0256
elseif ($this->resource == '' && $this->delay) {
$delay = strtotime($this->delay);
if ($this->last) $delay += $this->last;
return gmdate('Y-m-d H:i:s', $delay);
} elseif ($this->delay) {
return $this->delay;
} elseif ($this->idle) {
return $this->idle;
}
}

12
app/helpers/DateHelper.php

@ -6,9 +6,10 @@
* @param timestamp $string
* @return string
*/
function prepareDate($time = false, $hours = true, $compact = false, $dateOnly = false)
function prepareDate(string $datetime = '', bool $hours = true, bool $compact = false, bool $dateOnly = false): string
{
$time = $time ? $time : time();
$time = strtotime($datetime);
$time = $time !== false ? $time : time();
$t = $time + TIMEZONE_OFFSET;
$date = '';
@ -65,15 +66,16 @@ function prepareDate($time = false, $hours = true, $compact = false, $dateOnly =
* @param timestamp $string
* @return string
*/
function prepareTime($time = false)
function prepareTime(string $datetime = ''): string
{
$time = $time ? $time : time();
$time = strtotime($datetime);
$time = $time != false ? $time : time();
$t = $time + TIMEZONE_OFFSET;
return gmdate('H:i', $t);
}
function toSQLDate($date)
function toSQLDate($date): string
{
return date(MOVIM_SQL_DATE, strtotime((string)$date));
}

2
app/widgets/Account/_account_fingerprints.tpl

@ -35,7 +35,7 @@
</span>
</p>
{if="isset($value->latest)"}
<p>{$c->__('omemo.last_activity')}: {$value->latest|strtotime|prepareDate:true}</p>
<p>{$c->__('omemo.last_activity')}: {$value->latest|prepareDate:true}</p>
{/if}
</div>
</li>

2
app/widgets/AdminReported/_adminreported_reported.tpl

@ -30,7 +30,7 @@
</span>
<div>
<p class="line normal">
<span class="info">{$value->created_at|strtotime|prepareDate}</span>
<span class="info">{$value->created_at|prepareDate}</span>
{$value->id}
</p>
<p class="line" title="{$value->users()->pluck('id')->implode(', ')}">{$c->__('adminreported.reported_by', $value->users()->count())}</p>

2
app/widgets/AdminSessions/adminsessions.tpl

@ -24,7 +24,7 @@
{$user->truename} <span class="second">{$user->id}</span>
</p>
<p>
{$value->created_at|strtotime|prepareDate}
{$value->created_at|prepareDate}
</p>
</div>
</li>

8
app/widgets/Chat/Chat.php

@ -1343,17 +1343,17 @@ class Chat extends \Movim\Widget\Base
$message->rtl = isRTL($message->body);
}
$message->publishedPrepared = prepareTime(strtotime($message->published));
$message->publishedPrepared = prepareTime($message->published);
if ($message->delivered) {
$message->delivered = prepareDate(strtotime($message->delivered), true);
$message->delivered = prepareDate($message->delivered, true);
}
if ($message->displayed) {
$message->displayed = prepareDate(strtotime($message->displayed), true);
$message->displayed = prepareDate($message->displayed, true);
}
$date = prepareDate(strtotime($message->published), false, false, true);
$date = prepareDate($message->published, false, false, true);
if (empty($date)) {
$date = $this->__('date.today');

4
app/widgets/Chat/_chat_empty.tpl

@ -32,8 +32,8 @@
</p>
{if="$value->presence && $value->presence->seen"}
<p class="line" title="{$c->__('last.title')} {$value->presence->seen|strtotime|prepareDate:true,true}">
{$c->__('last.title')} {$value->presence->seen|strtotime|prepareDate:true,true}
<p class="line" title="{$c->__('last.title')} {$value->presence->seen|prepareDate:true,true}">
{$c->__('last.title')} {$value->presence->seen|prepareDate:true,true}
</p>
{elseif="$value->presence"}
<p class="line">{$value->presence->presencetext}</p>

2
app/widgets/Chat/_chat_header.tpl

@ -232,7 +232,7 @@
{$contact->locationDistance|humanDistance}
{/if}
{if="$roster && $roster->presence && $roster->presence->seen"}
{$c->__('last.title')} {$roster->presence->seen|strtotime|prepareDate:true,true}
{$c->__('last.title')} {$roster->presence->seen|prepareDate:true,true}
{elseif="$roster && $roster->presence && !empty($roster->presence->status)"}
{$roster->presence->status}
{elseif="$roster && $roster->presence"}

2
app/widgets/ChatActions/_chatactions_message.tpl

@ -1,7 +1,7 @@
<section id="chat_actions">
<ul class="list" id="message_preview">
<li {if="$message->isMine()"}class="oppose"{/if}>
<div class="bubble {if="$message->picture"}file{/if}" data-publishedprepared="{$message->published|strtotime|prepareTime}">
<div class="bubble {if="$message->picture"}file{/if}" data-publishedprepared="{$message->published|prepareTime}">
<div class="message">
{if="$message->retracted"}
<p class="retracted"><i class="material-symbols">delete</i>{$c->__('message.retracted')}</p>

6
app/widgets/Chats/_chats_item.tpl

@ -10,7 +10,7 @@
{/if}
{/if}
"
title="{$contact->jid}{if="isset($message)"} · {$message->published|strtotime|prepareDate}{/if}">
title="{$contact->jid}{if="isset($message)"} · {$message->published|prepareDate}{/if}">
<span class="primary icon bubble
{if="$roster && $roster->presence"}status {$roster->presence->presencekey}{/if}
{if="$contact->locationDistance"} location{/if}
@ -24,11 +24,11 @@
<p class="normal line">
{if="isset($message)"}
<span class="info">
{$message->published|strtotime|prepareDate:true,true}
{$message->published|prepareDate:true,true}
</span>
{/if}
{if="isset($message)"}
<span class="info" title="{$message->published|strtotime|prepareDate}">
<span class="info" title="{$message->published|prepareDate}">
{if="$message->jidfrom == $message->user_id"}
{if="$message->displayed"}
<span class="material-symbols">done_all</span>

2
app/widgets/CommunitiesServer/_communitiesserver_ticket.tpl

@ -40,7 +40,7 @@
{if="$community->published"}
<span class="info">
<i class="material-symbols">update</i>
{$community->published|strtotime|prepareDate:true}
{$community->published|prepareDate:true}
</span>
{/if}
</p>

2
app/widgets/CommunityData/_communitydata_card.tpl

@ -29,7 +29,7 @@
{if="$info->created"}
<br />
<i class="material-symbols icon-text">calendar</i>
{$info->created|strtotime|prepareDate:true,true}
{$info->created|prepareDate:true,true}
{/if}
<br />

6
app/widgets/ContactActions/_contactactions_drawer.tpl

@ -80,7 +80,7 @@
{if="$roster && $roster->presence && $roster->presence->seen"}
<i class="material-symbols icon-text">schedule</i>
{$c->__('last.title')} {$roster->presence->seen|strtotime|prepareDate:true,true}
{$c->__('last.title')} {$roster->presence->seen|prepareDate:true,true}
<br />
{/if}
@ -97,7 +97,7 @@
{if="$contact->date && strtotime($contact->date) != 0"}
<i class="material-symbols icon-text">cake</i>
{$contact->date|strtotime|prepareDate:false}
{$contact->date|prepareDate:false}
<br />
{/if}
@ -125,7 +125,7 @@
{if="$contact->locationDistance != null"}
<i class="material-symbols icon-text">place</i>
<a href="{$contact->locationUrl}" target="_blank">{$contact->locationDistance|humanDistance}</a> - {$contact->loctimestamp|strtotime|prepareDate:true,true}
<a href="{$contact->locationUrl}" target="_blank">{$contact->locationDistance|humanDistance}</a> - {$contact->loctimestamp|prepareDate:true,true}
<br />
{/if}
</p>

2
app/widgets/ContactActions/_contactactions_drawer_fingerprints.tpl

@ -37,7 +37,7 @@
&nbsp;-&nbsp;
{/if}
{if="isset($value->latest)"}
{$c->__('omemo.last_activity')}: {$value->latest|strtotime|prepareDate:true}
{$c->__('omemo.last_activity')}: {$value->latest|prepareDate:true}
{/if}
</p>
</div>

4
app/widgets/ContactData/_contactdata.tpl

@ -39,8 +39,8 @@
<div>
<p class="normal">
{if="isset($message)"}
<span class="info" title="{$message->published|strtotime|prepareDate}">
{$message->published|strtotime|prepareDate:true,true}
<span class="info" title="{$message->published|prepareDate}">
{$message->published|prepareDate:true,true}
</span>
{/if}
{$c->__('button.chat')}

6
app/widgets/ContactData/_contactdata_card.tpl

@ -31,7 +31,7 @@
{if="$roster && $roster->presence && $roster->presence->seen"}
<i class="material-symbols icon-text">schedule</i>
{$c->__('last.title')} {$roster->presence->seen|strtotime|prepareDate:true,true}
{$c->__('last.title')} {$roster->presence->seen|prepareDate:true,true}
<br />
{/if}
@ -73,11 +73,11 @@
{if="$contact->locationDistance != null && $contact->locationUrl != null"}
<i class="material-symbols icon-text">place</i>
<a href="{$contact->locationUrl}" target="_blank">{$contact->locationDistance|humanDistance}</a> - {$contact->loctimestamp|strtotime|prepareDate:true,true}
<a href="{$contact->locationUrl}" target="_blank">{$contact->locationDistance|humanDistance}</a> - {$contact->loctimestamp|prepareDate:true,true}
<br />
{elseif="$contact->hasLocation() && $contact->locationUrl != null"}
<i class="material-symbols icon-text">place</i>
<a href="{$contact->locationUrl}" target="_blank">{$c->__('location.last_published')}</a> - {$contact->loctimestamp|strtotime|prepareDate:true,true}
<a href="{$contact->locationUrl}" target="_blank">{$c->__('location.last_published')}</a> - {$contact->loctimestamp|prepareDate:true,true}
<br />
{/if}
</p>

2
app/widgets/Location/_location_toggle.tpl

@ -18,7 +18,7 @@
{/if}
{if="$contact->loctimestamp"}
-
{$contact->loctimestamp|strtotime|prepareDate:true,true}
{$contact->loctimestamp|prepareDate:true,true}
{/if}
</p>
</div>

4
app/widgets/NotificationConfig/_notificationconfig_push.tpl

@ -34,11 +34,11 @@
<div>
<p class="normal">
{if="$value->activity_at"}
<span class="info">{$c->__('omemo.last_activity')}: {$value->activity_at|strtotime|prepareDate}</span>
<span class="info">{$c->__('omemo.last_activity')}: {$value->activity_at|prepareDate}</span>
{/if}
{$value->browser ?? $c->__('notificationconfig.unknown_browser')}
</p>
<p>{$value->platform ?? $c->__('notificationconfig.unknown_platform')} - {$value->created_at|strtotime|prepareDate}</p>
<p>{$value->platform ?? $c->__('notificationconfig.unknown_platform')} - {$value->created_at|prepareDate}</p>
</div>
</li>
{if="$value->self"}<br /><hr /><br />{/if}

2
app/widgets/Notifications/_notifications.tpl

@ -83,7 +83,7 @@
{/if}
</p>
<p class="line" onclick="MovimUtils.reload('{$c->route('post', [$parent->server, $parent->node, $parent->nodeid])}'); Drawer.clear();">
<span class="info">{$value->published|strtotime|prepareDate:true,true}</span>
<span class="info">{$value->published|prepareDate:true,true}</span>
{if="!$value->isLike()"}
{$c->__('post.commented')}
{if="$value->content"}

4
app/widgets/Post/_post.tpl

@ -125,9 +125,9 @@
{$post->node}
{if="!$public"}</a>{/if} ·
{/if}
{$post->published|strtotime|prepareDate}
{$post->published|prepareDate}
{if="$post->published != $post->updated"}
<i class="material-symbols" title="{$post->updated|strtotime|prepareDate}">
<i class="material-symbols" title="{$post->updated|prepareDate}">
edit
</i>
{/if}

4
app/widgets/Post/_post_card.tpl

@ -62,9 +62,9 @@
{$post->node}
</a> ·
{/if}
{$post->published|strtotime|prepareDate}
{$post->published|prepareDate}
{if="$post->published != $post->updated"}
<i class="material-symbols" title="{$post->updated|strtotime|prepareDate}">
<i class="material-symbols" title="{$post->updated|prepareDate}">
edit
</i>
{/if}

6
app/widgets/Post/_post_comments.tpl

@ -16,7 +16,7 @@
{if="$value->isMine()"}
{$liked = [$value->server, $value->node, $value->nodeid]}
{/if}
<a title="{$value->published|strtotime|prepareDate:true,true}"
<a title="{$value->published|prepareDate:true,true}"
href="{$c->route('contact', $value->aid)}">
{$value->truename}</a>{if="$key + 1 < $post->likes->count()"},{/if}
{/if}
@ -71,8 +71,8 @@
{/if}
<div>
<p class="normal line">
<span class="info" title="{$value->published|strtotime|prepareDate}">
{$value->published|strtotime|prepareDate:true,true}
<span class="info" title="{$value->published|prepareDate}">
{$value->published|prepareDate:true,true}
</span>
{if="$value->truename"}
{if="$public"}

2
app/widgets/Post/_post_reply.tpl

@ -28,7 +28,7 @@
<i class="material-symbols">group_work</i> {$reply->node}
{/if}
<span class="info">
{$reply->published|strtotime|prepareDate:true,true}
{$reply->published|prepareDate:true,true}
</span>
</p>
</div>

4
app/widgets/Post/_post_ticket.tpl

@ -53,7 +53,7 @@
</a>
{/if}
<span class="info" title="{$post->published|strtotime|prepareDate}">
<span class="info" title="{$post->published|prepareDate}">
{$count = $post->pictures->count()}
{if="$count > 1"}
{$count} <i class="material-symbols">collections</i> ·
@ -78,7 +78,7 @@
{$count} <i class="material-symbols">chat_bubble_outline</i> ·
{/if}
{$post->published|strtotime|prepareDate:true,true}
{$post->published|prepareDate:true,true}
</span>
</p>
</div>

2
app/widgets/RoomsUtils/_rooms_presences_list.tpl

@ -53,7 +53,7 @@
</p>
{if="$value->seen"}
<p class="line">
{$c->__('last.title')} {$value->seen|strtotime|prepareDate:true,true}
{$c->__('last.title')} {$value->seen|prepareDate:true,true}
</p>
{elseif="$value->status"}
<p class="line" title="{$value->status}">{$value->status}</p>

2
app/widgets/Search/_search_roster.tpl

@ -71,7 +71,7 @@
{if="$value->presence && $value->presence->seen"}
<p>
{$c->__('last.title')} {$value->presence->seen|strtotime|prepareDate:true,true}
{$c->__('last.title')} {$value->presence->seen|prepareDate:true,true}
</p>
{elseif="$value->presence"}
<p>{$value->presence->presencetext}</p>

Loading…
Cancel
Save