Răsfoiți Sursa

Fix nav_menu mark-as-read (#2909)

* Fix nav_menu mark-as-read

#Fix https://github.com/FreshRSS/FreshRSS/issues/2905
Fix regression from https://github.com/FreshRSS/FreshRSS/pull/2588

We need info about the first item (id_max) before being able to output
nav_menu. Before https://github.com/FreshRSS/FreshRSS/pull/2588 we used
to output everything in memory before starting to produce an output. Now
that we stream the output, we need a temporary buffer until we have
received the first item/article.

* Repair loading page

* Simplify CSS

Make it work in Chrome as well

* Lint

* Partial revert

* Base max_id solely on current time
Alexandre Alapetite 5 ani în urmă
părinte
comite
0442243037

+ 4 - 11
app/Controllers/indexController.php

@@ -48,6 +48,8 @@ class FreshRSS_index_Controller extends Minz_ActionController {
 		}
 		Minz_View::prependTitle($title . ' · ');
 
+		FreshRSS_Context::$id_max = time() . '000000';
+
 		$this->view->callbackBeforeFeeds = function ($view) {
 			try {
 				$tagDAO = FreshRSS_Factory::createTagDao();
@@ -66,29 +68,20 @@ class FreshRSS_index_Controller extends Minz_ActionController {
 				FreshRSS_Context::$number++;	//+1 for pagination
 				$view->entries = FreshRSS_index_Controller::listEntriesByContext();
 				FreshRSS_Context::$number--;
-				ob_start();
+				ob_start();	//Buffer "one entry at a time"
 			} catch (FreshRSS_EntriesGetter_Exception $e) {
 				Minz_Log::notice($e->getMessage());
 				Minz_Error::error(404);
 			}
 		};
 
-		$this->view->callbackBeforePagination = function ($view, $nbEntries, $firstEntry, $lastEntry) {
+		$this->view->callbackBeforePagination = function ($view, $nbEntries, $lastEntry) {
 			if ($nbEntries >= FreshRSS_Context::$number) {
 				//We have enough entries: we discard the last one to use it for the next pagination
 				ob_clean();
 				FreshRSS_Context::$next_id = $lastEntry->id();
 			}
 			ob_end_flush();
-
-			FreshRSS_Context::$id_max = $firstEntry === null ? (time() - 1) . '000000' : $firstEntry->id();
-			if (FreshRSS_Context::$order === 'ASC') {
-				// In this case we do not know but we guess id_max
-				$id_max = (time() - 1) . '000000';
-				if (strcmp($id_max, FreshRSS_Context::$id_max) > 0) {
-					FreshRSS_Context::$id_max = $id_max;
-				}
-			}
 		};
 	}
 

+ 3 - 0
app/layout/aside_feed.phtml

@@ -109,6 +109,9 @@
 	</form>
 </div>
 
+<div id="first_load" class="loading"></div>
+<?php flush(); ?>
+
 <script id="tag_config_template" type="text/html">
 	<ul class="dropdown-menu">
 		<li class="dropdown-close"><a href="#close">❌</a></li>

+ 0 - 3
app/layout/nav_menu.phtml

@@ -1,8 +1,5 @@
-<div id="first_load" class="loading"></div>
-
 <?php
 	$actual_view = Minz_Request::actionName();
-	flush();
 ?>
 
 <div class="nav_menu">

+ 1 - 6
app/views/index/normal.phtml

@@ -1,5 +1,4 @@
 <?php
-
 $this->partial('aside_feed');
 $this->partial('nav_menu');
 
@@ -19,13 +18,9 @@ $today = @strtotime('today');
 	<div id="new-article">
 		<a href="<?= Minz_Url::display(Minz_Request::currentRequest()) ?>"><?= _t('gen.js.new_article'); /* TODO: move string in JS*/ ?></a>
 	</div><?php
-	$firstEntry = null;
 	$lastEntry = null;
 	$nbEntries = 0;
 	foreach ($this->entries as $item):
-		if ($nbEntries === 0) {
-			$firstEntry = $item;
-		}
 		$lastEntry = $item;
 		$nbEntries++;
 		ob_flush();
@@ -100,7 +95,7 @@ $today = @strtotime('today');
 	endforeach;
 
 	if ($nbEntries > 0):
-		call_user_func($this->callbackBeforePagination, $this, $nbEntries, $firstEntry, $lastEntry);
+		call_user_func($this->callbackBeforePagination, $this, $nbEntries, $lastEntry);
 		$this->renderHelper('pagination');
 ?></div><?php
 	else:

+ 1 - 5
app/views/index/reader.phtml

@@ -12,13 +12,9 @@ $content_width = FreshRSS_Context::$user_conf->content_width;
 	<div id="new-article">
 		<a href="<?= Minz_Url::display(Minz_Request::currentRequest()) ?>"><?= _t('gen.js.new_article'); /* TODO: move string in JS*/ ?></a>
 	</div><?php
-	$firstEntry = null;
 	$lastEntry = null;
 	$nbEntries = 0;
 	foreach ($this->entries as $item):
-		if ($nbEntries === 0) {
-			$firstEntry = $item;
-		}
 		$lastEntry = $item;
 		$nbEntries++;
 		ob_flush();
@@ -76,7 +72,7 @@ $content_width = FreshRSS_Context::$user_conf->content_width;
 	endforeach;
 
 	if ($nbEntries > 0):
-		call_user_func($this->callbackBeforePagination, $this, $nbEntries, $firstEntry, $lastEntry);
+		call_user_func($this->callbackBeforePagination, $this, $nbEntries, $lastEntry);
 		$this->renderHelper('pagination');
 ?></div><?php
 	else:

+ 2 - 6
p/themes/Alternative-Dark/template.css

@@ -883,13 +883,9 @@ br {
 }
 
 /*=== "Load" parts */
-
-/* Only matches while waiting for div#stream to be received */
-#first_load:nth-last-of-type(1), #first_load:nth-last-of-type(2) {
-	margin: -40px auto 0 auto;
+#first_load {
+	margin: 130px auto -170px auto;
 	height: 40px;
-	position: relative;
-	top: 290px;
 }
 
 #load_more {

+ 2 - 6
p/themes/Alternative-Dark/template.rtl.css

@@ -883,13 +883,9 @@ br {
 }
 
 /*=== "Load" parts */
-
-/* Only matches while waiting for div#stream to be received */
-#first_load:nth-last-of-type(1), #first_load:nth-last-of-type(2) {
-	margin: -40px auto 0 auto;
+#first_load {
+	margin: 130px auto -170px auto;
 	height: 40px;
-	position: relative;
-	top: 290px;
 }
 
 #load_more {

+ 2 - 6
p/themes/base-theme/template.css

@@ -891,13 +891,9 @@ br {
 }
 
 /*=== "Load" parts */
-
-/* Only matches while waiting for div#stream to be received */
-#first_load:nth-last-of-type(1), #first_load:nth-last-of-type(2) {
-	margin: -40px auto 0 auto;
+#first_load {
+	margin: 130px auto -170px auto;
 	height: 40px;
-	position: relative;
-	top: 290px;
 }
 
 #load_more {

+ 2 - 6
p/themes/base-theme/template.rtl.css

@@ -891,13 +891,9 @@ br {
 }
 
 /*=== "Load" parts */
-
-/* Only matches while waiting for div#stream to be received */
-#first_load:nth-last-of-type(1), #first_load:nth-last-of-type(2) {
-	margin: -40px auto 0 auto;
+#first_load {
+	margin: 130px auto -170px auto;
 	height: 40px;
-	position: relative;
-	top: 290px;
 }
 
 #load_more {