Skip to content

Commit

Permalink
型の変更
Browse files Browse the repository at this point in the history
  • Loading branch information
kozakura913 committed Jan 28, 2025
1 parent bd98338 commit 7701eac
Show file tree
Hide file tree
Showing 14 changed files with 96 additions and 35 deletions.
2 changes: 1 addition & 1 deletion packages/backend/src/core/AvatarDecorationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export class AvatarDecorationService implements OnApplicationShutdown {
return;
}

const instanceHost = instance.host;
const instanceHost = instance!.host;
const decorationApiUrl = `https://${instanceHost}/api/get-avatar-decorations`;
const allRes = await this.httpRequestService.send(decorationApiUrl, {
method: 'POST',
Expand Down
4 changes: 1 addition & 3 deletions packages/backend/src/core/TruncateAccountService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ export class TruncateAccountService {
}): Promise<void> {
const _user = await this.usersRepository.findOneByOrFail({ id: user.id });

this.queueService.createTruncateAccountJob(user, {
soft: false,
});
this.queueService.createTruncateAccountJob(user);
}
}

6 changes: 6 additions & 0 deletions packages/backend/src/core/WebhookTestService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@ function generateDummyNote(override?: Partial<MiNote>): MiNote {
replyUserHost: null,
renoteUserId: null,
renoteUserHost: null,
updatedAt: null,
updatedAtHistory: null,
noteEditHistory: [],
hasEvent: false,
disableRightClick: false,
deleteAt: null,
...override,
};
}
Expand Down
25 changes: 23 additions & 2 deletions packages/backend/src/models/json-schema/notification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -449,10 +449,31 @@ export const packedNotificationSchema = {
optional: false, nullable: false,
enum: ['groupInvited'],
},
user: {
type: 'object',
ref: 'UserLite',
optional: false, nullable: false,
},
invitation: {
type: 'string',
type: 'object',
properties: {
id: {
type: 'string',
optional: false, nullable: false,
format: 'id',
},
group: {
type: 'object',
properties: {
name: {
type: 'string',
optional: false, nullable: false,
},
},
optional: false, nullable: false,
},
},
optional: false, nullable: false,
format: 'id',
},
},
}],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,15 +367,10 @@ export class CheckModeratorsActivityProcessorService {

// -- SystemWebhook

const systemWebhooks = await this.systemWebhookService.fetchActiveSystemWebhooks()
.then(it => it.filter(it => it.on.includes('inactiveModeratorsDisablePublicNoteChanged')));
for (const systemWebhook of systemWebhooks) {
this.systemWebhookService.enqueueSystemWebhook(
systemWebhook,
'inactiveModeratorsDisablePublicNoteChanged',
{},
);
}
this.systemWebhookService.enqueueSystemWebhook(
'inactiveModeratorsDisablePublicNoteChanged',
{},
);
}

@bindThis
Expand Down
20 changes: 14 additions & 6 deletions packages/backend/src/server/api/endpoints/notes/polls/translate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,14 @@ export const meta = {
optional: true, nullable: false,
properties: {
sourceLang: { type: 'string' },
text: { type: 'string' },
text: {
type: 'array',
optional: true, nullable: false,
items: {
type: 'string',
optional: false, nullable: true,
},
},
},
},

Expand Down Expand Up @@ -130,7 +137,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-

return Promise.resolve({
sourceLang: translationResult.sourceLang || '',
text: translationResult.text || '',
text: translationResult.text || [],
translator: translationResult.translator || [],
});
});
Expand Down Expand Up @@ -175,15 +182,16 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
};
}

