mirror of
https://github.com/stoatchat/javascript-client-sdk.git
synced 2026-07-20 20:16:06 -04:00
Add helper functions for timestamps, closes #17.
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user