make file transfer initiate automatically

This commit is contained in:
marlon-erler
2026-04-06 15:50:13 +00:00
parent 7eaf07918c
commit 3fb9785882
15 changed files with 112 additions and 53 deletions
+31 -3
View File
@@ -17,9 +17,13 @@ export default class FileTransferModel {
storageModel: StorageModel;
connectionModel: ConnectionModel;
static READY_MESSAGE = "ready";
// data
transferData: TransferData | undefined;
fileHandlerManager: HandlerManager<string> = new HandlerManager();
readyToSendHandlerManager: HandlerManager<boolean> = new HandlerManager();
direction: TransferDirections = TransferDirections.Send;
// general
generateTransferData = (): TransferData => {
@@ -31,16 +35,36 @@ export default class FileTransferModel {
return transferData;
};
prepareToReceive = (transferData: TransferData) => {
prepareToSend = (): void => {
this.direction = TransferDirections.Send;
this.connectionModel.addChannel(this.transferData.channel);
};
prepareToReceive = (transferData: TransferData): void => {
this.direction = TransferDirections.Receive;
this.connectionModel.addChannel(transferData.channel);
this.transferData = transferData;
this.connectionModel.sendPlainMessage(
transferData.channel,
FileTransferModel.READY_MESSAGE,
);
};
// handlers
handleMessage = (data: Message): void => {
console.log(this.transferData);
if (data.messageChannel != this.transferData.channel) return;
if (
data.messageBody == FileTransferModel.READY_MESSAGE &&
this.direction == TransferDirections.Send
) {
console.log("TRIGGER");
this.readyToSendHandlerManager.trigger(true);
}
if (this.transferData == undefined) return;
if (data.messageBody == undefined) return;
if (data.messageChannel != this.transferData.channel) return;
this.handleFile(data.messageBody);
};
@@ -52,7 +76,6 @@ export default class FileTransferModel {
encryptedFileData,
this.transferData.key,
);
console.log(decrypted);
const parsed: any = parse(decrypted);
const isFileData: boolean = checkMatchesObjectStructure(
@@ -131,3 +154,8 @@ export const FileDataReference: FileData = {
path: [""],
body: "",
};
export enum TransferDirections {
Send,
Receive,
}
+2 -13
View File
@@ -281,12 +281,8 @@ function TransferDataDisplayModal(
>
{translations.general.backButton}
</button>
<button
class="primary flex"
on:click={fileTransferViewModel.initiateTransfer}
>
{translations.dataTransferModal.sendButton}
<span class="icon">arrow_forward</span>
<button disabled class="flex">
{translations.general.waitingLabel}
</button>
</div>
</div>
@@ -461,13 +457,6 @@ function DataReceptionModal(fileTransferViewModel: FileTransferViewModel) {
{translations.dataTransferModal.transferDataHeadline}
</h2>
<p class="secondary">
{
translations.dataTransferModal
.readyToReceiveDescription
}
</p>
<p
class="secondary"
subscribe:innerText={
+1 -1
View File
@@ -25,7 +25,7 @@ export function TaskSettingsModal(taskViewModel: TaskViewModel) {
};
return (
<div class="modal" open>
<div class="modal" open metakey:s={taskViewModel.closeAndSave}>
<div>
<main>
<h2>{translations.chatPage.task.taskSettingsHeadline}</h2>
+3 -5
View File
@@ -21,6 +21,7 @@ const englishTranslations = {
fileVersionLabel: "Version",
searchLabel: "Search",
waitingLabel: "Waiting...",
restoreConnection: "Restore connection",
},
@@ -89,7 +90,6 @@ const englishTranslations = {
dataEntryDescription: "Enter this data on the other device.",
dataEntryInputDescription:
"Enter the data displayed on the other device.",
readyToReceiveDescription: "Click 'send' on the other device.",
notConnectedError: "You are not connected to any server.",
@@ -298,6 +298,7 @@ const allTranslations: { [language: string]: typeof englishTranslations } = {
fileVersionLabel: "Version",
searchLabel: "Suche",
waitingLabel: "Warten...",
restoreConnection: "Verbindung wiederherstellen",
},
@@ -362,8 +363,6 @@ const allTranslations: { [language: string]: typeof englishTranslations } = {
"Gib diese Informationen auf dem anderen Gerät ein.",
dataEntryInputDescription:
"Gib die auf dem anderen Gerät angezeigten Informationen ein.",
readyToReceiveDescription:
"Klicke auf dem anderen Gerät auf 'Senden'.",
notConnectedError: "Du bist mit keinem Server verbunden.",
@@ -543,6 +542,7 @@ const allTranslations: { [language: string]: typeof englishTranslations } = {
fileVersionLabel: "Versión",
searchLabel: "Buscar",
waitingLabel: "Esperando...",
restoreConnection: "Conectar de nuevo",
},
@@ -607,8 +607,6 @@ const allTranslations: { [language: string]: typeof englishTranslations } = {
"Introduce estos datos en el otro dispositivo.",
dataEntryInputDescription:
"Introduce los datos mostrados en el otro dispositivo.",
readyToReceiveDescription:
"Haz clic en 'enviar' en el otro dispositivo.",
notConnectedError: "No estás conectado a ningún servidor.",
+9 -6
View File
@@ -116,12 +116,15 @@ export default class ChatViewModel {
};
subscribeReadStatus = (): void => {
React.createProxyState([this.selectedPage, this.chatListViewModel.selectedChat], () => {
if (this.chatListViewModel.selectedChat.value != this) return;
if (this.selectedPage.value != ChatPageType.Messages) return;
this.setReadStatus(false);
})
}
React.createProxyState(
[this.selectedPage, this.chatListViewModel.selectedChat],
() => {
if (this.chatListViewModel.selectedChat.value != this) return;
if (this.selectedPage.value != ChatPageType.Messages) return;
this.setReadStatus(false);
},
);
};
// init
constructor(
@@ -52,6 +52,7 @@ export default class ConnectionViewModel {
};
connectToAddress = (address: string): void => {
console.log(address);
this.connectionModel.connect(address);
};
+2 -1
View File
@@ -6,7 +6,8 @@ export default class CoreViewModel {
// SUGGESTIONS
// boards & tasks
boardSearchSuggestions: React.ListState<string> = new React.ListState();
boardFilterStringSuggestions: React.ListState<string> =
new React.ListState();
taskCategorySuggestions: React.ListState<string> = new React.ListState();
taskStatusSuggestions: React.ListState<string> = new React.ListState();
@@ -128,6 +128,7 @@ export default class FileTransferViewModel {
showTransferDataModal = (): void => {
this.presentedModal.value = FileTransferModal.TransferDataDisplay;
this.getTransferData();
this.fileTransferModel.prepareToSend();
};
initiateTransfer = (): void => {
@@ -176,6 +177,10 @@ export default class FileTransferViewModel {
this.fileTransferModel.fileHandlerManager.addHandler(
this.handleReceivedFile,
);
this.fileTransferModel.readyToSendHandlerManager.addHandler(() =>
this.initiateTransfer(),
);
}
}
@@ -43,6 +43,7 @@ export default class NotificationViewModel {
(chat) => chat.chatModel.info.primaryChannel == notification.chat,
);
chat.open();
chat.selectedPage.value = ChatPageType.Messages;
};
// loop
+8 -4
View File
@@ -121,8 +121,12 @@ export default class BoardViewModel extends TaskContainingPageViewModel {
searchTerm,
];
this.storageModel.write(suggestionPath, "");
if (!this.coreViewModel.boardSearchSuggestions.value.has(searchTerm)) {
this.coreViewModel.boardSearchSuggestions.add(searchTerm);
if (
!this.coreViewModel.boardFilterStringSuggestions.value.has(
searchTerm,
)
) {
this.coreViewModel.boardFilterStringSuggestions.add(searchTerm);
}
const lastSearchPath: string[] = this.getLastSearchPath();
@@ -221,7 +225,7 @@ export default class BoardViewModel extends TaskContainingPageViewModel {
loadSearchSuggestions = (): void => {
const dirPath: string[] = this.getPreviousSearchesPath();
const searches: string[] = this.storageModel.list(dirPath);
this.coreViewModel.boardSearchSuggestions.add(...searches);
this.coreViewModel.boardFilterStringSuggestions.add(...searches);
};
restoreSearch = (): void => {
@@ -290,7 +294,7 @@ export default class BoardViewModel extends TaskContainingPageViewModel {
this.taskViewModels,
this.filteredTaskViewModels,
TaskViewModel.getStringsForFilter,
this.coreViewModel.boardSearchSuggestions,
this.coreViewModel.boardFilterStringSuggestions,
);
this.searchViewModel.appliedQuery.subscribeSilent((newQuery) => {
this.handleNewSearch(newQuery);
+2
View File
@@ -164,6 +164,8 @@ export default class TaskPageViewModel {
this.chatViewModel = chatViewModel;
this.loadData();
// handlers
boardModel.boardHandlerManager.addHandler(
(boardInfoFileContent: BoardInfoFileContent) => {
+2 -2
View File
@@ -101,7 +101,8 @@ export default class TaskViewModel {
this.loadTaskData();
};
closeAndSave = (): void => {
closeAndSave = (e: Event): void => {
e.preventDefault();
this.close();
this.save();
};
@@ -234,7 +235,6 @@ export default class TaskViewModel {
static getStringsForFilter = (taskViewModel: TaskViewModel): string[] => {
return [
taskViewModel.task.name,
taskViewModel.task.description ?? "",
taskViewModel.task.category ?? "",
taskViewModel.task.status ?? "",
taskViewModel.task.priority ?? "",