private async apiCloudTranslationAdvanced(text: string, targetLang: string, saKey: string, projectId: string, location: string, model: string | null, glossary: string | null, provider: string) {
private async apiCloudTranslationAdvanced(text: string[], targetLang: string, saKey: string, projectId: string, location: string, model: string | null, glossary: string | null, provider: string) {
const [path, cleanup] = await createTemp();
fs.writeFileSync(path, saKey);

const translationClient = new TranslationServiceClient({ keyFilename: path });

const detectText = text.join('\n');
const detectRequest = {
parent: `projects/${projectId}/locations/${location}`,
content: text,
content: detectText,
};

let detectedLanguage = null;
Expand All @@ -203,15 +211,15 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-

const translateRequest = {
parent: `projects/${projectId}/locations/${location}`,
contents: [text],
contents: text,
mimeType: 'text/plain',
sourceLanguageCode: null,
targetLanguageCode: detectedLanguage !== null ? detectedLanguage : targetLang,
model: modelConfig,
glossaryConfig: glossaryConfig,
};
const [translateResponse] = await translationClient.translateText(translateRequest);
const translatedText = translateResponse.translations && translateResponse.translations[0]?.translatedText;
const translatedText = translateResponse.translations && translateResponse.translations.map(t => t.translatedText ?? '');
const detectedLanguageCode = translateResponse.translations && translateResponse.translations[0]?.detectedLanguageCode;

cleanup();
Expand Down
4 changes: 3 additions & 1 deletion packages/backend/src/server/api/stream/Connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,9 @@ export default class Connection {
}

@bindThis
private typingOnMessaging(param: { partner?: MiUser['id']; group?: MiUserGroup['id']; }) {
private typingOnMessaging(data: JsonValue | undefined) {
if (!data) return;
const param = data as { partner?: MiUser['id']; group?: MiUserGroup['id']; };
if (this.user) {
if (param.partner) {
// this.globalEventService.publishMessagingStream(param.partner, this.user.id, 'typing', this.user.id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class BubbleTimelineChannel extends Channel {

if (isRenotePacked(note) && !isQuotePacked(note) && !this.withRenotes) return;

if (note.user.isSilenced && !this.following[note.userId] && note.userId !== this.user!.id) return;
if (!this.following[note.userId] && note.userId !== this.user!.id) return;

if (this.isNoteMutedOrBlocked(note)) return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ class ReversiGameChannel extends Channel {
this.putStone(body.pos, body.id);
break;
case 'claimTimeIsUp': this.claimTimeIsUp(); break;
case 'reaction': this.sendReaction(body); break;
case 'reaction':
if (typeof body !== 'string') return;
this.sendReaction(body); break;
}
}

Expand Down
6 changes: 6 additions & 0 deletions packages/backend/test/unit/NoteCreateService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ describe('NoteCreateService', () => {
replyUserHost: null,
renoteUserId: null,
renoteUserHost: null,
updatedAt: null,
updatedAtHistory: null,
noteEditHistory: [],
hasEvent: false,
disableRightClick: false,
deleteAt: null,
};

const poll: IPoll = {
Expand Down
6 changes: 6 additions & 0 deletions packages/backend/test/unit/misc/is-renote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ const base: MiNote = {
replyUserHost: null,
renoteUserId: null,
renoteUserHost: null,
updatedAt: null,
updatedAtHistory: null,
noteEditHistory: [],
hasEvent: false,
disableRightClick: false,
deleteAt: null,
};

describe('misc:is-renote', () => {
Expand Down
10 changes: 9 additions & 1 deletion packages/cherrypick-js/etc/cherrypick-js.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -2485,7 +2485,15 @@ type ISigninHistoryRequest = operations['i___signin-history']['requestBody']['co
type ISigninHistoryResponse = operations['i___signin-history']['responses']['200']['content']['application/json'];

// @public (undocumented)
function isPureRenote(note: Note): note is PureRenote;
function isPureRenote(note: {
renote?: object | null;
reply?: object | null;
text: string | null;
cw?: string | null;
fileIds?: string[];
poll?: object | null;
event?: Record<string, never> | null;
}): note is PureRenote;

// @public (undocumented)
export interface IStream extends EventEmitter<StreamEvents> {
Expand Down
17 changes: 9 additions & 8 deletions packages/cherrypick-js/src/autogen/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4805,8 +4805,14 @@ export type components = {
createdAt: string;
/** @enum {string} */
type: 'groupInvited';
/** Format: id */
invitation: string;
user: components['schemas']['UserLite'];
invitation: {
/** Format: id */
id: string;
group: {
name: string;
};
};
};
DriveFile: {
/**
Expand Down Expand Up @@ -24684,7 +24690,7 @@ export type operations = {
content: {
'application/json': {
sourceLang: string;
text: string;
text?: (string | null)[];
};
};
};
Expand Down Expand Up @@ -25331,11 +25337,6 @@ export type operations = {
untilId?: string;
/** @default 10 */
limit?: number;
/**
* @default combined
* @enum {string}
*/
origin?: 'local' | 'remote' | 'combined';
/** @default 0 */
offset?: number;
/** @description The local host is represented with `.`. */
Expand Down
12 changes: 10 additions & 2 deletions packages/cherrypick-js/src/note.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import type { Note, PureRenote } from './entities.js';
import type { PureRenote } from './entities.js';

export function isPureRenote(note: Note): note is PureRenote {
export function isPureRenote(note: {
renote?:object|null,
reply?:object|null,
text:string|null,
cw?:string|null,
fileIds?: string[],
poll?:object|null,
event?: Record<string, never> | null,
}): note is PureRenote {
return (
note.renote != null &&
note.reply == null &&
Expand Down

0 comments on commit 7701eac

Please sign in to comment.