What object owns last_seen_at?


(Mittineague) #1

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”?


(Dean Taylor) #2

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);

(Mittineague) #3

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.


(Kane York) #4

[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.


(Mittineague) #5

Thank You!

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


(Dean Taylor) #6

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).


(Mittineague) #7

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:


(Dean Taylor) #8

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).