repo_name string | dataset string | owner string | lang string | func_name string | code string | docstring string | url string | sha string |
|---|---|---|---|---|---|---|---|---|
design-studio | github_2023 | Tiledesk | typescript | FirebaseAuthService.sendPasswordResetEmail | sendPasswordResetEmail(email: string): any {
const that = this;
return this.firebase.auth().sendPasswordResetEmail(email).then(() => {
that.logger.debug('[FIREBASEAuthSERVICE] firebase-send-password-reset-email');
// that.firebaseSendPasswordResetEmail.next(email);
}).catch((error) => {
that.logger.error('[FIREBASEAuthSERVICE] sendPasswordResetEmail error: ', error);
});
} | /**
* FIREBASE: sendPasswordResetEmail
*/ | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/firebase/firebase-auth-service.ts#L169-L177 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | FirebaseAuthService.signOut | private signOut(): Promise<boolean> {
const that = this;
return new Promise((resolve, reject)=> {that.firebase.auth().signOut().then(() => {
that.logger.debug('[FIREBASEAuthSERVICE] firebase-sign-out');
// cancello token
// this.appStorage.removeItem('tiledeskToken');
//localStorage.removeItem('firebaseToken');
that.BSSignOut.next(true);
resolve(true)
}).catch((error) => {
resolve(false)
that.logger.error('[FIREBASEAuthSERVICE] signOut error: ', error);
});
});
} | /**
* FIREBASE: signOut
*/ | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/firebase/firebase-auth-service.ts#L182-L196 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | FirebaseAuthService.delete | delete() {
const that = this;
this.firebase.auth().currentUser.delete().then(() => {
that.logger.debug('[FIREBASEAuthSERVICE] firebase-current-user-delete');
// that.firebaseCurrentUserDelete.next();
}).catch((error) => {
that.logger.error('[FIREBASEAuthSERVICE] delete error: ', error);
});
} | /**
* FIREBASE: currentUser delete
*/ | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/firebase/firebase-auth-service.ts#L202-L210 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | FirebaseAuthService.createCustomToken | createCustomToken(tiledeskToken: string) {
const headers = new HttpHeaders({
'Content-type': 'application/json',
Authorization: tiledeskToken
});
const responseType = 'text';
const postData = {};
const that = this;
this.http.post(this.URL_TILEDESK_CREATE_CUSTOM_TOKEN, postData, { headers, responseType }).subscribe(data => {
that.firebaseToken = data;
//localStorage.setItem('firebaseToken', that.firebaseToken);
that.signInFirebaseWithCustomToken(data)
}, error => {
that.logger.error('[FIREBASEAuthSERVICE] createFirebaseCustomToken ERR ', error)
});
} | /**
*
* @param token
*/ | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/firebase/firebase-auth-service.ts#L219-L234 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | FirebaseConversationHandler.initialize | async initialize(recipientId: string, recipientFullName: string, loggedUser: UserModel, tenant: string, translationMap: Map<string, string>) {
this.logger.log('[FIREBASEConversationHandlerSERVICE] initWithRecipient', recipientId, recipientFullName, loggedUser, tenant, translationMap)
this.recipientId = recipientId;
this.recipientFullname = recipientFullName;
this.loggedUser = loggedUser;
if (loggedUser) {
this.senderId = loggedUser.uid;
}
this.tenant = tenant;
this.translationMap = translationMap;
this.listSubsriptions = [];
this.CLIENT_BROWSER = navigator.userAgent;
this.conversationWith = recipientId;
this.messages = [];
// this.attributes = this.setAttributes();
const { default: firebase} = await import("firebase/app");
await Promise.all([import("firebase/database")]);
this.firebase = firebase
this.ref = this.firebase.database['Query'];
} | /**
* inizializzo conversation handler
*/ | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/firebase/firebase-conversation-handler.ts#L66-L86 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | FirebaseConversationHandler.connect | connect() {
this.lastDate = '';
const that = this;
this.urlNodeFirebase = conversationMessagesRef(this.tenant, this.loggedUser.uid);
this.urlNodeFirebase = this.urlNodeFirebase + this.conversationWith;
this.logger.debug('[FIREBASEConversationHandlerSERVICE] urlNodeFirebase *****', this.urlNodeFirebase);
const firebaseMessages = this.firebase.database().ref(this.urlNodeFirebase);
this.ref = firebaseMessages.orderByChild('timestamp').limitToLast(100);
this.ref.on('child_added', (childSnapshot) => {
that.logger.debug('[FIREBASEConversationHandlerSERVICE] >>>>>>>>>>>>>> child_added: ', childSnapshot.val())
const msg: MessageModel = childSnapshot.val();
msg.uid = childSnapshot.key;
that.addedNew(msg);
});
this.ref.on('child_changed', (childSnapshot) => {
that.logger.debug('[FIREBASEConversationHandlerSERVICE] >>>>>>>>>>>>>> child_changed: ', childSnapshot.val())
that.changed(childSnapshot);
});
this.ref.on('child_removed', (childSnapshot) => {
that.removed(childSnapshot);
});
} | /**
* mi connetto al nodo messages
* recupero gli ultimi 100 messaggi
* creo la reference
* mi sottoscrivo a change, removed, added
*/ | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/firebase/firebase-conversation-handler.ts#L94-L116 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | FirebaseConversationHandler.sendMessage | sendMessage(
msg: string,
typeMsg: string,
metadataMsg: string,
conversationWith: string,
conversationWithFullname: string,
sender: string,
senderFullname: string,
channelType: string,
attributes: any
) {
const that = this;
if (!channelType || channelType === 'undefined') {
channelType = TYPE_DIRECT;
}
const firebaseMessagesCustomUid = this.firebase.database().ref(this.urlNodeFirebase);
// const key = messageRef.key;
const lang = document.documentElement.lang;
const recipientFullname = conversationWithFullname;
const timestamp = this.firebase.database.ServerValue.TIMESTAMP
const message = new MessageModel(
'',
lang,
conversationWith,
recipientFullname,
sender,
senderFullname,
0,
metadataMsg,
msg,
timestamp,
//dateSendingMessage,
typeMsg,
attributes,
channelType,
false
);
const messageRef = firebaseMessagesCustomUid.push({
language: lang,
recipient: conversationWith,
recipient_fullname: recipientFullname,
sender: sender,
sender_fullname: senderFullname,
status: 0,
metadata: metadataMsg,
text: msg,
timestamp: this.firebase.database.ServerValue.TIMESTAMP,
type: typeMsg,
attributes: attributes,
channel_type: channelType
// isSender: true
});
// const message = new MessageModel(
// key,
// language, // language
// conversationWith, // recipient
// recipientFullname, // recipient_full_name
// sender, // sender
// senderFullname, // sender_full_name
// 0, // status
// metadata, // metadata
// msg, // text
// 0, // timestamp
// type, // type
// this.attributes, // attributes
// channelType, // channel_type
// true // is_sender
// );
this.logger.debug('[FIREBASEConversationHandlerSERVICE] sendMessage --> messages: ', this.messages);
this.logger.debug('[FIREBASEConversationHandlerSERVICE] sendMessage --> senderFullname: ', senderFullname);
this.logger.debug('[FIREBASEConversationHandlerSERVICE] sendMessage --> sender: ', sender);
this.logger.debug('[FIREBASEConversationHandlerSERVICE] sendMessage --> SEND MESSAGE: ', msg, channelType);
return message
} | /**
* bonifico url in testo messaggio
* recupero time attuale
* recupero lingua app
* recupero senderFullname e recipientFullname
* aggiungo messaggio alla reference
* @param msg
* @param conversationWith
* @param conversationWithDetailFullname
*/ | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/firebase/firebase-conversation-handler.ts#L129-L204 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | FirebaseConversationHandler.dispose | dispose() {
// this.ref.off();
} | /**
* dispose reference della conversazione
*/ | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/firebase/firebase-conversation-handler.ts#L209-L211 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | FirebaseConversationHandler.added | private added(childSnapshot: any) {
const msg = this.messageGenerate(childSnapshot);
// msg.attributes && msg.attributes['subtype'] === 'info'
if (this.skipMessage && messageType(MESSAGE_TYPE_INFO, msg)) {
return;
}
if(!this.skipMessage && messageType(MESSAGE_TYPE_INFO, msg)) {
this.messageInfo.next(msg)
}
this.addRepalceMessageInArray(childSnapshot.key, msg);
this.messageAdded.next(msg);
} | /** */ | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/firebase/firebase-conversation-handler.ts#L248-L259 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | FirebaseConversationHandler.changed | private changed(childSnapshot: any) {
const msg = this.messageGenerate(childSnapshot);
// imposto il giorno del messaggio per visualizzare o nascondere l'header data
// msg.attributes && msg.attributes['subtype'] === 'info'
if (this.skipMessage && messageType(MESSAGE_TYPE_INFO, msg)) {
return;
}
this.addRepalceMessageInArray(childSnapshot.key, msg);
this.messageChanged.next(msg);
} | /** */ | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/firebase/firebase-conversation-handler.ts#L279-L289 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | FirebaseConversationHandler.removed | private removed(childSnapshot: any) {
const index = searchIndexInArrayForUid(this.messages, childSnapshot.key);
// controllo superfluo sarà sempre maggiore
if (index > -1) {
this.messages.splice(index, 1);
this.messageRemoved.next(childSnapshot.key);
}
} | /** */ | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/firebase/firebase-conversation-handler.ts#L292-L299 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | FirebaseConversationHandler.messageGenerate | private messageGenerate(childSnapshot: any) {
const msg: MessageModel = childSnapshot.val();
msg.uid = childSnapshot.key;
msg.text = msg.text.trim() //remove black msg with only spaces
// controllo fatto per i gruppi da rifattorizzare
if (!msg.sender_fullname || msg.sender_fullname === 'undefined') {
msg.sender_fullname = msg.sender;
}
// bonifico messaggio da url
// if (msg.type === 'text') {
// msg.text = htmlEntities(msg.text)
// msg.text = replaceEndOfLine(msg.text)
// }
// verifico che il sender è il logged user
msg.isSender = isSender(msg.sender, this.loggedUser.uid);
//check if message contains only an emojii
// msg.emoticon = isEmojii(msg.text)
// traduco messaggi se sono del server
if (messageType(MESSAGE_TYPE_INFO, msg)) {
this.translateInfoSupportMessages(msg);
}
return msg;
} | /** */ | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/firebase/firebase-conversation-handler.ts#L302-L327 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | FirebaseConversationHandler.addRepalceMessageInArray | private addRepalceMessageInArray(key: string, msg: MessageModel) {
const index = searchIndexInArrayForUid(this.messages, key);
if (index > -1) {
this.messages.splice(index, 1, msg);
} else {
this.messages.splice(0, 0, msg);
}
this.messages.sort(compareValues('timestamp', 'asc'));
// aggiorno stato messaggio, questo stato indica che è stato consegnato al client e NON che è stato letto
this.setStatusMessage(msg, this.conversationWith);
} | /** */ | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/firebase/firebase-conversation-handler.ts#L355-L365 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | FirebaseConversationHandler.translateInfoSupportMessages | private translateInfoSupportMessages(message: MessageModel) {
// check if the message attributes has parameters and it is of the "MEMBER_JOINED_GROUP" type
const INFO_SUPPORT_USER_ADDED_SUBJECT = this.translationMap.get('INFO_SUPPORT_USER_ADDED_SUBJECT');
const INFO_SUPPORT_USER_ADDED_YOU_VERB = this.translationMap.get('INFO_SUPPORT_USER_ADDED_YOU_VERB');
const INFO_SUPPORT_USER_ADDED_COMPLEMENT = this.translationMap.get('INFO_SUPPORT_USER_ADDED_COMPLEMENT');
const INFO_SUPPORT_USER_ADDED_VERB = this.translationMap.get('INFO_SUPPORT_USER_ADDED_VERB');
const INFO_SUPPORT_CHAT_REOPENED = this.translationMap.get('INFO_SUPPORT_CHAT_REOPENED');
const INFO_SUPPORT_CHAT_CLOSED = this.translationMap.get('INFO_SUPPORT_CHAT_CLOSED');
const INFO_SUPPORT_LEAD_UPDATED = this.translationMap.get('INFO_SUPPORT_LEAD_UPDATED');
const INFO_SUPPORT_MEMBER_LEFT_GROUP = this.translationMap.get('INFO_SUPPORT_MEMBER_LEFT_GROUP');
const INFO_A_NEW_SUPPORT_REQUEST_HAS_BEEN_ASSIGNED_TO_YOU = this.translationMap.get('INFO_A_NEW_SUPPORT_REQUEST_HAS_BEEN_ASSIGNED_TO_YOU');
const INFO_SUPPORT_LIVE_PAGE = this.translationMap.get('INFO_SUPPORT_LIVE_PAGE');
if (message.attributes.messagelabel
&& message.attributes.messagelabel.parameters
&& message.attributes.messagelabel.key === MEMBER_JOINED_GROUP
) {
let subject: string;
let verb: string;
let complement: string;
if (message.attributes.messagelabel.parameters.member_id === this.loggedUser.uid) {
subject = INFO_SUPPORT_USER_ADDED_SUBJECT;
verb = INFO_SUPPORT_USER_ADDED_YOU_VERB;
complement = INFO_SUPPORT_USER_ADDED_COMPLEMENT;
} else {
if (message.attributes.messagelabel.parameters.fullname) {
// other user has been added to the group (and he has a fullname)
subject = message.attributes.messagelabel.parameters.fullname;
verb = INFO_SUPPORT_USER_ADDED_VERB;
complement = INFO_SUPPORT_USER_ADDED_COMPLEMENT;
} else {
// other user has been added to the group (and he has not a fullname, so use hes useruid)
subject = message.attributes.messagelabel.parameters.member_id;
verb = INFO_SUPPORT_USER_ADDED_VERB;
complement = INFO_SUPPORT_USER_ADDED_COMPLEMENT;
}
}
message.text = subject + ' ' + verb + ' ' + complement;
} else if ((message.attributes.messagelabel && message.attributes.messagelabel.key === CHAT_REOPENED)) {
message.text = INFO_SUPPORT_CHAT_REOPENED;
} else if ((message.attributes.messagelabel && message.attributes.messagelabel.key === CHAT_CLOSED)) {
message.text = INFO_SUPPORT_CHAT_CLOSED;
} else if ((message.attributes && message.attributes.messagelabel && message.attributes.messagelabel.key === TOUCHING_OPERATOR) && message.sender === "system") {
// console.log('FIREBASEConversationHandlerSERVICE message text', message.text)
const textAfterColon = message.text.split(":")[1]
// console.log('FIREBASEConversationHandlerSERVICE message text - textAfterColon', textAfterColon)
if (textAfterColon !== undefined) {
message.text = INFO_A_NEW_SUPPORT_REQUEST_HAS_BEEN_ASSIGNED_TO_YOU + ': ' + textAfterColon;
}
} else if ((message.attributes.messagelabel && message.attributes.messagelabel.key === LEAD_UPDATED)) {
message.text = INFO_SUPPORT_LEAD_UPDATED;
} else if ((message.attributes.messagelabel && message.attributes.messagelabel.key === MEMBER_LEFT_GROUP)) {
let subject: string;
if (message.attributes.messagelabel.parameters.fullname) {
subject = message.attributes.messagelabel.parameters.fullname;
}else{
subject = message.attributes.messagelabel.parameters.member_id;
}
message.text = subject + ' ' + INFO_SUPPORT_MEMBER_LEFT_GROUP ;
} else if(message.attributes.messagelabel && message.attributes.messagelabel.key === LIVE_PAGE){
let sourceUrl: string = '';
if(message.attributes && message.attributes.sourcePage){
sourceUrl = message.attributes.sourcePage
}
if(message.attributes && message.attributes.sourceTitle){
sourceUrl = '['+message.attributes.sourceTitle+']('+sourceUrl+')'
}
message.text= INFO_SUPPORT_LIVE_PAGE + ': ' + sourceUrl
}
} | /** */ | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/firebase/firebase-conversation-handler.ts#L368-L438 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | FirebaseConversationHandler.setStatusMessage | private setStatusMessage(msg: MessageModel, conversationWith: string) {
if (msg.status < MSG_STATUS_RECEIVED) {
if (msg.sender !== this.loggedUser.uid && msg.status < MSG_STATUS_RECEIVED) {
const urlNodeMessagesUpdate = this.urlNodeFirebase + '/' + msg.uid;
this.logger.debug('[FIREBASEConversationHandlerSERVICE] update message status', urlNodeMessagesUpdate);
this.firebase.database().ref(urlNodeMessagesUpdate).update({ status: MSG_STATUS_RECEIVED });
}
}
} | /**
* aggiorno lo stato del messaggio
* questo stato indica che è stato consegnato al client e NON che è stato letto
* se il messaggio NON è stato inviato da loggedUser AGGIORNO stato a 200
* @param item
* @param conversationWith
*/ | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/firebase/firebase-conversation-handler.ts#L448-L456 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | FirebaseConversationHandler.isValidField | private isValidField(field: any): boolean {
return (field === null || field === undefined) ? false : true;
} | /**
*
* @param field
*/ | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/firebase/firebase-conversation-handler.ts#L497-L499 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | FirebaseConversationsHandler.initialize | async initialize(tenant: string,userId: string,translationMap: Map<string, string>) {
this.tenant = tenant;
this.loggedUserId = userId;
this.translationMap = translationMap;
this.conversations = [];
this.isConversationClosingMap = new Map();
//this.databaseProvider.initialize(userId, this.tenant);
//this.getConversationsFromStorage();
this.BASE_URL = this.appConfig.getConfig().firebaseConfig.chat21ApiUrl;
this.BASE_URL_DATABASE = this.appConfig.getConfig().firebaseConfig.databaseURL;
const { default: firebase} = await import("firebase/app");
await Promise.all([import("firebase/database"), import("firebase/auth")]);
this.firebase = firebase
this.ref = this.firebase.database['Query'];
} | /**
* inizializzo conversations handler
*/ | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/firebase/firebase-conversations-handler.ts#L69-L84 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | FirebaseConversationsHandler.subscribeToConversations | subscribeToConversations(callback) {
const that = this;
const urlNodeFirebase = conversationsPathForUserId(this.tenant, this.loggedUserId);
this.logger.debug('[FIREBASEConversationsHandlerSERVICE] SubscribeToConversations conversations::ACTIVE urlNodeFirebase', urlNodeFirebase)
this.ref = this.firebase.database().ref(urlNodeFirebase).orderByChild('timestamp').limitToLast(200);
this.ref.on('child_changed', (childSnapshot) => {
that.changed(childSnapshot);
});
this.ref.on('child_removed', (childSnapshot) => {
that.removed(childSnapshot);
});
this.ref.on('child_added', (childSnapshot) => {
that.added(childSnapshot);
});
setTimeout(() => {
callback()
}, 2000);
// SET AUDIO
// this.audio = new Audio();
// this.audio.src = URL_SOUND;
// this.audio.load();
} | //---------------------------------------------------------------------------------- | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/firebase/firebase-conversations-handler.ts#L120-L142 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | FirebaseConversationsHandler.countIsNew | countIsNew(): number {
let num = 0;
this.conversations.forEach((element) => {
if (element.is_new === true) {
num++;
}
});
return num;
} | /**
* restituisce il numero di conversazioni nuove
*/ | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/firebase/firebase-conversations-handler.ts#L186-L194 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | FirebaseConversationsHandler.getClosingConversation | getClosingConversation(conversationId: string) {
return this.isConversationClosingMap[conversationId];
} | /**
* Returns the status of the conversations with conversationId from isConversationClosingMap
* @param conversationId the conversation id
* @returns true if the conversation is waiting to be closed, false otherwise
*/ | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/firebase/firebase-conversations-handler.ts#L209-L211 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | FirebaseConversationsHandler.setClosingConversation | setClosingConversation(conversationId: string, status: boolean) {
this.isConversationClosingMap[conversationId] = status;
} | /**
* Add the conversation with conversationId to the isConversationClosingMap
* @param conversationId the id of the conversation of which it wants to save the state
* @param status true if the conversation is waiting to be closed, false otherwise
*/ | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/firebase/firebase-conversations-handler.ts#L218-L220 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | FirebaseConversationsHandler.deleteClosingConversation | deleteClosingConversation(conversationId: string) {
this.isConversationClosingMap.delete(conversationId);
} | /**
* Delete the conversation with conversationId from the isConversationClosingMap
* @param conversationId the id of the conversation of which is wants to delete
*/ | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/firebase/firebase-conversations-handler.ts#L226-L228 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | FirebaseConversationsHandler.archiveConversation | archiveConversation(conversationId: string) {
const that = this
this.setClosingConversation(conversationId, true);
this.setConversationRead(conversationId)
const index = searchIndexInArrayForUid(this.conversations, conversationId);
// if (index > -1) {
// this.conversations.splice(index, 1);
// fare chiamata delete per rimuoverle la conversazione da remoto
this.deleteConversation(conversationId, function (response) {
that.logger.debug('[FIREBASEConversationsHandlerSERVICE] ARCHIVE-CONV', response)
if (response === 'success') {
if (index > -1) {
that.conversations.splice(index, 1);
}
} else if (response === 'error') {
that.setClosingConversation(conversationId, false);
}
})
// }
} | // -------->>>> ARCHIVE CONVERSATION SECTION START <<<<---------------// | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/firebase/firebase-conversations-handler.ts#L231-L251 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | FirebaseConversationsHandler.getConversationDetail | public getConversationDetail(conversationId: string, callback: (conv: ConversationModel) => void): void {
// fare promise o callback ??
const conversation = this.conversations.find(item => item.uid === conversationId);
this.logger.debug('[FIREBASEConversationsHandlerSERVICE] conversations *****: ', this.conversations)
this.logger.debug('[FIREBASEConversationsHandlerSERVICE] getConversationDetail *****: ', conversation)
if (conversation) {
callback(conversation)
// return conversationSelected
// this.BSConversationDetail.next(conversationSelected);
} else {
// const urlNodeFirebase = '/apps/' + this.tenant + '/users/' + this.loggedUserId + '/conversations/' + conversationId;
const urlNodeFirebase = conversationsPathForUserId(this.tenant, this.loggedUserId) // + '/' + conversationId;
this.logger.debug('[FIREBASEConversationsHandlerSERVICE] conversationDetail urlNodeFirebase *****', urlNodeFirebase)
const firebaseMessages = this.firebase.database().ref(urlNodeFirebase);
// if(this.subscribe){
// this.logger.log('[FIREBASEConversationsHandlerSERVICE] getConversationDetail ALREADY SUBSCRIBED')
// return;
// }
this.subscribe = firebaseMessages.on('value', (snap) => {
const childSnapshot = snap.child('/'+conversationId)
if(!childSnapshot.exists()){
this.logger.log('[FIREBASEConversationsHandlerSERVICE] getConversationDetail conversation NOT exist', conversationId)
callback(null)
} else {
const childData: ConversationModel = childSnapshot.val();
this.logger.debug('[FIREBASEConversationsHandlerSERVICE] getConversationDetail conversation exist', childSnapshot.val(), childSnapshot.key)
if (childSnapshot && childSnapshot.key && childData) {
childData.uid = childSnapshot.key;
const conversation = this.completeConversation(childData);
if (conversation) {
callback(conversation)
} else {
callback(null)
}
}
// this.BSConversationDetail.next(conversation);
}
// const childData: ConversationModel = childSnapshot.val();
// this.logger.debug('[FIREBASEConversationsHandlerSERVICE] conversationDetail childSnapshot *****', childSnapshot.val())
// if (childSnapshot && childSnapshot.key && childData) {
// childData.uid = childSnapshot.key;
// const conversation = this.completeConversation(childData);
// if (conversation) {
// callback(conversation)
// } else {
// callback(null)
// }
// }
// this.BSConversationDetail.next(conversation);
});
}
} | // -------->>>> ARCHIVE CONVERSATION SECTION END <<<<---------------// | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/firebase/firebase-conversations-handler.ts#L307-L360 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | FirebaseConversationsHandler.dispose | dispose() {
this.conversations = [];
this.uidConvSelected = '';
//this.ref.off();
// this.ref.off("child_changed");
// this.ref.off("child_removed");
// this.ref.off("child_added");
this.logger.debug('[FIREBASEConversationsHandlerSERVICE] DISPOSE::: ', this.ref)
} | /**
* dispose reference di conversations
*/ | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/firebase/firebase-conversations-handler.ts#L364-L372 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | FirebaseConversationsHandler.conversationGenerate | private conversationGenerate(childSnapshot: any): boolean {
const childData: ConversationModel = childSnapshot.val();
childData.uid = childSnapshot.key;
const conversation = this.completeConversation(childData);
if (this.isValidConversation(conversation)) {
this.setClosingConversation(childSnapshot.key, false);
const index = searchIndexInArrayForUid(this.conversations, conversation.uid);
if (index > -1) {
this.conversations.splice(index, 1, conversation);
} else {
this.conversations.splice(0, 0, conversation);
}
//this.databaseProvider.setConversation(conversation);
this.conversations.sort(compareValues('timestamp', 'desc'));
return true;
} else {
return false;
}
} | // */ | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/firebase/firebase-conversations-handler.ts#L397-L415 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | FirebaseConversationsHandler.added | private added(childSnapshot: any) {
if (this.conversationGenerate(childSnapshot)) {
const index = searchIndexInArrayForUid(this.conversations, childSnapshot.key);
if (index > -1) {
const conversationAdded = this.conversations[index]
this.conversationAdded.next(conversationAdded);
}
} else {
this.logger.error('[FIREBASEConversationsHandlerSERVICE]ADDED::conversations with conversationId: ', childSnapshot.key, 'is not valid')
}
} | //TODO-GAB: ora emit singola conversation e non dell'intero array di conversations | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/firebase/firebase-conversations-handler.ts#L456-L467 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | FirebaseConversationsHandler.changed | private changed(childSnapshot: any) {
const oldConversation = this.conversations[searchIndexInArrayForUid(this.conversations, childSnapshot.key)]
//skip info message updates
if(messageType(MESSAGE_TYPE_INFO, childSnapshot.val()) ){
return;
}
if (this.conversationGenerate(childSnapshot)) {
const index = searchIndexInArrayForUid(this.conversations, childSnapshot.key);
if (index > -1) {
const conversationChanged = this.conversations[index]
this.conversationChanged.next(conversationChanged);
this.conversationChangedDetailed.next({value: conversationChanged, previousValue: oldConversation});
}
} else {
this.logger.error('[FIREBASEConversationsHandlerSERVICE]CHANGED::conversations with conversationId: ', childSnapshot.key, 'is not valid')
}
} | //TODO-GAB: ora emit singola conversation e non dell'intero array di conversations | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/firebase/firebase-conversations-handler.ts#L480-L496 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | FirebaseConversationsHandler.removed | private removed(childSnapshot: any) {
const index = searchIndexInArrayForUid(this.conversations, childSnapshot.key);
if (index > -1) {
const conversationRemoved = this.conversations[index]
this.conversations.splice(index, 1);
// this.conversations.sort(compareValues('timestamp', 'desc'));
//this.databaseProvider.removeConversation(childSnapshot.key);
this.conversationRemoved.next(conversationRemoved);
}
// remove the conversation from the isConversationClosingMap
this.deleteClosingConversation(childSnapshot.key);
} | //TODO-GAB: ora emit singola conversation e non dell'intero array di conversations | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/firebase/firebase-conversations-handler.ts#L506-L517 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | FirebaseConversationsHandler.completeConversation | private completeConversation(conv): ConversationModel {
this.logger.debug('[FIREBASEConversationsHandlerSERVICE] completeConversation --> conv from firebase', conv)
conv.selected = false;
if (!conv.sender_fullname || conv.sender_fullname === 'undefined' || conv.sender_fullname.trim() === '') {
conv.sender_fullname = conv.sender;
}
if (!conv.recipient_fullname || conv.recipient_fullname === 'undefined' || conv.recipient_fullname.trim() === '') {
conv.recipient_fullname = conv.recipient;
}
let conversation_with_fullname = conv.sender_fullname;
let conversation_with = conv.sender;
if (conv.sender === this.loggedUserId) {
conversation_with = conv.recipient;
conversation_with_fullname = conv.recipient_fullname;
conv.sender_fullname = this.translationMap.get('YOU')
// conv.last_message_text = YOU + conv.last_message_text;
// } else if (conv.channel_type === TYPE_GROUP) {
} else if (isGroup(conv)) {
// conversation_with_fullname = conv.sender_fullname;
// conv.last_message_text = conv.last_message_text;
conversation_with = conv.recipient;
conversation_with_fullname = conv.recipient_fullname;
}
// Fixes the bug: if a snippet of code is pasted and sent it is not displayed correctly in the convesations list
// conv.time_last_message = this.getTimeLastMessage(conv.timestamp);
conv.conversation_with = conversation_with;
conv.conversation_with_fullname = conversation_with_fullname;
conv.status = this.setStatusConversation(conv.sender, conv.uid);
conv.avatar = avatarPlaceholder(conversation_with_fullname);
conv.color = getColorBck(conversation_with_fullname);
//conv.image = this.imageRepo.getImagePhotoUrl(conversation_with);
// getImageUrlThumbFromFirebasestorage(conversation_with, this.FIREBASESTORAGE_BASE_URL_IMAGE, this.urlStorageBucket);
return conv;
} | /**
* Completo conversazione aggiungendo:
* 1 - nel caso in cui sender_fullname e recipient_fullname sono vuoti, imposto i rispettivi id come fullname,
* in modo da avere sempre il campo fullname popolato
* 2 - imposto conversation_with e conversation_with_fullname con i valori del sender o al recipient,
* a seconda che il sender corrisponda o meno all'utente loggato. Aggiungo 'tu:' se il sender coincide con il loggedUser
* Se il sender NON è l'utente loggato, ma è una conversazione di tipo GROUP, il conversation_with_fullname
* sarà uguale al recipient_fullname
* 3 - imposto stato conversazione, che indica se ci sono messaggi non letti nella conversazione
* 4 - imposto il tempo trascorso tra l'ora attuale e l'invio dell'ultimo messaggio
* 5 - imposto avatar, colore e immagine
* @param conv
*/ | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/firebase/firebase-conversations-handler.ts#L533-L566 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | FirebaseConversationsHandler.setStatusConversation | private setStatusConversation(sender: string, uid: string): string {
let status = '0'; // letto
if (sender === this.loggedUserId || uid === this.uidConvSelected) {
status = '0';
} else {
status = '1'; // non letto
}
return status;
} | /** */ | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/firebase/firebase-conversations-handler.ts#L569-L577 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | FirebaseConversationsHandler.isValidConversation | private isValidConversation(convToCheck: ConversationModel): boolean {
if (!this.isValidField(convToCheck.uid)) {
return false;
}
if (!this.isValidField(convToCheck.is_new)) {
return false;
}
if (!this.isValidField(convToCheck.last_message_text)) {
return false;
}
if (!this.isValidField(convToCheck.recipient)) {
return false;
}
if (!this.isValidField(convToCheck.recipient_fullname)) {
return false;
}
if (!this.isValidField(convToCheck.sender)) {
return false;
}
if (!this.isValidField(convToCheck.sender_fullname)) {
return false;
}
if (!this.isValidField(convToCheck.status)) {
return false;
}
if (!this.isValidField(convToCheck.timestamp)) {
return false;
}
if (!this.isValidField(convToCheck.channel_type)) {
return false;
}
return true;
} | /**
* check if the conversations is valid or not
*/ | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/firebase/firebase-conversations-handler.ts#L582-L615 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | FirebaseConversationsHandler.isValidField | private isValidField(field: any): boolean {
return (field === null || field === undefined) ? false : true;
} | /**
*
* @param field
*/ | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/firebase/firebase-conversations-handler.ts#L621-L623 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | FirebaseGroupsHandler.initialize | async initialize(tenant: string, loggedUserId: string) {
this.tenant = tenant;
this.loggedUserId = loggedUserId;
this.BASE_URL = this.appConfig.getConfig().firebaseConfig.chat21ApiUrl;
this.logger.debug('[FIREBASEGroupHandlerSERVICE] initialize', this.tenant, this.loggedUserId);
const { default: firebase} = await import("firebase/app");
await Promise.all([import("firebase/database")]);
this.firebase = firebase
this.ref = this.firebase.database['Query'];
} | /**
* inizializzo groups handler
*/ | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/firebase/firebase-groups-handler.ts#L62-L72 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | FirebaseGroupsHandler.connect | connect() {
//********* NOT IN USE ********** */
const that = this;
const urlNodeGroups = '/apps/' + this.tenant + '/users/' + this.loggedUserId + '/groups';
this.logger.debug('[FIREBASEGroupHandlerSERVICE] connect -------> groups::', urlNodeGroups)
this.ref = this.firebase.database().ref(urlNodeGroups)
this.ref.on('child_added', (childSnapshot) => {
that.logger.debug('[FIREBASEGroupHandlerSERVICE] child_added ------->', childSnapshot.val())
// that.added(childSnapshot);
});
this.ref.on('child_changed', (childSnapshot) => {
that.logger.debug('[FIREBASEGroupHandlerSERVICE] child_changed ------->', childSnapshot.val())
// that.changed(childSnapshot);
});
this.ref.on('child_removed', (childSnapshot) => {
that.logger.debug('[FIREBASEGroupHandlerSERVICE] child_removed ------->', childSnapshot.val())
// that.removed(childSnapshot);
});
} | /**
* mi connetto al nodo groups
* creo la reference
* mi sottoscrivo a change, removed, added
*/ | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/firebase/firebase-groups-handler.ts#L79-L97 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | FirebaseGroupsHandler.getDetail | getDetail(groupId: string, callback?: (group: GroupModel)=>void): Promise<GroupModel>{
const urlNodeGroupById = '/apps/' + this.tenant + '/users/' + this.loggedUserId + '/groups/' + groupId;
this.logger.debug('[FIREBASEGroupHandlerSERVICE] getDetail -------> urlNodeGroupById::', urlNodeGroupById)
const ref = this.firebase.database().ref(urlNodeGroupById)
return new Promise((resolve) => {
ref.off()
ref.on('value', (childSnapshot) => {
const group: GroupModel = childSnapshot.val();
group.uid = childSnapshot.key
// that.BSgroupDetail.next(group)
if (callback) {
callback(group)
}
resolve(group)
});
});
} | /**
* mi connetto al nodo groups/GROUPID
* creo la reference
* mi sottoscrivo a value
*/ | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/firebase/firebase-groups-handler.ts#L104-L121 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | FirebaseGroupsHandler.create | create(groupName: string, members: [string], callback?: (res: any, error: any) => void): Promise<any> {
var that = this;
let listMembers = {};
members.forEach(member => {
listMembers[member] = 1
});
return new Promise((resolve, reject) =>{
this.getFirebaseToken((error, idToken) => {
that.logger.debug('[FIREBASEGroupHandlerSERVICE] CREATE GROUP idToken', idToken, error)
if (idToken) {
const httpOptions = {
headers: new HttpHeaders({
'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + idToken,
})
}
const body = {
"group_name": groupName,
"group_members": listMembers
}
const url = that.BASE_URL + '/api/' + that.tenant + '/groups'
that.http.post(url, body, httpOptions).toPromise().then((res) => {
callback(res, null);
resolve(res)
}).catch(function (error) {
// Handle error
that.logger.error('[FIREBASEGroupHandlerSERVICE] createGROUP error: ', error);
callback(null, error);
reject(error);
});
}else{
callback(null, error)
reject(error)
}
});
});
} | // } | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/firebase/firebase-groups-handler.ts#L162-L200 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | FirebaseGroupsHandler.getFirebaseToken | private getFirebaseToken(callback) {
const firebase_currentUser = this.firebase.auth().currentUser;
this.logger.debug('[FIREBASEGroupHandlerSERVICE] // firebase current user ', firebase_currentUser);
if (firebase_currentUser) {
const that = this;
firebase_currentUser.getIdToken(/* forceRefresh */ true)
.then(function (idToken) {
// qui richiama la callback
callback(null, idToken);
}).catch(function (error) {
// Handle error
that.logger.error('[FIREBASEGroupHandlerSERVICE] ERROR -> idToken.', error);
callback(error, null);
});
}
} | // // -------->>>> PRIVATE METHOD SECTION START <<<<---------------// | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/firebase/firebase-groups-handler.ts#L279-L294 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | FirebaseImageRepoService.getImagePhotoUrl | getImagePhotoUrl(uid: string): string {
this.baseImageURL = this.getImageBaseUrl()
let sender_id = '';
if (uid && uid.includes('bot_')) {
sender_id = uid.slice(4)
} else {
sender_id = uid
}
const firebase_photo = '/o/profiles%2F'+ sender_id + '%2Fphoto.jpg?alt=media'
const firebase_thumbnail = '/o/profiles%2F'+ sender_id + '%2Fthumb_photo.jpg?alt=media'
const imageurl = this.baseImageURL + this.firebase.storage().ref().bucket + firebase_thumbnail
return imageurl;
} | /**
* @param uid
*/ | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/firebase/firebase-image-repo.ts#L31-L43 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | FirebasePresenceService.initialize | public async initialize(tenant: string) {
// this.tenant = this.getTenant();
this.tenant = tenant;
this.logger.debug('[FIREBASEPresenceSERVICE] initialize this.tenant', this.tenant);
this.urlNodePresence = '/apps/' + this.tenant + '/presence/';
const { default: firebase} = await import("firebase/app");
await Promise.all([import("firebase/database")]);
this.firebase = firebase
return;
} | /**
*
*/ | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/firebase/firebase-presence.service.ts#L41-L51 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | FirebasePresenceService.userIsOnline | public userIsOnline(userid: string): Observable<any> {
const that = this;
let local_BSIsOnline = new BehaviorSubject<any>(null);
const urlNodeConnections = this.urlNodePresence + userid + '/connections';
this.logger.debug('[FIREBASEPresenceSERVICE] userIsOnline: ', urlNodeConnections);
const connectionsRef = this.firebase.database().ref().child(urlNodeConnections);
connectionsRef.off()
connectionsRef.on('value', (child) => {
that.logger.debug('[FIREBASEPresenceSERVICE] CONVERSATION-DETAIL group detail userIsOnline id user', userid, '- child.val: ', child.val());
if (child.val()) {
that.BSIsOnline.next({ uid: userid, isOnline: true });
local_BSIsOnline.next({ uid: userid, isOnline: true });
} else {
that.BSIsOnline.next({ uid: userid, isOnline: false });
local_BSIsOnline.next({ uid: userid, isOnline: false });
}
});
return local_BSIsOnline
} | // } | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/firebase/firebase-presence.service.ts#L77-L95 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | FirebasePresenceService.lastOnlineForUser | public lastOnlineForUser(userid: string) {
this.logger.debug('[FIREBASEPresenceSERVICE] lastOnlineForUser', userid);
const that = this;
const lastOnlineRef = this.referenceLastOnlineForUser(userid);
lastOnlineRef.on('value', (child) => {
if (child.val()) {
this.BSLastOnline.next({ uid: userid, lastOnline: child.val() });
} else {
this.BSLastOnline.next({ uid: userid, lastOnline: null });
}
});
} | /**
* lastOnlineForUser
* @param userid
*/ | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/firebase/firebase-presence.service.ts#L102-L113 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | FirebasePresenceService.setPresence | public setPresence(userid: string): void {
this.onlineConnectionsRef = this.referenceOnlineForUser(userid);
this.lastOnlineConnectionsRef = this.referenceLastOnlineForUser(userid);
const connectedRefURL = '/.info/connected';
const conn = this.firebase.database().ref(connectedRefURL);
conn.on('value', (dataSnapshot) => {
this.logger.debug('[FIREBASEPresenceSERVICE] self.deviceConnectionRef: ', dataSnapshot.val());
if (dataSnapshot.val()) {
if (this.onlineConnectionsRef) {
this.keyConnectionRef = this.onlineConnectionsRef.push(true);
this.keyConnectionRef.onDisconnect().remove();
const now: Date = new Date();
const timestamp = now.valueOf();
this.lastOnlineConnectionsRef.onDisconnect().set(timestamp);
} else {
this.logger.error('[FIREBASEPresenceSERVICE] setPresence --> This is an error. self.deviceConnectionRef already set. Cannot be set again.');
}
}
});
} | /**
* 1 - imposto reference online/offline
* 2 - imposto reference lastConnection
* 3 - mi sincronizzo con /.info/connected
* 4 - se il valore esiste l'utente è online
* 5 - aggiungo nodo a connection (true)
* 6 - aggiungo job su onDisconnect di deviceConnectionRef che rimuove nodo connection
* 7 - aggiungo job su onDisconnect di lastOnlineRef che imposta timestamp
* 8 - salvo reference connected nel singlelton !!!!! DA FARE
* https://firebase.google.com/docs/database/web/offline-capabilities?hl=it
* @param userid
*/ | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/firebase/firebase-presence.service.ts#L128-L147 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | FirebasePresenceService.removePresence | public removePresence(): void {
if (this.onlineConnectionsRef) {
const now: Date = new Date();
const timestamp = now.valueOf();
this.lastOnlineConnectionsRef.set(timestamp);
this.onlineConnectionsRef.off();
this.onlineConnectionsRef.remove();
this.logger.debug('[FIREBASEPresenceSERVICE] goOffline onlineConnectionsRef', this.onlineConnectionsRef);
}
} | /**
* removePresence
* richiamato prima del logout
*/ | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/firebase/firebase-presence.service.ts#L157-L166 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | FirebasePresenceService.referenceLastOnlineForUser | private referenceLastOnlineForUser(userid: string): any {
const urlNodeLastOnLine = this.urlNodePresence + userid + '/lastOnline';
this.logger.log('referenceLastOnlineForUser', urlNodeLastOnLine)
const lastOnlineRef = this.firebase.database().ref().child(urlNodeLastOnLine);
return lastOnlineRef;
} | /**
* recupero la reference di lastOnline del currentUser
* usata in setupMyPresence
* @param userid
*/ | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/firebase/firebase-presence.service.ts#L173-L178 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | FirebasePresenceService.referenceOnlineForUser | private referenceOnlineForUser(userid: string): any {
const urlNodeConnections = this.urlNodePresence + userid + '/connections';
const connectionsRef = this.firebase.database().ref().child(urlNodeConnections);
return connectionsRef;
} | /**
* recupero la reference di connections (online/offline) del currentUser
* usata in setupMyPresence
* @param userid
*/ | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/firebase/firebase-presence.service.ts#L185-L189 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | FirebaseTypingService.initialize | public async initialize(tenant: string) {
this.tenant = tenant;
this.logger.debug('[FIREBASETypingSERVICE] initialize - tenant ', this.tenant)
this.urlNodeTypings = '/apps/' + this.tenant + '/typings/';
const { default: firebase} = await import("firebase/app");
await Promise.all([import("firebase/database")]);
this.firebase = firebase
this.ref = this.firebase.database['Query'];
} | /** */ | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/firebase/firebase-typing.service.ts#L49-L59 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | FirebaseTypingService.isTyping | public isTyping(idConversation: string, idCurrentUser: string, isDirect: boolean ) {
const that = this;
let urlTyping = this.urlNodeTypings + idConversation;
if (isDirect) {
urlTyping = this.urlNodeTypings + idCurrentUser + '/' + idConversation;
}
this.logger.debug('[FIREBASETypingSERVICE] urlTyping: ', urlTyping);
this.ref = this.firebase.database().ref(urlTyping);
this.ref.on('child_changed', (childSnapshot) => {
const precence: TypingModel = childSnapshot.val();
this.logger.debug('[FIREBASETypingSERVICE] child_changed: ', precence);
this.BSIsTyping.next({uid: idConversation, uidUserTypingNow: precence.uid, nameUserTypingNow: precence.name, waitTime: TIME_TYPING_MESSAGE});
});
} | /** */ | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/firebase/firebase-typing.service.ts#L62-L75 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | FirebaseTypingService.setTyping | public setTyping(idConversation: string, message: string, recipientId: string, userFullname: string) {
const that = this;
clearTimeout(this.setTimeoutWritingMessages);
this.setTimeoutWritingMessages = setTimeout(() => {
const urlTyping = this.urlNodeTypings + idConversation + '/' + recipientId;// + '/user';
this.logger.debug('[FIREBASETypingSERVICE] setWritingMessages:', urlTyping, userFullname);
const timestampData = this.firebase.database.ServerValue.TIMESTAMP;
const precence = new TypingModel(recipientId, timestampData, message, userFullname);
that.firebase.database().ref(urlTyping).set(precence, ( error ) => {
if (error) {
this.logger.error('[FIREBASETypingSERVICE] setTyping error', error);
} else {
this.BSSetTyping.next({uid: idConversation, typing: precence});
}
});
}, 500);
} | /** */ | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/firebase/firebase-typing.service.ts#L78-L94 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | FirebaseUploadService.deleteFile | private deleteFile(pathToFile, fileName){
const ref = this.firebase.storage().ref(pathToFile);
const childRef = ref.child(fileName);
return childRef.delete()
} | // // ------------------------------------ | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/firebase/firebase-upload.service.ts#L231-L235 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | MQTTArchivedConversationsHandler.initialize | initialize(tenant: string, userId: string,translationMap: Map<string, string>) {
this.logger.debug('[MQTTArchivedConversationsHandler] initialize');
this.loggedUserId = userId;
this.translationMap = translationMap;
this.archivedConversations = [];
this.isConversationClosingMap = new Map();
} | /**
* inizializzo conversations handler
*/ | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/mqtt/mqtt-archivedconversations-handler.ts#L51-L57 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | MQTTArchivedConversationsHandler.subscribeToConversations | subscribeToConversations(loaded) {
this.logger.debug('[MQTTArchivedConversationsHandler] connecting MQTT conversations handler');
const handlerConversationAdded = this.chat21Service.chatClient.onArchivedConversationAdded( (conv) => {
this.logger.log('[MQTTArchivedConversationsHandler] Added conv ->', conv.text)
this.added(conv);
});
// const handlerConversationUpdated = this.chat21Service.chatClient.onConversationUpdated( (conv) => {
// console.log('conversation updated:', conv.text);
// this.changed(conv);
// });
const handlerConversationDeleted = this.chat21Service.chatClient.onArchivedConversationDeleted( (conv) => {
this.logger.debug('[MQTTArchivedConversationsHandler] conversation deleted:', conv);
this.removed(conv);
});
this.chat21Service.chatClient.lastConversations( true, (err, conversations) => {
this.logger.debug('[MQTTArchivedConversationsHandler] Last conversations', conversations, 'err', err);
if (!err) {
conversations.forEach(conv => {
this.added(conv);
});
loaded();
}
});
} | //---------------------------------------------------------------------------------- | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/mqtt/mqtt-archivedconversations-handler.ts#L144-L167 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | MQTTArchivedConversationsHandler.added | private added(childSnapshot: any) {
this.logger.debug('[MQTTArchivedConversationsHandler] NEW CONV childSnapshot', childSnapshot)
let conversation = this.completeConversation(childSnapshot);
conversation.uid = conversation.conversation_with;
// console.log("NUOVA CONVER;" + conversation.uid)
if (this.isValidConversation(conversation)) {
this.setClosingConversation(conversation.conversation_with, false);
this.logger.debug('[MQTTArchivedConversationsHandler] conversations:', conversation.uid, this.archivedConversations);
const index = this.searchIndexInArrayForConversationWith(this.archivedConversations, conversation.conversation_with);
console.log("NUOVA CONVER;.uid2" + conversation.uid)
if (index > -1) {
this.logger.debug('[MQTTArchivedConversationsHandler] TROVATO')
this.archivedConversations.splice(index, 1, conversation);
} else {
this.logger.debug('[MQTTArchivedConversationsHandler] NON TROVATO')
this.archivedConversations.splice(0, 0, conversation);
// this.databaseProvider.setConversation(conversation);
}
this.logger.debug('[MQTTArchivedConversationsHandler] NUOVA CONVER;.uid3' + conversation.uid)
this.archivedConversations.sort(compareValues('timestamp', 'desc'));
this.logger.debug('[MQTTArchivedConversationsHandler] TUTTE:', this.archivedConversations)
this.archivedConversationChanged.next(conversation);
this.archivedConversationAdded.next(conversation);
// this.events.publish('conversationsChanged', this.conversations);
} else {
this.logger.error('[MQTTArchivedConversationsHandler] ChatConversationsHandler::added::conversations with conversationId: ', conversation.conversation_with, 'is not valid');
}
} | /**
* 1 - completo la conversazione con i parametri mancanti
* 2 - verifico che sia una conversazione valida
* 3 - salvo stato conversazione (false) nell'array delle conversazioni chiuse
* 4 - aggiungo alla pos 0 la nuova conversazione all'array di conversazioni
* o sostituisco la conversazione con quella preesistente
* 5 - salvo la conversazione nello storage
* 6 - ordino l'array per timestamp
* 7 - pubblico conversations:update
*/ | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/mqtt/mqtt-archivedconversations-handler.ts#L180-L208 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | MQTTArchivedConversationsHandler.removed | private removed(childSnapshot) {
const index = searchIndexInArrayForUid(this.archivedConversations, childSnapshot.key);
if (index > -1) {
const conversationRemoved = this.archivedConversations[index]
this.archivedConversations.splice(index, 1);
// this.conversations.sort(compareValues('timestamp', 'desc'));
// this.databaseProvider.removeConversation(childSnapshot.key);
this.archivedConversationRemoved.next(conversationRemoved);
}
// remove the conversation from the isConversationClosingMap
this.deleteClosingConversation(childSnapshot.key);
} | /**
* 1 - cerco indice conversazione da eliminare
* 2 - elimino conversazione da array conversations
* 3 - elimino la conversazione dallo storage
* 4 - pubblico conversations:update
* 5 - elimino conversazione dall'array delle conversazioni chiuse
*/ | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/mqtt/mqtt-archivedconversations-handler.ts#L254-L265 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | MQTTArchivedConversationsHandler.dispose | dispose() {
this.archivedConversations = [];
this.archivedConversations.length = 0;
this.uidConvSelected = '';
} | /**
* dispose reference di conversations
*/ | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/mqtt/mqtt-archivedconversations-handler.ts#L270-L274 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | MQTTArchivedConversationsHandler.completeConversation | private completeConversation(conv): ConversationModel {
// conv.selected = false;
if (!conv.sender_fullname || conv.sender_fullname === 'undefined' || conv.sender_fullname.trim() === '') {
conv.sender_fullname = conv.sender;
}
if (!conv.recipient_fullname || conv.recipient_fullname === 'undefined' || conv.recipient_fullname.trim() === '') {
conv.recipient_fullname = conv.recipient;
}
let conversation_with_fullname = conv.sender_fullname;
let conversation_with = conv.sender;
if (conv.sender === this.loggedUserId) {
conversation_with = conv.recipient;
conversation_with_fullname = conv.recipient_fullname;
conv.last_message_text = conv.last_message_text;
} else if (conv.channel_type === TYPE_GROUP) {
conversation_with = conv.recipient;
conversation_with_fullname = conv.recipient_fullname;
conv.last_message_text = conv.last_message_text;
}
conv.conversation_with_fullname = conversation_with_fullname;
conv.conversation_with = conversation_with;
conv.status = this.setStatusConversation(conv.sender, conv.uid);
conv.avatar = avatarPlaceholder(conversation_with_fullname);
conv.color = getColorBck(conversation_with_fullname);
if (!conv.last_message_text) {
conv.last_message_text = conv.text; // building conv with a message
}
return conv;
} | /**
* Completo conversazione aggiungendo:
* 1 - nel caso in cui sender_fullname e recipient_fullname sono vuoti, imposto i rispettivi id come fullname,
* in modo da avere sempre il campo fullname popolato
* 2 - imposto conversation_with e conversation_with_fullname con i valori del sender o al recipient,
* a seconda che il sender corrisponda o meno all'utente loggato. Aggiungo 'tu:' se il sender coincide con il loggedUser
* Se il sender NON è l'utente loggato, ma è una conversazione di tipo GROUP, il conversation_with_fullname
* sarà uguale al recipient_fullname
* 3 - imposto stato conversazione, che indica se ci sono messaggi non letti nella conversazione
* 4 - imposto il tempo trascorso tra l'ora attuale e l'invio dell'ultimo messaggio
* 5 - imposto avatar, colore e immagine
* @param conv
*/ | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/mqtt/mqtt-archivedconversations-handler.ts#L308-L336 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | MQTTArchivedConversationsHandler.setStatusConversation | private setStatusConversation(sender, uid): string {
let status = '0'; // letto
if (sender === this.loggedUserId || uid === this.uidConvSelected) {
status = '0';
} else {
status = '1'; // non letto
}
return status;
} | /** */ | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/mqtt/mqtt-archivedconversations-handler.ts#L363-L371 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | MQTTArchivedConversationsHandler.countIsNew | countIsNew(): number {
let num = 0;
this.archivedConversations.forEach((element) => {
if (element.is_new === true) {
num++;
}
});
return num;
} | /**
* restituisce il numero di conversazioni nuove
*/ | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/mqtt/mqtt-archivedconversations-handler.ts#L376-L384 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | MQTTArchivedConversationsHandler.isValidConversation | private isValidConversation(convToCheck: ConversationModel) : boolean {
//console.log("[BEGIN] ChatConversationsHandler:: convToCheck with uid: ", convToCheckId);
this.logger.debug('[MQTTArchivedConversationsHandler] checking uid of', convToCheck)
this.logger.debug('[MQTTArchivedConversationsHandler] conversation.uid', convToCheck.uid)
this.logger.debug('[MQTTArchivedConversationsHandler] channel_type is:', convToCheck.channel_type)
if (!this.isValidField(convToCheck.uid)) {
this.logger.error('[MQTTArchivedConversationsHandler] ChatConversationsHandler::isValidConversation:: "uid is not valid" ');
return false;
}
// if (!this.isValidField(convToCheck.is_new)) {
// this.logger.error("ChatConversationsHandler::isValidConversation:: 'is_new is not valid' ");
// return false;
// }
if (!this.isValidField(convToCheck.last_message_text)) {
this.logger.error('[MQTTArchivedConversationsHandler] ChatConversationsHandler::isValidConversation:: "last_message_text is not valid" ');
return false;
}
if (!this.isValidField(convToCheck.recipient)) {
this.logger.error('[MQTTArchivedConversationsHandler] ChatConversationsHandler::isValidConversation:: "recipient is not valid" ');
return false;
}
if (!this.isValidField(convToCheck.recipient_fullname)) {
this.logger.error('[MQTTArchivedConversationsHandler] ChatConversationsHandler::isValidConversation:: "recipient_fullname is not valid" ');
return false;
}
if (!this.isValidField(convToCheck.sender)) {
this.logger.error('[MQTTArchivedConversationsHandler] ChatConversationsHandler::isValidConversation:: "sender is not valid" ');
return false;
}
if (!this.isValidField(convToCheck.sender_fullname)) {
this.logger.error('[MQTTArchivedConversationsHandler] ChatConversationsHandler::isValidConversation:: "sender_fullname is not valid" ');
return false;
}
if (!this.isValidField(convToCheck.status)) {
this.logger.error('[MQTTArchivedConversationsHandler] ChatConversationsHandler::isValidConversation:: "status is not valid" ');
return false;
}
if (!this.isValidField(convToCheck.timestamp)) {
this.logger.error('[MQTTArchivedConversationsHandler] ChatConversationsHandler::isValidConversation:: "timestamp is not valid" ');
return false;
}
if (!this.isValidField(convToCheck.channel_type)) {
this.logger.error('[MQTTArchivedConversationsHandler] ChatConversationsHandler::isValidConversation:: "channel_type is not valid" ');
return false;
}
//console.log("[END] ChatConversationsHandler:: convToCheck with uid: ", convToCheckId);
// any other case
return true;
} | /**
* check if the conversations is valid or not
*/ | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/mqtt/mqtt-archivedconversations-handler.ts#L418-L467 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | MQTTArchivedConversationsHandler.isValidField | private isValidField(field) : boolean{
return (field === null || field === undefined) ? false : true;
} | // checks if a conversation's field is valid or not | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/mqtt/mqtt-archivedconversations-handler.ts#L470-L472 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | MQTTAuthService.initialize | initialize() {
this.SERVER_BASE_URL = this.getBaseUrl();
this.URL_TILEDESK_CREATE_CUSTOM_TOKEN = this.SERVER_BASE_URL + 'chat21/native/auth/createCustomToken';
this.logger.log('[MQTTAuthService] initialize ');
// this.checkIsAuth();
// this.onAuthStateChanged();
} | /**
*
*/ | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/mqtt/mqtt-auth-service.ts#L51-L57 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | MQTTAuthService.logout | logout(): Promise<boolean> {
this.logger.debug("[MQTTAuthService] logout: closing mqtt connection...");
return new Promise((resolve, reject) => {
this.chat21Service.chatClient.close(() => {
// remove
// this.appStorage.removeItem('tiledeskToken');
// this.appStorage.removeItem('currentUser');
this.currentUser = null;
this.logger.debug("[MQTTAuthService] logout: mqtt connection closed. user removed. OK");
this.BSSignOut.next(true);
this.BSAuthStateChanged.next('offline');
resolve(true)
// if (callback) {
// callback();
// }
});
});
} | // logout(callback) { | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/mqtt/mqtt-auth-service.ts#L60-L77 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | MQTTAuthService.getUser | getUser(): any {
return this.currentUser;
} | /**
*
*/ | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/mqtt/mqtt-auth-service.ts#L82-L84 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | MQTTAuthService.getToken | getToken(): string {
this.logger.debug('[MQTTAuthService]::getToken');
return this.token;
} | /** */ | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/mqtt/mqtt-auth-service.ts#L89-L92 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | MQTTAuthService.createCustomToken | createCustomToken(tiledeskToken: any): void {
this.connectWithCustomToken(tiledeskToken)
} | // } | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/mqtt/mqtt-auth-service.ts#L124-L126 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | MQTTAuthService.connectWithCustomToken | private connectWithCustomToken(tiledeskToken: string): any {
const headers = new HttpHeaders({
'Content-type': 'application/json',
Authorization: tiledeskToken
});
const responseType = 'text';
const postData = {};
// const that = this;
this.http.post(this.URL_TILEDESK_CREATE_CUSTOM_TOKEN, postData, { headers, responseType})
.subscribe(data => {
this.logger.debug("[MQTTAuthService] connectWithCustomToken: **** data", data)
const result = JSON.parse(data);
this.connectMQTT(result);
}, error => {
this.logger.error(error);
});
} | // } | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/mqtt/mqtt-auth-service.ts#L241-L257 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | MQTTConversationHandler.initialize | initialize(recipientId: string,recipientFullName: string,loggedUser: UserModel,tenant: string, translationMap: Map<string, string>) {
this.logger.log('[MQTTConversationHandler] initWithRecipient:', tenant);
this.recipientId = recipientId;
this.recipientFullname = recipientFullName;
this.loggedUser = loggedUser;
if (loggedUser) {
this.senderId = loggedUser.uid;
}
this.tenant = tenant;
this.translationMap = translationMap;
this.listSubsriptions = [];
this.CLIENT_BROWSER = navigator.userAgent;
this.conversationWith = recipientId;
this.messages = [];
// this.attributes = this.setAttributes();
} | /**
* inizializzo conversation handler
*/ | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/mqtt/mqtt-conversation-handler.ts#L70-L86 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | MQTTConversationHandler.connect | connect() {
this.logger.log('[MQTTConversationHandler] connecting conversation handler...', this.conversationWith);
if (this.conversationWith == null) {
this.logger.error('[MQTTConversationHandler] cant connect invalid this.conversationWith', this.conversationWith);
return;
}
this.chat21Service.chatClient.lastMessages(this.conversationWith, (err, messages) => {
if (!err) {
messages.sort(compareValues('timestamp', 'asc'));
messages.forEach(message => {
const msg: MessageModel = message;
msg.uid = message.message_id;
this.addedMessage(msg);
});
}
});
const handler_message_added = this.chat21Service.chatClient.onMessageAddedInConversation(
this.conversationWith, (message, topic) => {
this.logger.log('[MQTTConversationHandler] message added:', message, 'on topic:', topic);
const msg: MessageModel = message;
//allow to replace message in unknown status (pending status: '0')
if(message.attributes && message.attributes.tempUID){
msg.uid = message.attributes.tempUID;
}else{
msg.uid = message.message_id
}
this.addedMessage(msg);
});
const handler_message_updated = this.chat21Service.chatClient.onMessageUpdatedInConversation(
this.conversationWith, (message, topic) => {
this.logger.log('[MQTTConversationHandler] message updated:', message, 'on topic:', topic);
this.changed(message);
});
} | /**
* mi connetto al nodo messages
* recupero gli ultimi 100 messaggi
* creo la reference
* mi sottoscrivo a change, removed, added
*/ | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/mqtt/mqtt-conversation-handler.ts#L94-L130 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | MQTTConversationHandler.sendMessage | sendMessage(
msg: string,
typeMsg: string,
metadataMsg: string,
conversationWith: string,
conversationWithFullname: string,
sender: string,
senderFullname: string,
channelType: string,
attributes: any
) {
const that = this;
if (!channelType || channelType === 'undefined') {
channelType = TYPE_DIRECT;
}
this.logger.log('[MQTTConversationHandler] Senderfullname', senderFullname);
const language = document.documentElement.lang;
const recipientFullname = conversationWithFullname;
const recipientId = conversationWith;
attributes.lang = language;
attributes.tempUID = uuidv4(); //allow to show message in a pending status
this.chat21Service.chatClient.sendMessage(
msg,
typeMsg,
recipientId,
recipientFullname,
senderFullname,
attributes,
metadataMsg,
channelType,
// language,
(err, message) => {
if (err) {
message.status = '-100';
this.logger.log('[MQTTConversationHandler] ERROR', err);
} else {
message.status = '150';
}
}
);
const message = new MessageModel(
attributes.tempUID, //allow to show message in a pending status
language,
conversationWith,
recipientFullname,
sender,
senderFullname,
0,
metadataMsg,
msg,
Date.now(),
typeMsg,
attributes,
channelType,
false
);
this.addedMessage(message) //allow to show message in a pending status: add pending message in array of messages
return new MessageModel(
'',
language,
conversationWith,
recipientFullname,
sender,
senderFullname,
0,
metadataMsg,
msg,
Date.now(),
typeMsg,
this.attributes,
channelType,
false
);
} | // ); | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/mqtt/mqtt-conversation-handler.ts#L159-L235 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | MQTTConversationHandler.dispose | dispose() {
// this.ref.off();
} | /**
* dispose reference della conversazione
*/ | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/mqtt/mqtt-conversation-handler.ts#L240-L242 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | MQTTConversationHandler.addedMessage | private addedMessage(messageSnapshot: any) {
const msg = this.messageGenerate(messageSnapshot);
if(this.skipInfoMessage && messageType(MESSAGE_TYPE_INFO, msg)){
return;
}
if(!this.skipInfoMessage && messageType(MESSAGE_TYPE_INFO, msg)){
this.messageInfo.next(msg)
}
this.logger.log('[MQTTConversationHandler] adding message:' + JSON.stringify(msg));
// this.logger.log('childSnapshot.message_id:' + msg.message_id);
// this.logger.log('childSnapshot.key:' + msg.key);
// this.logger.log('childSnapshot.uid:' + msg.uid);
this.addReplaceMessageInArray(msg.uid, msg);
this.updateMessageStatusReceived(msg);
this.messageAdded.next(msg);
} | /** */ | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/mqtt/mqtt-conversation-handler.ts#L265-L282 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | MQTTConversationHandler.changed | private changed(patch: any) {
if(this.skipInfoMessage && messageType(MESSAGE_TYPE_INFO, patch) ){
return;
}
this.logger.log('[MQTTConversationHandler] updating message with patch', patch);
const index = searchIndexInArrayForUid(this.messages, patch.message_id);
if (index > -1) {
const message = this.messages[index];
if (message) {
message.status = patch.status;
this.logger.log('[MQTTConversationHandler] message found and patched (replacing)', message);
this.addReplaceMessageInArray(message.uid, message);
this.messageChanged.next(message);
}
}
} | /** */ | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/mqtt/mqtt-conversation-handler.ts#L285-L300 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | MQTTConversationHandler.removed | private removed(childSnapshot: any) {
const index = searchIndexInArrayForUid(this.messages, childSnapshot.key);
// controllo superfluo sarà sempre maggiore
if (index > -1) {
this.messages.splice(index, 1);
this.messageRemoved.next(childSnapshot.key);
}
} | /** */ | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/mqtt/mqtt-conversation-handler.ts#L303-L310 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | MQTTConversationHandler.messageGenerate | private messageGenerate(childSnapshot: any) {
// const msg: MessageModel = childSnapshot.val();
this.logger.log("[MQTTConversationHandler] childSnapshot >" + JSON.stringify(childSnapshot));
const msg = childSnapshot;
// msg.uid = childSnapshot.key;
msg.text = msg.text? msg.text.trim(): "";//remove black msg with only spaces
// controllo fatto per i gruppi da rifattorizzare
if (!msg.sender_fullname || msg.sender_fullname === 'undefined') {
msg.sender_fullname = msg.sender;
}
// bonifico messaggio da url
// if (msg.type === 'text') {
// msg.text = htmlEntities(msg.text);
// }
// verifico che il sender è il logged user
this.logger.log("[MQTTConversationHandler] ****>msg.sender:" + msg.sender);
msg.isSender = isSender(msg.sender, this.loggedUser.uid);
// traduco messaggi se sono del server
if (messageType(MESSAGE_TYPE_INFO, msg)) {
this.translateInfoSupportMessages(msg);
}
return msg;
} | /** */ | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/mqtt/mqtt-conversation-handler.ts#L313-L335 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | MQTTConversationHandler.addReplaceMessageInArray | private addReplaceMessageInArray(uid: string, msg: MessageModel) {
const index = searchIndexInArrayForUid(this.messages, uid);
if (index > -1) {
// const headerDate = this.messages[index].headerDate;
// msg.headerDate = headerDate;
this.messages.splice(index, 1, msg);
} else {
this.messages.splice(0, 0, msg);
}
this.messages.sort(compareValues('timestamp', 'asc'));
} | /** */ | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/mqtt/mqtt-conversation-handler.ts#L338-L348 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | MQTTConversationHandler.translateInfoSupportMessages | private translateInfoSupportMessages(message: MessageModel) {
// check if the message attributes has parameters and it is of the "MEMBER_JOINED_GROUP" type
const INFO_SUPPORT_USER_ADDED_SUBJECT = this.translationMap.get('INFO_SUPPORT_USER_ADDED_SUBJECT');
const INFO_SUPPORT_USER_ADDED_YOU_VERB = this.translationMap.get('INFO_SUPPORT_USER_ADDED_YOU_VERB');
const INFO_SUPPORT_USER_ADDED_COMPLEMENT = this.translationMap.get('INFO_SUPPORT_USER_ADDED_COMPLEMENT');
const INFO_SUPPORT_USER_ADDED_VERB = this.translationMap.get('INFO_SUPPORT_USER_ADDED_VERB');
const INFO_SUPPORT_CHAT_REOPENED = this.translationMap.get('INFO_SUPPORT_CHAT_REOPENED');
const INFO_SUPPORT_CHAT_CLOSED = this.translationMap.get('INFO_SUPPORT_CHAT_CLOSED');
const INFO_SUPPORT_LEAD_UPDATED = this.translationMap.get('INFO_SUPPORT_LEAD_UPDATED');
const INFO_SUPPORT_MEMBER_LEFT_GROUP = this.translationMap.get('INFO_SUPPORT_MEMBER_LEFT_GROUP');
const INFO_A_NEW_SUPPORT_REQUEST_HAS_BEEN_ASSIGNED_TO_YOU = this.translationMap.get('INFO_A_NEW_SUPPORT_REQUEST_HAS_BEEN_ASSIGNED_TO_YOU');
const INFO_SUPPORT_LIVE_PAGE = this.translationMap.get('INFO_SUPPORT_LIVE_PAGE');
if (message.attributes.messagelabel
&& message.attributes.messagelabel.parameters
&& message.attributes.messagelabel.key === MEMBER_JOINED_GROUP
) {
let subject: string;
let verb: string;
let complement: string;
if (message.attributes.messagelabel.parameters.member_id === this.loggedUser.uid) {
subject = INFO_SUPPORT_USER_ADDED_SUBJECT;
verb = INFO_SUPPORT_USER_ADDED_YOU_VERB;
complement = INFO_SUPPORT_USER_ADDED_COMPLEMENT;
} else {
if (message.attributes.messagelabel.parameters.fullname) {
// other user has been added to the group (and he has a fullname)
subject = message.attributes.messagelabel.parameters.fullname;
verb = INFO_SUPPORT_USER_ADDED_VERB;
complement = INFO_SUPPORT_USER_ADDED_COMPLEMENT;
} else {
// other user has been added to the group (and he has not a fullname, so use hes useruid)
subject = message.attributes.messagelabel.parameters.member_id;
verb = INFO_SUPPORT_USER_ADDED_VERB;
complement = INFO_SUPPORT_USER_ADDED_COMPLEMENT;
}
}
message.text = subject + ' ' + verb + ' ' + complement;
} else if ((message.attributes.messagelabel && message.attributes.messagelabel.key === CHAT_REOPENED)) {
message.text = INFO_SUPPORT_CHAT_REOPENED;
} else if ((message.attributes.messagelabel && message.attributes.messagelabel.key === CHAT_CLOSED)) {
message.text = INFO_SUPPORT_CHAT_CLOSED;
} else if ((message.attributes && message.attributes.messagelabel && message.attributes.messagelabel.key === TOUCHING_OPERATOR) && message.sender === "system") {
// console.log('FIREBASEConversationHandlerSERVICE message text', message.text)
const textAfterColon = message.text.split(":")[1]
// console.log('FIREBASEConversationHandlerSERVICE message text - textAfterColon', textAfterColon)
if (textAfterColon !== undefined) {
message.text = INFO_A_NEW_SUPPORT_REQUEST_HAS_BEEN_ASSIGNED_TO_YOU + ': ' + textAfterColon;
}
} else if ((message.attributes.messagelabel && message.attributes.messagelabel.key === LEAD_UPDATED)) {
message.text = INFO_SUPPORT_LEAD_UPDATED;
} else if ((message.attributes.messagelabel && message.attributes.messagelabel.key === MEMBER_LEFT_GROUP)) {
let subject: string;
if (message.attributes.messagelabel.parameters.fullname) {
subject = message.attributes.messagelabel.parameters.fullname;
}else{
subject = message.attributes.messagelabel.parameters.member_id;
}
message.text = subject + ' ' + INFO_SUPPORT_MEMBER_LEFT_GROUP ;
} else if(message.attributes.messagelabel && message.attributes.messagelabel.key === LIVE_PAGE){
let sourceUrl: string = '';
if(message.attributes && message.attributes.sourcePage){
sourceUrl = message.attributes.sourcePage
}
if(message.attributes && message.attributes.sourceTitle){
sourceUrl = '['+message.attributes.sourceTitle+']('+sourceUrl+')'
}
message.text= INFO_SUPPORT_LIVE_PAGE + ': ' + sourceUrl
}
} | /** */ | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/mqtt/mqtt-conversation-handler.ts#L351-L420 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | MQTTConversationHandler.updateMessageStatusReceived | private updateMessageStatusReceived(msg) {
this.logger.log('[MQTTConversationHandler] updateMessageStatusReceived', msg);
if (msg['status'] < MSG_STATUS_RECEIVED && msg['status'] > 0) {
this.logger.log('[MQTTConversationHandler] status ', msg['status'], ' < (RECEIVED:200)', MSG_STATUS_RECEIVED);
if (msg.sender !== this.loggedUser.uid && msg.status < MSG_STATUS_RECEIVED) {
this.logger.log('[MQTTConversationHandler] updating message with status received');
this.chat21Service.chatClient.updateMessageStatus(msg.message_id, this.conversationWith, MSG_STATUS_RECEIVED, null);
}
}
// if (msg.status < MSG_STATUS_RECEIVED) {
// if (msg.sender !== this.loggedUser.uid && msg.status < MSG_STATUS_RECEIVED) {
// const urlNodeMessagesUpdate = this.urlNodeFirebase + '/' + msg.uid;
// this.logger.log('AGGIORNO STATO MESSAGGIO', urlNodeMessagesUpdate);
// firebase.database().ref(urlNodeMessagesUpdate).update({ status: MSG_STATUS_RECEIVED });
// }
// }
} | /**
* aggiorno lo stato del messaggio
* questo stato indica che è stato consegnato al client e NON che è stato letto
* se il messaggio NON è stato inviato da loggedUser AGGIORNO stato a 200
* @param item
* @param conversationWith
*/ | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/mqtt/mqtt-conversation-handler.ts#L430-L446 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | MQTTConversationsHandler.subscribeToConversations | subscribeToConversations(lastTimestamp, loaded) {
// lastTimestamp temporarily ignored
this.logger.debug('[MQTTConversationsHandler] connecting MQTT conversations handler');
const handlerConversationAdded = this.chat21Service.chatClient.onConversationAdded( (conv) => {
let conversation = this.completeConversation(conv); // needed to get the "conversation_with", and find the conv in the conv-history
conversation.sound = true
this.logger.log("onConversationAdded completed:",conversation);
const index = this.searchIndexInArrayForConversationWith(this.conversations, conversation.conversation_with);
if (index > -1) {
this.logger.log('[MQTTConversationsHandler] Added conv -> Changed!')
this.changed(conversation);
}
else {
this.logger.log('[MQTTConversationsHandler] Added conv -> Added!')
this.added(conversation);
}
});
const handlerConversationUpdated = this.chat21Service.chatClient.onConversationUpdated( (conv, topic) => {
conv.sound = true;
this.logger.debug('[MQTTConversationsHandler] conversation updated:', JSON.stringify(conv));
this.changed(conv);
});
const handlerConversationDeleted = this.chat21Service.chatClient.onConversationDeleted( (conv, topic) => {
this.logger.debug('[MQTTConversationsHandler] conversation deleted:', conv, topic);
// example topic: apps.tilechat.users.ME.conversations.CONVERS-WITH.clientdeleted
// const topic_parts = topic.split("/")
// this.logger.debug('[MQTTConversationsHandler] topic and parts', topic_parts)
// if (topic_parts.leßngth < 7) {
// this.logger.error('[MQTTConversationsHandler] Error. Not a conversation-deleted topic:', topic);
// return
// }
// const convers_with = topic_parts[5];
const convers_with = topic.conversWith;
this.removed({
uid: convers_with
});
});
this.chat21Service.chatClient.lastConversations( false, (err, conversations) => {
this.logger.debug('[MQTTConversationsHandler] Last conversations', conversations, 'err', err);
if (!err) {
conversations.forEach(conv => {
conv.sound = false;
this.added(conv);
});
loaded();
}
});
} | //---------------------------------------------------------------------------------- | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/mqtt/mqtt-conversations-handler.ts#L150-L197 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | MQTTConversationsHandler.changed | private changed(conversation: any) {
// const childData: ConversationModel = childSnapshot;
// childData.uid = childSnapshot.key;
// this.logger.log('changed conversation: ', childData);
// const conversation = this.completeConversation(childData);
this.logger.debug('[MQTTConversationsHandler] Conversation changed:', conversation)
// let conversation = this.completeConversation(childSnapshot);
// childSnapshot.uid = childSnapshot.conversation_with;
// let conversation = this.completeConversation(childSnapshot);
// this.logger.log("Conversation completed:", conversation);
// conversation.uid = conversation.conversation_with;
// this.logger.log("conversation.uid" + conversation.uid)
// this.logger.log("conversation.uid", conversation.uid)
// if (this.isValidConversation(conversation)) {
// this.setClosingConversation(conversation.uid, false);
if (!conversation.conversation_with) {
conversation.conversation_with = conversation.conversWith // conversWith comes from remote
}
//skip info message updates
if(messageType(MESSAGE_TYPE_INFO, conversation) ){
return;
}
const index = searchIndexInArrayForUid(this.conversations, conversation.conversation_with);
const oldConversation = this.conversations[index]
if (index > -1) {
// const conv = this.conversations[index];
this.logger.log("Conversation to update found", this.conversations[index]);
this.updateConversationWithSnapshot(this.conversations[index], conversation);
this.logger.debug('[MQTTConversationsHandler] conversationchanged.isnew', JSON.stringify(conversation))
this.logger.log("this.conversations:" + JSON.stringify(this.conversations));
this.logger.log("Conversation updated --> ", this.conversations[index]);
this.conversationChangedDetailed.next({value: this.conversations[index], previousValue: oldConversation})
this.conversationChanged.next(this.conversations[index]);
this.conversations.sort(compareValues('timestamp', 'desc'));
}
} | /**
* 1 - completo la conversazione con i parametri mancanti
* 2 - verifico che sia una conversazione valida
* 3 - aggiungo alla pos 0 la nuova conversazione all'array di conversazioni
* 4 - salvo la conversazione nello storage
* 5 - ordino l'array per timestamp
* 6 - pubblico conversations:update
* 7 - attivo sound se è un msg nuovo
*/ | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/mqtt/mqtt-conversations-handler.ts#L240-L278 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | MQTTConversationsHandler.removed | private removed(childSnapshot) {
const index = searchIndexInArrayForUid(this.conversations, childSnapshot.uid);
if (index > -1) {
const conversationRemoved = this.conversations[index]
this.conversations.splice(index, 1);
// this.conversations.sort(compareValues('timestamp', 'desc'));
// this.databaseProvider.removeConversation(childSnapshot.key);
this.logger.debug('[MQTTConversationsHandler] conversationRemoved::', conversationRemoved)
this.conversationRemoved.next(conversationRemoved);
}
// remove the conversation from the isConversationClosingMap
this.deleteClosingConversation(childSnapshot.uid);
} | /**
* 1 - cerco indice conversazione da eliminare
* 2 - elimino conversazione da array conversations
* 3 - elimino la conversazione dallo storage
* 4 - pubblico conversations:update
* 5 - elimino conversazione dall'array delle conversazioni chiuse
*/ | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/mqtt/mqtt-conversations-handler.ts#L341-L353 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | MQTTConversationsHandler.dispose | dispose() {
this.conversations.length = 0;
this.conversations = [];
this.uidConvSelected = '';
} | /**
* dispose reference di conversations
*/ | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/mqtt/mqtt-conversations-handler.ts#L358-L362 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | MQTTConversationsHandler.setStatusConversation | private setStatusConversation(sender, uid): string {
let status = '0'; // letto
if (sender === this.loggedUserId || uid === this.uidConvSelected) {
status = '0';
} else {
status = '1'; // non letto
}
return status;
} | /** */ | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/mqtt/mqtt-conversations-handler.ts#L426-L434 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | MQTTConversationsHandler.countIsNew | countIsNew(): number {
let num = 0;
this.conversations.forEach((element) => {
if (element.is_new === true) {
num++;
}
});
return num;
} | /**
* restituisce il numero di conversazioni nuove
*/ | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/mqtt/mqtt-conversations-handler.ts#L439-L447 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | MQTTConversationsHandler.isValidConversation | private isValidConversation(convToCheck: ConversationModel) : boolean {
//this.logger.log("[BEGIN] ChatConversationsHandler:: convToCheck with uid: ", convToCheckId);
this.logger.debug('[MQTTConversationsHandler] checking uid of', convToCheck)
this.logger.debug('[MQTTConversationsHandler] conversation.uid', convToCheck.uid)
this.logger.debug('[MQTTConversationsHandler] channel_type is:', convToCheck.channel_type)
if (!this.isValidField(convToCheck.uid)) {
this.logger.error('[MQTTConversationsHandler] ChatConversationsHandler::isValidConversation:: "uid is not valid" ');
return false;
}
// if (!this.isValidField(convToCheck.is_new)) {
// this.logger.error("ChatConversationsHandler::isValidConversation:: 'is_new is not valid' ");
// return false;
// }
if (!this.isValidField(convToCheck.last_message_text)) {
this.logger.error('[MQTTConversationsHandler] ChatConversationsHandler::isValidConversation:: "last_message_text is not valid" ');
return false;
}
if (!this.isValidField(convToCheck.recipient)) {
this.logger.error('[MQTTConversationsHandler] ChatConversationsHandler::isValidConversation:: "recipient is not valid" ');
return false;
}
if (!this.isValidField(convToCheck.recipient_fullname)) {
this.logger.error('[MQTTConversationsHandler] ChatConversationsHandler::isValidConversation:: "recipient_fullname is not valid" ');
return false;
}
if (!this.isValidField(convToCheck.sender)) {
this.logger.error('[MQTTConversationsHandler] ChatConversationsHandler::isValidConversation:: "sender is not valid" ');
return false;
}
if (!this.isValidField(convToCheck.sender_fullname)) {
this.logger.error('[MQTTConversationsHandler] ChatConversationsHandler::isValidConversation:: "sender_fullname is not valid" ');
return false;
}
if (!this.isValidField(convToCheck.status)) {
this.logger.error('[MQTTConversationsHandler] ChatConversationsHandler::isValidConversation:: "status is not valid" ');
return false;
}
if (!this.isValidField(convToCheck.timestamp)) {
this.logger.error('[MQTTConversationsHandler] ChatConversationsHandler::isValidConversation:: "timestamp is not valid" ');
return false;
}
if (!this.isValidField(convToCheck.channel_type)) {
this.logger.error('[MQTTConversationsHandler] ChatConversationsHandler::isValidConversation:: "channel_type is not valid" ');
return false;
}
//this.logger.log("[END] ChatConversationsHandler:: convToCheck with uid: ", convToCheckId);
// any other case
return true;
} | /**
* check if the conversations is valid or not
*/ | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/mqtt/mqtt-conversations-handler.ts#L530-L579 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | MQTTConversationsHandler.isValidField | private isValidField(field) : boolean{
return (field === null || field === undefined) ? false : true;
} | // checks if a conversation's field is valid or not | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/mqtt/mqtt-conversations-handler.ts#L582-L584 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | MQTTGroupsHandler.initialize | initialize(tenant: string, loggedUserId: string): void {
this.logger.log('[MQTT-GROUPS-HANDLER] initialize');
this.tenant = tenant;
this.loggedUserId = loggedUserId;
} | /**
* inizializzo groups handler
*/ | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/mqtt/mqtt-groups-handler.ts#L37-L41 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | MQTTGroupsHandler.connect | connect(): void {
// TODO deprecated method.
} | /**
* mi connetto al nodo groups
* creo la reference
* mi sottoscrivo a change, removed, added
*/ | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/mqtt/mqtt-groups-handler.ts#L48-L50 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | MQTTGroupsHandler.getDetail | getDetail(groupId: string, callback?: (group: GroupModel) => void): Promise<GroupModel> {
//throw new Error('Method not implemented.');
// Ignorare versione firebase
this.logger.log('Method not implemented.');
return;
} | /**
* mi connetto al nodo groups/GROUPID
* creo la reference
* mi sottoscrivo a value
*/ | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/mqtt/mqtt-groups-handler.ts#L57-L62 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | MQTTGroupsHandler.onGroupChange | onGroupChange(groupId: string): Observable<GroupModel> {
if (this.isGroup(groupId)) {
this.chat21Service.chatClient.groupData(groupId, (err, group) => {
this.logger.log('[MQTT-GROUPS-HANDLER] onGroupChange: got result by REST call:', group);
this.groupValue(group.result);
this.logger.log('[MQTT-GROUPS-HANDLER] onGroupChange: subscribing to group updates...', groupId);
const handler_group_updated = this.chat21Service.chatClient.onGroupUpdated( (group, topic) => {
if (topic.conversWith === groupId) {
this.groupValue(group);
}
});
});
}
return this.SgroupDetail
} | // abstract onGroupChange(groupId: string): Observable<GroupModel>; | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/mqtt/mqtt-groups-handler.ts#L64-L78 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | MQTTGroupsHandler.leave | leave(groupId: string, callback?: (res: any, error: any) => void): Promise<any> {
// throw new Error('Method not implemented.');
// Ignorare versione firebase
this.logger.log('Method not implemented.');
return;
} | // } | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/mqtt/mqtt-groups-handler.ts#L115-L120 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | MQTTPresenceService.removePresence | public removePresence(): void {
// if (this.onlineConnectionsRef) {
// const now: Date = new Date();
// const timestamp = now.valueOf();
// this.lastOnlineConnectionsRef.set(timestamp);
// this.onlineConnectionsRef.off();
// this.onlineConnectionsRef.remove();
// console.log('goOffline onlineConnectionsRef', this.onlineConnectionsRef);
// }
} | /**
* removePresence
* richiamato prima del logout
*/ | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/mqtt/mqtt-presence.service.ts#L109-L118 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | MQTTTypingService.initialize | initialize(tenant: string) {
// this.tenant = this.getTenant();
this.tenant = tenant;
this.logger.info('[MQTT-TYPING] initialize this.tenant', this.tenant);
this.urlNodeTypings = '/apps/' + this.tenant + '/typings/';
} | /** */ | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/mqtt/mqtt-typing.service.ts#L50-L55 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | MQTTTypingService.isTyping | isTyping(idConversation: string, idUser: string) {
// const that = this;
// let urlTyping = this.urlNodeTypings + idConversation;
// if (idUser) {
// urlTyping = this.urlNodeTypings + idUser + '/' + idConversation;
// }
// console.log('urlTyping: ', urlTyping);
// const ref = firebase.database().ref(urlTyping).orderByChild('timestamp').limitToLast(1);
// ref.on('child_changed', (childSnapshot) => {
// console.log('urlTyping: ', childSnapshot.val());
// that.events.publish('isTypings', childSnapshot);
// });
} | /** */ | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/mqtt/mqtt-typing.service.ts#L58-L70 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | MQTTTypingService.setTyping | setTyping(idConversation: string, message: string, idUser: string, userFullname: string) {
// const that = this;
// this.setTimeoutWritingMessages = setTimeout(() => {
// let urlTyping = this.urlNodeTypings + idConversation;
// if (idUser) {
// urlTyping = this.urlNodeTypings + idUser + '/' + idConversation;
// }
// console.log('setWritingMessages:', urlTyping, userFullname);
// const timestampData = firebase.database.ServerValue.TIMESTAMP;
// const precence = new TypingModel(timestampData, message, userFullname);
// console.log('precence::::', precence);
// firebase.database().ref(urlTyping).set(precence, ( error ) => {
// if (error) {
// console.log('ERRORE', error);
// } else {
// console.log('OK update typing');
// }
// that.events.publish('setTyping', precence, error);
// });
// }, 500);
} | /** */ | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/mqtt/mqtt-typing.service.ts#L73-L94 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | NativeImageRepoService.getImagePhotoUrl | getImagePhotoUrl(uid: string): string {
this.baseImageURL = this.getImageBaseUrl() + 'images'
let sender_id = '';
if (uid.includes('bot_')) {
sender_id = uid.slice(4)
} else {
sender_id = uid
}
const filename_photo = '?path=uploads/users/'+ sender_id + '/images/photo.jpg'
const filename_thumbnail = '?path=uploads/users/'+ sender_id + '/images/thumbnails_200_200-photo.jpg'
return this.baseImageURL + filename_photo
} | /**
* @param uid
*/ | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/native/native-image-repo.ts#L18-L29 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | TiledeskAuthService.signInWithEmailAndPassword | signInWithEmailAndPassword(email: string, password: string): Promise<string> {
this.logger.log('[TILEDESK-AUTH-SERV] - signInWithEmailAndPassword', email, password);
const httpHeaders = new HttpHeaders();
httpHeaders.append('Accept', 'application/json');
httpHeaders.append('Content-Type', 'application/json');
const requestOptions = { headers: httpHeaders };
const postData = {
email: email,
password: password
};
const that = this;
return new Promise((resolve, reject) => {
this.http.post(this.URL_TILEDESK_SIGNIN, postData, requestOptions).subscribe((data) => {
if (data['success'] && data['token']) {
that.tiledeskToken = data['token'];
that.createCompleteUser(data['user']);
this.checkAndSetInStorageTiledeskToken(that.tiledeskToken)
this.BS_IsONLINE.next(true)
resolve(that.tiledeskToken)
}
}, (error) => {
reject(error)
});
});
} | /**
* @param email
* @param password
*/ | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/tiledesk/tiledesk-auth.service.ts#L52-L77 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | TiledeskAuthService.signInAnonymously | signInAnonymously(projectID: string): Promise<any> {
this.logger.debug('[TILEDESK-AUTH] - signInAnonymously - projectID', projectID);
const httpHeaders = new HttpHeaders();
httpHeaders.append('Accept', 'application/json');
httpHeaders.append('Content-Type', 'application/json');
const requestOptions = { headers: httpHeaders };
const postData = {
id_project: projectID
};
const that = this;
return new Promise((resolve, reject) => {
this.http.post(this.URL_TILEDESK_SIGNIN_ANONYMOUSLY, postData, requestOptions).subscribe({next: (data) => {
if (data['success'] && data['token']) {
that.tiledeskToken = data['token'];
that.createCompleteUser(data['user']);
this.checkAndSetInStorageTiledeskToken(that.tiledeskToken)
this.BS_IsONLINE.next(true)
resolve(that.tiledeskToken)
}
}, error: (error) => {
reject(error)
}});
})
} | /**
* @param projectID
*/ | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/tiledesk/tiledesk-auth.service.ts#L83-L108 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | TiledeskAuthService.signInWithCustomToken | signInWithCustomToken(tiledeskToken: string): Promise<any> {
const headers = new HttpHeaders({
'Content-type': 'application/json',
Authorization: tiledeskToken
});
const requestOptions = { headers: headers };
const that = this;
return new Promise((resolve, reject) => {
this.http.post(this.URL_TILEDESK_SIGNIN_WITH_CUSTOM_TOKEN, null, requestOptions).subscribe({next: (data)=>{
if (data['success'] && data['token']) {
that.tiledeskToken = data['token'];
that.createCompleteUser(data['user']);
this.checkAndSetInStorageTiledeskToken(that.tiledeskToken)
this.BS_IsONLINE.next(true)
resolve(this.currentUser)
}
}, error: (error)=>{
reject(error)
}})
});
} | /**
* @param tiledeskToken
*/ | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/tiledesk/tiledesk-auth.service.ts#L113-L133 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | TiledeskAuthService.createCompleteUser | private createCompleteUser(user: any) {
const member = new UserModel(user._id);
try {
const uid = user._id;
const firstname = user.firstname ? user.firstname : '';
const lastname = user.lastname ? user.lastname : '';
const email = user.email ? user.email : '';
const fullname = (firstname + ' ' + lastname).trim();
const avatar = avatarPlaceholder(fullname);
const color = getColorBck(fullname);
member.uid = uid;
member.email = email;
member.firstname = firstname;
member.lastname = lastname;
member.fullname = fullname;
member.avatar = avatar;
member.color = color;
this.currentUser = member;
this.logger.log('[TILEDESK-AUTH] - createCompleteUser member ', member);
this.appStorage.setItem('currentUser', JSON.stringify(this.currentUser));
} catch (err) {
this.logger.error('[TILEDESK-AUTH]- createCompleteUser ERR ', err)
}
} | /**
* createCompleteUser
* @param user
*/ | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/providers/tiledesk/tiledesk-auth.service.ts#L159-L184 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
design-studio | github_2023 | Tiledesk | typescript | UserTypingComponent.constructor | constructor(private elementRef: ElementRef) { } | // @Input() membersConversation: [string]; | https://github.com/Tiledesk/design-studio/blob/297d30da01d98a1299e7197eb88cff5b2390a386/src/chat21-core/utils/user-typing/user-typing.component.ts#L20-L20 | 297d30da01d98a1299e7197eb88cff5b2390a386 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.