diff --git a/src/maps/Channels.ts b/src/maps/Channels.ts index 13e8296c..fe42325e 100644 --- a/src/maps/Channels.ts +++ b/src/maps/Channels.ts @@ -6,7 +6,7 @@ import type { User } from 'revolt-api/types/Users'; import { action, computed, makeAutoObservable, runInAction } from 'mobx'; import isEqual from 'lodash.isequal'; -import { ulid } from 'ulid'; +import { decodeTime, ulid } from 'ulid'; import { Nullable, toNullable } from '../util/null'; import Collection from './Collection'; @@ -152,6 +152,13 @@ export class Channel { return Array.from(this.typing_ids).map(id => this.client.users.get(id)); } + /** + * Get timestamp when this channel was created. + */ + get createdAt() { + return decodeTime(this._id); + } + constructor(client: Client, data: ChannelI) { this.client = client; diff --git a/src/maps/Messages.ts b/src/maps/Messages.ts index 0110f06f..8574a9c9 100644 --- a/src/maps/Messages.ts +++ b/src/maps/Messages.ts @@ -9,6 +9,7 @@ import isEqual from 'lodash.isequal'; import { Nullable, toNullable, toNullableDate } from '../util/null'; import Collection from './Collection'; import { Client } from ".."; +import { decodeTime } from 'ulid'; export class Message { client: Client; @@ -47,6 +48,13 @@ export class Message { return this.mention_ids?.map(id => this.client.users.get(id)); } + /** + * Get timestamp when this message was created. + */ + get createdAt() { + return decodeTime(this._id); + } + @computed get asSystemMessage() { const content = this.content; diff --git a/src/maps/Servers.ts b/src/maps/Servers.ts index 75483b10..0138f971 100644 --- a/src/maps/Servers.ts +++ b/src/maps/Servers.ts @@ -10,6 +10,7 @@ import { U32_MAX } from '../api/permissions'; import Collection from './Collection'; import { User } from './Users'; import { Client, FileArgs } from '..'; +import { decodeTime } from 'ulid'; export class Server { client: Client; @@ -36,6 +37,13 @@ export class Server { return this.channel_ids.map(x => this.client.channels.get(x)); } + /** + * Get timestamp when this server was created. + */ + get createdAt() { + return decodeTime(this._id); + } + constructor(client: Client, data: ServerI) { this.client = client; diff --git a/src/maps/Users.ts b/src/maps/Users.ts index 41d38b47..a8faa4a5 100644 --- a/src/maps/Users.ts +++ b/src/maps/Users.ts @@ -10,6 +10,7 @@ import { toNullable, Nullable } from '../util/null'; import Collection from './Collection'; import { Client, FileArgs } from '..'; import _ from 'lodash'; +import { decodeTime } from 'ulid'; enum RelationshipStatus { None = "None", @@ -35,6 +36,13 @@ export class User { flags: Nullable; bot: Nullable; + /** + * Get timestamp when this user was created. + */ + get createdAt() { + return decodeTime(this._id); + } + constructor(client: Client, data: UserI) { this.client = client;