Skip to content

Commit

Permalink
imp: Allow actions on news dates
Browse files Browse the repository at this point in the history
  • Loading branch information
marienfressinaud committed Mar 25, 2024
1 parent a0ee2b8 commit 7b5cb20
Show file tree
Hide file tree
Showing 7 changed files with 217 additions and 87 deletions.
Binary file modified locales/fr_FR/LC_MESSAGES/main.mo
Binary file not shown.
37 changes: 17 additions & 20 deletions locales/fr_FR/LC_MESSAGES/main.po
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
msgid ""
msgstr ""
"Project-Id-Version: flusio\n"
"POT-Creation-Date: 2024-03-25 15:41+0100\n"
"PO-Revision-Date: 2024-03-25 15:41+0100\n"
"POT-Creation-Date: 2024-03-25 19:05+0100\n"
"PO-Revision-Date: 2024-03-25 19:05+0100\n"
"Last-Translator: Marien Fressinaud <dev@marienfressinaud.fr>\n"
"Language-Team: \n"
"Language: fr_FR\n"
Expand Down Expand Up @@ -77,8 +77,8 @@ msgstr "L’une des thématiques associées n’existe pas."
#: controllers/Groups.php:161 controllers/Importations.php:48
#: controllers/Links.php:499 controllers/Mastodon.php:87
#: controllers/Messages.php:93 controllers/Messages.php:141
#: controllers/Sessions.php:206 controllers/collections/Read.php:73
#: controllers/collections/Read.php:139 controllers/collections/Read.php:200
#: controllers/Sessions.php:206 controllers/collections/Read.php:80
#: controllers/collections/Read.php:154 controllers/collections/Read.php:222
#: controllers/importations/Opml.php:79 controllers/importations/Pocket.php:110
#: controllers/importations/Pocket.php:157
#: controllers/importations/Pocket.php:258
Expand Down Expand Up @@ -1086,6 +1086,7 @@ msgstr "Publiée par %s"
#: views/collections/show.phtml:74 views/collections/show_public.phtml:112
#: views/links/_link.phtml:221 views/links/_link.phtml:225
#: views/links/show.phtml:121 views/links/show.phtml:125
#: views/news/index.phtml:41
msgid "Actions"
msgstr "Actions"

Expand Down Expand Up @@ -1143,7 +1144,7 @@ msgstr "Régler pour le journal"
msgid "Copy the link"
msgstr "Copier le lien"

#: views/collections/show_public.phtml:165 views/news/index.phtml:70
#: views/collections/show_public.phtml:165 views/news/index.phtml:54
msgid "Mark all as read"
msgstr "Tout marquer comme lu"

Expand Down Expand Up @@ -2118,57 +2119,53 @@ msgstr "aujourd’hui"
msgid "yesterday"
msgstr "hier"

#: views/news/index.phtml:59
msgid "Empty the news"
msgstr "Vider le journal"

#: views/news/index.phtml:80
#: views/news/index.phtml:65
msgid "Read the links later"
msgstr "Lire les liens plus tard"

#: views/news/index.phtml:89
#: views/news/index.phtml:74
msgid ""
"You’ll remove all the news links, this action cannot be canceled. Are you "
"sure?"
msgstr ""
"Vous allez retirer tous les liens du journal, cette action ne peut pas être "
"annulée. Confirmez-vous ?"

#: views/news/index.phtml:97
#: views/news/index.phtml:83
msgid "Never see the links again"
msgstr "Ne plus revoir les liens"

#: views/news/index.phtml:105
#: views/news/index.phtml:109
msgid ""
"Fill your news feed with the content published by the feeds that you follow."
msgstr ""
"Remplissez votre journal avec le contenu publié par les flux que vous suivez."

#: views/news/index.phtml:119
#: views/news/index.phtml:123
msgid "Refresh the news"
msgstr "Rafraichir le journal"

#: views/news/index.phtml:124
#: views/news/index.phtml:128
msgid "Fill the news with…"
msgstr "Remplissez votre journal avec…"

#: views/news/index.phtml:147
#: views/news/index.phtml:151
msgid "the latest publications"
msgstr "les dernières publications"

#: views/news/index.phtml:148
#: views/news/index.phtml:152
msgid "from your followed feeds"
msgstr "depuis vos flux suivis"

#: views/news/index.phtml:163
#: views/news/index.phtml:167
msgid "3 links of -10 minutes"
msgstr "3 liens de -10 minutes"

#: views/news/index.phtml:164 views/news/index.phtml:180
#: views/news/index.phtml:168 views/news/index.phtml:184
msgid "from your bookmarks"
msgstr "depuis vos signets"

#: views/news/index.phtml:179
#: views/news/index.phtml:183
msgid "1 link of +10 minutes"
msgstr "1 lien de +10 minutes"

Expand Down
46 changes: 34 additions & 12 deletions src/controllers/collections/Read.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class Read
* @request_param string id
* @request_param string csrf
* @request_param string from
* @request_param date date
*
* @response 302 /login?redirect_to=:from
* if not connected
Expand All @@ -37,19 +38,25 @@ public function create(Request $request): Response
$from = $request->param('from', '');
$csrf = $request->param('csrf', '');
$collection_id = $request->param('id', '');
$date = $request->paramDatetime('date', format: 'Y-m-d');

