(wip): migrate ttp to mtp -> snake case to pascal case
Some checks failed
/ build-web (push) Successful in 6m13s
/ build-desktop (linux) (push) Successful in 7m1s
/ build-mobile (push) Failing after 9m20s
/ release (push) Has been skipped

This commit is contained in:
Alois 2026-07-03 11:08:38 +02:00
commit 7f75a36d73
23 changed files with 214 additions and 248 deletions

View file

@ -6,19 +6,19 @@ import type { RawMessages } from "../values";
* @param send Parameter send.
* @param amount Parameter amount.
* @param offset Parameter offset.
* @param user_id Parameter user_id.
* @param UserId Parameter UserId.
* @returns Promise<RawMessages>.
*/
export async function getMessages(
send: BoundSendFn,
amount: number,
offset: number,
user_id: number,
UserId: number,
): Promise<RawMessages> {
const messages = await send("messages_get", {
amount: amount,
offset: offset,
user_id: user_id,
UserId,
});
if (messages.type.startsWith("error")) {

View file

@ -73,11 +73,11 @@ export default function InputComponent({
const reference = addLiveMessage({
height: 0,
not_encrypted: true,
send_time: time,
NotEncrypted: true,
SendTime: time,
content: currentValue,
sent_by_self: true,
message_state: "awaiting",
SentBySelf: true,
MessageState: "awaiting",
});
log(3, "chat", "purple", "Live message added, encrypting...");
@ -97,14 +97,14 @@ export default function InputComponent({
send("message_send", {
height: 0,
content: encryptedContext,
receiver_id: userId,
send_time: time,
ReceiverId: userId,
SendTime: time,
}).catch((e) => {
log(0, "Chat", "red", "Failed to send message", e, {
content: currentValue,
encryptedContext,
receiver_id: userId,
send_time: time,
ReceiverId: userId,
SendTime: time,
});
reference.setFailed(true);
toast("error", "Failed to send message");

View file

@ -41,13 +41,13 @@ function MessageComponent({
};
user: User | null;
}) {
const actuallyFailed = message.failed && message.message_state === "awaiting";
const actuallyFailed = message.failed && message.MessageState === "awaiting";
// Fade-in
const [hasFadedIn, setHasFadedIn] = useState(false);
const opacityClass = !hasFadedIn
? "opacity-0"
: actuallyFailed || message.message_state === "awaiting"
: actuallyFailed || message.MessageState === "awaiting"
? "opacity-50"
: "opacity-100";
useEffect(() => {
@ -80,21 +80,21 @@ function MessageComponent({
const readConfirmations = await load("settings.read_confirmations");
if (readConfirmations) {
if (!user?.user_id) return;
if (!user?.UserId) return;
await send("message_state", {
chat_partner_id: user?.user_id,
send_time: message.send_time,
message_state: "read",
ChatPartnerId: user?.UserId,
SendTime: message.SendTime,
MessageState: "read",
});
} else {
await send("message_state", {
chat_partner_id: user?.user_id,
send_time: message.send_time,
message_state: "received",
ChatPartnerId: user?.UserId,
SendTime: message.SendTime,
MessageState: "received",
});
}
}, [load, message.send_time, user?.user_id, send]);
}, [load, message.SendTime, user?.UserId, send]);
useEffect(() => {
let cancelled = false;
@ -102,7 +102,7 @@ function MessageComponent({
const receiveConfirmations = await load("settings.receive_confirmations");
if (cancelled) return;
switch (message.message_state) {
switch (message.MessageState) {
case "sent":
if (receiveConfirmations) {
messageStateReadUpdate();
@ -123,7 +123,7 @@ function MessageComponent({
return () => {
cancelled = true;
};
}, [message.message_state, load, messageStateReadUpdate]);
}, [message.MessageState, load, messageStateReadUpdate]);
return (
<div
@ -132,7 +132,7 @@ function MessageComponent({
>
<MessageContextMenu
content={message.content}
messageId={message.send_time}
messageId={message.SendTime}
>
<div
className={cn(
@ -147,7 +147,7 @@ function MessageComponent({
<>
{grouped ? (
<p className="w-9 text-xs group-hover:visible invisible text-muted-foreground">
{new Date(message.send_time).toLocaleString([], {
{new Date(message.SendTime).toLocaleString([], {
hour: "2-digit",
minute: "2-digit",
})}
@ -160,7 +160,7 @@ function MessageComponent({
</AvatarFallback>
</Avatar>
)}
{message.failed && message.message_state === "awaiting" && (
{message.failed && message.MessageState === "awaiting" && (
<Tooltip>
<TooltipContent>
<p>Failed to send message</p>
@ -192,22 +192,22 @@ function MessageComponent({
<div className="flex items-center gap-1">
<p className="font-medium">{user.display}</p>
<p className="text-xs text-muted-foreground">
{new Date(message.send_time).toLocaleString([], {
{new Date(message.SendTime).toLocaleString([], {
hour: "2-digit",
minute: "2-digit",
})}
</p>
<div>
{message.message_state === "read" ? (
{message.MessageState === "read" ? (
<Check
size={12}
color="var(--primary-foreground-alt)"
/>
) : message.message_state === "received" ? (
) : message.MessageState === "received" ? (
<Check size={12} color="var(--muted-foreground)" />
) : message.message_state === "sent" ? (
) : message.MessageState === "sent" ? (
<RefreshCw size={12} color="var(--muted-foreground)" />
) : message.message_state === "sending" ? (
) : message.MessageState === "sending" ? (
<Ellipse size={12} color="var(--muted-foreground)" />
) : null}
</div>
@ -231,11 +231,11 @@ function MessageComponent({
export default React.memo(MessageComponent, (prev, next) => {
return (
prev.message.send_time === next.message.send_time &&
prev.message.SendTime === next.message.SendTime &&
prev.message.content === next.message.content &&
prev.message.height === next.message.height &&
prev.message.sent_by_self === next.message.sent_by_self &&
prev.message.message_state === next.message.message_state &&
prev.message.SentBySelf === next.message.SentBySelf &&
prev.message.MessageState === next.message.MessageState &&
prev.message.failed === next.message.failed &&
prev.grouped === next.grouped &&
prev.user === next.user

View file

@ -24,23 +24,23 @@ export const context = createContext<contextType | undefined>(undefined);
const queryClient = new QueryClient();
function updateMessageStateBySendTime<
T extends { send_time: number; message_state: RawMessage["message_state"] },
T extends { SendTime: number; MessageState: RawMessage["MessageState"] },
>(
messages: T[],
sendTime: number,
messageState: RawMessage["message_state"],
messageState: RawMessage["MessageState"],
): { next: T[]; updated: boolean } {
let updated = false;
const next = messages.map((item) => {
if (item.send_time !== sendTime || item.message_state === messageState) {
if (item.SendTime !== sendTime || item.MessageState === messageState) {
return item;
}
updated = true;
return {
...item,
message_state: messageState,
MessageState: messageState,
};
});
@ -105,8 +105,8 @@ export default function Provider(props: { children: ReactNode }) {
const ownData = await get(ownId);
const sharedSecret = await getSharedSecret(
privateKey,
ownData.public_key,
recipientData.public_key,
ownData.PublicKey,
recipientData.PublicKey,
);
if (active) {
@ -135,7 +135,7 @@ export default function Provider(props: { children: ReactNode }) {
const messages = await send("messages_get", {
amount,
offset,
user_id: userIdValue,
UserId: userIdValue,
});
if (messages.type.startsWith("error")) {
@ -143,14 +143,14 @@ export default function Provider(props: { children: ReactNode }) {
}
const rawMessages = messages.data.messages;
const sorted = [...rawMessages].sort((a, b) => a.send_time - b.send_time);
const sorted = [...rawMessages].sort((a, b) => a.SendTime - b.SendTime);
if (sorted.length > 0) {
const fetchedSendTimes = new Set(sorted.map((item) => item.send_time));
const fetchedSendTimes = new Set(sorted.map((item) => item.SendTime));
setLiveMessagesState((prev) => {
const filtered = prev.filter(
(liveMessage) => !fetchedSendTimes.has(liveMessage.send_time),
(liveMessage) => !fetchedSendTimes.has(liveMessage.SendTime),
);
return filtered.length === prev.length ? prev : filtered;
@ -179,7 +179,7 @@ export default function Provider(props: { children: ReactNode }) {
globalThis.crypto?.randomUUID?.() ??
`${Date.now()}-${Math.random().toString(36).slice(2)}`;
if (!message.sent_by_self) {
if (!message.SentBySelf) {
moveUserIdToTop(userIdValue);
}
@ -219,20 +219,20 @@ export default function Provider(props: { children: ReactNode }) {
}
const rawData = message.data as {
chat_partner_id: unknown;
send_time: unknown;
message_state: RawMessage["message_state"];
ChatPartnerId: unknown;
SendTime: unknown;
MessageState: RawMessage["MessageState"];
};
const nextState = {
chat_partner_id: Number(rawData.chat_partner_id),
send_time: Number(rawData.send_time),
message_state: rawData.message_state,
ChatPartnerId: Number(rawData.ChatPartnerId),
SendTime: Number(rawData.SendTime),
MessageState: rawData.MessageState,
};
if (
!Number.isFinite(nextState.chat_partner_id) ||
!Number.isFinite(nextState.send_time)
!Number.isFinite(nextState.ChatPartnerId) ||
!Number.isFinite(nextState.SendTime)
) {
log(
3,
@ -243,7 +243,7 @@ export default function Provider(props: { children: ReactNode }) {
return;
}
if (nextState.chat_partner_id !== userIdValue) {
if (nextState.ChatPartnerId !== userIdValue) {
log(
3,
"chat",
@ -251,7 +251,7 @@ export default function Provider(props: { children: ReactNode }) {
"Cancel message state update due to user ID mismatch",
{
expected: userIdValue,
received: nextState.chat_partner_id,
received: nextState.ChatPartnerId,
},
);
return;
@ -260,8 +260,8 @@ export default function Provider(props: { children: ReactNode }) {
setLiveMessagesState((prev) => {
const { next, updated } = updateMessageStateBySendTime(
prev,
nextState.send_time,
nextState.message_state,
nextState.SendTime,
nextState.MessageState,
);
return updated ? next : prev;
});
@ -283,8 +283,8 @@ export default function Provider(props: { children: ReactNode }) {
const pages = current.pages.map((page) => {
const nextPage = updateMessageStateBySendTime(
page,
nextState.send_time,
nextState.message_state,
nextState.SendTime,
nextState.MessageState,
);
if (nextPage.updated) {

View file

@ -48,7 +48,7 @@ function shouldFetchPreviousPage({
}
function getMessageRenderKey(message: RawMessage | LiveMessage) {
return "localId" in message ? message.localId : String(message.send_time);
return "localId" in message ? message.localId : String(message.SendTime);
}
function buildMessageChunks(
@ -184,11 +184,11 @@ export default function Screen() {
const dedupedMessages: RawMessage[] = [];
for (const message of [...pages].reverse().flat()) {
if (seenSendTimes.has(message.send_time)) {
if (seenSendTimes.has(message.SendTime)) {
continue;
}
seenSendTimes.add(message.send_time);
seenSendTimes.add(message.SendTime);
dedupedMessages.push(message);
}
@ -199,11 +199,11 @@ export default function Screen() {
const liveWithoutDuplicates = React.useMemo(() => {
const historicalSendTimes = new Set(
historicalMessages.map((message) => message.send_time),
historicalMessages.map((message) => message.SendTime),
);
return liveMessagesSnapshot.filter(
(message) => !historicalSendTimes.has(message.send_time),
(message) => !historicalSendTimes.has(message.SendTime),
);
}, [historicalMessages, liveMessagesSnapshot]);
@ -559,9 +559,9 @@ export default function Screen() {
const lastMessage = messages[messageIndex - 1];
const isGrouped =
lastMessage &&
lastMessage.sent_by_self === message.sent_by_self &&
Math.round(lastMessage.send_time / 10000) ===
Math.round(message.send_time / 10000);
lastMessage.SentBySelf === message.SentBySelf &&
Math.round(lastMessage.SendTime / 10000) ===
Math.round(message.SendTime / 10000);
return (
<Message
@ -569,7 +569,7 @@ export default function Screen() {
grouped={isGrouped}
message={message}
user={
message.sent_by_self
message.SentBySelf
? (messageUsers.own ?? null)
: (messageUsers.peer ?? null)
}