Skip to content

Commit

Permalink
imp: Reorganize links actions
Browse files Browse the repository at this point in the history
  • Loading branch information
marienfressinaud committed Sep 21, 2022
1 parent 7124f45 commit 933815d
Show file tree
Hide file tree
Showing 14 changed files with 300 additions and 275 deletions.
Binary file modified locales/fr_FR/LC_MESSAGES/main.mo
Binary file not shown.
202 changes: 97 additions & 105 deletions locales/fr_FR/LC_MESSAGES/main.po

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/static/icons.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/assets/icons/uncheck.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion src/assets/stylesheets/components/cards.css
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,14 @@

font-size: var(--size-normal);
font-weight: bold;
line-height: 1.3;
line-height: 1.25;
text-overflow: ellipsis;
}

.card__title a {
display: block;

text-decoration: none;
}

.card__text {
Expand Down
29 changes: 18 additions & 11 deletions src/models/Link.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,6 @@ class Link extends \Minz\Model
],
];

/** @var array */
private $cache_is_read = [];

/**
* @param string $url
* @param string $user_id
Expand Down Expand Up @@ -229,25 +226,35 @@ public function viaUser()
}

/**
* Return whether or not the given user read the link URL.
* Return whether or not the given user has the link URL in its bookmarks.
*
* @param \flusio\models\User $user
* @param \flusio\models\User|null $user
*
* @return boolean
*/
public function isReadBy($user)
public function isInBookmarksOf($user)
{
if (!$user) {
return false;
}

$user_id = $user->id;
if (!isset($this->cache_is_read[$user_id])) {
$is_read = Link::daoCall('isUrlReadByUserId', $user_id, $this->url);
$this->cache_is_read[$user_id] = $is_read;
return Link::daoCall('isUrlInBookmarksOfUserId', $user->id, $this->url);
}

/**
* Return whether or not the given user read the link URL.
*
* @param \flusio\models\User|null $user
*
* @return boolean
*/
public function isReadBy($user)
{
if (!$user) {
return false;
}

return $this->cache_is_read[$user_id];
return Link::daoCall('isUrlReadByUserId', $user->id, $this->url);
}

/**
Expand Down
32 changes: 32 additions & 0 deletions src/models/dao/Link.php
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,38 @@ public function countByCollectionId($collection_id, $options = [])
return intval($statement->fetchColumn());
}

/**
* Return whether or not the given user id has the link URL in its
* bookmarks.
*
* @param string $user_id
* @param string $url
*
* @return boolean
*/
public function isUrlInBookmarksOfUserId($user_id, $url)
{
$sql = <<<'SQL'
SELECT 1
FROM links l, collections c, links_to_collections lc
WHERE l.user_id = :user_id
AND l.url_lookup = simplify_url(:url)
AND c.type = 'bookmarks'
AND lc.collection_id = c.id
AND lc.link_id = l.id;
SQL;

$statement = $this->prepare($sql);
$statement->execute([
':user_id' => $user_id,
':url' => $url,
]);
return (bool)$statement->fetchColumn();
}

/**
* Return whether or not the given user id read the link URL.
*
Expand Down
3 changes: 2 additions & 1 deletion src/views/collections/show.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@
'display_hidden' => $collection->is_public && $link->is_hidden,
'display_edit' => $link->user_id === $current_user->id,
'display_repair' => $link->user_id === $current_user->id,
'display_mark_as_read' => !$link->isReadBy($current_user),
'display_read_later' => 'auto',
'display_mark_as_read' => 'auto',
'collections_mode' => 'managing',
]); ?>
<?php endforeach; ?>
Expand Down
3 changes: 2 additions & 1 deletion src/views/collections/show_public.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,8 @@
'from' => \Minz\Url::for('collection', $current_url_params),
'display_comments' => $collection->type !== 'feed',
'display_hidden' => $collection->is_public && $link->is_hidden,
'display_mark_as_read' => $current_user && !$link->isReadBy($current_user),
'display_read_later' => 'auto',
'display_mark_as_read' => 'auto',
'collections_mode' => 'adding',
]); ?>
<?php endforeach; ?>
Expand Down

0 comments on commit 933815d

Please sign in to comment.