Skip to content
This repository has been archived by the owner on Nov 13, 2024. It is now read-only.

Commit

Permalink
fix #9
Browse files Browse the repository at this point in the history
  • Loading branch information
williamhorning committed Aug 17, 2024
1 parent 6ded2eb commit 04dc576
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 11 deletions.
20 changes: 20 additions & 0 deletions src/api/uploads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ export interface api_attachment {
id: string;
}

/** api emoji */
export interface api_emoji {
/** file id */
_id: string;
/** emoji name */
name: string;
/** animated */
animated: boolean;
}

/** uploads class construction options */
export interface uploads_opts {
/** base url for uploads */
Expand Down Expand Up @@ -42,6 +52,16 @@ export function is_api_attachment(obj: unknown): obj is api_attachment {
return true;
}

/** check if object is an api emoji */
export function is_api_emoji(obj: unknown): obj is api_emoji {
if (obj === null || typeof obj !== 'object') return false;
if (!('_id' in obj) || typeof obj._id !== 'string') return false;
if (!('name' in obj) || typeof obj.name !== 'string') return false;
if (!('animated' in obj) || typeof obj.animated !== 'boolean') return false;

return true;
}

/** access to meower uploads */
export class uploads {
private opts: uploads_opts;
Expand Down
14 changes: 7 additions & 7 deletions src/interfaces/chat.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type api_attachment, is_api_attachment } from '../api/uploads.ts';
import { type api_emoji, is_api_emoji } from '../api/uploads.ts';
import { type api_post, post } from './post.ts';

/** chat types */
Expand Down Expand Up @@ -34,9 +34,9 @@ export interface api_chat {
/** chat type */
type: chat_type;
/** emojis */
emojis: api_attachment[];
emojis: api_emoji[];
/** stickers */
stickers: api_attachment[];
stickers: api_emoji[];
}

/** chat construction options */
Expand Down Expand Up @@ -95,11 +95,11 @@ export function is_api_chat(obj: unknown): obj is api_chat {
if (!('type' in obj) || typeof obj.type !== 'number') return false;
if (!('emojis' in obj) || !Array.isArray(obj.emojis)) return false;
for (const i of obj.emojis) {
if (!is_api_attachment(i)) return false;
if (!is_api_emoji(i)) return false;
}
if (!('stickers' in obj) || !Array.isArray(obj.stickers)) return false;
for (const i of obj.stickers) {
if (!is_api_attachment(i)) return false;
if (!is_api_emoji(i)) return false;
}

return true;
Expand Down Expand Up @@ -134,9 +134,9 @@ export class chat {
/** chat type */
type!: chat_type;
/** emojis */
emojis!: api_attachment[];
emojis!: api_emoji[];
/** stickers */
stickers!: api_attachment[];
stickers!: api_emoji[];

constructor(opts: chat_construction_opts) {
this.api_url = opts.api_url;
Expand Down
8 changes: 4 additions & 4 deletions src/interfaces/post.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type api_attachment, is_api_attachment } from '../api/uploads.ts';
import { type api_attachment, type api_emoji, is_api_attachment, is_api_emoji } from '../api/uploads.ts';
import type { message_send_opts } from './chat.ts';

/** types of posts */
Expand Down Expand Up @@ -35,7 +35,7 @@ export interface api_post {
/** username */
u: string;
/** stickers */
stickers: api_attachment[];
stickers: api_emoji[];
/** reply to */
reply_to: api_post[];
/** reactions */
Expand Down Expand Up @@ -97,7 +97,7 @@ export function is_api_post(obj: unknown): obj is api_post {
if (!('u' in obj) || typeof obj.u !== 'string') return false;
if (!('stickers' in obj) || !Array.isArray(obj.stickers)) return false;
for (const i of obj.stickers) {
if (!is_api_attachment(i)) return false;
if (!is_api_emoji(i)) return false;
}
if (!('reply_to' in obj) || !Array.isArray(obj.reply_to)) return false;
for (const i of obj.reply_to) {
Expand Down Expand Up @@ -138,7 +138,7 @@ export class post {
/** reply to */
replies!: post[];
/** stickers */
stickers!: api_attachment[];
stickers!: api_emoji[];
/** reactions */
reactions!: api_post['reactions'];

Expand Down

0 comments on commit 04dc576

Please sign in to comment.