Move sticker creator API to chat service

This commit is contained in:
Fedor Indutny
2024-05-15 15:26:37 -07:00
committed by GitHub
parent a1e090d1f1
commit 31cbb89b0d
21 changed files with 124 additions and 587 deletions

View File

@@ -16,7 +16,6 @@ import * as Errors from '../types/errors';
import * as Stickers from '../types/Stickers';
import type { ConversationType } from '../state/ducks/conversations';
import type { AuthorizeArtCreatorDataType } from '../state/ducks/globalModals';
import { calling } from '../services/calling';
import { resolveUsernameByLinkBase64 } from '../services/username';
import { writeProfile } from '../services/writeProfile';
@@ -96,7 +95,6 @@ export type IPCEventsValuesType = {
};
export type IPCEventsCallbacksType = {
openArtCreator(): Promise<void>;
getAvailableIODevices(): Promise<{
availableCameras: Array<
Pick<MediaDeviceInfo, 'deviceId' | 'groupId' | 'kind' | 'label'>
@@ -106,7 +104,6 @@ export type IPCEventsCallbacksType = {
}>;
addCustomColor: (customColor: CustomColorType) => void;
addDarkOverlay: () => void;
authorizeArtCreator: (data: AuthorizeArtCreatorDataType) => void;
deleteAllData: () => Promise<void>;
deleteAllMyStories: () => Promise<void>;
editCustomColor: (colorId: string, customColor: CustomColorType) => void;
@@ -141,6 +138,10 @@ export type IPCEventsCallbacksType = {
customColor?: { id: string; value: CustomColorType }
) => void;
getDefaultConversationColor: () => DefaultConversationColorType;
uploadStickerPack: (
manifest: Uint8Array,
stickers: ReadonlyArray<Uint8Array>
) => Promise<string>;
};
type ValuesWithGetters = Omit<
@@ -239,15 +240,6 @@ export function createIPCEvents(
};
return {
openArtCreator: async () => {
const auth = await window.textsecure.server?.getArtAuth();
if (!auth) {
return;
}
window.openArtCreator(auth);
},
getDeviceName: () => window.textsecure.storage.user.getDeviceName(),
getPhoneNumber: () => {
try {
@@ -530,14 +522,6 @@ export function createIPCEvents(
});
document.body.prepend(newOverlay);
},
authorizeArtCreator: (data: AuthorizeArtCreatorDataType) => {
// We can get these events even if the user has never linked this instance.
if (!Registration.everDone()) {
log.warn('authorizeArtCreator: Not registered, returning early');
return;
}
window.reduxActions.globalModals.showAuthorizeArtCreator(data);
},
removeDarkOverlay: () => {
const elems = document.querySelectorAll('.dark-overlay');
@@ -717,6 +701,16 @@ export function createIPCEvents(
}
},
uploadStickerPack: (
manifest: Uint8Array,
stickers: ReadonlyArray<Uint8Array>
): Promise<string> => {
strictAssert(window.textsecure.server, 'WebAPI must be available');
return window.textsecure.server.putStickers(manifest, stickers, () =>
ipcRenderer.send('art-creator:onUploadProgress')
);
},
...overrideEvents,
};
}

View File

@@ -439,38 +439,6 @@ export const artAddStickersRoute = _route('artAddStickers', {
},
});
/**
* Art Service Authentication
* @example
* ```ts
* artAuthRoute.toAppUrl({
* token: "123",
* pubKey: "abc",
* })
* // URL { "sgnl://art-auth?token=123&pub_key=abc" }
*/
export const artAuthRoute = _route('artAuth', {
patterns: [_pattern('sgnl:', 'art-auth', '{/}?', { search: ':params' })],
schema: z.object({
token: paramSchema, // opaque
pubKey: paramSchema, // base64url
}),
parse(result) {
const params = new URLSearchParams(result.search.groups.params);
return {
token: params.get('token'),
pubKey: params.get('pub_key'),
};
},
toAppUrl(args) {
const params = new URLSearchParams({
token: args.token,
pub_key: args.pubKey,
});
return new URL(`sgnl://art-auth?${params.toString()}`);
},
});
/**
* Show a conversation
* @example
@@ -594,7 +562,6 @@ const _allSignalRoutes = [
captchaRoute,
linkCallRoute,
artAddStickersRoute,
artAuthRoute,
showConversationRoute,
startCallLobbyRoute,
showWindowRoute,