diff --git a/package-lock.json b/package-lock.json old mode 100755 new mode 100644 index e159e89..1fcaa4e --- a/package-lock.json +++ b/package-lock.json @@ -2490,7 +2490,7 @@ "node_modules/@belomonte/ngx-parody-api": { "version": "0.1.0", "resolved": "file:belomonte-ngx-parody-api-0.1.0.tgz", - "integrity": "sha512-wHj1+p2QCUfLYotB/5P5xUBm2oAafs8vnB7yGTHlEjx+uxyuefvIhQMJuSrHfNa0PaK63oEkxTSnUYeV5y4dJQ==", + "integrity": "sha512-slrGNBistYIfjjrPVVS+dtMwPFgZAkUHCHqf1kWcN2EFTz+Atuef45xwCdmpb91DZw/UZ995Ny/0clCpGpTvtg==", "license": "Ungovernable", "dependencies": { "tslib": "^2.3.0" @@ -5021,9 +5021,9 @@ } }, "node_modules/@types/node": { - "version": "22.9.0", - "resolved": "https://registry.npmjs.org/@types/node/-/node-22.9.0.tgz", - "integrity": "sha512-vuyHg81vvWA1Z1ELfvLko2c8f34gyA0zaic0+Rllc5lbCnbSyuvb2Oxpm6TAUAC/2xZN3QGqxBNggD1nNR2AfQ==", + "version": "22.9.1", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.9.1.tgz", + "integrity": "sha512-p8Yy/8sw1caA8CdRIQBG5tiLHmxtQKObCijiAa9Ez+d4+PRffM4054xbju0msf+cvhJpnFEeNjxmVT/0ipktrg==", "dev": true, "license": "MIT", "dependencies": { @@ -5814,9 +5814,9 @@ "license": "MIT" }, "node_modules/bonjour-service": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/bonjour-service/-/bonjour-service-1.2.1.tgz", - "integrity": "sha512-oSzCS2zV14bh2kji6vNe7vrpJYCHGvcZnlffFQ1MEoX/WOeQ/teD8SYWKR942OI3INjq8OMNJlbPK5LLLUxFDw==", + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/bonjour-service/-/bonjour-service-1.3.0.tgz", + "integrity": "sha512-3YuAUiSkWykd+2Azjgyxei8OWf8thdn8AITIog2M4UICzoqfjlqr64WIjEXZllf/W6vK1goqleSR6brGomxQqA==", "dev": true, "license": "MIT", "dependencies": { @@ -6615,9 +6615,9 @@ } }, "node_modules/cross-spawn": { - "version": "7.0.5", - "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.5.tgz", - "integrity": "sha512-ZVJrKKYunU38/76t0RMOulHOnUcbU9GbpWKAOZ0mhjr7CX6FVrH+4FrAapSOekrgFQ3f/8gwMEuIft0aKq6Hug==", + "version": "7.0.6", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz", + "integrity": "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==", "dev": true, "license": "MIT", "dependencies": { @@ -6998,9 +6998,9 @@ "license": "MIT" }, "node_modules/electron-to-chromium": { - "version": "1.5.62", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.62.tgz", - "integrity": "sha512-t8c+zLmJHa9dJy96yBZRXGQYoiCEnHYgFwn1asvSPZSUdVxnB62A4RASd7k41ytG3ErFBA0TpHlKg9D9SQBmLg==", + "version": "1.5.63", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.63.tgz", + "integrity": "sha512-ddeXKuY9BHo/mw145axlyWjlJ1UBt4WK3AlvkT7W2AbqfRQoacVoRUCF6wL3uIx/8wT9oLKXzI+rFqHHscByaA==", "dev": true, "license": "ISC" }, @@ -7732,9 +7732,9 @@ } }, "node_modules/flatted": { - "version": "3.3.1", - "resolved": "https://registry.npmjs.org/flatted/-/flatted-3.3.1.tgz", - "integrity": "sha512-X8cqMLLie7KsNUDSdzeN8FYK9rEt4Dt67OsG/DNGnYTSDBG4uFAJFBnUeiV+zCVAvwFy56IjM9sH51jVaEhNxw==", + "version": "3.3.2", + "resolved": "https://registry.npmjs.org/flatted/-/flatted-3.3.2.tgz", + "integrity": "sha512-AiwGJM8YcNOaobumgtng+6NHuOqC3A7MixFeDafM3X9cIUM+xUXoS5Vfgf+OihAYe20fxqNM9yPBXJzRtZ/4eA==", "dev": true, "license": "ISC" }, @@ -10607,9 +10607,9 @@ } }, "node_modules/node-gyp-build": { - "version": "4.8.3", - "resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.8.3.tgz", - "integrity": "sha512-EMS95CMJzdoSKoIiXo8pxKoL8DYxwIZXYlLmgPb8KUv794abpnLK6ynsCAWNliOjREKruYKdzbh76HHYUHX7nw==", + "version": "4.8.4", + "resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.8.4.tgz", + "integrity": "sha512-LA4ZjwlnUblHVgq0oBF3Jl/6h/Nvs5fzBLwdEF4nuxnFdsfajde4WfxtJr3CaiH+F6ewcIB/q4jQ4UzPyid+CQ==", "dev": true, "license": "MIT", "optional": true, diff --git a/src/app/pages/chat/chat.component.ts b/src/app/pages/chat/chat.component.ts index cd64aaf..a638f6e 100755 --- a/src/app/pages/chat/chat.component.ts +++ b/src/app/pages/chat/chat.component.ts @@ -8,7 +8,7 @@ import { ModalService } from '@belomonte/async-modal-ngx'; import { RelayConfigComponent } from '@shared/relay-config/relay-config.component'; import { GlobalErrorHandler } from '@shared/error-handling/global.error-handler'; import { SoundNotificationService } from '@shared/sound/sound-notification.service'; -import { FindStrangerService, NostrPublicUser, TalkToStrangerNostr } from '@belomonte/ngx-parody-api'; +import { FindStrangerParody, NostrPublicUser, TalkToStrangerParody } from '@belomonte/ngx-parody-api'; @Component({ selector: 'omg-chat', @@ -45,8 +45,8 @@ export class ChatComponent implements OnDestroy, OnInit { constructor( private globalErrorHandler: GlobalErrorHandler, - private findStrangerService: FindStrangerService, - private talkToStrangerNostr: TalkToStrangerNostr, + private findStrangerParody: FindStrangerParody, + private talkToStrangerParody: TalkToStrangerParody, private soundNotificationService: SoundNotificationService, private modalService: ModalService ) { } @@ -56,7 +56,7 @@ export class ChatComponent implements OnDestroy, OnInit { } private countStrangers(): void { - this.subscriptions.add(this.talkToStrangerNostr + this.subscriptions.add(this.talkToStrangerParody .listenCurrenOnlineUsers() .subscribe(currentOnline => this.currentOnline = currentOnline || 1)); } @@ -82,7 +82,7 @@ export class ChatComponent implements OnDestroy, OnInit { this.currentState = this.stateSearchingStranger; this.messages = []; - this.findStrangerService + this.findStrangerParody .searchStranger({ signal: this.controller.signal, searchTags: [ 'omegle' ], @@ -91,33 +91,24 @@ export class ChatComponent implements OnDestroy, OnInit { .then(stranger => this.startConversation(stranger)) .catch(e => { console.error(new Date().toLocaleString(), e); - this.currentState = ChatState.DISCONNECTED; - this.strangerIsTyping = false; - this.whoDisconnected = null; - this.stranger = null; - + this.clearSession(); throw e; }); } - // FIXME: preciso revisar este método, pois o endSession já é executado internamente na biblioteca quando se recebe um status de disconnected - endSession(): Promise { + clearSession(): void { + this.currentState = ChatState.DISCONNECTED; + this.strangerIsTyping = false; + this.whoDisconnected = null; + this.stranger = null; this.subscriptions.unsubscribe(); this.subscriptions = new Subscription(); + } - this.stranger = null; - return this.findStrangerService + endSession(): Promise { + return this.findStrangerParody .endSession() - .then(() => { - this.currentState = ChatState.DISCONNECTED; - this.strangerIsTyping = false; - - if (!this.whoDisconnected) { - this.whoDisconnected = MessageAuthor.YOU; - } - - return Promise.resolve(); - }); + .then(() => this.clearSession()); } private startConversation(stranger: NostrPublicUser): void { @@ -129,13 +120,13 @@ export class ChatComponent implements OnDestroy, OnInit { } this.soundNotificationService.notify(); - this.subscriptions.add(this.talkToStrangerNostr + this.subscriptions.add(this.talkToStrangerParody .listenMessages(stranger) .subscribe({ next: event => this.addMessageFromStranger(stranger, event) })); - this.subscriptions.add(this.talkToStrangerNostr + this.subscriptions.add(this.talkToStrangerParody .listenStrangerStatus(stranger) .subscribe({ next: event => this.handleStrangerStatus(event) @@ -143,7 +134,7 @@ export class ChatComponent implements OnDestroy, OnInit { } private addMessageFromStranger(stranger: NostrPublicUser, event: NostrEvent): void { - this.talkToStrangerNostr + this.talkToStrangerParody .openEncryptedDirectMessage(stranger, event) .then(text => { this.messages.push([{ @@ -182,7 +173,9 @@ export class ChatComponent implements OnDestroy, OnInit { this.scrollConversationToTheEnd(); try { - await this.talkToStrangerNostr.sendMessage(stranger, message); + const typingPromise = this.talkToStrangerParody.isTyping(); + const messagePromise = this.talkToStrangerParody.sendMessage(stranger, message); + await Promise.all([typingPromise, messagePromise]); } catch (e) { touple[1] = this.globalErrorHandler.getErrorMessage(e as Error).join('; '); } @@ -207,12 +200,12 @@ export class ChatComponent implements OnDestroy, OnInit { onTyping(): void { if (!this.typingTimeoutId) { - this.talkToStrangerNostr.isTyping(); + this.talkToStrangerParody.isTyping(); } clearTimeout(this.typingTimeoutId); this.typingTimeoutId = Number(setTimeout(() => { - this.talkToStrangerNostr.stopTyping(); + this.talkToStrangerParody.stopTyping(); this.typingTimeoutId = 0; }, this.typingTimeoutAmount)); }