Skip to content

Commit

Permalink
fix: do not emit messages$ when sending a message
Browse files Browse the repository at this point in the history
  • Loading branch information
trampi committed Jan 10, 2019
1 parent fdee840 commit cb906a5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand All @@ -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);
}
Expand All @@ -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);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});

Expand Down

0 comments on commit cb906a5

Please sign in to comment.