Skip to content

Commit a351205

Browse files
committed
feat: add mute and unmute user
closes #76
1 parent a229ced commit a351205

File tree

4 files changed

+64
-0
lines changed

4 files changed

+64
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
- [x] 关注
3333
- [x] 取消关注
3434
- [x] 是否关注用户
35+
- [x] 不看 TA 的内容
36+
- [x] 重新看 TA 的内容
3537
- 动态帖子
3638
- [x] 发送动态
3739
- [x] 获取动态详情

src/api/user-relation.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,29 @@ export const unfollow = <T = UserRelation.UnfollowResponse>(
8282
},
8383
})
8484
)
85+
86+
/**
87+
* 不看 TA 的内容
88+
* @param userId 用户 ID
89+
*/
90+
export const mute = <T = UserRelation.MuteResponse>(userId: string) =>
91+
toResponse<T>(
92+
request.post('1.0/userRelation/mute', {
93+
json: {
94+
id: userId,
95+
},
96+
})
97+
)
98+
99+
/**
100+
* 重新看 TA 的内容
101+
* @param userId 用户 ID
102+
*/
103+
export const unmute = <T = UserRelation.UnmuteResponse>(userId: string) =>
104+
toResponse<T>(
105+
request.post('1.0/userRelation/unmute', {
106+
json: {
107+
id: userId,
108+
},
109+
})
110+
)

src/client/user.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ export class JikeUser<M extends boolean = boolean> {
3131
this.#profile = profile
3232
}
3333

34+
/**
35+
* 获取用户 ID
36+
* @returns 用户 ID
37+
*/
38+
async getId() {
39+
return (await this.queryProfile()).user.id
40+
}
41+
3442
/**
3543
* 获取用户名
3644
* @returns 用户名
@@ -259,4 +267,24 @@ export class JikeUser<M extends boolean = boolean> {
259267
)
260268
if (!isSuccess(result)) throwRequestFailureError(result, '取消关注用户')
261269
}
270+
271+
/**
272+
* 不看 TA 的内容
273+
*/
274+
async mute() {
275+
const result = await this.#client.apiClient.userRelation.mute(
276+
await this.getId()
277+
)
278+
if (!isSuccess(result)) throwRequestFailureError(result, '不看 TA 的内容')
279+
}
280+
281+
/**
282+
* 重新看 TA 的内容
283+
*/
284+
async unmute() {
285+
const result = await this.#client.apiClient.userRelation.unmute(
286+
await this.getId()
287+
)
288+
if (!isSuccess(result)) throwRequestFailureError(result, '重新看 TA 的内容')
289+
}
262290
}

src/types/api-responses.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,14 @@ export namespace UserRelation {
6262
export interface UnfollowResponse {
6363
toast: LiteralUnion<'关注已取消'>
6464
}
65+
66+
export interface MuteResponse {
67+
toast: LiteralUnion<'操作成功!'>
68+
}
69+
70+
export interface UnmuteResponse {
71+
toast: LiteralUnion<'操作成功!'>
72+
}
6573
}
6674

6775
export namespace Users {

0 commit comments

Comments
 (0)