From 28ae2e307eda8124d7ada279edf77873fec30114 Mon Sep 17 00:00:00 2001 From: Paul Date: Tue, 30 Mar 2021 21:34:49 +0100 Subject: [PATCH] Fix a bug where we don't open saved messages channels. --- package.json | 2 +- src/index.ts | 2 +- src/maps/Users.ts | 20 ++++++++++++++++---- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index efae05fa..e23e3fe9 100644 --- a/package.json +++ b/package.json @@ -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 ", diff --git a/src/index.ts b/src/index.ts index f0bbb18f..8cb705b1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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', diff --git a/src/maps/Users.ts b/src/maps/Users.ts index e17c19ad..f779e37e 100644 --- a/src/maps/Users.ts +++ b/src/maps/Users.ts @@ -20,10 +20,22 @@ export default class Users extends Collection { 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);