@@ -15,6 +15,8 @@ function checkJSON<T>(raw: T): T {
15
15
}
16
16
}
17
17
18
+ type ChatType = "group" | "room" ;
19
+
18
20
export default class Client {
19
21
public config : Types . ClientConfig ;
20
22
private http : HTTPClient ;
@@ -67,28 +69,37 @@ export default class Client {
67
69
return this . http . get < Types . Profile > ( `/profile/${ userId } ` ) . then ( checkJSON ) ;
68
70
}
69
71
70
- public getGroupMemberProfile (
71
- groupId : string ,
72
+ private getChatMemberProfile (
73
+ chatType : ChatType ,
74
+ chatId : string ,
72
75
userId : string ,
73
76
) : Promise < Types . Profile > {
74
77
return this . http
75
- . get < Types . Profile > ( `/group /${ groupId } /member/${ userId } ` )
78
+ . get < Types . Profile > ( `/${ chatType } /${ chatId } /member/${ userId } ` )
76
79
. then ( checkJSON ) ;
77
80
}
78
81
82
+ public getGroupMemberProfile (
83
+ groupId : string ,
84
+ userId : string ,
85
+ ) : Promise < Types . Profile > {
86
+ return this . getChatMemberProfile ( "group" , groupId , userId ) ;
87
+ }
88
+
79
89
public getRoomMemberProfile (
80
90
roomId : string ,
81
91
userId : string ,
82
92
) : Promise < Types . Profile > {
83
- return this . http
84
- . get < Types . Profile > ( `/room/${ roomId } /member/${ userId } ` )
85
- . then ( checkJSON ) ;
93
+ return this . getChatMemberProfile ( "room" , roomId , userId ) ;
86
94
}
87
95
88
- public getGroupMemberIds ( groupId : string ) : Promise < string [ ] > {
96
+ private getChatMemberIds (
97
+ chatType : ChatType ,
98
+ chatId : string ,
99
+ ) : Promise < string [ ] > {
89
100
const load = ( start ?: string ) : Promise < string [ ] > =>
90
101
this . http
91
- . get ( `/group /${ groupId } /members/ids` , start ? { start } : null )
102
+ . get ( `/${ chatType } /${ chatId } /members/ids` , start ? { start } : null )
92
103
. then ( checkJSON )
93
104
. then ( ( res : { memberIds : string [ ] ; next ?: string } ) => {
94
105
if ( ! res . next ) {
@@ -102,33 +113,28 @@ export default class Client {
102
113
return load ( ) ;
103
114
}
104
115
105
- public getRoomMemberIds ( roomId : string ) : Promise < string [ ] > {
106
- const load = ( start ?: string ) : Promise < string [ ] > =>
107
- this . http
108
- . get ( `/room/${ roomId } /members/ids` , start ? { start } : null )
109
- . then ( checkJSON )
110
- . then ( ( res : { memberIds : string [ ] ; next ?: string } ) => {
111
- if ( ! res . next ) {
112
- return res . memberIds ;
113
- }
116
+ public getGroupMemberIds ( groupId : string ) : Promise < string [ ] > {
117
+ return this . getChatMemberIds ( "group" , groupId ) ;
118
+ }
114
119
115
- return load ( res . next ) . then ( extraIds =>
116
- res . memberIds . concat ( extraIds ) ,
117
- ) ;
118
- } ) ;
119
- return load ( ) ;
120
+ public getRoomMemberIds ( roomId : string ) : Promise < string [ ] > {
121
+ return this . getChatMemberIds ( "room" , roomId ) ;
120
122
}
121
123
122
124
public getMessageContent ( messageId : string ) : Promise < Readable > {
123
125
return this . http . getStream ( `/message/${ messageId } /content` ) ;
124
126
}
125
127
128
+ private leaveChat ( chatType : ChatType , chatId : string ) : Promise < any > {
129
+ return this . http . post ( `/${ chatType } /${ chatId } /leave` ) ;
130
+ }
131
+
126
132
public leaveGroup ( groupId : string ) : Promise < any > {
127
- return this . http . post ( `/ group/ ${ groupId } /leave` ) ;
133
+ return this . leaveChat ( " group" , groupId ) ;
128
134
}
129
135
130
136
public leaveRoom ( roomId : string ) : Promise < any > {
131
- return this . http . post ( `/ room/ ${ roomId } /leave` ) ;
137
+ return this . leaveChat ( " room" , roomId ) ;
132
138
}
133
139
134
140
public getRichMenu ( richMenuId : string ) : Promise < Types . RichMenuResponse > {
0 commit comments