TTP -> MTP, A lot of other stuff #21

Merged
alois merged 81 commits from dev into main 2026-07-21 11:57:33 +03:00
6 changed files with 86 additions and 45 deletions
Showing only changes of commit 3ce708b86a - Show all commits

(feat): add MessageDeleteLive
All checks were successful
/ build-web (push) Successful in 6m34s
/ build-desktop (linux) (push) Successful in 12m5s
/ build-mobile (push) Successful in 19m39s
/ release (push) Successful in 3m2s

Alois 2026-07-11 23:12:42 +02:00

View file

@ -242,6 +242,14 @@ export default function CacheSync() {
);
return;
}
if (message.type === "MessageDeleteLive") {
const deleteData = message.data as {
ChatPartnerId: number;
SendTime: number;
};
await removeMessage(deleteData.ChatPartnerId, deleteData.SendTime);
return;
}
if (message.type === "MessageState") {
await replaceMessage(
Number(data.ChatPartnerId),
@ -257,7 +265,7 @@ export default function CacheSync() {
);
}
},
[accountId, insertMessage, replaceMessage],
[accountId, insertMessage, removeMessage, replaceMessage],
);
useEffect(() => {

View file

@ -470,6 +470,52 @@ export default function Provider({ children }: { children: ReactNode }) {
[currentChatSecret, userIdValue],
);
const removeMessage = useCallback(
(sendTime: number) => {
setLiveMessagesState((prev) =>
prev.filter((message) => message.SendTime !== sendTime),
);
const queryKey = [
"chat-messages",
String(userIdValue),
currentChatSecret !== null,
] as const;
queryClient.setQueryData<InfiniteData<RawMessages>>(
queryKey,
(current) => {
if (!current) {
return current;
}
let updated = false;
const pages = current.pages.map((page) => {
const nextPage = page.filter((message) => {
const keep = message.SendTime !== sendTime;
if (!keep) {
updated = true;
}
return keep;
});
return nextPage;
});
if (!updated) {
return current;
}
return {
...current,
pages,
};
},
);
},
[currentChatSecret, userIdValue],
);
const deleteMessage = useCallback(
async (sendTime: number) => {
try {
@ -479,53 +525,13 @@ export default function Provider({ children }: { children: ReactNode }) {
});
assertProtocolSuccess("MessageDelete", response);
setLiveMessagesState((prev) =>
prev.filter((message) => message.SendTime !== sendTime),
);
const queryKey = [
"chat-messages",
String(userIdValue),
currentChatSecret !== null,
] as const;
queryClient.setQueryData<InfiniteData<RawMessages>>(
queryKey,
(current) => {
if (!current) {
return current;
}
let updated = false;
const pages = current.pages.map((page) => {
const nextPage = page.filter((message) => {
const keep = message.SendTime !== sendTime;
if (!keep) {
updated = true;
}
return keep;
});
return nextPage;
});
if (!updated) {
return current;
}
return {
...current,
pages,
};
},
);
removeMessage(sendTime);
} catch (err) {
log(1, "chat", "red", "Failed to delete message", err);
toast("error", "Failed to delete message", String(err));
}
},
[currentChatSecret, send, userIdValue],
[removeMessage, send, userIdValue],
);
const setReaction = useCallback(
@ -717,6 +723,18 @@ export default function Provider({ children }: { children: ReactNode }) {
return;
}
if (message.type === "MessageDeleteLive") {
const data = message.data as {
ChatPartnerId: number;
SendTime: number;
};
if (data.ChatPartnerId !== userIdValue) return;
removeMessage(data.SendTime);
return;
}
if (message.type !== "MessageState") return;
const rawData = message.data as {
@ -762,7 +780,14 @@ export default function Provider({ children }: { children: ReactNode }) {
MessageState: nextState.MessageState,
});
});
}, [currentChatSecret, editMessage, send, subscribePush, userIdValue]);
}, [
currentChatSecret,
editMessage,
removeMessage,
send,
subscribePush,
userIdValue,
]);
// Replys
const [replyTo, setReplyTo] = useState<number | undefined>(undefined);

View file

@ -212,6 +212,7 @@ export function Provider(props: {
"MessageLive",
"MessageEditLive",
"MessageReactionLive",
"MessageDeleteLive",
"MessageState",
"CallInvite",
"ErrorNoIota",

View file

@ -1 +0,0 @@
- Get omikron url & public key from omega

View file

@ -209,6 +209,13 @@ export const mtp = {
}),
response: z.object({}),
},
MessageDeleteLive: {
request: z.object({}),
response: z.object({
ChatPartnerId: z.number(),
SendTime: z.number(),
}),
},
MessageEditLive: {
request: z.object({}),
response: z.object({

View file

@ -149,6 +149,7 @@ type_maps:
MessageReactionAdd: 146
MessageReactionRemove: 147
MessageReactionLive: 148
MessageDeleteLive: 150
DataTypes:
ErrorType: 32
ErrorProtocol: 33