-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Expand file tree
/
Copy pathChannelPinMixin.ts
More file actions
65 lines (57 loc) · 2.08 KB
/
ChannelPinMixin.ts
File metadata and controls
65 lines (57 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import type { ChannelType, ThreadChannelType } from 'discord-api-types/v10';
import { kLastPinTimestamp, kMixinConstruct, kMixinToJSON } from '../../utils/symbols.js';
import type { Channel, ChannelDataType } from '../Channel.js';
export interface ChannelPinMixin<
Type extends ChannelType.DM | ChannelType.GuildAnnouncement | ChannelType.GuildText | ThreadChannelType,
> extends Channel<Type> {}
export class ChannelPinMixin<
Type extends ChannelType.DM | ChannelType.GuildAnnouncement | ChannelType.GuildText | ThreadChannelType,
> {
/**
* The timestamp of when the last pin in the channel happened
*/
declare protected [kLastPinTimestamp]: number | null;
/**
* The template used for removing data from the raw data stored for each Channel.
*
* @remarks This template has defaults, if you want to remove additional data and keep the defaults,
* use `Object.defineProperties`. To override the defaults, set this value directly.
*/
public static readonly DataTemplate: Partial<
ChannelDataType<ChannelType.DM | ChannelType.GuildAnnouncement | ChannelType.GuildText | ThreadChannelType>
> = {
set last_pin_timestamp(_: string) {},
};
public [kMixinConstruct]() {
this[kLastPinTimestamp] ??= null;
}
/**
* {@inheritDoc Structure.optimizeData}
*/
protected optimizeData(data: Partial<ChannelDataType<Type>>) {
if (data.last_pin_timestamp) {
this[kLastPinTimestamp] = Date.parse(data.last_pin_timestamp);
}
}
/**
* The timestamp of when the last pin in the channel happened.
*/
public get lastPinTimestamp() {
return this[kLastPinTimestamp];
}
/**
* The Date of when the last pin in the channel happened
*/
public get lastPinAt() {
const lastPinTimestamp = this.lastPinTimestamp;
return lastPinTimestamp ? new Date(lastPinTimestamp) : null;
}
/**
* Adds data from optimized properties omitted from [kData].
*
* @param data - the result of {@link (Structure:class).toJSON}
*/
protected [kMixinToJSON](data: Partial<ChannelDataType<Type>>) {
data.last_pin_timestamp = this[kLastPinTimestamp] ? new Date(this[kLastPinTimestamp]).toISOString() : null;
}
}