A way to add a timestamp to a tiddler every time it is opened/viewed in the story river?

80 views
Skip to first unread message

si

unread,
Jun 30, 2020, 12:02:30 PM6/30/20
to tiddl...@googlegroups.com
Does anyone know if anything like this exists? I couldn't find anything with a google search, but you never know.

Reason: I thought it might be cool to generate a list of tiddlers that I haven't seen in a while.

TW Tones

unread,
Jun 30, 2020, 10:36:28 PM6/30/20
to TiddlyWiki
Si,

If you provide the method by which when a tiddler is opened in the story river you could include an action that sets the clock by setting a date/time field to now.

By default there are multiple ways to open something in the story view, via contents, the result of a search, following an "in tiddler link", from the sidebar or a button using "to=".

I have prepared a way to execute additional actions on any standard button, but the navigation to open a tiddler does not have an easy way to trigger an action on every open, that I am aware of. Hackability of default triggers - "Buttons" #4272


Jeremy was discussing a related hack-ability improvement  Implement more of TiddlyWiki's black box logic as customisable action strings #3967
This could provide a method to add an action to all the navigation methods.

In the mean time, I recently discovered I could identify the last opened tiddler, in the story, what I call the "focused tiddler". Macro and sidebar attached.
The thing I like about this little macro is if you have a lot of tiddlers open, it is easy to return to the one with focus. I intend to add a button that focuses the current tiddler with a click if not.

I did see somewhere the ability to invoke an action when a tiddler changed. Perhaps you could find that and use this focus tiddlername.field to trigger what you want on the focus tiddler? I would however consider not allowing this for shadow/system tiddler or saving the time stamp for last read independently of the tiddler so it could operate on shadow tiddlers without editing them.

I also recently shared a read-date autonomous field which you have to stamp the tiddler with, that does not interfeat with the created/modified datestamps. https://groups.google.com/forum/?hl=en#!topic/tiddlywiki/RP3RYc6Opxc

Regards
Tony
focus-tiddler.json

Mat

unread,
Jul 1, 2020, 6:59:11 AM7/1/20
to TiddlyWiki
si wrote:
Reason: I thought it might be cool to generate a list of tiddlers that I haven't seen in a while.

I agree that would be cool. It would be tricky to modify links to also add a timestamp when clicked, at least I don't know how to do that, but it would be simpler to modify the Close tiddler button to do it. Could be a hidden field, like created or modified, named last-opened or some such.

<:-)


Saq Imtiaz

unread,
Jul 1, 2020, 8:01:25 AM7/1/20
to TiddlyWiki
Hmm. If we had something like a history list but with timestamps and actually saved it...

Eric Shulman

unread,
Jul 1, 2020, 9:11:58 AM7/1/20
to TiddlyWiki
On Wednesday, July 1, 2020 at 5:01:25 AM UTC-7, Saq Imtiaz wrote:
Hmm. If we had something like a history list but with timestamps and actually saved it...

The $:/HistoryList is updated whenever you open a tiddler in the story river.

This is accomplished by the <$navigator> widget called from the $:/core/ui/PageTemplate:
<$navigator story="$:/StoryList" history="$:/HistoryList" openLinkFromInsideRiver={{$:/config/Navigation/openLinkFromInsideRiver}} openLinkFromOutsideRiver={{$:/config/Navigation/openLinkFromOutsideRiver}} relinkOnRename={{$:/config/RelinkOnRename}}>

The code that actually does the work is in $:/core/modules/widgets/navigator.js:
NavigatorWidget.prototype.addToHistory = function(title,fromPageRect) {
 
this.wiki.addToHistory(title,fromPageRect,this.historyTitle);
};

and the "wiki.addToHistory" function is defined in $:/core/modules/wiki.js
exports.addToHistory = function(title,fromPageRect,historyTitle) {
 
var story = new $tw.Story({wiki: this, historyTitle: historyTitle});
 story
.addToHistory(title,fromPageRect);
};

and the "story.addToHistory" function is defined in $:/core/modules/story.js:
Story.prototype.addToHistory = function(navigateTo,navigateFromClientRect) {
 
var titles = $tw.utils.isArray(navigateTo) ? navigateTo : [navigateTo];
 
// Add a new record to the top of the history stack
 
var historyList = this.wiki.getTiddlerData(this.historyTitle,[]);
 $tw
.utils.each(titles,function(title) {
    historyList
.push({title: title, fromPageRect: navigateFromClientRect});
 
});
 
this.wiki.setTiddlerData(this.historyTitle,historyList,{"current-tiddler": titles[titles.length-1]});
};

