Catch last_message object.

This commit is contained in:
Paul Makles
2021-01-24 10:35:15 +00:00
parent 93404b82fb
commit 118b612631
4 changed files with 29 additions and 10 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "revolt.js",
"version": "3.0.1-beta.5",
"version": "3.0.1-beta.6",
"main": "dist/index.js",
"repository": "https://gitlab.insrt.uk/revolt/revolt.js",
"author": "Paul Makles <insrt.uk>",
+4 -3
View File
@@ -5,6 +5,7 @@ import { EventEmitter } from 'events';
import { defaultConfig } from '.';
import { Core } from './api/core';
import { Auth } from './api/auth';
import { Users } from './api/users';
import { Channels } from './api/channels';
import { Onboarding } from './api/onboarding';
import { WebSocketClient } from './websocket/client';
@@ -32,9 +33,9 @@ export declare interface Client {
on(event: 'create/message', listener: (message: Message) => void): this;
// Object mutations.
on(event: 'mutation/user', listener: (user: User, partial: Partial<User>) => void): this;
on(event: 'mutation/channel', listener: (channel: Channel, partial: Partial<Channel>) => void): this;
on(event: 'mutation/message', listener: (message: Message, partial: Partial<Message>) => void): this;
on(event: 'mutation/user', listener: (user: User, partial: Partial<Users.User>) => void): this;
on(event: 'mutation/channel', listener: (channel: Channel, partial: Partial<Channels.Channel>) => void): this;
on(event: 'mutation/message', listener: (message: Message, partial: Partial<Channels.Message>) => void): this;
// Object destruction.
on(event: 'delete/user', listener: (user: User, id: string) => void): this;
+10 -2
View File
@@ -1,4 +1,10 @@
export namespace Channels {
export type LastMessage = {
_id: string,
author: string,
short: string
}
export type SavedMessagesChannel = {
_id: string,
channel_type: 'SavedMessages',
@@ -9,7 +15,8 @@ export namespace Channels {
_id: string,
channel_type: 'DirectMessage',
active: boolean,
recipients: string[]
recipients: string[],
last_message: LastMessage
}
export type GroupChannel = {
@@ -18,7 +25,8 @@ export namespace Channels {
recipients: string[],
name: string,
owner: string,
description: string
description: string,
last_message: LastMessage
}
export type Channel = (SavedMessagesChannel | DirectMessageChannel | GroupChannel)
+14 -4
View File
@@ -130,15 +130,23 @@ export class DirectMessageChannel extends TextChannel {
recipient: User;
_recipients: string[];
_lastMessage: Channels.LastMessage;
constructor(client: Client, data: Channels.Channel) {
super(client, data);
}
patch(data: Channels.DirectMessageChannel) {
// ? info: there are no partial patches that can occur here
this.active = data.active;
this._recipients = data.recipients;
patch(data: Partial<Channels.DirectMessageChannel>, emitPatch?: boolean) {
let changedFields = hasChanged(this._data, data, !emitPatch);
this.active = data.active ?? this.active;
this._recipients = data.recipients ?? this._recipients;
this._lastMessage = data.last_message ?? this._lastMessage;
Object.assign(this._data, data);
if (changedFields.length > 0) {
this.client.emit('mutation/channel', this, data);
}
}
async $sync() {
@@ -160,6 +168,7 @@ export class GroupChannel extends TextChannel {
_owner: string;
_recipients: string[];
_lastMessage: Channels.LastMessage;
constructor(client: Client, data: Channels.Channel) {
super(client, data);
@@ -173,6 +182,7 @@ export class GroupChannel extends TextChannel {
this.description = data.description ?? this.description;
this._owner = data.owner ?? this._owner;
this._recipients = data.recipients ?? this._recipients;
this._lastMessage = data.last_message ?? this._lastMessage;
Object.assign(this._data, data);
if (changedFields.length > 0) {