Message reading instantaneous completed

pull/1102/head
Vincent 5 years ago
parent c074234fcc
commit 1d289c04ed

@ -2289,8 +2289,6 @@
}, },
async markRead(newestUnreadDate, providedOptions) { async markRead(newestUnreadDate, providedOptions) {
console.log(`[vince][unread] Marking messages as read!!`);
const options = providedOptions || {}; const options = providedOptions || {};
_.defaults(options, { sendReadReceipts: true }); _.defaults(options, { sendReadReceipts: true });
@ -2302,8 +2300,7 @@
); );
let unreadMessages = await this.getUnread(); let unreadMessages = await this.getUnread();
console.log(`[vince][unread] Unread: `, unreadMessages);
const oldUnread = unreadMessages.filter( const oldUnread = unreadMessages.filter(
message => message.get('received_at') <= newestUnreadDate message => message.get('received_at') <= newestUnreadDate

@ -1106,7 +1106,10 @@ export class Message extends React.PureComponent<Props, State> {
const enableContextMenu = !isRss && !multiSelectMode; const enableContextMenu = !isRss && !multiSelectMode;
return ( return (
<div className={classNames(divClasses)}> <div
id={id}
className={classNames(divClasses)}
>
<ContextMenuTrigger id={rightClickTriggerId}> <ContextMenuTrigger id={rightClickTriggerId}>
{this.renderAvatar()} {this.renderAvatar()}
<div <div

@ -87,6 +87,8 @@ export class SessionConversation extends React.Component<any, State> {
}); });
}, 100); }, 100);
}); });
console.log(`[unread] Loaded conversation:`, this.props.conversations.conversationLookup[this.state.conversationKey]);
} }
public componentDidUpdate(){ public componentDidUpdate(){
@ -389,6 +391,7 @@ export class SessionConversation extends React.Component<any, State> {
this.setState({ messages, messageFetchTimestamp: timestamp }, () => { this.setState({ messages, messageFetchTimestamp: timestamp }, () => {
if (this.state.isScrolledToBottom) { if (this.state.isScrolledToBottom) {
console.log(`[unread] Updating messages from getMessage`);
this.updateReadMessages(); this.updateReadMessages();
} }
}); });
@ -404,15 +407,21 @@ export class SessionConversation extends React.Component<any, State> {
return; return;
} }
console.log(`[unread] isScrollToBottom:`, isScrolledToBottom);
if (isScrolledToBottom) { if (isScrolledToBottom) {
unread = messages[messages.length - 1]; unread = messages[messages.length - 1];
} else { } else {
console.log(`[unread] Calling findNewestVisibleUnread`)
unread = this.findNewestVisibleUnread(); unread = this.findNewestVisibleUnread();
} }
//console.log(`[unread] Messages:`, messages);
console.log(`[unread] Updating read messages: `, unread);
if (unread) { if (unread) {
const model = window.ConversationController.get(conversationKey); const model = window.ConversationController.get(conversationKey);
model.markRead.bind(model)(unread.attributes.received_at); model.markRead(unread.attributes.received_at);
} }
} }
@ -424,6 +433,9 @@ export class SessionConversation extends React.Component<any, State> {
const { length } = messages; const { length } = messages;
const viewportBottom = (messageContainer?.clientHeight + messageContainer?.scrollTop) || 0; const viewportBottom = (messageContainer?.clientHeight + messageContainer?.scrollTop) || 0;
console.log(`[findNew] messages`, messages);
// Start with the most recent message, search backwards in time // Start with the most recent message, search backwards in time
let foundUnread = 0; let foundUnread = 0;
for (let i = length - 1; i >= 0; i -= 1) { for (let i = length - 1; i >= 0; i -= 1) {
@ -432,6 +444,7 @@ export class SessionConversation extends React.Component<any, State> {
// Why? local notifications can be unread but won't be reflected the // Why? local notifications can be unread but won't be reflected the
// conversation's unread count. // conversation's unread count.
if (i > 30 && foundUnread >= unreadCount) { if (i > 30 && foundUnread >= unreadCount) {
console.log(`[findNew] foundUnread > unreadCount`);
return null; return null;
} }
@ -439,6 +452,7 @@ export class SessionConversation extends React.Component<any, State> {
if (!message.attributes.unread) { if (!message.attributes.unread) {
// eslint-disable-next-line no-continue // eslint-disable-next-line no-continue
console.log(`[findNew] no message.attributes`);
continue; continue;
} }
@ -448,6 +462,7 @@ export class SessionConversation extends React.Component<any, State> {
if (!el) { if (!el) {
// eslint-disable-next-line no-continue // eslint-disable-next-line no-continue
console.log(`[findNew] no message.id`);
continue; continue;
} }
@ -461,10 +476,13 @@ export class SessionConversation extends React.Component<any, State> {
// We're fully below the viewport, continue searching up. // We're fully below the viewport, continue searching up.
if (top > viewportBottom) { if (top > viewportBottom) {
// eslint-disable-next-line no-continue // eslint-disable-next-line no-continue
console.log(`[findNew] top > viewportBottom`);
continue; continue;
} }
if (bottom <= viewportBottom) { if (bottom <= viewportBottom) {
console.log(`[findNew] bottom <= viewportBottom`);
console.log(`[findNew] Message set`);
return message; return message;
} }
@ -481,10 +499,8 @@ export class SessionConversation extends React.Component<any, State> {
const isScrolledToBottom = messageContainer.scrollHeight - messageContainer.clientHeight <= messageContainer.scrollTop + 1; const isScrolledToBottom = messageContainer.scrollHeight - messageContainer.clientHeight <= messageContainer.scrollTop + 1;
// FIXME VINCE: Update unread count // Mark messages read
// In models/conversations console.log(`[unread] Updating messages from handleScroll`);
// Update unread count by geting all divs of .session-message
// which are currently in view.
this.updateReadMessages(); this.updateReadMessages();
// Pin scroll to bottom on new message, unless user has scrolled up // Pin scroll to bottom on new message, unless user has scrolled up

@ -4,7 +4,7 @@ import { SessionConversation } from '../../components/session/conversation/Sessi
import { StateType } from '../reducer'; import { StateType } from '../reducer';
const mapStateToProps = async (state: StateType) => { const mapStateToProps = (state: StateType) => {
// Get messages here!!!!! // Get messages here!!!!!

Loading…
Cancel
Save