if (!$user) {
return Response::redirect('login', ['redirect_to' => $from]);
}

$collection = models\Collection::find($collection_id);
$links = [];

$options = [];
if ($date) {
$options['published_date'] = $date;
}

if ($collection && auth\CollectionsAccess::canUpdateRead($user, $collection)) {
$links = $collection->links();
$links = $collection->links(options: $options);
} elseif ($collection && $user->isFollowing($collection->id)) {
$collection_links = $collection->links([], [
'hidden' => $collection->sharedWith($user),
]);
$options['hidden'] = $collection->sharedWith($user);
$collection_links = $collection->links(options: $options);
$links = $user->obtainLinks($collection_links);
list($via_type, $via_resource_id) = utils\ViaHelper::extractFromPath($from);

Expand Down Expand Up @@ -86,6 +93,7 @@ public function create(Request $request): Response
* @request_param string id
* @request_param string csrf
* @request_param string from
* @request_param date date
*
* @response 302 /login?redirect_to=:from
* if not connected
Expand All @@ -103,20 +111,27 @@ public function later(Request $request): Response
$from = $request->param('from', '');
$csrf = $request->param('csrf', '');
$collection_id = $request->param('id', '');
$date = $request->paramDatetime('date', format: 'Y-m-d');

if (!$user) {
return Response::redirect('login', ['redirect_to' => $from]);
}

$collection = models\Collection::find($collection_id);
$links = [];

$options = [];
if ($date) {
$options['published_date'] = $date;
}

if ($collection && auth\CollectionsAccess::canUpdateRead($user, $collection)) {
$links = $collection->links();
$links = $collection->links(options: $options);
} elseif ($collection && $user->isFollowing($collection->id)) {
$collection_links = $collection->links([], [
'hidden' => $collection->sharedWith($user),
]);
$options['hidden'] = $collection->sharedWith($user);
$collection_links = $collection->links(options: $options);
$links = $user->obtainLinks($collection_links);

list($via_type, $via_resource_id) = utils\ViaHelper::extractFromPath($from);

$links_to_create = [];
Expand Down Expand Up @@ -152,6 +167,7 @@ public function later(Request $request): Response
* @request_param string id
* @request_param string csrf
* @request_param string from
* @request_param date date
*
* @response 302 /login?redirect_to=:from
* if not connected
Expand All @@ -169,19 +185,25 @@ public function never(Request $request): Response
$from = $request->param('from', '');
$csrf = $request->param('csrf', '');
$collection_id = $request->param('id', '');
$date = $request->paramDatetime('date', format: 'Y-m-d');

if (!$user) {
return Response::redirect('login', ['redirect_to' => $from]);
}

$collection = models\Collection::find($collection_id);
$links = [];

$options = [];
if ($date) {
$options['published_date'] = $date;
}

if ($collection && auth\CollectionsAccess::canUpdateRead($user, $collection)) {
$links = $collection->links();
$links = $collection->links(options: $options);
} elseif ($collection && $user->isFollowing($collection->id)) {
$collection_links = $collection->links([], [
'hidden' => $collection->sharedWith($user),
]);
$options['hidden'] = $collection->sharedWith($user);
$collection_links = $collection->links(options: $options);
$links = $user->obtainLinks($collection_links);

$links_to_create = [];
Expand Down
1 change: 1 addition & 0 deletions src/models/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ public function owner(): User
*
* @param string[] $selected_computed_props
* @param array{
* 'published_date'?: ?\DateTimeImmutable,
* 'hidden'?: bool,
* 'offset'?: int,
* 'limit'?: int|'ALL',
Expand Down
11 changes: 10 additions & 1 deletion src/models/dao/Link.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,13 +216,15 @@ public static function listComputedByUserId(
* select specific properties to avoid computing dispensable
* properties.
* @param array{
* 'published_date'?: ?\DateTimeImmutable,
* 'hidden'?: bool,
* 'offset'?: int,
* 'limit'?: int|'ALL',
* } $options
*
* Description of the options:
*
* - published_date (default to null), limits the selection to the given publication date
* - hidden (default to true), indicates if hidden links must be included
* - offset (default to 0), the offset for pagination
* - limit (default to 'ALL') the limit for pagination
Expand All @@ -235,6 +237,7 @@ public static function listComputedByCollectionId(
array $options = [],
): array {
$default_options = [
'published_date' => null,
'hidden' => true,
'offset' => 0,
'limit' => 'ALL',
Expand Down Expand Up @@ -263,6 +266,12 @@ public static function listComputedByCollectionId(
SQL;
}

$date_clause = '';
if ($options['published_date'] !== null) {
$date_clause = "AND date_trunc('day', lc.created_at) = :published_date";
$parameters[':published_date'] = $options['published_date']->format('Y-m-d');
}

$visibility_clause = '';
if (!$options['hidden']) {
$visibility_clause = 'AND l.is_hidden = false';
Expand All @@ -283,7 +292,7 @@ public static function listComputedByCollectionId(
WHERE l.id = lc.link_id
AND lc.collection_id = :collection_id
{$date_clause}
{$visibility_clause}
{$order_by_clause}
Expand Down

0 comments on commit 7b5cb20

Please sign in to comment.