so... in this function, we could add code to get the current timestamp and include it in the object being pushed to the historyList:
Story.prototype.addToHistory = function(navigateTo,navigateFromClientRect) {
 var titles = $tw.utils.isArray(navigateTo) ? navigateTo : [navigateTo];
 // Add a new record to the top of the history stack
 var historyList = this.wiki.getTiddlerData(this.historyTitle,[]);
 var now=$tw.utils.formatDateString(new Date(),"YYYY0MM0DD0hh0mm0ss0XXX");
 $tw.utils.each(titles,function(title) {
    historyList.push({title: title, fromPageRect: navigateFromClientRect, timestamp:now});
 });
 this.wiki.setTiddlerData(this.historyTitle,historyList,{"current-tiddler": titles[titles.length-1]});
};
(changes shown in bold)

Then, we just need to write some code that accesses the $:/HistoryList JSON data, and finds the most recent entry for the current tiddler, and then fetches the timestamp from that entry.

-e


Saq Imtiaz

unread,
Jul 1, 2020, 10:16:11 AM7/1/20
to TiddlyWiki


On Wednesday, July 1, 2020 at 3:11:58 PM UTC+2, Eric Shulman wrote:
On Wednesday, July 1, 2020 at 5:01:25 AM UTC-7, Saq Imtiaz wrote:
Hmm. If we had something like a history list but with timestamps and actually saved it...

The $:/HistoryList is updated whenever you open a tiddler in the story river.

Yes Eric, that was a hint towards using $:/HistoryList "but with timestamps" ;)

At least on node, it is excluded from being saved in the syncFilter, hence the bit about "actually saved it". 

I do wonder if there would be any performance impact as it gets longer, and just due to size alone I guess it would need to be pruned or reset at some point, dropping older entries.

PMario

unread,
Jul 1, 2020, 10:20:38 AM7/1/20
to TiddlyWiki
A way to add a timestamp to a tiddler every time it is opened/viewed in the story river?

The problem is, that you would change the modified field of the tiddler. So every tiddler that you recently watched will show up in the "Recent" tab. I don't think, that's what you intended. right?

It would be needed to keep a separate list, which contains the tiddler titles, that you watched + a timestamp.

Saq and Eric mentioned the $:/HistoryList. .. The problem here is, that this list can get huge. That's why it isn't saved with the wiki, by default.

A similar thing can happen with your "tracking list" ... Worst case it will contain a list of all your tiddler titles + a time stamp per title. Which shouldn't be that bad.

TW knows a th-navigating hook, that can be used by plugin authors. IMO it should be relatively simple to create a plugin that is activated by the hook and logs 1 line to a tracking tiddler.

There is an other possibility. ... But I don't want to talk about it, because it has the potential to "brick" wikis if not used properly ;)

-mario



PMario

unread,
Jul 1, 2020, 10:24:01 AM7/1/20
to TiddlyWiki
On Wednesday, July 1, 2020 at 4:16:11 PM UTC+2, Saq Imtiaz wrote:
...
I do wonder if there would be any performance impact as it gets longer, and just due to size alone I guess it would need to be pruned or reset at some point, dropping older entries.

As I wrote. If we use the tiddler title as the "key" in a data-tiddler, the max size will be limited by the number of "user" tiddlers. So we may want a configuration to exclude system tiddlers if needed.

If the timestamp is the "key" the whole system will be much more complex.

-mario

TW Tones

unread,
Jul 1, 2020, 7:29:19 PM7/1/20
to TiddlyWiki
Folks,

Could we simply ensure the designer of a wiki could have custom actions executed on navigate?

I already have a change to propose to allow custom actions on every existing button, this provides a great deal of customisation and appropriate triggers for lots of automation, the only gap in the navigate event. See my prior post.

Then let the designer decide how to handle timestamps and list sizes?

Si - You can do this now if you build the list that you use to navigate to, ask if you need assistance, You can list tiddlers each with a button to=tiddlername (Styled to look like a link) but the button widget allows you to trigger additional actions such as updating a field, you can set timestamp=no as well to leave modified date alone.

Regards
Tony

On Wednesday, July 1, 2020 at 2:02:30 AM UTC+10, si wrote:
Reply all
Reply to author
Forward
0 new messages