add lang field

This commit is contained in:
Namekuji 2023-09-22 12:34:50 -04:00
parent f0d3f71656
commit c050ee03fc
No known key found for this signature in database
GPG key ID: 1D62332C07FBA532
10 changed files with 61 additions and 43 deletions

View file

@ -0,0 +1,2 @@
ALTER TABLE note DROP "lang";
ALTER TABLE home_timeline DROP "lang";

View file

@ -0,0 +1,2 @@
ALTER TABLE note ADD "lang" ascii;
ALTER TABLE home_timeline ADD "lang" ascii;

View file

@ -16,6 +16,7 @@ pub struct Model {
pub renote_id: Option<String>,
#[sea_orm(column_type = "Text", nullable)]
pub text: Option<String>,
pub lang: Option<String>,
pub name: Option<String>,
pub cw: Option<String>,
#[sea_orm(column_name = "userId")]

View file

@ -369,6 +369,7 @@ impl Initializer {
id: note.id.clone(),
visibility: note.visibility.to_value(),
content: note.text,
lang: note.lang,
name: note.name,
cw: note.cw,
local_only: note.local_only,
@ -419,6 +420,7 @@ impl Initializer {
id: s_note.id,
visibility: s_note.visibility,
content: s_note.content,
lang: s_note.lang,
name: s_note.name,
cw: s_note.cw,
local_only: s_note.local_only,
@ -658,6 +660,7 @@ struct NoteTable {
id: String,
visibility: String,
content: Option<String>,
lang: Option<String>,
name: Option<String>,
cw: Option<String>,
local_only: bool,
@ -702,6 +705,7 @@ INSERT INTO note (
"id",
"visibility",
"content",
"lang",
"name",
"cw",
"localOnly",
@ -737,7 +741,7 @@ INSERT INTO note (
"reactions",
"noteEdit",
"updatedAt"
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
"#;
#[derive(Clone, ValueList)]
@ -748,6 +752,7 @@ struct HomeTimelineTable {
id: String,
visibility: String,
content: Option<String>,
lang: Option<String>,
name: Option<String>,
cw: Option<String>,
local_only: bool,
@ -793,6 +798,7 @@ INSERT INTO home_timeline (
"id",
"visibility",
"content",
"lang",
"name",
"cw",
"localOnly",
@ -828,7 +834,7 @@ INSERT INTO home_timeline (
"reactions",
"noteEdit",
"updatedAt"
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
"#;
#[derive(ValueList)]

View file

@ -6,6 +6,7 @@ export const scyllaQueries = {
"id",
"visibility",
"content",
"lang",
"name",
"cw",
"localOnly",
@ -41,7 +42,7 @@ export const scyllaQueries = {
"reactions",
"noteEdit",
"updatedAt"
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
select: {
byDate: `SELECT * FROM note WHERE "createdAtDate" = ?`,
byUri: `SELECT * FROM note WHERE "uri" = ?`,
@ -80,6 +81,7 @@ export const scyllaQueries = {
"id",
"visibility",
"content",
"lang",
"name",
"cw",
"localOnly",
@ -115,7 +117,7 @@ export const scyllaQueries = {
"reactions",
"noteEdit",
"updatedAt"
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
select: {
byUserAndDate: `SELECT * FROM home_timeline WHERE "feedUserId" = ? AND "createdAtDate" = ?`,
byId: `SELECT * FROM home_timeline WHERE "id" = ?`,

View file

@ -6,18 +6,9 @@ import { Client, types, tracker } from "cassandra-driver";
import type { User } from "@/models/entities/user.js";
import {
Cache,
ChannelFollowingsCache,
InstanceMutingsCache,
LocalFollowingsCache,
RenoteMutingsCache,
UserBlockedCache,
UserBlockingCache,
UserMutingsCache,
userWordMuteCache,
} from "@/misc/cache.js";
import { getTimestamp } from "@/misc/gen-id.js";
import Logger from "@/services/logger.js";
import { UserProfiles } from "@/models/index.js";
import { getWordHardMute } from "@/misc/check-word-mute.js";
import type { UserProfile } from "@/models/entities/user-profile.js";
import { scyllaQueries } from "@/db/cql.js";
@ -134,14 +125,14 @@ export function parseScyllaNotification(row: types.Row): ScyllaNotification {
createdAt: row.get("createdAt"),
id: row.get("id"),
type: row.get("type"),
notifierId: row.get("notifierId") ?? null,
notifierHost: row.get("notifierHost") ?? null,
entityId: row.get("entityId") ?? null,
notifierId: row.get("notifierId") || null,
notifierHost: row.get("notifierHost") || null,
entityId: row.get("entityId") || null,
reaction: row.get("reaction") ?? null,
choice: row.get("choice") ?? null,
customBody: row.get("customBody") ?? null,
customHeader: row.get("customHeader") ?? null,
customIcon: row.get("customIcon") ?? null,
customBody: row.get("customBody") || null,
customHeader: row.get("customHeader") || null,
customIcon: row.get("customIcon") || null,
};
}
@ -208,7 +199,7 @@ export function parseScyllaPollVote(row: types.Row): ScyllaPollVote {
return {
noteId: row.get("noteId"),
userId: row.get("userId"),
userHost: row.get("userHost") ?? null,
userHost: row.get("userHost") || null,
choice: new Set(row.get("choice") ?? []),
createdAt: row.get("createdAt"),
};
@ -236,14 +227,15 @@ export function parseScyllaNote(row: types.Row): ScyllaNote {
createdAt: row.get("createdAt"),
id: row.get("id"),
visibility: row.get("visibility"),
text: row.get("content") ?? null,
name: row.get("name") ?? null,
cw: row.get("cw") ?? null,
text: row.get("content") || null,
lang: row.get("lang") || null,
name: row.get("name") || null,
cw: row.get("cw") || null,
localOnly: row.get("localOnly"),
renoteCount: row.get("renoteCount"),
repliesCount: row.get("repliesCount"),
uri: row.get("uri") ?? null,
url: row.get("url") ?? null,
uri: row.get("uri") || null,
url: row.get("url") || null,
score: row.get("score"),
files,
fileIds: files.map((file) => file.id),
@ -254,26 +246,26 @@ export function parseScyllaNote(row: types.Row): ScyllaNote {
tags: row.get("tags") ?? [],
hasPoll: row.get("hasPoll") ?? false,
poll: row.get("poll") ?? null,
threadId: row.get("threadId") ?? null,
channelId: row.get("channelId") ?? null,
threadId: row.get("threadId") || null,
channelId: row.get("channelId") || null,
userId: row.get("userId"),
userHost: userHost !== "local" ? userHost : null,
replyId: row.get("replyId") ?? null,
replyUserId: row.get("replyUserId") ?? null,
replyUserHost: row.get("replyUserHost") ?? null,
replyText: row.get("replyContent") ?? null,
replyCw: row.get("replyCw") ?? null,
replyId: row.get("replyId") || null,
replyUserId: row.get("replyUserId") || null,
replyUserHost: row.get("replyUserHost") || null,
replyText: row.get("replyContent") || null,
replyCw: row.get("replyCw") || null,
replyFiles: row.get("replyFiles") ?? [],
renoteId: row.get("renoteId") ?? null,
renoteUserId: row.get("renoteUserId") ?? null,
renoteUserHost: row.get("renoteUserHost") ?? null,
renoteText: row.get("renoteContent") ?? null,
renoteCw: row.get("renoteCw") ?? null,
renoteId: row.get("renoteId") || null,
renoteUserId: row.get("renoteUserId") || null,
renoteUserHost: row.get("renoteUserHost") || null,
renoteText: row.get("renoteContent") || null,
renoteCw: row.get("renoteCw") || null,
renoteFiles: row.get("renoteFiles") ?? [],
reactions: row.get("reactions") ?? {},
noteEdit: row.get("noteEdit") ?? [],
updatedAt: row.get("updatedAt") ?? null,
mentionedRemoteUsers: row.get("mentionedRemoteUsers") ?? "[]",
mentionedRemoteUsers: row.get("mentionedRemoteUsers") || "[]",
/* unused postgres denormalization */
channel: null,
renote: null,

View file

@ -7,7 +7,6 @@ import { extractMentionedUsers } from "@/services/note/create.js";
import { resolvePerson } from "./person.js";
import { resolveImage } from "./image.js";
import type {
ILocalUser,
CacheableRemoteUser,
} from "@/models/entities/user.js";
import { htmlToMfm } from "../misc/html-to-mfm.js";
@ -52,7 +51,6 @@ import { In } from "typeorm";
import { DB_MAX_IMAGE_COMMENT_LENGTH } from "@/misc/hard-limits.js";
import { truncate } from "@/misc/truncate.js";
import { type Size, getEmojiSize } from "@/misc/emoji-meta.js";
import { fetchMeta } from "@/misc/fetch-meta.js";
import {
type ScyllaNote,
type ScyllaPoll,
@ -878,6 +876,7 @@ export async function updateNote(value: string | IObject, resolver?: Resolver) {
newScyllaNote.id,
scyllaNote.visibility,
newScyllaNote.text,
newScyllaNote.lang,
newScyllaNote.name,
newScyllaNote.cw,
newScyllaNote.localOnly,

View file

@ -143,7 +143,8 @@ export default define(meta, paramDef, async (ps, user) => {
.filter((xs) => xs.length > 0);
const filter = (notes: ScyllaNote[]) => {
let filtered = filterVisibility(notes, user, followingUserIds);
let filtered = notes.filter(note => note.visibility !== "home");
filtered = filterVisibility(filtered, user, followingUserIds);
filtered = filterReply(filtered, antenna.withReplies, user);
filtered = filterMutedUser(
filtered,

View file

@ -33,8 +33,6 @@ import { renderActivity } from "@/remote/activitypub/renderer/index.js";
import renderNote from "@/remote/activitypub/renderer/note.js";
import renderUpdate from "@/remote/activitypub/renderer/update.js";
import { deliverToRelays } from "@/services/relay.js";
// import { deliverQuestionUpdate } from "@/services/note/polls/update.js";
import { fetchMeta } from "@/misc/fetch-meta.js";
import {
type ScyllaNote,
type ScyllaPoll,
@ -690,6 +688,7 @@ export default define(meta, paramDef, async (ps, user) => {
newScyllaNote.id,
scyllaNote.visibility,
newScyllaNote.text,
newScyllaNote.lang,
newScyllaNote.name,
newScyllaNote.cw,
newScyllaNote.localOnly,

View file

@ -360,6 +360,8 @@ export default async (
const note = await insertNote(user, data, tags, emojis, mentionedUsers);
if (!note) return rej("empty note");
res(note);
// 統計を更新
@ -877,12 +879,24 @@ async function insertNote(
};
}
// Skip insertion if the post is empty
if (
!insert.text && // no content
!insert.hasPoll && // no poll
(!data.files || data.files.length === 0) && // no files
!insert.replyId && // no reply
!insert.renoteId // no boost
) {
return null;
}
const params = [
insert.createdAt,
insert.createdAt,
insert.id,
insert.visibility,
insert.text,
insert.lang,
insert.name,
insert.cw,
insert.localOnly,