Skip to content

Commit b8c320f

Browse files
author
piloking
committed
add
1 parent 683c715 commit b8c320f

File tree

1 file changed

+89
-68
lines changed

1 file changed

+89
-68
lines changed

packages/linejs/client/entities/message-classes.ts

Lines changed: 89 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ export class Note {
156156
constructor(
157157
public mid: string,
158158
private client: Client,
159-
) {}
159+
) { }
160160

161161
public createPost(options: {
162162
text?: string;
@@ -214,7 +214,7 @@ export class Square {
214214
public createdAt: Date;
215215
public me: SquareMember;
216216
public authority: LINETypes.SquareAuthority;
217-
public note: LINETypes.NoteStatus;
217+
public noteStatus: LINETypes.NoteStatus;
218218
public status: LINETypes.SquareStatus;
219219
public memberCount: number;
220220
public joinRequestCount: number;
@@ -223,7 +223,7 @@ export class Square {
223223

224224
public feature: LINETypes.SquareFeatureSet;
225225

226-
public noteClient: Note;
226+
public note: Note;
227227

228228
constructor(
229229
public rawSouce: LINETypes.GetSquareResponse,
@@ -253,8 +253,8 @@ export class Square {
253253

254254
this.me = new SquareMember(myMembership, client);
255255
this.authority = squareAuthority;
256-
this.note = noteStatus;
257-
this.noteClient = new Note(this.mid, this.client);
256+
this.noteStatus = noteStatus;
257+
this.note = new Note(this.mid, this.client);
258258
this.feature = squareFeatureSet as LINETypes.SquareFeatureSet;
259259
this.status = squareStatus;
260260
this.memberCount = squareStatus.memberCount;
@@ -269,10 +269,6 @@ export class Square {
269269
static async from(squareMid: string, client: Client) {
270270
return new this(await client.getSquare({ squareMid }), client);
271271
}
272-
273-
public getNote(): Note {
274-
return this.noteClient;
275-
}
276272
}
277273

278274
/**
@@ -320,22 +316,51 @@ export class SquareChat {
320316
static async from(squareChatMid: string, client: Client) {
321317
return new this(await client.getSquareChat({ squareChatMid }), client);
322318
}
319+
320+
public async getMembers(): Promise<SquareMember[]> {
321+
const r = await this.client.getSquareChatMembers({ squareChatMid: this.mid, continueRequest: true });
322+
return r.squareChatMembers.map(e => new SquareMember(e, this.client));
323+
}
324+
325+
/**
326+
* @description Send msg to square.
327+
*/
328+
public send(
329+
options:
330+
| string
331+
| {
332+
text?: string;
333+
contentType?: number;
334+
contentMetadata?: LooseType;
335+
relatedMessageId?: string;
336+
location?: LINETypes.Location;
337+
},
338+
): Promise<LINETypes.SendMessageResponse> {
339+
if (typeof options === "string") {
340+
return this.send({ text: options });
341+
} else {
342+
const _options: LooseType = options;
343+
_options.squareChatMid = this.mid;
344+
return this.client.sendSquareMessage(_options);
345+
}
346+
}
347+
323348
}
324349

325350
/**
326351
* @description LINE squareMember (Openchat user) utils
327352
*/
328353
export class SquareMember {
329-
mid: string;
330-
squareMid: string;
331-
displayName: string;
332-
profileImageObsHash: string;
333-
ableToReceiveMessage: boolean;
334-
membershipState: LINETypes.SquareMembershipState;
335-
role: LINETypes.SquareMemberRole;
336-
revision: number;
337-
preference: LINETypes.SquarePreference;
338-
joinMessage?: string;
354+
public mid: string;
355+
public squareMid: string;
356+
public displayName: string;
357+
public profileImageObsHash: string;
358+
public ableToReceiveMessage: boolean;
359+
public membershipState: LINETypes.SquareMembershipState;
360+
public role: LINETypes.SquareMemberRole;
361+
public revision: number;
362+
public preference: LINETypes.SquarePreference;
363+
public joinMessage?: string;
339364
constructor(
340365
public rawMember: LINETypes.SquareMember,
341366
private client: Client,
@@ -510,14 +535,14 @@ export class User {
510535
options:
511536
| string
512537
| {
513-
text?: string;
514-
contentType?: number;
515-
contentMetadata?: LooseType;
516-
relatedMessageId?: string;
517-
location?: LINETypes.Location;
518-
chunk?: string[] | Buffer[];
519-
e2ee?: boolean;
520-
},
538+
text?: string;
539+
contentType?: number;
540+
contentMetadata?: LooseType;
541+
relatedMessageId?: string;
542+
location?: LINETypes.Location;
543+
chunk?: string[] | Buffer[];
544+
e2ee?: boolean;
545+
},
521546
): Promise<LINETypes.Message> {
522547
if (typeof options === "string") {
523548
return this.send({ text: options });
@@ -534,7 +559,7 @@ export class User {
534559
public async updateStatus() {
535560
this.updateStatusFrom(
536561
(await this.client.getContactsV2({ mids: [this.mid] })).contacts[
537-
this.mid
562+
this.mid
538563
],
539564
);
540565
}
@@ -579,7 +604,7 @@ export class Group {
579604
public preventedJoinByTicket: boolean;
580605
public invitationTicket: string;
581606
public notificationDisabled: boolean;
582-
public noteClient: Note;
607+
public note: Note;
583608

584609
/**
585610
* @description Generate from groupMid or {Chat}.
@@ -662,7 +687,7 @@ export class Group {
662687
const { groupExtra } = chat.extra;
663688
this.preventedJoinByTicket = groupExtra.preventedJoinByTicket;
664689
this.invitationTicket = groupExtra.invitationTicket;
665-
this.noteClient = new Note(this.mid, client);
690+
this.note = new Note(this.mid, client);
666691
}
667692

668693
/**
@@ -672,14 +697,14 @@ export class Group {
672697
options:
673698
| string
674699
| {
675-
text?: string;
676-
contentType?: number;
677-
contentMetadata?: LooseType;
678-
relatedMessageId?: string;
679-
location?: LINETypes.Location;
680-
chunk?: string[] | Buffer[];
681-
e2ee?: boolean;
682-
},
700+
text?: string;
701+
contentType?: number;
702+
contentMetadata?: LooseType;
703+
relatedMessageId?: string;
704+
location?: LINETypes.Location;
705+
chunk?: string[] | Buffer[];
706+
e2ee?: boolean;
707+
},
683708
): Promise<LINETypes.Message> {
684709
if (typeof options === "string") {
685710
return this.send({ text: options });
@@ -722,10 +747,6 @@ export class Group {
722747
public kick(mid: string): Promise<LINETypes.DeleteOtherFromChatResponse> {
723748
return this.client.deleteOtherFromChat({ to: this.mid, mid: mid });
724749
}
725-
726-
public getNote(): Note {
727-
return this.noteClient;
728-
}
729750
}
730751

731752
/**
@@ -1686,14 +1707,14 @@ export class TalkMessage extends ClientMessage {
16861707
public async send(
16871708
options:
16881709
| {
1689-
text?: string | undefined;
1690-
contentType?: number | undefined;
1691-
contentMetadata?: LooseType;
1692-
relatedMessageId?: string | undefined;
1693-
location?: LooseType;
1694-
chunk?: string[] | undefined;
1695-
e2ee?: boolean | undefined;
1696-
}
1710+
text?: string | undefined;
1711+
contentType?: number | undefined;
1712+
contentMetadata?: LooseType;
1713+
relatedMessageId?: string | undefined;
1714+
location?: LooseType;
1715+
chunk?: string[] | undefined;
1716+
e2ee?: boolean | undefined;
1717+
}
16971718
| string,
16981719
): Promise<TalkMessage> {
16991720
if (typeof options === "string") {
@@ -1719,14 +1740,14 @@ export class TalkMessage extends ClientMessage {
17191740
public async reply(
17201741
options:
17211742
| {
1722-
text?: string | undefined;
1723-
contentType?: number | undefined;
1724-
contentMetadata?: LooseType;
1725-
relatedMessageId?: string | undefined;
1726-
location?: LooseType;
1727-
chunk?: string[] | undefined;
1728-
e2ee?: boolean | undefined;
1729-
}
1743+
text?: string | undefined;
1744+
contentType?: number | undefined;
1745+
contentMetadata?: LooseType;
1746+
relatedMessageId?: string | undefined;
1747+
location?: LooseType;
1748+
chunk?: string[] | undefined;
1749+
e2ee?: boolean | undefined;
1750+
}
17301751
| string,
17311752
): Promise<TalkMessage> {
17321753
if (typeof options === "string") {
@@ -1850,11 +1871,11 @@ export class SquareMessage extends ClientMessage {
18501871
public send(
18511872
options:
18521873
| {
1853-
text?: string | undefined;
1854-
contentType?: LooseType;
1855-
contentMetadata?: LooseType;
1856-
relatedMessageId?: string | undefined;
1857-
}
1874+
text?: string | undefined;
1875+
contentType?: LooseType;
1876+
contentMetadata?: LooseType;
1877+
relatedMessageId?: string | undefined;
1878+
}
18581879
| string,
18591880
safe: boolean = true,
18601881
): Promise<SquareMessage> {
@@ -1881,11 +1902,11 @@ export class SquareMessage extends ClientMessage {
18811902
public reply(
18821903
options:
18831904
| {
1884-
text?: string | undefined;
1885-
contentType?: LooseType;
1886-
contentMetadata?: LooseType;
1887-
relatedMessageId?: string | undefined;
1888-
}
1905+
text?: string | undefined;
1906+
contentType?: LooseType;
1907+
contentMetadata?: LooseType;
1908+
relatedMessageId?: string | undefined;
1909+
}
18891910
| string,
18901911
safe: boolean = true,
18911912
): Promise<SquareMessage> {

0 commit comments

Comments
 (0)