Skip to content

Commit

Permalink
fix: fix contact search + adorable return data (#5881)
Browse files Browse the repository at this point in the history
  • Loading branch information
asbiin authored Jan 12, 2022
1 parent 2812ed3 commit 3309785
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 31 deletions.
1 change: 0 additions & 1 deletion app/ExportResources/Contact/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public function data(): ?array
'avatar_source' => $this->avatar_source,
'avatar_gravatar_url' => $this->avatar_gravatar_url,
'avatar_adorable_uuid' => $this->avatar_adorable_uuid,
'avatar_adorable_url' => $this->avatar_adorable_url,
'avatar_default_url' => $this->avatar_default_url,
$this->mergeWhen($this->avatarPhoto !== null, function () {
return ['avatar_photo' => $this->avatarPhoto->uuid];
Expand Down
26 changes: 5 additions & 21 deletions app/Models/Contact/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class Contact extends Model
'is_partial',
'is_starred',
'avatar_source',
'avatar_adorable_url',
'avatar_adorable_uuid',
'avatar_gravatar_url',
'avatar_default_url',
'avatar_photo_id',
Expand Down Expand Up @@ -1121,26 +1121,10 @@ public function getAvatarDefaultURL()
* @param string|null $value
* @return string|null
*/
public function getAvatarAdorableUrlAttribute(?string $value): ?string
public function getAvatarAdorableDataUrlAttribute(?string $value): ?string
{
if (isset($value) && $value !== '') {
$url = Str::of($value)
->after('https://api.adorable.io/avatars/')
->ltrim('/');

$data = Str::of($url)->split('/\//');

if (! ctype_digit($data[0]) || count($data) === 1) {
$size = config('monica.avatar_size');
$hash = $data[0];
} else {
$size = (int) $data[0];
$hash = $data[1];
}

$hash = Str::of($hash)->split('/\.png/')[0];

return LaravelAdorable::get($size, $hash);
if (isset($this->avatar_adorable_uuid) && $this->avatar_adorable_uuid !== '') {
return LaravelAdorable::get(config('monica.avatar_size'), $this->avatar_adorable_uuid);
}

return null;
Expand All @@ -1162,7 +1146,7 @@ public function getAvatarURL()

switch ($this->avatar_source) {
case 'adorable':
$avatarURL = $this->avatar_adorable_url;
$avatarURL = $this->avatar_adorable_data_url;
break;
case 'gravatar':
$avatarURL = $this->avatar_gravatar_url;
Expand Down
4 changes: 2 additions & 2 deletions resources/js/components/people/ContactList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
<a :href="props.row.route">
<template v-if="props.row.is_starred">
<span :class="[dirltr === 'ltr' ? 'ml3' : 'mr3']">
{{ props.row.complete_name }}
{{ props.row.complete_name }}
</span>
<svg class="relative" style="top: 5px" width="23" height="22" viewBox="0 0 23 22"
fill="none"
Expand All @@ -92,7 +92,7 @@
</svg>
</template>
<span v-else>
{{ props.row.complete_name }}
{{ props.row.complete_name }}
</span>
</a>
</template>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export default {
needle: keyword
}).then(function(response) {
const data = [];
if (response.data.noResults === null) {
if (response.data.noResults === undefined || response.data.noResults === null) {
response.data.data
.forEach(function (contact) {
contact.keyword = keyword;
Expand Down
2 changes: 1 addition & 1 deletion resources/views/people/avatar/edit.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<contact-avatar
:avatar="'{{ $contact->avatar_source }}'"
:default-url="'{{ $contact->getAvatarDefaultURL() }}'"
:adorable-url="'{{ $contact->avatar_adorable_url }}'"
:adorable-url="'{{ $contact->avatar_adorable_data_url }}'"
:gravatar-url="'{{ $contact->avatar_gravatar_url }}'"
:photo-url="'{{ $contact->getAvatarURL() }}'"
:has-reached-account-storage-limit="false"
Expand Down
10 changes: 5 additions & 5 deletions tests/Unit/Models/ContactTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -517,10 +517,6 @@ public function it_sets_a_default_avatar_color()
/** @test */
public function it_returns_the_url_of_the_avatar()
{
$this->mock(LaravelAdorable::class, function (MockInterface $mock) {
$mock->shouldReceive('get')->andReturn('adorableURL');
});

// default
$contact = factory(Contact::class)->create([
'avatar_default_url' => 'defaultURL',
Expand All @@ -534,10 +530,14 @@ public function it_returns_the_url_of_the_avatar()

// adorable
$contact = factory(Contact::class)->create([
'avatar_adorable_url' => 'adorableURL',
'avatar_adorable_uuid' => 'uuid',
'avatar_source' => 'adorable',
]);

$this->mock(LaravelAdorable::class, function (MockInterface $mock) {
$mock->shouldReceive('get')->andReturn('adorableURL');
});

$this->assertEquals(
'adorableURL',
$contact->getAvatarURL()
Expand Down

0 comments on commit 3309785

Please sign in to comment.