refactor(api): move 10 profile methods to ProfileApi (#6 commit 8/13)
Inlines `actions/profile.ts` into `apis/profile.ts::ProfileApi`. The
file covers personal profile (nickname / long-nick / personal note),
online status (regular + DIY with custom face/wording), avatars
(personal + group via highway), input-status, likes (received from
others), unidirectional friend list, and custom face roaming.
Method renaming (Api namespace already says "profile"):
getProfileLike → getLike (only obvious shortening; rest keep
their `set*`/`fetch*` prefixes because
they're already minimal at the call
site under `apis.profile.X`)
Callers updated: `instance-context.ts`, `actions/group-admin.ts`,
`actions/extended.ts`. The extended-actions test gained a sizable
`APIS_ROUTING` block covering profile/interaction/friend (all of the
late-stage Api hubs need auto-promotion now), so legacy tests that
stub `setDiyOnlineStatus`/`setOnlineStatus`/`deleteFriend`/etc as flat
methods keep working.
Tests rewritten to use `new ProfileApi(bridge as any).method(...)`.
587/587 tests pass.
This commit is contained in:
1 parent
2ec72d59f9
commit
62c5590fe1
10 files changed
+335
-381
No files matched your search
@@ -661,7 +661,7 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
|
||||
|
||||
try {
|
||||
await ctx.bridge.setProfile(nickname, personalNote);
|
||||
await ctx.bridge.apis.profile.setProfile(nickname, personalNote);
|
||||
return okResponse();
|
||||
} catch (e) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, String(e));
|
||||
@@ -681,7 +681,7 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
|
||||
|
||||
try {
|
||||
await ctx.bridge.setOnlineStatus(status, extStatus, batteryStatus);
|
||||
await ctx.bridge.apis.profile.setOnlineStatus(status, extStatus, batteryStatus);
|
||||
return okResponse();
|
||||
} catch (e) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, String(e));
|
||||
@@ -699,7 +699,7 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
const wording = asString(params.wording);
|
||||
if (!faceId) return failedResponse(RETCODE.BAD_REQUEST, 'face_id is required');
|
||||
try {
|
||||
await ctx.bridge.setDiyOnlineStatus(faceId, wording, faceType);
|
||||
await ctx.bridge.apis.profile.setDiyOnlineStatus(faceId, wording, faceType);
|
||||
return okResponse();
|
||||
} catch (err) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, err instanceof Error ? err.message : String(err));
|
||||
@@ -808,7 +808,7 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
h.registerAction('fetch_custom_face', async (params) => {
|
||||
const count = asNumber(params.count) || 10;
|
||||
try {
|
||||
const urls = await ctx.bridge.fetchCustomFace(count);
|
||||
const urls = await ctx.bridge.apis.profile.fetchCustomFace(count);
|
||||
return okResponse(urls);
|
||||
} catch (e) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, String(e));
|
||||
@@ -898,7 +898,7 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
h.registerAction('get_unidirectional_friend_list', async () => {
|
||||
|
||||
try {
|
||||
const data = await ctx.bridge.getUnidirectionalFriendList();
|
||||
const data = await ctx.bridge.apis.profile.getUnidirectionalFriendList();
|
||||
return okResponse(data);
|
||||
} catch (e) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, String(e));
|
||||
@@ -914,7 +914,7 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
|
||||
|
||||
try {
|
||||
await ctx.bridge.setSelfLongNick(longNick);
|
||||
await ctx.bridge.apis.profile.setSelfLongNick(longNick);
|
||||
return okResponse({});
|
||||
} catch (e) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, String(e));
|
||||
@@ -935,7 +935,7 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
|
||||
|
||||
try {
|
||||
await ctx.bridge.setAvatar(file);
|
||||
await ctx.bridge.apis.profile.setAvatar(file);
|
||||
return okResponse();
|
||||
} catch (e) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, String(e));
|
||||
@@ -957,7 +957,7 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
|
||||
|
||||
try {
|
||||
await ctx.bridge.setInputStatus(userId, eventType);
|
||||
await ctx.bridge.apis.profile.setInputStatus(userId, eventType);
|
||||
return okResponse({});
|
||||
} catch (e) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, String(e));
|
||||
|
||||
@@ -113,7 +113,7 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
if (!groupId) return failedResponse(RETCODE.BAD_REQUEST, 'group_id is required');
|
||||
if (!file) return failedResponse(RETCODE.BAD_REQUEST, 'file is required');
|
||||
try {
|
||||
await ctx.bridge.setGroupAvatar(groupId, file);
|
||||
await ctx.bridge.apis.profile.setGroupAvatar(groupId, file);
|
||||
return okResponse();
|
||||
} catch (err) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, err instanceof Error ? err.message : String(err));
|
||||
|
||||
@@ -146,7 +146,7 @@ export function buildApiContext(ref: OneBotInstanceContext): ApiActionContext {
|
||||
|
||||
// Profile-like / get_group_essence — OneBot-specific defaults that the
|
||||
// action handlers don't supply.
|
||||
getProfileLike: (userId = undefined, start = 0, limit = 10) => bridge.getProfileLike(userId, start, limit),
|
||||
getProfileLike: (userId = undefined, start = 0, limit = 10) => bridge.apis.profile.getLike(userId, start, limit),
|
||||
getGroupEssence: (groupId, pageStart = 0, pageLimit = 50) => bridge.getGroupEssence(groupId, pageStart, pageLimit),
|
||||
|
||||
// Message-store-backed history reads.
|
||||
@@ -165,7 +165,7 @@ export function buildApiContext(ref: OneBotInstanceContext): ApiActionContext {
|
||||
forceFetchClientKey: () => bridge.forceFetchClientKey(),
|
||||
setFriendRemark: (userId, remark) => bridge.apis.friend.setRemark(userId, remark),
|
||||
setGroupRemark: (groupId, remark) => bridge.apis.groupAdmin.setRemark(groupId, remark),
|
||||
setGroupAvatar: (groupId, source) => bridge.setGroupAvatar(groupId, source),
|
||||
setGroupAvatar: (groupId, source) => bridge.apis.profile.setGroupAvatar(groupId, source),
|
||||
getGroupFileCount: (groupId) => bridge.apis.groupFile.getCount(groupId),
|
||||
|
||||
// Cross-store: looks up the meta then routes through Bridge.
|
||||
@@ -180,8 +180,8 @@ export function buildApiContext(ref: OneBotInstanceContext): ApiActionContext {
|
||||
},
|
||||
markGroupMsgAsRead: (groupId, sequence) => bridge.apis.message.markGroupRead(groupId, sequence),
|
||||
markPrivateMsgAsRead: (userId, sequence) => bridge.apis.message.markPrivateRead(userId, sequence),
|
||||
setOnlineStatus: (status: number, extStatus?: number, batteryStatus?: number) => bridge.setOnlineStatus(status, extStatus, batteryStatus),
|
||||
setProfile: (nickname?: string, personalNote?: string) => bridge.setProfile(nickname, personalNote),
|
||||
setOnlineStatus: (status: number, extStatus?: number, batteryStatus?: number) => bridge.apis.profile.setOnlineStatus(status, extStatus, batteryStatus),
|
||||
setProfile: (nickname?: string, personalNote?: string) => bridge.apis.profile.setProfile(nickname, personalNote),
|
||||
|
||||
// Web-backed actions.
|
||||
getGroupHonorInfo: (groupId: number, type: WebHonorType | string) => bridge.getGroupHonorInfo(groupId, type),
|
||||
@@ -200,7 +200,7 @@ export function buildApiContext(ref: OneBotInstanceContext): ApiActionContext {
|
||||
getCredentials: (domain) => bridge.getCredentials(domain),
|
||||
|
||||
// Extended
|
||||
fetchCustomFace: (count) => bridge.fetchCustomFace(count),
|
||||
fetchCustomFace: (count) => bridge.apis.profile.fetchCustomFace(count),
|
||||
getEmojiLikes: (groupId, sequence, emojiId, emojiType, count, cookie) => bridge.apis.interaction.getEmojiLikes(groupId, sequence, emojiId, emojiType, count, cookie),
|
||||
|
||||
// Media lookup.
|
||||
|
||||
Reference in new issue
Block a user