Skip to content

Commit

Permalink
refactor(ModmailConversationAuthor): convert to TS (not-an-aardvark#204)
Browse files Browse the repository at this point in the history
* refactor(ModmailConversationAuthor): convert to TS

* Fixed docs for TS files

* Updated TSConfig to help JSDoc
  • Loading branch information
Eric authored Aug 26, 2019
1 parent ffc4ac9 commit d492286
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 57 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"test:mocha": "npm run compile && mocha --require @babel/register test/snoowrap.spec.js",
"test:browser": "npm run compile && browserify --im test/snoowrap.spec.js -o test/_browser.spec.js -t [ babelify ] && open test/run-tests.html",
"smoketest": "npm run test -- -g 'smoketest'",
"build-docs": "scripts/build_docs.sh",
"build-docs": "npm run build:docs",
"build:docs": "scripts/build_docs.sh",
"build:babel": "babel -q -d dist/ src/",
"build:types": "tsc -p tsconfig.gen-dts.json",
"bundle-size": "npm run build-docs && gzip -c doc/snoowrap-v$(npm info . version).min.js | wc -c | xargs",
Expand Down
50 changes: 0 additions & 50 deletions src/objects/ModmailConversationAuthor.d.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,33 @@
import RedditContent from './RedditContent';
import RedditUser from './RedditUser';
import * as Snoowrap from '../snoowrap';

export interface BanStatus {
endDate?: string | null;
reason: string;
isBanned: boolean;
isPermanent: boolean;
}

export interface RecentPost {
date: string;
permalink: string;
title: string;
}

export interface RecentConvo {
date: string;
permalink: string;
id: string;
subject: string;
}

export interface RecentComment {
date: string;
permalink: string;
title: string;
comment: string;
}

/**
* A class representing an author from a modmail conversation
Expand All @@ -9,8 +38,24 @@ import RedditContent from './RedditContent';
* r.getNewModmailConversation('75hxt').getParticipant()
* @extends RedditContent
*/
const ModmailConversationAuthor = class ModmailParticipant extends RedditContent {
constructor (options, r, hasFetched) {
export default class ModmailConversationAuthor extends RedditContent<ModmailConversationAuthor> {
name!: string;
isMod?: boolean;
isAdmin?: boolean;
isOp?: boolean;
isParticipant?: boolean;
isHidden?: boolean;
isDeleted?: boolean;

// these fields only show up sometimes
banStatus?: BanStatus;
isSuspended?: boolean;
isShadowBanned?: boolean;
recentPosts?: { [id: string]: RecentPost };
recentConvos?: { [id: string]: RecentConvo };
recentComments?: { [id: string]: RecentComment };

constructor (options: any, r: Snoowrap, hasFetched: boolean) {
super(options, r, hasFetched);

options.recentComments = Object.keys(options.recentComments).map(commentId => this._r._newObject('Comment', {
Expand All @@ -34,9 +79,7 @@ const ModmailConversationAuthor = class ModmailParticipant extends RedditContent
* r.getNewModmailConversation('efy3lax').getParticipant().getUser().link_karma.then(console.log)
* // => 6
*/
getUser () {
getUser (): Promise<RedditUser> {
return this._r.getUser(this.name);
}
};

export default ModmailConversationAuthor;
3 changes: 3 additions & 0 deletions src/objects/RedditContent.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ export default class RedditContent<T> extends Promise<T> {
created: number;
id: string;
name: string;
protected _r: Snoowrap;
protected _fetch?: boolean;
protected _hasFetched: boolean;

constructor(options: any, _r: Snoowrap, _hasFetched: boolean);
fetch(): Promise<T>;
Expand Down
2 changes: 2 additions & 0 deletions src/snoowrap.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export = Snoowrap;
declare class Snoowrap {
static getAuthUrl(options: Snoowrap.AuthUrlOptions): string;
static fromAuthCode(options: Snoowrap.AuthCodeOptions): Promise<Snoowrap>;

_newObject (objectType: string, content: object[]|object, _hasFetched?: boolean): Array<unknown>|object;
static noConflict(): typeof Snoowrap;

accessToken: string;
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"lib": [
"es6",
"es2017",
"dom"
],
"noImplicitAny": true,
Expand Down

0 comments on commit d492286

Please sign in to comment.