What object owns last_seen_at?

Happy Independence Day :fireworks:

Before I lose what little hair I have left trying to work up a plugin I figured I should ask.

Iā€™ve tried the obvious, User, but last_seen_at is undefined.

Iā€™ve tried combinations of hyphens, underscores, camelCase, etc. etc. with no joy.

Iā€™ve used getOwnPropertyNames to try and drill down into various objects in hopes of finding it elsewhere.

Iā€™ve looked at the dev console in places Iā€™ve never looked before.

tl,dr Iā€™ve tried a lot

Iā€™m sure I must have danced close to the correct syntax, and I know the information has to be available somewhere, somehow, but my ā€œeducated guessesā€ have so far failed me.

AFAIK the property is neither ā€œprivateā€ nor ā€œuntrustedā€ so I hope it can be gotten.

Maybe I need to ā€œextendā€ or ā€œreopenā€?

For the current user (myself) I can access it this (non-plugin) way via the console:

var app = window.Discourse.__container__.lookup('controller:application');
console.log(app.currentUser.last_seen_at);

You can also do something like:

var u = Discourse.User.create({username: 'codinghorror'});
u.findDetails(); // obviously wait on the promise here.
console.log(u.last_seen_at);
3 Likes

That seems to be equivalent to
Discourse.User.current()

i.e. the same set of properties, and again
last_seen_at is undefined.

My guess is because itā€™s a datetime data type.
Or maybe it just isnā€™t able to be called by a plugin in the simple ways Iā€™ve been trying to get the value.

[quote=ā€œMittineague, post:3, topic:30788ā€]
My guess is because itā€™s a datetime data type. Or maybe it just isnā€™t able to be called by a plugin in the simple ways Iā€™ve been trying to get the value.
[/quote]Nope, itā€™s just not included in the basic data included in there. Discourse.User.current().findDetails().then(function(u) { console.log(u.last_seen_at); }); is what you want.

2 Likes

Thank You!

I donā€™t know why I didnā€™t find findDetails() but that is exactly what I needed.

Yeap, I mentioned it in my post above.

The information is already available if the user is on the their profile page (although might be out of date).

Ah, so you did. the create() threw me off as Iā€™m not trying to create a new user, but get the data from existing users.

I canā€™t blame my old eyeglass prescription for missing that one :blush:

1 Like

Yeah you need to create user objects if they donā€™t already exist before you can complete operations on them (like get info).

The odd one out is really the currentUser as the object already exists always (even if it doesnā€™t have all info loaded).