Lagrange [work/v1.8]

Remember redirected URLs as visited

=> a50a01da45a8fb6a4d6ee419fc1ad240b1f0dee5

diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c
index 3fc7e841..40f34db4 100644
--- a/src/ui/documentwidget.c
+++ b/src/ui/documentwidget.c
@@ -41,6 +41,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
 #include "scrollwidget.h"
 #include "util.h"
 #include "visbuf.h"
+#include "visited.h"
 
 #include 
 #include 
@@ -1051,6 +1052,7 @@ static void checkResponse_DocumentWidget_(iDocumentWidget *d) {
                     else if (equalCase_Rangecc(urlScheme_String(dstUrl),
                                                cstr_Rangecc(urlScheme_String(d->mod.url)))) {
                         /* Redirects with the same scheme are automatic. */
+                        visitUrl_Visited(visited_App(), d->mod.url, transient_VisitedUrlFlag);
                         postCommandf_App(
                             "open redirect:%d url:%s", d->redirectCount + 1, cstr_String(dstUrl));
                     }
diff --git a/src/ui/window.c b/src/ui/window.c
index a69dd7db..ba6ee869 100644
--- a/src/ui/window.c
+++ b/src/ui/window.c
@@ -254,7 +254,7 @@ static iBool handleNavBarCommands_(iWidget *navBar, const char *cmd) {
             if (equal_Command(cmd, "document.changed")) {
                 iInputWidget *url = findWidget_App("url");
                 const iString *urlStr = collect_String(suffix_Command(cmd, "url"));
-                visitUrl_Visited(visited_App(), urlStr);
+                visitUrl_Visited(visited_App(), urlStr, 0);
                 postCommand_App("visited.changed"); /* sidebar will update */
                 setText_InputWidget(url, urlStr);
                 updateTextCStr_LabelWidget(reloadButton, reloadCStr_);
diff --git a/src/visited.c b/src/visited.c
index e9dc9b94..b339198e 100644
--- a/src/visited.c
+++ b/src/visited.c
@@ -34,6 +34,7 @@ static const size_t maxAgeVisited_Visited_ = 3600 * 24 * 30; /* one month */
 void init_VisitedUrl(iVisitedUrl *d) {
     initCurrent_Time(&d->when);
     init_String(&d->url);
+    d->flags = 0;
 }
 
 void deinit_VisitedUrl(iVisitedUrl *d) {
@@ -81,13 +82,14 @@ void save_Visited(const iVisited *d, const char *dirPath) {
             iDate date;
             init_Date(&date, &item->when);
             format_String(line,
-                          "%04d-%02d-%02dT%02d:%02d:%02d %s\n",
+                          "%04d-%02d-%02dT%02d:%02d:%02d %04x %s\n",
                           date.year,
                           date.month,
                           date.day,
                           date.hour,
                           date.minute,
                           date.second,
+                          item->flags,
                           cstr_String(&item->url));
             writeData_File(f, cstr_String(line), size_String(line));
         }
@@ -106,11 +108,16 @@ void load_Visited(iVisited *d, const char *dirPath) {
         iTime          now;
         initCurrent_Time(&now);
         while (nextSplit_Rangecc(src, "\n", &line)) {
-            if (isEmpty_Range(&line)) continue;
+            if (size_Range(&line) < 22) continue;
             int y, m, D, H, M, S;
             sscanf(line.start, "%04d-%02d-%02dT%02d:%02d:%02d ", &y, &m, &D, &H, &M, &S);
             if (!y) break;
             iVisitedUrl item;
+            const char *urlStart = line.start + 20;
+            if (*urlStart == '0' && size_Range(&line) >= 25) {
+                item.flags = strtoul(line.start + 20, NULL, 16);
+                urlStart += 5;
+            }
             init_VisitedUrl(&item);
             init_Time(
                 &item.when,
@@ -118,7 +125,7 @@ void load_Visited(iVisited *d, const char *dirPath) {
             if (secondsSince_Time(&now, &item.when) > maxAgeVisited_Visited_) {
                 continue; /* Too old. */
             }
-            initRange_String(&item.url, (iRangecc){ line.start + 20, line.end });
+            initRange_String(&item.url, (iRangecc){ urlStart, line.end });
             insert_SortedArray(&d->visited, &item);
         }
         unlock_Mutex(d->mtx);
@@ -147,10 +154,11 @@ static size_t find_Visited_(const iVisited *d, const iString *url) {
     return pos;
 }
 
-void visitUrl_Visited(iVisited *d, const iString *url) {
+void visitUrl_Visited(iVisited *d, const iString *url, uint16_t visitFlags) {
     if (isEmpty_String(url)) return;
     iVisitedUrl visit;
     init_VisitedUrl(&visit);
+    visit.flags = visitFlags;
     set_String(&visit.url, url);
     size_t pos;
     lock_Mutex(d->mtx);
@@ -158,6 +166,7 @@ void visitUrl_Visited(iVisited *d, const iString *url) {
         iVisitedUrl *old = at_SortedArray(&d->visited, pos);
         if (cmpNewer_VisitedUrl_(&visit, old)) {
             old->when = visit.when;
+            old->flags = visitFlags;
             unlock_Mutex(d->mtx);
             deinit_VisitedUrl(&visit);
             return;
@@ -200,7 +209,10 @@ const iArray *list_Visited(const iVisited *d, size_t count) {
     iPtrArray *urls = collectNew_PtrArray();
     iGuardMutex(d->mtx, {
         iConstForEach(Array, i, &d->visited.values) {
-            pushBack_PtrArray(urls, i.value);
+            const iVisitedUrl *vis = i.value;
+            if (~vis->flags & transient_VisitedUrlFlag) {
+                pushBack_PtrArray(urls, vis);
+            }
         }
     });
     sort_Array(urls, cmpWhenDescending_VisitedUrlPtr_);
diff --git a/src/visited.h b/src/visited.h
index 5a34d008..d9eb02b6 100644
--- a/src/visited.h
+++ b/src/visited.h
@@ -32,8 +32,13 @@ iDeclareType(VisitedUrl)
 iDeclareTypeConstruction(VisitedUrl)
 
 struct Impl_VisitedUrl {
-    iString url;
-    iTime   when;
+    iString  url;
+    iTime    when;
+    uint16_t flags;
+};
+
+enum iVisitedUrlFlag {
+    transient_VisitedUrlFlag = 0x1, /* redirected; don't show in history */
 };
 
 iDeclareType(Visited)
@@ -44,7 +49,7 @@ void    load_Visited            (iVisited *, const char *dirPath);
 void    save_Visited            (const iVisited *, const char *dirPath);
 
 iTime   urlVisitTime_Visited    (const iVisited *, const iString *url);
-void    visitUrl_Visited        (iVisited *, const iString *url); /* adds URL to the visited URLs set */
+void    visitUrl_Visited        (iVisited *, const iString *url, uint16_t visitFlags); /* adds URL to the visited URLs set */
 void    removeUrl_Visited       (iVisited *, const iString *url);
 
 const iPtrArray *  list_Visited (const iVisited *, size_t count); /* returns collected */
Proxy Information
Original URL
gemini://git.skyjake.fi/lagrange/work%2Fv1.8/cdiff/a50a01da45a8fb6a4d6ee419fc1ad240b1f0dee5
Status Code
Success (20)
Meta
text/gemini; charset=utf-8
Capsule Response Time
70.26372 milliseconds
Gemini-to-HTML Time
0.376229 milliseconds

This content has been proxied by September (ba2dc).