Przeglądaj źródła

Prevent submitting data without conversations

Danilo Bargen 6 lat temu
rodzic
commit
166863eded
2 zmienionych plików z 12 dodań i 3 usunięć
  1. 4 1
      src/partials/messenger.ts
  2. 8 2
      src/services/state.ts

+ 4 - 1
src/partials/messenger.ts

@@ -521,7 +521,10 @@ class ConversationController {
     public submit = (type: threema.MessageContentType, contents: threema.MessageData[]): Promise<any> => {
         // Validate whether a connection is available
         return new Promise((resolve, reject) => {
-            if (!this.stateService.readyToSubmit(this.webClientService.chosenTask)) {
+            if (!this.stateService.readyToSubmit(
+                this.webClientService.chosenTask,
+                this.webClientService.startupDone,
+            )) {
                 // Invalid connection, show toast and abort
                 this.showError(this.$translate.instant('error.NO_CONNECTION'));
                 return reject();

+ 8 - 2
src/services/state.ts

@@ -225,13 +225,19 @@ export class StateService {
         }
     }
 
-    public readyToSubmit(chosenTask: ChosenTask): boolean {
+    /**
+     * Return whether messages can be submitted to the outgoing queue.
+     *
+     * The `startupDone` flag indicates, whether the initial data in the
+     * webclient service has been loaded or not.
+     */
+    public readyToSubmit(chosenTask: ChosenTask, startupDone: boolean): boolean {
         switch (chosenTask) {
             case ChosenTask.RelayedData:
                 return true;
             case ChosenTask.WebRTC:
             default:
-                return this.state === GlobalConnectionState.Ok;
+                return this.state === GlobalConnectionState.Ok && startupDone;
         }
     }