This commit is contained in:
rosetta
2026-01-30 05:01:05 +02:00
commit 83f38dc63f
327 changed files with 18725 additions and 0 deletions

Binary file not shown.

View File

@@ -0,0 +1,72 @@
import { useDatabase } from "@/app/providers/DatabaseProvider/useDatabase";
import { createContext, useEffect } from "react";
import { useSystemAccount } from "./useSystemAccount";
import { usePublicKey } from "../AccountProvider/usePublicKey";
import { usePrivatePlain } from "../AccountProvider/usePrivatePlain";
import { APP_VERSION, RELEASE_NOTICE } from "@/app/version";
import { chacha20Encrypt, encodeWithPassword, encrypt } from "@/app/crypto/crypto";
import { generateRandomKey } from "@/app/utils/utils";
import { DeliveredMessageState } from "../DialogProvider/DialogProvider";
import { UserInformation } from "../InformationProvider/InformationProvider";
import { useNotification } from "@/app/hooks/useNotification";
import { useDialogsList } from "../DialogListProvider/useDialogsList";
export const SystemAccountContext = createContext(null);
export interface SystemUserInformation extends UserInformation {
avatar: string;
}
interface SystemAccountProviderProps {
children: React.ReactNode;
}
export function SystemAccountProvider(props : SystemAccountProviderProps) {
const {runQuery} = useDatabase();
const lastNoticeVersion = localStorage.getItem("lastNoticeVersion") || "0.0.0";
const updateAccount = useSystemAccount("updates");
const publicKey = usePublicKey();
const privatePlain = usePrivatePlain();
const {updateDialog} = useDialogsList();
const notify = useNotification();
useEffect(() => {
if(publicKey == ""){
return;
}
if(lastNoticeVersion !== APP_VERSION){
sendReleaseNoticeFromUpdatesAccount();
localStorage.setItem("lastNoticeVersion", APP_VERSION);
}
}, [lastNoticeVersion, publicKey]);
const sendReleaseNoticeFromUpdatesAccount = async () => {
const message = RELEASE_NOTICE;
if(message.trim() == ""){
return;
}
const cahchaEncrypted = await chacha20Encrypt(message.trim());
const key = Buffer.concat([
Buffer.from(cahchaEncrypted.key, "hex"),
Buffer.from(cahchaEncrypted.nonce, "hex")]);
const encryptedKey = await encrypt(key.toString('binary'), publicKey);
const messageId = generateRandomKey(16);
const plainMessage = await encodeWithPassword(privatePlain, message.trim());
await runQuery(`
INSERT INTO messages
(from_public_key, to_public_key, content, timestamp, read, chacha_key, from_me, plain_message, account, message_id, delivered, attachments) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
`, [updateAccount!.publicKey, publicKey, cahchaEncrypted.ciphertext, Date.now(), 0, encryptedKey, 0, plainMessage, publicKey, messageId, DeliveredMessageState.DELIVERED, JSON.stringify([])]);
updateDialog(updateAccount!.publicKey);
notify("New message", "You have a new message");
}
return (
<SystemAccountContext.Provider value={null}>
{props.children}
</SystemAccountContext.Provider>
)
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

View File

@@ -0,0 +1,8 @@
import { SystemUserInformation } from "./SystemAccountsProvider";
import { useSystemAccounts } from "./useSystemAccounts";
export function useSystemAccount(username: string) : SystemUserInformation | undefined {
const systemAccounts = useSystemAccounts();
return systemAccounts.find((v) => v.username == username);
}

View File

@@ -0,0 +1,18 @@
import { OnlineState } from "@/app/providers/ProtocolProvider/protocol/packets/packet.onlinestate";
import { SystemUserInformation } from "./SystemAccountsProvider";
import updates from './avatars/updates.png';
export function useSystemAccounts() : SystemUserInformation[] {
const accounts : SystemUserInformation[] = [
{
publicKey: "0x000000000000000000000000000000000000000001",
verified: 1,
title: "Rosetta Updates",
username: "updates",
online: OnlineState.OFFLINE,
avatar: updates
}
];
return accounts;
}