Fix a bug where we don't open saved messages channels.

This commit is contained in:
Paul
2021-03-30 21:34:49 +01:00
parent 2bb1567c63
commit 28ae2e307e
3 changed files with 18 additions and 6 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "revolt.js",
"version": "4.0.0-alpha.14",
"version": "4.0.0-alpha.15",
"main": "dist/index.js",
"repository": "https://gitlab.insrt.uk/revolt/revolt.js",
"author": "Paul Makles <insrt.uk>",
+1 -1
View File
@@ -1,7 +1,7 @@
export * from './Client';
export { Channel, User, Message } from './api/objects';
export const LIBRARY_VERSION = '4.0.0-alpha.14';
export const LIBRARY_VERSION = '4.0.0-alpha.15';
export const defaultConfig = {
apiURL: 'https://api.revolt.chat',
+16 -4
View File
@@ -20,10 +20,22 @@ export default class Users extends Collection<User> {
async openDM(id: string) {
this.getThrow(id);
let channel = this.client.channels
.toArray()
.find(channel => channel.channel_type === 'DirectMessage'
&& channel.recipients.find(user => user === id));
let channel;
if (id === this.client.user?._id) {
channel = this.client
.channels
.toArray()
.find(channel => channel.channel_type === 'SavedMessages');
} else {
channel = this.client
.channels
.toArray()
.find(channel =>
(channel.channel_type === 'DirectMessage'
&& channel.recipients.find(user => user === id))
);
}
if (typeof channel === 'undefined') {
channel = await this.client.req<'GET', '/users/:id/dm'>('GET', `/users/${id}/dm` as any);