@chat21/chat21-ionic 3.4.6 → 3.4.7-rc.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # chat21-ionic ver 3.0
2
2
 
3
+ ### 3.4.7-rc.2
4
+ - minior fix
5
+
6
+ ### 3.4.7-rc.1
7
+ - added: uploaded control after file is loaded
8
+
3
9
  ### 3.4.6 in PROD
4
10
 
5
11
  ### 3.4.5 in PROD
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@chat21/chat21-ionic",
3
3
  "author": "Tiledesk SRL",
4
- "version": "3.4.6",
4
+ "version": "3.4.7-rc.2",
5
5
  "license": "MIT License",
6
6
  "homepage": "https://tiledesk.com/",
7
7
  "repository": {
@@ -21,6 +21,7 @@ import { LoggerService } from 'src/chat21-core/providers/abstract/logger.service
21
21
  import { LoggerInstance } from 'src/chat21-core/providers/logger/loggerInstance';
22
22
  import { EventsService } from 'src/app/services/events-service';
23
23
  import { isOnMobileDevice } from 'src/chat21-core/utils/utils';
24
+ import { checkAcceptedFile } from 'src/chat21-core/utils/utils';
24
25
 
25
26
 
26
27
  @Component({
@@ -282,7 +283,7 @@ export class MessageTextAreaComponent implements OnInit, AfterViewInit, OnChange
282
283
  private async presentModal(e: any): Promise<any> {
283
284
  this.onPresentModalScrollToBottom.emit(true);
284
285
  const that = this;
285
- let dataFiles = " "
286
+ let dataFiles: any = " "
286
287
  if (e.type === 'change') {
287
288
 
288
289
  this.logger.log('[CONVS-DETAIL][MSG-TEXT-AREA] presentModal change e', e);
@@ -309,6 +310,13 @@ export class MessageTextAreaComponent implements OnInit, AfterViewInit, OnChange
309
310
  // this.logger.log('presentModal e.target.files.length', e.target.files.length);
310
311
 
311
312
  const attributes = { files: dataFiles, enableBackdropDismiss: false, msg: this.msg };
313
+
314
+ const canUploadFile = checkAcceptedFile(dataFiles[0].type, this.fileUploadAccept)
315
+ if(!canUploadFile){
316
+ this.presentToastOnlyImageFilesAreAllowed()
317
+ return;
318
+ }
319
+
312
320
  this.logger.log('[CONVS-DETAIL][MSG-TEXT-AREA] attributes', attributes);
313
321
  const modal: HTMLIonModalElement =
314
322
  await this.modalController.create({
@@ -391,7 +399,6 @@ export class MessageTextAreaComponent implements OnInit, AfterViewInit, OnChange
391
399
  that.fileInput.nativeElement.value = '';
392
400
  }
393
401
  });
394
-
395
402
  return await modal.present();
396
403
  }
397
404
 
@@ -46,7 +46,7 @@ import { ArchivedConversationsHandlerService } from 'src/chat21-core/providers/a
46
46
  import { ConversationHandlerService } from 'src/chat21-core/providers/abstract/conversation-handler.service'
47
47
  import { ContactsService } from 'src/app/services/contacts/contacts.service'
48
48
  import { CannedResponsesService } from '../../services/canned-responses/canned-responses.service'
49
- import {getDateDifference} from 'src/chat21-core/utils/utils'
49
+ import {checkAcceptedFile, getDateDifference} from 'src/chat21-core/utils/utils'
50
50
  import { ImageRepoService } from 'src/chat21-core/providers/abstract/image-repo.service'
51
51
  import { PresenceService } from 'src/chat21-core/providers/abstract/presence.service'
52
52
  import { CreateCannedResponsePage } from 'src/app/modals/create-canned-response/create-canned-response.page'
@@ -654,7 +654,7 @@ export class ConversationDetailPage implements OnInit, OnDestroy, AfterViewInit
654
654
  'LABEL_ENTER_MSG_SHORT',
655
655
  'LABEL_ENTER_MSG_SHORTER',
656
656
  'ONLY_IMAGE_FILES_ARE_ALLOWED_TO_PASTE',
657
- 'FAILED_TO_UPLOAD_THE_FORMAT_IS NOT_SUPPORTED',
657
+ 'FAILED_TO_UPLOAD_THE_FORMAT_IS_NOT_SUPPORTED',
658
658
  'NO_INFORMATION_AVAILABLE',
659
659
  'CONTACT_ID',
660
660
 
@@ -2132,19 +2132,15 @@ export class ConversationDetailPage implements OnInit, OnDestroy, AfterViewInit
2132
2132
 
2133
2133
  var mimeType = fileList[0].type
2134
2134
  this.logger.log('[CONVS-DETAIL] ----> FILE - DROP mimeType files ', mimeType)
2135
-
2136
- // if (mimeType.startsWith("image") || mimeType.startsWith("application")) {
2137
- // this.logger.log('[CONVS-DETAIL] ----> FILE - DROP mimeType files: ', this.appConfigProvider.getConfig().fileUploadAccept);
2138
- // this.checkAcceptedFile(mimeType);
2139
- const isAccepted = this.checkAcceptedFile(mimeType)
2140
- this.logger.log('[CONVS-DETAIL] > checkAcceptedFile - fileUploadAccept isAcceptFile FILE - DROP', isAccepted)
2141
- if (isAccepted === true) {
2142
- this.handleDropEvent(ev)
2143
- } else {
2144
- this.logger.log('[CONVS-DETAIL] ----> FILE - DROP mimeType files ', mimeType, 'NOT SUPPORTED FILE TYPE')
2135
+
2136
+ // const isAccepted = this.checkAcceptedFile(mimeType)
2137
+ const canUploadFile = checkAcceptedFile(mimeType, this.appConfigProvider.getConfig().fileUploadAccept)
2138
+ if(!canUploadFile){
2145
2139
  this.presentToast(this.translationsMap.get('FAILED_TO_UPLOAD_THE_FORMAT_IS_NOT_SUPPORTED'), 'danger', 'toast-custom-class', 5000)
2146
- // this.presentToastOnlyImageFilesAreAllowedToDrag()
2140
+ return;
2147
2141
  }
2142
+ this.handleDropEvent(ev)
2143
+
2148
2144
  }
2149
2145
  }
2150
2146
 
@@ -864,3 +864,59 @@ export function isGroup(conv: ConversationModel) {
864
864
  };
865
865
  return false
866
866
  }
867
+
868
+ export function checkAcceptedFile(fileType, fileUploadAccept ): boolean{
869
+
870
+ if (fileUploadAccept === '*/*') {
871
+ return true
872
+ }
873
+ // Dividi la stringa fileUploadAccept in un array di tipi accettati
874
+ const acceptedTypes = fileUploadAccept.split(',');
875
+
876
+ // Verifica se il tipo di file è accettato
877
+ return acceptedTypes.some((accept) => {
878
+ accept = accept.trim();
879
+ // Controlla per i tipi MIME con wildcard, come image/*
880
+ if (accept.endsWith('/*')) {
881
+ const baseMimeType = fileType.split('/')[0]; // Ottieni la parte principale del MIME type
882
+ return accept.replace('/*', '') === baseMimeType;
883
+ }
884
+
885
+ // Controlla se l'accettazione è un MIME type esatto (come image/jpeg)
886
+ if (accept === fileType) {
887
+ return true;
888
+ }
889
+ // Controlla per le estensioni di file specifiche come .pdf o .txt
890
+ return fileType === getMimeTypeFromExtension(accept);
891
+ });
892
+
893
+ }
894
+
895
+ function getMimeTypeFromExtension(extension: string): string {
896
+ // Rimuovi il punto dall'estensione e ottieni il MIME type
897
+ const mimeTypes: { [key: string]: string } = {
898
+ '.jpg': 'image/jpeg',
899
+ '.jpeg': 'image/jpeg',
900
+ '.png': 'image/png',
901
+ '.gif': 'image/gif',
902
+ '.pdf': 'application/pdf',
903
+ '.txt': 'text/plain',
904
+ '.doc': 'application/msword',
905
+ '.docx': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
906
+ // Aggiungi altri tipi MIME se necessario
907
+ };
908
+ return mimeTypes[extension] || '';
909
+ }
910
+
911
+ export function getProjectIdSelectedConversation(conversationWith: string): string{
912
+ const conversationWith_segments = conversationWith.split('-')
913
+ // Removes the last element of the array if is = to the separator
914
+ if (conversationWith_segments[conversationWith_segments.length - 1] === '') {
915
+ conversationWith_segments.pop()
916
+ }
917
+ let projectId = ''
918
+ if (conversationWith_segments.length >= 4) {
919
+ projectId = conversationWith_segments[2]
920
+ }
921
+ return projectId
922
+ }