Add helper functions for timestamps, closes #17.

This commit is contained in:
Paul
2021-10-10 19:30:16 +01:00
parent 5db8f486dd
commit 6fd39b40d7
4 changed files with 32 additions and 1 deletions
+8 -1
View File
@@ -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;
+8
View File
@@ -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;
+8
View File
@@ -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;
+8
View File
@@ -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<number>;
bot: Nullable<BotInformation>;
/**
* Get timestamp when this user was created.
*/
get createdAt() {
return decodeTime(this._id);
}
constructor(client: Client, data: UserI) {
this.client = client;