@chat21/chat21-ionic 3.0.106 → 3.0.107-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 +9 -0
- package/package.json +1 -1
- package/src/app/app.component.html +11 -6
- package/src/app/app.component.scss +34 -11
- package/src/app/app.component.ts +70 -39
- package/src/app/app.module.ts +7 -1
- package/src/app/chatlib/conversation-detail/conversation-content/conversation-content.component.ts +0 -5
- package/src/app/chatlib/conversation-detail/ion-conversation-detail/ion-conversation-detail.component.html +0 -1
- package/src/app/chatlib/conversation-detail/ion-conversation-detail/ion-conversation-detail.component.scss +4 -4
- package/src/app/components/conversations-list/header-conversations-list/header-conversations-list.component.html +2 -3
- package/src/app/components/navbar/navbar.component.scss +0 -5
- package/src/app/pages/conversation-detail/conversation-detail.page.ts +10 -13
- package/src/app/pages/conversations-list/conversations-list.page.ts +10 -20
- package/src/app/services/global-settings/global-settings.service.spec.ts +16 -0
- package/src/app/services/global-settings/global-settings.service.ts +138 -0
- package/src/app/services/triggerEvents/trigerEvents.spec.ts +11 -0
- package/src/app/services/triggerEvents/triggerEvents.ts +92 -0
- package/src/app/utils/globals.ts +51 -0
- package/src/app/utils/toast.ts +1 -1
- package/src/assets/test.html +23 -0
- package/src/chat21-core/models/department.ts +12 -0
- package/src/chat21-core/providers/abstract/upload.service.ts +2 -0
- package/src/chat21-core/providers/chat-manager.ts +0 -20
- package/src/chat21-core/providers/firebase/firebase-upload.service.ts +83 -0
- package/src/chat21-core/providers/native/native-upload-service.ts +46 -0
- package/src/chat21-core/utils/utils.ts +33 -86
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { HttpClient } from '@angular/common/http';
|
|
2
|
+
import { ElementRef, Injectable } from '@angular/core';
|
|
3
|
+
import { AppStorageService } from 'src/chat21-core/providers/abstract/app-storage.service';
|
|
4
|
+
import { AppConfigProvider } from '../app-config';
|
|
5
|
+
import { BehaviorSubject } from 'rxjs';
|
|
6
|
+
import { LoggerService } from 'src/chat21-core/providers/abstract/logger.service';
|
|
7
|
+
import { LoggerInstance } from 'src/chat21-core/providers/logger/loggerInstance';
|
|
8
|
+
import { Globals } from 'src/app/utils/globals';
|
|
9
|
+
import { getParameterByName, stringToBoolean } from 'src/chat21-core/utils/utils';
|
|
10
|
+
import { environment } from 'src/environments/environment';
|
|
11
|
+
|
|
12
|
+
@Injectable({
|
|
13
|
+
providedIn: 'root'
|
|
14
|
+
})
|
|
15
|
+
export class GlobalSettingsService {
|
|
16
|
+
|
|
17
|
+
globals: Globals;
|
|
18
|
+
el: ElementRef;
|
|
19
|
+
obsSettingsService: BehaviorSubject<boolean>;
|
|
20
|
+
private logger: LoggerService = LoggerInstance.getInstance()
|
|
21
|
+
|
|
22
|
+
constructor(
|
|
23
|
+
public http: HttpClient,
|
|
24
|
+
private appStorageService: AppStorageService,
|
|
25
|
+
// private settingsService: SettingsService,
|
|
26
|
+
public appConfigService: AppConfigProvider
|
|
27
|
+
) {
|
|
28
|
+
this.obsSettingsService = new BehaviorSubject<boolean>(null);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* load paramiters
|
|
33
|
+
* 0 - imposto globals con i valori di default
|
|
34
|
+
* 3 - richiamo setParameters per il settaggio dei parametri
|
|
35
|
+
*/
|
|
36
|
+
initParamiters(globals: Globals, el: ElementRef) {
|
|
37
|
+
const that = this;
|
|
38
|
+
this.globals = globals;
|
|
39
|
+
this.el = el;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* SETTING LOCAL DEFAULT:
|
|
43
|
+
* set the default globals parameters
|
|
44
|
+
*/
|
|
45
|
+
this.globals.initDefafultParameters();
|
|
46
|
+
|
|
47
|
+
/**SET TENANT parameter */
|
|
48
|
+
this.globals.tenant = this.appConfigService.getConfig().firebaseConfig.tenant
|
|
49
|
+
/**SET LOGLEVEL parameter */
|
|
50
|
+
this.globals.logLevel = this.appConfigService.getConfig().logLevel
|
|
51
|
+
/**SET PERSISTENCE parameter */
|
|
52
|
+
this.globals.persistence = this.appConfigService.getConfig().authPersistence
|
|
53
|
+
/**SET SUPPORTMODE parameter */
|
|
54
|
+
this.globals.supportMode = this.appConfigService.getConfig().supportMode
|
|
55
|
+
/** INIT STORAGE SERVICE */
|
|
56
|
+
this.appStorageService.initialize(environment.storage_prefix, this.globals.persistence, '')
|
|
57
|
+
|
|
58
|
+
/** LOAD PARAMETERS
|
|
59
|
+
* set parameters in globals
|
|
60
|
+
*/
|
|
61
|
+
this.setParameters()
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* 3: setParameters
|
|
67
|
+
* imposto i parametri secondo il seguente ordine:
|
|
68
|
+
* D: imposto i parametri recuperati dallo storage in global
|
|
69
|
+
* E: imposto i parametri recuperati da url parameters in global
|
|
70
|
+
*/
|
|
71
|
+
setParameters() {
|
|
72
|
+
this.logger.debug('[GLOBAL-SET] ***** setParameters ***** ')
|
|
73
|
+
this.setVariableFromStorage(this.globals);
|
|
74
|
+
this.setVariablesFromUrlParameters(this.globals);
|
|
75
|
+
this.logger.debug('[GLOBAL-SET] ***** END SET PARAMETERS *****');
|
|
76
|
+
this.obsSettingsService.next(true);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* D: setVariableFromStorage
|
|
82
|
+
* recupero il dictionary global dal local storage
|
|
83
|
+
* aggiorno tutti i valori di globals
|
|
84
|
+
* @param globals
|
|
85
|
+
*/
|
|
86
|
+
setVariableFromStorage(globals: Globals) {
|
|
87
|
+
this.logger.debug('[GLOBAL-SET] setVariableFromStorage :::::::: SET VARIABLE ---------->', Object.keys(globals));
|
|
88
|
+
for (const key of Object.keys(globals)) {
|
|
89
|
+
const val = this.appStorageService.getItem(key);
|
|
90
|
+
// this.logger.debug('[GLOBAL-SET] setVariableFromStorage SET globals KEY ---------->', key);
|
|
91
|
+
// this.logger.debug('[GLOBAL-SET] setVariableFromStorage SET globals VAL ---------->', val);
|
|
92
|
+
if (val && val !== null) {
|
|
93
|
+
// globals.setParameter(key, val);
|
|
94
|
+
globals[key] = stringToBoolean(val);
|
|
95
|
+
}
|
|
96
|
+
// this.logger.debug('[GLOBAL-SET] setVariableFromStorage SET globals == ---------->', globals);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* E: setVariableFromUrlParameters
|
|
102
|
+
*/
|
|
103
|
+
setVariablesFromUrlParameters(globals: Globals) {
|
|
104
|
+
this.logger.debug('[GLOBAL-SET] setVariablesFromUrlParameters: ');
|
|
105
|
+
const windowContext = globals.windowContext;
|
|
106
|
+
let TEMP: any;
|
|
107
|
+
TEMP = getParameterByName(windowContext, 'tiledesk_tenant');
|
|
108
|
+
if (TEMP) {
|
|
109
|
+
globals.tenant = stringToBoolean(TEMP);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
TEMP = getParameterByName(windowContext, 'tiledesk_supportMode');
|
|
113
|
+
if (TEMP) {
|
|
114
|
+
globals.supportMode = stringToBoolean(TEMP);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
TEMP = getParameterByName(windowContext, 'tiledesk_lang');
|
|
118
|
+
if (TEMP) {
|
|
119
|
+
globals.lang = stringToBoolean(TEMP);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
TEMP = getParameterByName(windowContext, 'tiledesk_persistence');
|
|
123
|
+
if (TEMP) {
|
|
124
|
+
globals.persistence = TEMP;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
TEMP = getParameterByName(windowContext, 'jwt');
|
|
128
|
+
if (TEMP) {
|
|
129
|
+
globals.jwt = TEMP;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
TEMP = getParameterByName(windowContext, 'tiledesk_logLevel');
|
|
133
|
+
if (TEMP) {
|
|
134
|
+
globals.logLevel = TEMP;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
}
|
|
138
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { TestBed } from '@angular/core/testing';
|
|
2
|
+
import { TriggerEvents } from './triggerEvents';
|
|
3
|
+
|
|
4
|
+
describe('TriggerEvents', () => {
|
|
5
|
+
beforeEach(() => TestBed.configureTestingModule({}));
|
|
6
|
+
|
|
7
|
+
it('should be created', () => {
|
|
8
|
+
const service: TriggerEvents = TestBed.get(TriggerEvents);
|
|
9
|
+
expect(service).toBeTruthy();
|
|
10
|
+
});
|
|
11
|
+
});
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { MessageModel } from "src/chat21-core/models/message";
|
|
2
|
+
import { LoggerService } from "src/chat21-core/providers/abstract/logger.service";
|
|
3
|
+
import { LoggerInstance } from "src/chat21-core/providers/logger/loggerInstance";
|
|
4
|
+
import { AppConfigProvider } from "../app-config";
|
|
5
|
+
import { ConversationModel } from "src/chat21-core/models/conversation";
|
|
6
|
+
import { ElementRef, Injectable } from "@angular/core";
|
|
7
|
+
|
|
8
|
+
@Injectable({
|
|
9
|
+
providedIn: 'root'
|
|
10
|
+
})
|
|
11
|
+
export class TriggerEvents {
|
|
12
|
+
|
|
13
|
+
private el: ElementRef;
|
|
14
|
+
private windowContext;
|
|
15
|
+
private logger: LoggerService = LoggerInstance.getInstance()
|
|
16
|
+
|
|
17
|
+
constructor(
|
|
18
|
+
private appConfig: AppConfigProvider
|
|
19
|
+
){}
|
|
20
|
+
|
|
21
|
+
public setElement(el: ElementRef){
|
|
22
|
+
this.el = el
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public setWindowContext(windowContext){
|
|
26
|
+
this.windowContext = windowContext
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
public triggerOnAuthStateChanged(detailObj: {}) {
|
|
31
|
+
this.logger.debug(' ---------------- triggerOnAuthStateChanged ---------------- ', detailObj);
|
|
32
|
+
try {
|
|
33
|
+
const onAuthStateChanged = new CustomEvent('onAuthStateChanged', { detail: detailObj});
|
|
34
|
+
const windowContext = this.windowContext;
|
|
35
|
+
if (windowContext){
|
|
36
|
+
// window.parent.dispatchEvent(onAuthStateChanged);
|
|
37
|
+
window.parent.postMessage({type: "onAuthStateChanged", detail: detailObj}, '*')
|
|
38
|
+
// this.el.nativeElement.dispatchEvent(onAuthStateChanged);
|
|
39
|
+
}
|
|
40
|
+
} catch (e) {
|
|
41
|
+
this.logger.error('[TRIGGER-HANDLER] > Error:' + e);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
public triggerAfterSendMessageEvent(messageSent: MessageModel){
|
|
46
|
+
this.logger.debug(' ---------------- triggerAfterSendMessageEvent ---------------- ', messageSent);
|
|
47
|
+
try {
|
|
48
|
+
const onAfterMessageSend = new CustomEvent('onAfterMessageSend', { detail: { message: messageSent } });
|
|
49
|
+
const windowContext = this.windowContext;
|
|
50
|
+
if (windowContext){
|
|
51
|
+
// windowContext.document.dispatchEvent(onAfterMessageSend);
|
|
52
|
+
window.parent.postMessage({type: "onAfterMessageSend", detail: { message: messageSent }}, '*')
|
|
53
|
+
}
|
|
54
|
+
} catch (e) {
|
|
55
|
+
this.logger.error('[TRIGGER-HANDLER] > Error:' + e);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
public triggerAfterMessageReceived(message: MessageModel){
|
|
62
|
+
this.logger.debug(' ---------------- triggerAfterMessageReceived ---------------- ', message);
|
|
63
|
+
try {
|
|
64
|
+
const onAfterMessageReceived = new CustomEvent('onAfterMessageReceived', { detail: { message: message } });
|
|
65
|
+
const windowContext = this.windowContext;
|
|
66
|
+
if (windowContext){
|
|
67
|
+
// windowContext.document.dispatchEvent(onAfterMessageReceived);
|
|
68
|
+
window.parent.postMessage({type: "onAfterMessageReceived", detail: { message: message }}, '*')
|
|
69
|
+
}
|
|
70
|
+
} catch (e) {
|
|
71
|
+
this.logger.error('[TRIGGER-HANDLER] > Error:' + e);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
public triggerOnNewConversationInit(conversation: ConversationModel){
|
|
77
|
+
this.logger.debug(' ---------------- triggerOnNewConversation ---------------- ', conversation);
|
|
78
|
+
try {
|
|
79
|
+
const onNewConversation = new CustomEvent('onNewConversation', { detail: { conversation: conversation} });
|
|
80
|
+
const windowContext = this.windowContext;
|
|
81
|
+
if (windowContext){
|
|
82
|
+
// windowContext.document.dispatchEvent(onNewConversation);
|
|
83
|
+
window.parent.postMessage({type: "onNewConversation", detail: { conversation: conversation}}, '*')
|
|
84
|
+
}
|
|
85
|
+
} catch (e) {
|
|
86
|
+
this.logger.error('[TRIGGER-HANDLER] > Error:' + e);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { style } from '@angular/animations';
|
|
2
|
+
import { Injectable } from '@angular/core';
|
|
3
|
+
import { BehaviorSubject } from 'rxjs';
|
|
4
|
+
import { environment } from '../../environments/environment';
|
|
5
|
+
|
|
6
|
+
/** CONSTANTS */
|
|
7
|
+
import { CHANNEL_TYPE_GROUP } from 'src/chat21-core/utils/constants';
|
|
8
|
+
import { getParameterByName } from 'src/chat21-core/utils/utils';
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@Injectable({
|
|
12
|
+
providedIn: 'root'
|
|
13
|
+
})
|
|
14
|
+
export class Globals {
|
|
15
|
+
|
|
16
|
+
windowContext;
|
|
17
|
+
|
|
18
|
+
supportMode: boolean;
|
|
19
|
+
tenant: string;
|
|
20
|
+
logLevel: string
|
|
21
|
+
persistence: string;
|
|
22
|
+
lang: string;
|
|
23
|
+
jwt: string;
|
|
24
|
+
|
|
25
|
+
constructor(
|
|
26
|
+
) { }
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* 1: initParameters
|
|
31
|
+
*/
|
|
32
|
+
initDefafultParameters() {
|
|
33
|
+
|
|
34
|
+
let wContext: any = window;
|
|
35
|
+
// this.parameters['windowContext'] = windowContext;
|
|
36
|
+
this.windowContext = wContext;
|
|
37
|
+
|
|
38
|
+
this.supportMode = true
|
|
39
|
+
this.tenant = 'tilechat'
|
|
40
|
+
this.logLevel = 'ERROR'
|
|
41
|
+
this.persistence = 'local';
|
|
42
|
+
this.lang = 'en'
|
|
43
|
+
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
}
|
package/src/app/utils/toast.ts
CHANGED
|
@@ -4,7 +4,7 @@ export class Toast {
|
|
|
4
4
|
|
|
5
5
|
public toastController: ToastController = new ToastController()
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
constructor() {}
|
|
8
8
|
|
|
9
9
|
async presentToast(message: string, color: string, cssClass: string, duration: number = 2000, position: 'top' | 'bottom' | 'middle'= 'bottom') {
|
|
10
10
|
const toast = await this.toastController.create({
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
|
|
4
|
+
<head>
|
|
5
|
+
<meta charset="utf-8">
|
|
6
|
+
<meta name="viewport" content="width=device-width">
|
|
7
|
+
<title>replit</title>
|
|
8
|
+
</head>
|
|
9
|
+
|
|
10
|
+
<body style="height: 100%;">
|
|
11
|
+
<div id="titolo">CHAT IONIC TEST PAGE</div>
|
|
12
|
+
|
|
13
|
+
<script>
|
|
14
|
+
window.addEventListener('message', event => {
|
|
15
|
+
console.log('[CHAT-IONIC] test page event::', event)
|
|
16
|
+
})
|
|
17
|
+
</script>
|
|
18
|
+
|
|
19
|
+
<iframe id="myIFrame" frameBorder="0" width="100%" style="display: flex; height: 95vh"
|
|
20
|
+
src="http://localhost:8080/#/conversation-detail?jwt=JWT eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI1ZmQzNGU0MjQ5NjEwZTAwMzQ5ODUwNzgiLCJlbWFpbCI6ImdhYnJpZWxlLnBhbmljb0Bmcm9udGllcmUyMS5pdCIsImZpcnN0bmFtZSI6IkdhYnJpZWxlMiIsImxhc3RuYW1lIjoiUGFuaWNvIC1wcmUiLCJlbWFpbHZlcmlmaWVkIjp0cnVlLCJpYXQiOjE2OTgzMzYyMTMsImF1ZCI6Imh0dHBzOi8vdGlsZWRlc2suY29tIiwiaXNzIjoiaHR0cHM6Ly90aWxlZGVzay5jb20iLCJzdWIiOiJ1c2VyIiwianRpIjoiNjAzZGY3NDQtZWY0OS00Mjg2LWJlMWQtYWM5OGYyYTNkMTJiIn0.bof5QPQP262yCQfpeSjqyoYPkSCttg5NQFkcV8d634xzeq7wJBdhtiO7IJY6hS81a1YyXrAsxlK7RiNS-UZdYiTXR81UXurQd1fnE9jtaggB82tyNL8vmiZEOs6xh4TqO3-kkBzRxQIp74bY53fk_mu5RmNbAjIgUWEufaNDiv8"></iframe>
|
|
21
|
+
</body>
|
|
22
|
+
|
|
23
|
+
</html>
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export class DepartmentModel {
|
|
2
|
+
constructor(
|
|
3
|
+
public appId: string,
|
|
4
|
+
public createdAt: string,
|
|
5
|
+
public createdBy: string,
|
|
6
|
+
public name: string,
|
|
7
|
+
public updatedAt: string,
|
|
8
|
+
public _id: string,
|
|
9
|
+
public offline_msg: string,
|
|
10
|
+
public online_msg: string
|
|
11
|
+
) { }
|
|
12
|
+
}
|
|
@@ -36,5 +36,7 @@ export abstract class UploadService {
|
|
|
36
36
|
// functions
|
|
37
37
|
abstract initialize(): void;
|
|
38
38
|
abstract upload(userId: string, upload: UploadModel): Promise<any>;
|
|
39
|
+
abstract uploadProfile(userId: string, upload: UploadModel): Promise<any>;
|
|
39
40
|
abstract delete(userId: string, path: string): Promise<any>;
|
|
41
|
+
abstract deleteProfile(userId: string, path: string): Promise<any>
|
|
40
42
|
}
|
|
@@ -23,7 +23,6 @@ export class ChatManager {
|
|
|
23
23
|
|
|
24
24
|
BSStart: BehaviorSubject<any> = new BehaviorSubject<any>(null);
|
|
25
25
|
|
|
26
|
-
// supportMode = environment.supportMode;
|
|
27
26
|
// tenant = environment.tenant;
|
|
28
27
|
tenant: string
|
|
29
28
|
|
|
@@ -113,25 +112,6 @@ export class ChatManager {
|
|
|
113
112
|
// this.contactsSynchronizer = null;
|
|
114
113
|
}
|
|
115
114
|
|
|
116
|
-
/**
|
|
117
|
-
* invocato da user.ts al LOGIN:
|
|
118
|
-
* LOGIN:
|
|
119
|
-
* 1 - imposto lo stato di connessione utente
|
|
120
|
-
* 2 - aggiungo il token
|
|
121
|
-
* 3 - pubblico stato loggedUser come login
|
|
122
|
-
*/
|
|
123
|
-
// goOnLine(user) {
|
|
124
|
-
// if (user) {
|
|
125
|
-
// const uid = user.uid;
|
|
126
|
-
// this.loggedUser = new UserModel(uid);
|
|
127
|
-
// this.logger.('[CHAT MANAGER]goOnLine::: ', this.loggedUser);
|
|
128
|
-
// this.loadCurrentUserDetail();
|
|
129
|
-
// if (this.supportMode === false) {
|
|
130
|
-
// //this.initContactsSynchronizer();
|
|
131
|
-
// }
|
|
132
|
-
// }
|
|
133
|
-
// }
|
|
134
|
-
|
|
135
115
|
|
|
136
116
|
|
|
137
117
|
|
|
@@ -103,6 +103,62 @@ export class FirebaseUploadService extends UploadService {
|
|
|
103
103
|
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
+
public uploadProfile(userId: string, upload: UploadModel): Promise<any> {
|
|
107
|
+
const that = this;
|
|
108
|
+
const urlImagesNodeFirebase = '/profiles/' + userId + '/photo.jpg'
|
|
109
|
+
this.logger.debug('[FIREBASEUploadSERVICE] uploadProfile ', urlImagesNodeFirebase, upload.file);
|
|
110
|
+
|
|
111
|
+
// Create a root reference
|
|
112
|
+
const storageRef = firebase.storage().ref();
|
|
113
|
+
this.logger.debug('[FIREBASEUploadSERVICE] storageRef', storageRef);
|
|
114
|
+
|
|
115
|
+
// Create a reference to 'mountains.jpg'
|
|
116
|
+
const mountainsRef = storageRef.child(urlImagesNodeFirebase);
|
|
117
|
+
this.logger.debug('[FIREBASEUploadSERVICE] mountainsRef ', mountainsRef);
|
|
118
|
+
|
|
119
|
+
// const metadata = {};
|
|
120
|
+
const metadata = { name: upload.file.name, contentType: upload.file.type, contentDisposition: 'attachment; filename=' + upload.file.name };
|
|
121
|
+
|
|
122
|
+
let uploadTask = mountainsRef.put(upload.file, metadata);
|
|
123
|
+
|
|
124
|
+
return new Promise((resolve, reject) => {
|
|
125
|
+
uploadTask.on('state_changed', function progress(snapshot) {
|
|
126
|
+
// Observe state change events such as progress, pause, and resume
|
|
127
|
+
// Get task progress, including the number of bytes uploaded and the total number of bytes to be uploaded
|
|
128
|
+
var progress = (snapshot.bytesTransferred / snapshot.totalBytes) * 100;
|
|
129
|
+
that.logger.debug('[FIREBASEUploadSERVICE] Upload is ' + progress + '% done');
|
|
130
|
+
|
|
131
|
+
// ----------------------------------------------------------------------------------------------------------------------------------------------
|
|
132
|
+
// BehaviorSubject publish the upload progress state - the subscriber is in ion-conversastion-detail.component.ts > listenToUploadFileProgress()
|
|
133
|
+
// ----------------------------------------------------------------------------------------------------------------------------------------------
|
|
134
|
+
|
|
135
|
+
that.BSStateUpload.next({ upload: progress, type: upload.file.type });
|
|
136
|
+
|
|
137
|
+
switch (snapshot.state) {
|
|
138
|
+
case firebase.storage.TaskState.PAUSED: // or 'paused'
|
|
139
|
+
that.logger.debug('[FIREBASEUploadSERVICE] Upload is paused');
|
|
140
|
+
|
|
141
|
+
break;
|
|
142
|
+
case firebase.storage.TaskState.RUNNING: // or 'running'
|
|
143
|
+
that.logger.debug('[FIREBASEUploadSERVICE] Upload is running');
|
|
144
|
+
|
|
145
|
+
break;
|
|
146
|
+
}
|
|
147
|
+
}, function error(error) {
|
|
148
|
+
// Handle unsuccessful uploads
|
|
149
|
+
reject(error)
|
|
150
|
+
}, function complete() {
|
|
151
|
+
// Handle successful uploads on complete
|
|
152
|
+
that.logger.debug('[FIREBASEUploadSERVICE] Upload is complete', upload);
|
|
153
|
+
|
|
154
|
+
resolve(uploadTask.snapshot.ref.getDownloadURL())
|
|
155
|
+
// that.BSStateUpload.next({upload: upload});
|
|
156
|
+
|
|
157
|
+
});
|
|
158
|
+
})
|
|
159
|
+
|
|
160
|
+
}
|
|
161
|
+
|
|
106
162
|
public async delete(userId: string, path: string): Promise<any>{
|
|
107
163
|
const that = this;
|
|
108
164
|
const file_name_photo = 'photo.jpg';
|
|
@@ -133,6 +189,33 @@ export class FirebaseUploadService extends UploadService {
|
|
|
133
189
|
})
|
|
134
190
|
}
|
|
135
191
|
|
|
192
|
+
public async deleteProfile(userId: string, path: string): Promise<any>{
|
|
193
|
+
const that = this;
|
|
194
|
+
const file_name_photo = 'photo.jpg';
|
|
195
|
+
const file_name_thumb_photo = 'thumb_photo.jpg';
|
|
196
|
+
|
|
197
|
+
that.logger.debug('[FIREBASEUploadSERVICE] delete image for USER', userId, path);
|
|
198
|
+
|
|
199
|
+
// Create a root reference
|
|
200
|
+
const storageRef = firebase.storage().ref();
|
|
201
|
+
const ref = storageRef.child('profiles/' + userId + '/')
|
|
202
|
+
let arrayPromise = []
|
|
203
|
+
await ref.listAll().then((dir => {
|
|
204
|
+
dir.items.forEach(fileRef => arrayPromise.push(this.deleteFile(ref.fullPath, fileRef.name)));
|
|
205
|
+
})).catch(error => {
|
|
206
|
+
that.logger.error('[FIREBASEUploadSERVICE] delete: listAll error', error)
|
|
207
|
+
})
|
|
208
|
+
|
|
209
|
+
//AWAIT to return ALL the promise delete()
|
|
210
|
+
return new Promise((resolve, reject)=> {
|
|
211
|
+
Promise.all(arrayPromise).then(()=>{
|
|
212
|
+
resolve(true)
|
|
213
|
+
}).catch((error)=>{
|
|
214
|
+
reject(error)
|
|
215
|
+
})
|
|
216
|
+
})
|
|
217
|
+
}
|
|
218
|
+
|
|
136
219
|
// // ------------------------------------
|
|
137
220
|
// // Delete the file photo
|
|
138
221
|
// // ------------------------------------
|
|
@@ -78,6 +78,30 @@ export class NativeUploadService extends UploadService {
|
|
|
78
78
|
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
+
uploadProfile(userId: string, upload: UploadModel): Promise<any> {
|
|
82
|
+
this.logger.log('[NATIVE UPLOAD] - upload new photo profile ... upload', upload)
|
|
83
|
+
const headers = new HttpHeaders({
|
|
84
|
+
Authorization: this.tiledeskToken,
|
|
85
|
+
// 'Content-Type': 'multipart/form-data',
|
|
86
|
+
});
|
|
87
|
+
const requestOptions = { headers: headers };
|
|
88
|
+
const formData = new FormData();
|
|
89
|
+
formData.append('file', upload.file);
|
|
90
|
+
|
|
91
|
+
// USE IMAGE API
|
|
92
|
+
const that = this;
|
|
93
|
+
const url = this.URL_TILEDESK_IMAGES + `/users/photo?force=true&user_id=${userId}`
|
|
94
|
+
return new Promise((resolve, reject) => {
|
|
95
|
+
that.http.put(url, formData, requestOptions).subscribe(data => {
|
|
96
|
+
const downloadURL = this.URL_TILEDESK_IMAGES + '?path=' + data['thumbnail'];
|
|
97
|
+
resolve(downloadURL)
|
|
98
|
+
// that.BSStateUpload.next({upload: upload});
|
|
99
|
+
}, (error) => {
|
|
100
|
+
reject(error)
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
81
105
|
delete(userId: string, path: string): Promise<any>{
|
|
82
106
|
this.logger.log('[NATIVE UPLOAD] - delete image ... upload', userId)
|
|
83
107
|
const headers = new HttpHeaders({
|
|
@@ -99,4 +123,26 @@ export class NativeUploadService extends UploadService {
|
|
|
99
123
|
});
|
|
100
124
|
});
|
|
101
125
|
}
|
|
126
|
+
|
|
127
|
+
deleteProfile(userId: string, path: string): Promise<any>{
|
|
128
|
+
this.logger.log('[NATIVE UPLOAD] - delete image ... upload', userId)
|
|
129
|
+
const headers = new HttpHeaders({
|
|
130
|
+
Authorization: this.tiledeskToken,
|
|
131
|
+
//'Content-Type': 'multipart/form-data',
|
|
132
|
+
});
|
|
133
|
+
const requestOptions = { headers: headers };
|
|
134
|
+
|
|
135
|
+
//USE IMAGE API
|
|
136
|
+
const that = this;
|
|
137
|
+
const url = this.URL_TILEDESK_IMAGES + '/users' + '?path=' + "uploads/users/"+ userId + "/images/photo.jpg"
|
|
138
|
+
return new Promise((resolve, reject) => {
|
|
139
|
+
that.http.delete(url, requestOptions).subscribe(data => {
|
|
140
|
+
// const downloadURL = this.URL_TILEDESK_IMAGES + '?path=' + data['filename'];
|
|
141
|
+
resolve(true)
|
|
142
|
+
// that.BSStateUpload.next({upload: upload});
|
|
143
|
+
}, (error) => {
|
|
144
|
+
reject(error)
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
}
|
|
102
148
|
}
|