Compare commits
No commits in common. "0409015c9672f8cc2cd4e812cc8ba2861bf306b5" and "283275c80dae524f3b20599eb0aacf5f280fdcb3" have entirely different histories.
0409015c96
...
283275c80d
|
@ -41,6 +41,7 @@ export async function importCkPost(
|
||||||
localOnly,
|
localOnly,
|
||||||
visibility: "hidden",
|
visibility: "hidden",
|
||||||
visibleUsers: [],
|
visibleUsers: [],
|
||||||
|
channel: null,
|
||||||
apMentions: new Array(0),
|
apMentions: new Array(0),
|
||||||
apHashtags: undefined,
|
apHashtags: undefined,
|
||||||
apEmojis: undefined,
|
apEmojis: undefined,
|
||||||
|
|
|
@ -65,9 +65,9 @@ export default abstract class Channel {
|
||||||
public onMessage?(type: string, body: any): void;
|
public onMessage?(type: string, body: any): void;
|
||||||
|
|
||||||
protected withPackedNote(
|
protected withPackedNote(
|
||||||
callback: (noteMessage: { type: "note", body: Packed<"Note"> }) => void,
|
callback: (note: Packed<"Note">) => void,
|
||||||
): (noteMessage: { type: "note", body: Note }) => void {
|
): (Note) => void {
|
||||||
return async ({body: note}) => {
|
return async (note: Note) => {
|
||||||
try {
|
try {
|
||||||
// because `note` was previously JSON.stringify'ed, the fields that
|
// because `note` was previously JSON.stringify'ed, the fields that
|
||||||
// were objects before are now strings and have to be restored or
|
// were objects before are now strings and have to be restored or
|
||||||
|
@ -79,7 +79,7 @@ export default abstract class Channel {
|
||||||
|
|
||||||
const packed = await Notes.pack(note, this.user, { detail: true });
|
const packed = await Notes.pack(note, this.user, { detail: true });
|
||||||
|
|
||||||
callback({ type: "note", body: packed });
|
callback(packed);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (
|
if (
|
||||||
err instanceof IdentifiableError &&
|
err instanceof IdentifiableError &&
|
||||||
|
|
|
@ -34,7 +34,7 @@ export default class extends Channel {
|
||||||
this.subscriber.off("notesStream", this.onNote);
|
this.subscriber.off("notesStream", this.onNote);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async onNote({body: note}: { type: "note", body: Packed<"Note"> }) {
|
private async onNote(note: Packed<"Note">) {
|
||||||
if (note.visibility !== "public") return;
|
if (note.visibility !== "public") return;
|
||||||
|
|
||||||
// 関係ない返信は除外
|
// 関係ない返信は除外
|
||||||
|
|
|
@ -4,9 +4,9 @@ import {isUserRelated} from "@/misc/is-user-related.js";
|
||||||
import type { Packed } from "@/misc/schema.js";
|
import type { Packed } from "@/misc/schema.js";
|
||||||
|
|
||||||
export default class extends Channel {
|
export default class extends Channel {
|
||||||
|
public readonly chName = "hashtag";
|
||||||
public static shouldShare = false;
|
public static shouldShare = false;
|
||||||
public static requireCredential = false;
|
public static requireCredential = false;
|
||||||
public readonly chName = "hashtag";
|
|
||||||
private q: string[][];
|
private q: string[][];
|
||||||
|
|
||||||
constructor(id: string, connection: Channel["connection"]) {
|
constructor(id: string, connection: Channel["connection"]) {
|
||||||
|
@ -23,12 +23,7 @@ export default class extends Channel {
|
||||||
this.subscriber.on("notesStream", this.onNote);
|
this.subscriber.on("notesStream", this.onNote);
|
||||||
}
|
}
|
||||||
|
|
||||||
public dispose() {
|
private async onNote(note: Packed<"Note">) {
|
||||||
// Unsubscribe events
|
|
||||||
this.subscriber.off("notesStream", this.onNote);
|
|
||||||
}
|
|
||||||
|
|
||||||
private async onNote({body: note}: {type: "note", body: Packed<"Note">}) {
|
|
||||||
if (note.visibility === "hidden") return;
|
if (note.visibility === "hidden") return;
|
||||||
const noteTags = note.tags
|
const noteTags = note.tags
|
||||||
? note.tags.map((t: string) => t.toLowerCase())
|
? note.tags.map((t: string) => t.toLowerCase())
|
||||||
|
@ -49,4 +44,9 @@ export default class extends Channel {
|
||||||
|
|
||||||
this.send("note", note);
|
this.send("note", note);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public dispose() {
|
||||||
|
// Unsubscribe events
|
||||||
|
this.subscriber.off("notesStream", this.onNote);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ export default class extends Channel {
|
||||||
this.subscriber.off("notesStream", this.onNote);
|
this.subscriber.off("notesStream", this.onNote);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async onNote({ body: note }: { type: "note", body: Packed<"Note"> }) {
|
private async onNote(note: Packed<"Note">) {
|
||||||
if (note.visibility === "hidden") return;
|
if (note.visibility === "hidden") return;
|
||||||
|
|
||||||
// Filter away notes that are not authored by the user or any of the followed users
|
// Filter away notes that are not authored by the user or any of the followed users
|
||||||
|
|
|
@ -36,7 +36,7 @@ export default class extends Channel {
|
||||||
this.subscriber.off("notesStream", this.onNote);
|
this.subscriber.off("notesStream", this.onNote);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async onNote({ body: note }: { type: "note", "body": Packed<"Note"> }) {
|
private async onNote(note: Packed<"Note">) {
|
||||||
if (note.visibility === "hidden")
|
if (note.visibility === "hidden")
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ export default class extends Channel {
|
||||||
this.subscriber.off("notesStream", this.onNote);
|
this.subscriber.off("notesStream", this.onNote);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async onNote({ body: note }: { type: "note", body: Packed<"Note"> }) {
|
private async onNote(note: Packed<"Note">) {
|
||||||
if (note.user.host !== null) return;
|
if (note.user.host !== null) return;
|
||||||
if (note.visibility !== "public") return;
|
if (note.visibility !== "public") return;
|
||||||
|
|
||||||
|
|
|
@ -6,9 +6,9 @@ import {isInstanceMuted} from "@/misc/is-instance-muted.js";
|
||||||
import type { Packed } from "@/misc/schema.js";
|
import type { Packed } from "@/misc/schema.js";
|
||||||
|
|
||||||
export default class extends Channel {
|
export default class extends Channel {
|
||||||
|
public readonly chName = "recommendedTimeline";
|
||||||
public static shouldShare = true;
|
public static shouldShare = true;
|
||||||
public static requireCredential = true;
|
public static requireCredential = true;
|
||||||
public readonly chName = "recommendedTimeline";
|
|
||||||
private withReplies: boolean;
|
private withReplies: boolean;
|
||||||
|
|
||||||
constructor(id: string, connection: Channel["connection"]) {
|
constructor(id: string, connection: Channel["connection"]) {
|
||||||
|
@ -31,12 +31,7 @@ export default class extends Channel {
|
||||||
this.subscriber.on("notesStream", this.onNote);
|
this.subscriber.on("notesStream", this.onNote);
|
||||||
}
|
}
|
||||||
|
|
||||||
public dispose() {
|
private async onNote(note: Packed<"Note">) {
|
||||||
// Unsubscribe events
|
|
||||||
this.subscriber.off("notesStream", this.onNote);
|
|
||||||
}
|
|
||||||
|
|
||||||
private async onNote({ body: note }: { type: "note", body: Packed<"Note"> }) {
|
|
||||||
if (note.visibility === "hidden") return;
|
if (note.visibility === "hidden") return;
|
||||||
// チャンネルの投稿ではなく、自分自身の投稿 または
|
// チャンネルの投稿ではなく、自分自身の投稿 または
|
||||||
// チャンネルの投稿ではなく、その投稿のユーザーをフォローしている または
|
// チャンネルの投稿ではなく、その投稿のユーザーをフォローしている または
|
||||||
|
@ -95,4 +90,9 @@ export default class extends Channel {
|
||||||
|
|
||||||
this.send("note", note);
|
this.send("note", note);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public dispose() {
|
||||||
|
// Unsubscribe events
|
||||||
|
this.subscriber.off("notesStream", this.onNote);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,11 +5,11 @@ import {isUserRelated} from "@/misc/is-user-related.js";
|
||||||
import type { Packed } from "@/misc/schema.js";
|
import type { Packed } from "@/misc/schema.js";
|
||||||
|
|
||||||
export default class extends Channel {
|
export default class extends Channel {
|
||||||
|
public readonly chName = "userList";
|
||||||
public static shouldShare = false;
|
public static shouldShare = false;
|
||||||
public static requireCredential = false;
|
public static requireCredential = false;
|
||||||
public readonly chName = "userList";
|
|
||||||
public listUsers: User["id"][] = [];
|
|
||||||
private listId: string;
|
private listId: string;
|
||||||
|
public listUsers: User["id"][] = [];
|
||||||
private listUsersClock: NodeJS.Timer;
|
private listUsersClock: NodeJS.Timer;
|
||||||
|
|
||||||
constructor(id: string, connection: Channel["connection"]) {
|
constructor(id: string, connection: Channel["connection"]) {
|
||||||
|
@ -37,14 +37,6 @@ export default class extends Channel {
|
||||||
this.listUsersClock = setInterval(this.updateListUsers, 5000);
|
this.listUsersClock = setInterval(this.updateListUsers, 5000);
|
||||||
}
|
}
|
||||||
|
|
||||||
public dispose() {
|
|
||||||
// Unsubscribe events
|
|
||||||
this.subscriber.off(`userListStream:${this.listId}`, this.send);
|
|
||||||
this.subscriber.off("notesStream", this.onNote);
|
|
||||||
|
|
||||||
clearInterval(this.listUsersClock);
|
|
||||||
}
|
|
||||||
|
|
||||||
private async updateListUsers() {
|
private async updateListUsers() {
|
||||||
const users = await UserListJoinings.find({
|
const users = await UserListJoinings.find({
|
||||||
where: {
|
where: {
|
||||||
|
@ -56,7 +48,7 @@ export default class extends Channel {
|
||||||
this.listUsers = users.map((x) => x.userId);
|
this.listUsers = users.map((x) => x.userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async onNote({ body: note }: { type: "note", body: Packed<"Note"> }) {
|
private async onNote(note: Packed<"Note">) {
|
||||||
if (note.visibility === "hidden") return;
|
if (note.visibility === "hidden") return;
|
||||||
if (!this.listUsers.includes(note.userId)) return;
|
if (!this.listUsers.includes(note.userId)) return;
|
||||||
|
|
||||||
|
@ -69,4 +61,12 @@ export default class extends Channel {
|
||||||
|
|
||||||
this.send("note", note);
|
this.send("note", note);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public dispose() {
|
||||||
|
// Unsubscribe events
|
||||||
|
this.subscriber.off(`userListStream:${this.listId}`, this.send);
|
||||||
|
this.subscriber.off("notesStream", this.onNote);
|
||||||
|
|
||||||
|
clearInterval(this.listUsersClock);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -148,6 +148,10 @@ type NoteStreamEventTypes = {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export interface ChannelStreamTypes {
|
||||||
|
typing: User["id"];
|
||||||
|
}
|
||||||
|
|
||||||
export interface UserListStreamTypes {
|
export interface UserListStreamTypes {
|
||||||
userAdded: Packed<"User">;
|
userAdded: Packed<"User">;
|
||||||
userRemoved: Packed<"User">;
|
userRemoved: Packed<"User">;
|
||||||
|
@ -213,7 +217,7 @@ export type StreamMessages = {
|
||||||
};
|
};
|
||||||
notes: {
|
notes: {
|
||||||
name: "notesStream";
|
name: "notesStream";
|
||||||
payload: EventUnionFromDictionary<{ note: Note }>;
|
payload: Note;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -108,7 +108,7 @@ class Publisher {
|
||||||
};
|
};
|
||||||
|
|
||||||
public publishNotesStream = (note: Note): void => {
|
public publishNotesStream = (note: Note): void => {
|
||||||
this.publish("notesStream", "note", note);
|
this.publish("notesStream", null, note);
|
||||||
};
|
};
|
||||||
|
|
||||||
public publishAdminStream = <K extends keyof AdminStreamTypes>(
|
public publishAdminStream = <K extends keyof AdminStreamTypes>(
|
||||||
|
@ -125,10 +125,15 @@ class Publisher {
|
||||||
|
|
||||||
private publish = (
|
private publish = (
|
||||||
channel: StreamChannels,
|
channel: StreamChannels,
|
||||||
type: string,
|
type: string | null,
|
||||||
value?: any,
|
value?: any,
|
||||||
): void => {
|
): void => {
|
||||||
const message = { type: type, body: value };
|
const message =
|
||||||
|
type == null
|
||||||
|
? value
|
||||||
|
: value == null
|
||||||
|
? { type: type, body: null }
|
||||||
|
: { type: type, body: value };
|
||||||
|
|
||||||
redisClient.publish(
|
redisClient.publish(
|
||||||
config.host,
|
config.host,
|
||||||
|
|
Loading…
Reference in New Issue