From cb906a56be1c7f1a40f7eebf44d809ba13384e76 Mon Sep 17 00:00:00 2001 From: Fabian Trampusch Date: Thu, 10 Jan 2019 12:44:05 +0100 Subject: [PATCH] fix: do not emit messages$ when sending a message --- .../services/adapters/xmpp/plugins/message.plugin.ts | 8 +++----- .../adapters/xmpp/xmpp-chat-adapter.service.spec.ts | 10 ++-------- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/projects/pazznetwork/ngx-chat/src/lib/services/adapters/xmpp/plugins/message.plugin.ts b/projects/pazznetwork/ngx-chat/src/lib/services/adapters/xmpp/plugins/message.plugin.ts index 04f03e70..16884173 100644 --- a/projects/pazznetwork/ngx-chat/src/lib/services/adapters/xmpp/plugins/message.plugin.ts +++ b/projects/pazznetwork/ngx-chat/src/lib/services/adapters/xmpp/plugins/message.plugin.ts @@ -25,7 +25,6 @@ export class MessagePlugin extends AbstractXmppPlugin { private handleMessageStanza(messageStanza: MessageWithBodyStanza) { this.logService.debug('message received <=', messageStanza.getChildText('body')); - const contact = this.xmppChatAdapter.getOrCreateContactById(messageStanza.attrs.from); const message = { body: messageStanza.getChildText('body'), @@ -35,7 +34,7 @@ export class MessagePlugin extends AbstractXmppPlugin { }; this.xmppChatAdapter.plugins.forEach(plugin => plugin.afterReceiveMessage(message, messageStanza)); - + const contact = this.xmppChatAdapter.getOrCreateContactById(messageStanza.attrs.from); contact.addMessage(message); this.xmppChatAdapter.message$.next(contact); } @@ -46,18 +45,17 @@ export class MessagePlugin extends AbstractXmppPlugin { ); this.xmppChatAdapter.plugins.forEach(plugin => plugin.beforeSendMessage(messageStanza)); - const contact = this.xmppChatAdapter.getOrCreateContactById(jid); const message: Message = { direction: Direction.out, body, datetime: new Date(), delayed: false }; - // TODO: on rejection mark message that it was not sent successfully + const contact = this.xmppChatAdapter.getOrCreateContactById(jid); contact.addMessage(message); + // TODO: on rejection mark message that it was not sent successfully this.xmppChatAdapter.chatConnectionService.send(messageStanza).then(() => { this.xmppChatAdapter.plugins.forEach(plugin => plugin.afterSendMessage(message, messageStanza)); - this.xmppChatAdapter.message$.next(contact); }, (rej) => { this.logService.error('rejected message ' + message.id, rej); }); diff --git a/projects/pazznetwork/ngx-chat/src/lib/services/adapters/xmpp/xmpp-chat-adapter.service.spec.ts b/projects/pazznetwork/ngx-chat/src/lib/services/adapters/xmpp/xmpp-chat-adapter.service.spec.ts index 9dfe6689..6478b914 100644 --- a/projects/pazznetwork/ngx-chat/src/lib/services/adapters/xmpp/xmpp-chat-adapter.service.spec.ts +++ b/projects/pazznetwork/ngx-chat/src/lib/services/adapters/xmpp/xmpp-chat-adapter.service.spec.ts @@ -97,14 +97,8 @@ describe('XmppChatAdapter', () => { xml('body', {}, 'message text')) as Stanza); }); - it('#messages$ should emit contact on sending messages', (done) => { - chatService.message$.pipe(first()).subscribe(contact => { - expect(contact.jidBare.toString()).toEqual(contact1.jidBare.toString()); - expect(contact.messages.length).toEqual(1); - expect(contact.messages[0].body).toEqual('send message text'); - expect(contact.messages[0].direction).toEqual(Direction.out); - done(); - }); + it('#messages$ should not emit contact on sending messages', () => { + chatService.message$.pipe(first()).subscribe(() => fail()); chatService.sendMessage(contact1.jidBare.toString(), 'send message text'); });