feat(protocol): read and change group category tags
A group profile category can be listed, and a tag name can be added or removed. An empty name is rejected instead of being dropped. Refs #506
This commit is contained in:
4 files changed
+161
No files matched your search
@@ -0,0 +1,23 @@
|
|||||||
|
import type { pb, pb_optional, pb_repeated, uint_32 } from '@snowluma/proton';
|
||||||
|
|
||||||
|
/** One tag shown under a group-profile category. */
|
||||||
|
export interface OidbGroupCategoryTag {
|
||||||
|
id?: pb<1, uint_32>;
|
||||||
|
name?: pb<2, string>;
|
||||||
|
type?: pb<3, uint_32>;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** List the tags of one category. Category 0 is a real value and must be sent. */
|
||||||
|
export interface OidbGetGroupCategoryTags {
|
||||||
|
groupClass?: pb_optional<1, uint_32>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface OidbGetGroupCategoryTagsResp {
|
||||||
|
tags?: pb_repeated<1, OidbGroupCategoryTag>;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Add or remove one tag name in a category. */
|
||||||
|
export interface OidbChangeGroupCategoryTag {
|
||||||
|
groupClass?: pb_optional<1, uint_32>;
|
||||||
|
name?: pb<2, string>;
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||||
|
import type { OidbBase, OidbEmpty } from '@snowluma/proto-defs/oidb';
|
||||||
|
import type { OidbChangeGroupCategoryTag } from '@snowluma/proto-defs/oidb-actions/group-category-tag';
|
||||||
|
import { invokeOidb, type OidbSender } from '../../oidb-service';
|
||||||
|
|
||||||
|
export namespace AddGroupCategoryTag {
|
||||||
|
export const command = 0x967D;
|
||||||
|
export const subCommand = 0;
|
||||||
|
|
||||||
|
export interface Params {
|
||||||
|
groupClass: number;
|
||||||
|
name: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type Deps = OidbSender;
|
||||||
|
|
||||||
|
export const serialize = (_ctx: Deps, p: Params): OidbChangeGroupCategoryTag => {
|
||||||
|
assertTagChange(p.groupClass, p.name);
|
||||||
|
return { groupClass: p.groupClass, name: p.name };
|
||||||
|
};
|
||||||
|
|
||||||
|
export const deserialize = (_ctx: Deps, _: OidbEmpty): void => {};
|
||||||
|
|
||||||
|
export const encode = (env: OidbBase<OidbChangeGroupCategoryTag>): Uint8Array =>
|
||||||
|
protobuf_encode<OidbBase<OidbChangeGroupCategoryTag>>(env);
|
||||||
|
|
||||||
|
export const decode = (bytes: Uint8Array): OidbBase<OidbEmpty> =>
|
||||||
|
protobuf_decode<OidbBase<OidbEmpty>>(bytes);
|
||||||
|
|
||||||
|
export const invoke = (deps: Deps, params: Params): Promise<void> =>
|
||||||
|
invokeOidb(deps, AddGroupCategoryTag, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
function assertTagChange(groupClass: number, name: string): void {
|
||||||
|
if (!Number.isInteger(groupClass) || groupClass < 0 || groupClass > 0xFFFFFFFF) {
|
||||||
|
throw new Error(`group class ${groupClass} is out of range`);
|
||||||
|
}
|
||||||
|
if (name.length === 0) throw new Error('tag name must not be empty');
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||||
|
import type { OidbBase, OidbEmpty } from '@snowluma/proto-defs/oidb';
|
||||||
|
import type { OidbChangeGroupCategoryTag } from '@snowluma/proto-defs/oidb-actions/group-category-tag';
|
||||||
|
import { invokeOidb, type OidbSender } from '../../oidb-service';
|
||||||
|
|
||||||
|
export namespace DeleteGroupCategoryTag {
|
||||||
|
export const command = 0x967E;
|
||||||
|
export const subCommand = 0;
|
||||||
|
|
||||||
|
export interface Params {
|
||||||
|
groupClass: number;
|
||||||
|
name: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type Deps = OidbSender;
|
||||||
|
|
||||||
|
export const serialize = (_ctx: Deps, p: Params): OidbChangeGroupCategoryTag => {
|
||||||
|
assertTagChange(p.groupClass, p.name);
|
||||||
|
return { groupClass: p.groupClass, name: p.name };
|
||||||
|
};
|
||||||
|
|
||||||
|
export const deserialize = (_ctx: Deps, _: OidbEmpty): void => {};
|
||||||
|
|
||||||
|
export const encode = (env: OidbBase<OidbChangeGroupCategoryTag>): Uint8Array =>
|
||||||
|
protobuf_encode<OidbBase<OidbChangeGroupCategoryTag>>(env);
|
||||||
|
|
||||||
|
export const decode = (bytes: Uint8Array): OidbBase<OidbEmpty> =>
|
||||||
|
protobuf_decode<OidbBase<OidbEmpty>>(bytes);
|
||||||
|
|
||||||
|
export const invoke = (deps: Deps, params: Params): Promise<void> =>
|
||||||
|
invokeOidb(deps, DeleteGroupCategoryTag, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
function assertTagChange(groupClass: number, name: string): void {
|
||||||
|
if (!Number.isInteger(groupClass) || groupClass < 0 || groupClass > 0xFFFFFFFF) {
|
||||||
|
throw new Error(`group class ${groupClass} is out of range`);
|
||||||
|
}
|
||||||
|
if (name.length === 0) throw new Error('tag name must not be empty');
|
||||||
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||||
|
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
||||||
|
import type {
|
||||||
|
OidbGetGroupCategoryTags,
|
||||||
|
OidbGetGroupCategoryTagsResp,
|
||||||
|
OidbGroupCategoryTag,
|
||||||
|
} from '@snowluma/proto-defs/oidb-actions/group-category-tag';
|
||||||
|
import { invokeOidb, type OidbSender } from '../../oidb-service';
|
||||||
|
|
||||||
|
export interface GroupCategoryTag {
|
||||||
|
id: number;
|
||||||
|
name: string;
|
||||||
|
type: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export namespace GetGroupCategoryTags {
|
||||||
|
export const command = 0x967C;
|
||||||
|
export const subCommand = 0;
|
||||||
|
|
||||||
|
export interface Params {
|
||||||
|
groupClass: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type Deps = OidbSender;
|
||||||
|
|
||||||
|
export const serialize = (_ctx: Deps, p: Params): OidbGetGroupCategoryTags => {
|
||||||
|
assertGroupClass(p.groupClass);
|
||||||
|
return { groupClass: p.groupClass };
|
||||||
|
};
|
||||||
|
|
||||||
|
export const deserialize = (
|
||||||
|
_ctx: Deps,
|
||||||
|
body: OidbGetGroupCategoryTagsResp,
|
||||||
|
): { tags: GroupCategoryTag[] } => ({
|
||||||
|
tags: (body.tags ?? []).map(toTag),
|
||||||
|
});
|
||||||
|
|
||||||
|
export const encode = (env: OidbBase<OidbGetGroupCategoryTags>): Uint8Array =>
|
||||||
|
protobuf_encode<OidbBase<OidbGetGroupCategoryTags>>(env);
|
||||||
|
|
||||||
|
export const decode = (bytes: Uint8Array): OidbBase<OidbGetGroupCategoryTagsResp> =>
|
||||||
|
protobuf_decode<OidbBase<OidbGetGroupCategoryTagsResp>>(bytes);
|
||||||
|
|
||||||
|
export const invoke = (deps: Deps, params: Params): Promise<{ tags: GroupCategoryTag[] }> =>
|
||||||
|
invokeOidb(deps, GetGroupCategoryTags, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
function assertGroupClass(groupClass: number): void {
|
||||||
|
if (!Number.isInteger(groupClass) || groupClass < 0 || groupClass > 0xFFFFFFFF) {
|
||||||
|
throw new Error(`group class ${groupClass} is out of range`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function toTag(tag: OidbGroupCategoryTag): GroupCategoryTag {
|
||||||
|
return {
|
||||||
|
id: tag.id ?? 0,
|
||||||
|
name: tag.name ?? '',
|
||||||
|
type: tag.type ?? 0,
|
||||||
|
};
|
||||||
|
}
|
||||||
Reference in new issue
Block a user