Skip to content

Commit

Permalink
FIx #114 Check nullish value in getLatestLinkList
Browse files Browse the repository at this point in the history
  • Loading branch information
storycraft committed Feb 1, 2021
1 parent 984f64f commit 7a25b51
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 86 deletions.
37 changes: 17 additions & 20 deletions src/chat/chat-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,50 +6,47 @@

import { Chat } from "./chat";
import { ChatType, KnownChatType } from "./chat-type";
import { ChatContent } from "./content";

/**
* Build Chat object
*/
export class ChatBuilder {
export class ChatBuilder<T extends ChatType> {

private _attachment: Record<string, any>;
private _text: string;

constructor(private _type: ChatType, private _text: string = '') {
constructor(private _type: T) {
this._attachment = {};
this._text = '';
}

/**
* Set chat text
* @param text
* Append text or chat content
*
* @param content
*/
text(text: string): this {
this._text = text;
append(content: string | ChatContent): this {
if (typeof content === 'string') {
this._text += content;
return this;
}

return this;
}


/**
* Set json attachment
* @param attachment
*/
attachment(attachment: Record<string, any>): this {
this._attachment = attachment;
return this;
}

/**
* Build into chat
* Build into chat object
*/
build(): Chat {
const chat: Chat = {
type: this._type,
text: this._text
text: this._text,
attachment: this._attachment
};

if (this._attachment) {
chat['attachment'] = this._attachment;
}

return chat;
}

Expand Down
11 changes: 11 additions & 0 deletions src/chat/content/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* Created on Mon Feb 01 2021
*
* Copyright (c) storycraft. Licensed under the MIT Licence.
*/

export interface ChatContent {



}
1 change: 1 addition & 0 deletions src/chat/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

export * from "./attachment";
export * from "./chat-builder";
export * from "./content";
export * from "./chat-type";
export * from "./chat";
export * from "./feed";
2 changes: 1 addition & 1 deletion src/packet/chat/sync-link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { InformedOpenLinkStruct, OpenLinkStruct } from "../struct/openlink";

export interface SyncLinkRes {

ols: InformedOpenLinkStruct[];
ols?: InformedOpenLinkStruct[];

ltk: number;

Expand Down
51 changes: 0 additions & 51 deletions src/talk/block/talk-block-list.ts

This file was deleted.

14 changes: 1 addition & 13 deletions src/talk/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { OpenLinkService } from "../openlink/open-link-service";
import { TalkChannelList } from "../talk-channel-list";
import { ClientEvents } from "../event";
import { Long } from "bson";
import { TalkBlockList } from "../block/talk-block-list";
import { TypedEmitter } from "../../event";

export * from "./talk-client-session";
Expand Down Expand Up @@ -59,8 +58,6 @@ export class TalkClient extends TypedEmitter<ClientEvents> implements CommandSes

private _openLink: OpenLinkService;

private _blockList: TalkBlockList;

constructor(config: Partial<ClientConfig> = {}, private _sessionFactory: SessionFactory = new TalkSessionFactory()) {
super();

Expand All @@ -75,8 +72,6 @@ export class TalkClient extends TypedEmitter<ClientEvents> implements CommandSes
this._cilentUser = { userId: Long.ZERO };

this._openLink = new OpenLinkService(this.createSessionProxy());

this._blockList = new TalkBlockList(this.createSessionProxy());
}

get configuration() {
Expand Down Expand Up @@ -105,12 +100,6 @@ export class TalkClient extends TypedEmitter<ClientEvents> implements CommandSes
return this._openLink;
}

get blockList() {
if (!this.logon) throw new Error('Cannot access without logging in');

return this._blockList;
}

/**
* true if session created
*/
Expand Down Expand Up @@ -142,8 +131,7 @@ export class TalkClient extends TypedEmitter<ClientEvents> implements CommandSes

await TalkChannelList.initialize(this._channelList, loginRes.result.channelList);
await OpenLinkService.initialize(this._openLink);
await TalkBlockList.initialize(this._blockList);


return { status: loginRes.status, success: true, result: loginRes.result };
}

Expand Down
2 changes: 1 addition & 1 deletion src/talk/openlink/talk-openlink-session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class TalkOpenLinkSession implements OpenLinkSession {
);
if (res.status !== KnownDataStatusCode.SUCCESS) return { status: res.status, success: false };

const list: InformedOpenLink[] = res.ols.map(struct => {
const list: InformedOpenLink[] = !res.ols ? [] : res.ols.map(struct => {
return { openLink: structToOpenLink(struct), info: structToOpenLinkInfo(struct) };
});

Expand Down

0 comments on commit 7a25b51

Please sign in to comment.