Skip to content

Commit

Permalink
fix: unread messages only counts incoming messages, not sent ones
Browse files Browse the repository at this point in the history
  • Loading branch information
trampi committed Jan 11, 2019
1 parent 65a8a67 commit fe89ab8
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { x as xml } from '@xmpp/xml';
import { Element } from 'ltx';
import { BehaviorSubject, Observable } from 'rxjs';
import { debounceTime, delay, distinctUntilChanged, filter, map, share } from 'rxjs/operators';
import { Contact } from '../../../../core';
import { Contact, Direction } from '../../../../core';
import { findSortedInsertionIndexLast } from '../../../../core/utils-array';
import { extractValues, sum } from '../../../../core/utils-object';
import { ChatMessageListRegistryService } from '../../../chat-message-list-registry.service';
Expand Down Expand Up @@ -152,7 +152,10 @@ export class UnreadMessageCountPlugin extends AbstractXmppPlugin {
}

private calculateUnreadMessageCount(contact: Contact, date: Date) {
return contact.messages.length - findSortedInsertionIndexLast(date, contact.messages, message => message.datetime);
const firstUnreadMessageIndex = findSortedInsertionIndexLast(date, contact.messages, message => message.datetime);
return contact.messages.slice(firstUnreadMessageIndex)
.filter(message => message.direction === Direction.in)
.length;
}

private persistLastSeenDates() {
Expand Down

0 comments on commit fe89ab8

Please sign in to comment.