Jelajahi Sumber

Split long messages into smaller chunks

This reduces the potential for quoted chunks to exceed message length
limits.
Danilo Bargen 5 tahun lalu
induk
melakukan
3870af7dde
1 mengubah file dengan 8 tambahan dan 2 penghapusan
  1. 8 2
      src/directives/compose_area.ts

+ 8 - 2
src/directives/compose_area.ts

@@ -202,7 +202,14 @@ export default [
                         // Check for max length
                         const byteLength = (new TextEncoder().encode(text)).length;
                         if (byteLength > scope.maxTextLength) {
-                            const pieces: string[] = stringService.byteChunk(text, scope.maxTextLength, 50);
+                            // Messages that use the entire available message size become a problem
+                            // when being quoted, since the quote also becomes part of the message.
+                            // As a workaround, until a better quote system is implemented, reduce
+                            // the chunk size so that reaching the limit becomes more unlikely.
+                            const chunkSize = scope.maxTextLength * 0.85;
+
+                            const pieces: string[] = stringService.byteChunk(text, chunkSize, 50);
+
                             const confirm = $mdDialog.confirm()
                                 .title($translate.instant('messenger.MESSAGE_TOO_LONG_SPLIT_SUBJECT'))
                                 .textContent($translate.instant('messenger.MESSAGE_TOO_LONG_SPLIT_BODY', {
@@ -211,7 +218,6 @@ export default [
                                 }))
                                 .ok($translate.instant('common.YES'))
                                 .cancel($translate.instant('common.NO'));
-
                             $mdDialog.show(confirm).then(function() {
                                 submitTexts(pieces);
                             }, () => {