Merge branch 'develop' into notification-read-api

This commit is contained in:
tamaina
2021-11-12 19:22:46 +09:00
64 changed files with 158 additions and 437 deletions

View File

@@ -215,11 +215,27 @@ export function initDb(justBorrow = false, sync = false, forceRecreate = false)
}
export async function resetDb() {
const conn = await getConnection();
const tables = await conn.query(`SELECT relname AS "table"
FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)
WHERE nspname NOT IN ('pg_catalog', 'information_schema')
AND C.relkind = 'r'
AND nspname !~ '^pg_toast';`);
await Promise.all(tables.map(t => t.table).map(x => conn.query(`DELETE FROM "${x}" CASCADE`)));
const reset = async () => {
const conn = await getConnection();
const tables = await conn.query(`SELECT relname AS "table"
FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)
WHERE nspname NOT IN ('pg_catalog', 'information_schema')
AND C.relkind = 'r'
AND nspname !~ '^pg_toast';`);
await Promise.all(tables.map(t => t.table).map(x => conn.query(`DELETE FROM "${x}" CASCADE`)));
};
for (let i = 1; i <= 3; i++) {
try {
await reset();
} catch (e) {
if (i === 3) {
throw e;
} else {
await new Promise(resolve => setTimeout(resolve, 1000));
continue;
}
}
break;
}
}

View File

@@ -81,11 +81,6 @@ export class Note {
@JoinColumn()
public user: User | null;
@Column('boolean', {
default: false
})
public viaMobile: boolean;
@Column('boolean', {
default: false
})

View File

@@ -230,7 +230,6 @@ export class NoteRepository extends Repository<Note> {
visibility: note.visibility,
localOnly: note.localOnly || undefined,
visibleUserIds: note.visibility === 'specified' ? note.visibleUserIds : undefined,
viaMobile: note.viaMobile || undefined,
renoteCount: note.renoteCount,
repliesCount: note.repliesCount,
reactions: convertLegacyReactions(note.reactions),
@@ -377,10 +376,6 @@ export const packedNoteSchema = {
optional: true as const, nullable: true as const,
ref: 'Note' as const,
},
viaMobile: {
type: 'boolean' as const,
optional: true as const, nullable: false as const,
},
isHidden: {
type: 'boolean' as const,
optional: true as const, nullable: false as const,

View File

@@ -46,18 +46,18 @@ export async function exportNotes(job: Bull.Job<DbUserJobData>, done: any): Prom
});
let exportedNotesCount = 0;
let cursor: any = null;
let cursor: Note['id'] | null = null;
while (true) {
const notes = await Notes.find({
where: {
userId: user.id,
...(cursor ? { id: MoreThan(cursor) } : {})
...(cursor ? { id: MoreThan(cursor) } : {}),
},
take: 100,
order: {
id: 1
}
id: 1,
},
});
if (notes.length === 0) {
@@ -115,7 +115,7 @@ export async function exportNotes(job: Bull.Job<DbUserJobData>, done: any): Prom
done();
}
function serialize(note: Note, poll: Poll | null = null): any {
function serialize(note: Note, poll: Poll | null = null): Record<string, unknown> {
return {
id: note.id,
text: note.text,
@@ -125,9 +125,8 @@ function serialize(note: Note, poll: Poll | null = null): any {
renoteId: note.renoteId,
poll: poll,
cw: note.cw,
viaMobile: note.viaMobile,
visibility: note.visibility,
visibleUserIds: note.visibleUserIds,
localOnly: note.localOnly
localOnly: note.localOnly,
};
}

View File

@@ -250,7 +250,6 @@ export async function createNote(value: string | IObject, resolver?: Resolver, s
name: note.name,
cw,
text,
viaMobile: false,
localOnly: false,
visibility,
visibleUsers,

View File

@@ -57,11 +57,6 @@ export const meta = {
validator: $.optional.nullable.str.pipe(Notes.validateCw),
},
viaMobile: {
validator: $.optional.bool,
default: false,
},
localOnly: {
validator: $.optional.bool,
default: false,
@@ -283,7 +278,6 @@ export default define(meta, async (ps, user) => {
reply,
renote,
cw: ps.cw,
viaMobile: ps.viaMobile,
localOnly: ps.localOnly,
visibility: ps.visibility,
visibleUsers,

View File

@@ -23,6 +23,7 @@ const _filename = __filename;
const _dirname = dirname(_filename);
const staticAssets = `${_dirname}/../../../assets/`;
const clientAssets = `${_dirname}/../../../../client/assets/`;
const assets = `${_dirname}/../../../../../built/_client_dist_/`;
// Init app
@@ -59,6 +60,13 @@ router.get('/static-assets/(.*)', async ctx => {
});
});
router.get('/client-assets/(.*)', async ctx => {
await send(ctx as any, ctx.path.replace('/client-assets/', ''), {
root: clientAssets,
maxage: ms('7 days'),
});
});
router.get('/assets/(.*)', async ctx => {
await send(ctx as any, ctx.path.replace('/assets/', ''), {
root: assets,

View File

@@ -98,7 +98,6 @@ type Option = {
renote?: Note | null;
files?: DriveFile[] | null;
poll?: IPoll | null;
viaMobile?: boolean | null;
localOnly?: boolean | null;
cw?: string | null;
visibility?: string;
@@ -131,7 +130,6 @@ export default async (user: { id: User['id']; username: User['username']; host:
if (data.createdAt == null) data.createdAt = new Date();
if (data.visibility == null) data.visibility = 'public';
if (data.viaMobile == null) data.viaMobile = false;
if (data.localOnly == null) data.localOnly = false;
if (data.channel != null) data.visibility = 'public';
if (data.channel != null) data.visibleUsers = [];
@@ -478,7 +476,6 @@ async function insertNote(user: { id: User['id']; host: User['host']; }, data: O
tags: tags.map(tag => normalizeForSearch(tag)),
emojis,
userId: user.id,
viaMobile: data.viaMobile!,
localOnly: data.localOnly!,
visibility: data.visibility as any,
visibleUserIds: data.visibility == 'specified'