diff --git a/package.json b/package.json index 95aafb19..6f3e8c74 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "revolt.js", - "version": "3.0.3-alpha.7", + "version": "3.0.3-alpha.8", "main": "dist/index.js", "repository": "https://gitlab.insrt.uk/revolt/revolt.js", "author": "Paul Makles ", diff --git a/src/Client.ts b/src/Client.ts index 61cf65ae..f52a8964 100644 --- a/src/Client.ts +++ b/src/Client.ts @@ -8,9 +8,10 @@ import { Core, Auth, Users, Channels } from './api/objects'; import { Route, RoutePath, RouteMethod } from './api/routes'; -import User, { SystemUser } from './objects/User'; import Channel from './objects/Channel'; import Message from './objects/Message'; +import User, { SystemUser } from './objects/User'; +import { ClientboundNotification } from './websocket/notifications'; export interface ClientOptions { apiURL: string, @@ -24,6 +25,7 @@ export declare interface Client { on(event: 'connecting', listener: () => void): this; on(event: 'dropped', listener: () => void): this; on(event: 'ready', listener: () => void): this; + on(event: 'packet', listener: (packet: ClientboundNotification) => void): this; // Object creation. on(event: 'create/user', listener: (user: User) => void): this; diff --git a/src/api/routes.ts b/src/api/routes.ts index bbfb8329..f498a240 100644 --- a/src/api/routes.ts +++ b/src/api/routes.ts @@ -187,6 +187,15 @@ type Routes = status: Users.Relationship } } + | { + // Fetch your mutual relationships with another user. + method: 'GET', + route: '/users/:id/mutual', + data: undefined, + response: { + users: string[] + } + } | { // Send a friend request / accept a friend request. method: 'PUT', diff --git a/src/index.ts b/src/index.ts index 3f377359..32a3af2d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,7 +4,7 @@ export { default as User } from './objects/User'; export { default as Message } from './objects/Message'; export { default as Channel, SavedMessagesChannel, DirectMessageChannel, GroupChannel } from './objects/Channel'; -export const LIBRARY_VERSION = '3.0.3-alpha.7'; +export const LIBRARY_VERSION = '3.0.3-alpha.8'; export const defaultConfig = { apiURL: 'https://api.revolt.chat', diff --git a/src/objects/User.ts b/src/objects/User.ts index 23d12b12..4ff27e41 100644 --- a/src/objects/User.ts +++ b/src/objects/User.ts @@ -1,3 +1,4 @@ +import { result } from 'lodash'; import { Client, Channel } from '..'; import { Users } from '../api/objects'; import { hasChanged } from '../util/object'; @@ -78,6 +79,17 @@ export default class User { return relationship; } + async fetchMutualConnections(): Promise<{ users: User[] }> { + let data = await this.client.req<'GET', '/users/:id/mutual'>('GET', `/users/${this.id}/mutual` as any); + let users = []; + + for (let user of data.users) { + users.push(await this.client.fetchUser(user)); + } + + return { users }; + } + async addFriend() { let data = await this.client.req<'PUT', '/users/:id/friend'>('PUT', `/users/${this.username}/friend` as any); this.patch({ relationship: data.status }, true); diff --git a/src/websocket/notifications.ts b/src/websocket/notifications.ts index 7a25228b..617b6dd4 100644 --- a/src/websocket/notifications.ts +++ b/src/websocket/notifications.ts @@ -5,7 +5,9 @@ type WebSocketError = { }; export type ServerboundNotification = ( - ({ type: 'Authenticate' } & Auth.Session) + ({ type: 'Authenticate' } & Auth.Session) | + ({ type: 'BeginTyping', channel: string }) | + ({ type: 'EndTyping', channel: string }) ); export type ClientboundNotification = ( @@ -22,6 +24,8 @@ export type ClientboundNotification = ( ({ type: 'ChannelGroupJoin', id: string, user: string }) | ({ type: 'ChannelGroupLeave', id: string, user: string }) | ({ type: 'ChannelDelete', id: string }) | + ({ type: 'ChannelStartTyping', id: string, user: string }) | + ({ type: 'ChannelStopTyping', id: string, user: string }) | { type: 'UserRelationship', user: string, status: Users.Relationship } | { type: 'UserPresence', id: string, online: boolean }