Onload scroll to unread

pull/1102/head
Vincent 5 years ago
parent 8a609efffe
commit a5905536fa

@ -61,6 +61,7 @@ window.isBeforeVersion = (toCheck, baseVersion) => {
}; };
window.CONSTANTS = { window.CONSTANTS = {
SECS_IN_DAY: 60*60*24,
MAX_LOGIN_TRIES: 3, MAX_LOGIN_TRIES: 3,
MAX_PASSWORD_LENGTH: 32, MAX_PASSWORD_LENGTH: 32,
MAX_USERNAME_LENGTH: 20, MAX_USERNAME_LENGTH: 20,

@ -41,7 +41,7 @@
@include session-color-subtle($session-color-white); @include session-color-subtle($session-color-white);
} }
@at-root .dark-theme #{&} { @at-root .dark-theme #{&} {
background-color: $session-shade-8; background-color: $session-shade-5;
} }
} }

@ -56,6 +56,15 @@ export class Timestamp extends React.Component<Props> {
return null; return null;
} }
// Use relative time for under 24hrs ago.
const now = Math.floor(Date.now());
const messageAgeInDays = (now - timestamp) / (1000 * window.CONSTANTS.SECS_IN_DAY);
const daysBeforeRelativeTiming = 1;
const dateString = messageAgeInDays > daysBeforeRelativeTiming
? formatRelativeTime(timestamp, { i18n, extended })
: moment(timestamp).fromNow();
return ( return (
<span <span
className={classNames( className={classNames(
@ -65,7 +74,7 @@ export class Timestamp extends React.Component<Props> {
)} )}
title={moment(timestamp).format('llll')} title={moment(timestamp).format('llll')}
> >
{formatRelativeTime(timestamp, { i18n, extended })} {dateString}
</span> </span>
); );
} }

@ -139,9 +139,8 @@ export class SessionConversation extends React.Component<any, State> {
public renderMessages() { public renderMessages() {
const { messages } = this.state; const { messages } = this.state;
// IF MESSAGE IS THE TOP OF UNREAD, THEN INSERT AN UNREAD BANNER
// FIXME VINCE: IF MESSAGE IS THE TOP OF UNREAD, THEN INSERT AN UNREAD BANNER
return ( return (
<>{ <>{
@ -218,8 +217,6 @@ export class SessionConversation extends React.Component<any, State> {
} }
public renderMessage(messageProps: any, firstMessageOfSeries: boolean, quoteProps?: any) { public renderMessage(messageProps: any, firstMessageOfSeries: boolean, quoteProps?: any) {
return ( return (
@ -311,8 +308,8 @@ export class SessionConversation extends React.Component<any, State> {
// If we have pulled messages in the last interval, don't bother rescanning // If we have pulled messages in the last interval, don't bother rescanning
// This avoids getting messages on every re-render. // This avoids getting messages on every re-render.
if (timestamp >= messageFetchTimestamp + fetchInterval) { if (timestamp - messageFetchTimestamp < fetchInterval) {
return; return { newTopMessage: undefined, previousTopMessage: undefined };
} }
const msgCount = numMessages || window.CONSTANTS.DEFAULT_MESSAGE_FETCH_COUNT + this.state.unreadCount; const msgCount = numMessages || window.CONSTANTS.DEFAULT_MESSAGE_FETCH_COUNT + this.state.unreadCount;
@ -341,9 +338,6 @@ export class SessionConversation extends React.Component<any, State> {
this.setState({ messages, messageFetchTimestamp }); this.setState({ messages, messageFetchTimestamp });
console.log(`[vince][messages] Previous Top Message: `, previousTopMessage);
console.log(`[vince][messages] New Top Message: `, newTopMessage);
return { newTopMessage, previousTopMessage }; return { newTopMessage, previousTopMessage };
} }
@ -373,9 +367,9 @@ export class SessionConversation extends React.Component<any, State> {
const numMessages = this.state.messages.length + window.CONSTANTS.DEFAULT_MESSAGE_FETCH_COUNT; const numMessages = this.state.messages.length + window.CONSTANTS.DEFAULT_MESSAGE_FETCH_COUNT;
// Prevent grabbing messags with scroll more frequently than once per 5s. // Prevent grabbing messags with scroll more frequently than once per 5s.
// const messageFetchInterval = 5; const messageFetchInterval = 5;
// const previousTopMessage = (await this.getMessages(numMessages, messageFetchInterval))?.previousTopMessage; const previousTopMessage = (await this.getMessages(numMessages, messageFetchInterval))?.previousTopMessage;
// this.scrollToMessage(previousTopMessage); previousTopMessage && this.scrollToMessage(previousTopMessage);
} }
} }
@ -391,7 +385,7 @@ export class SessionConversation extends React.Component<any, State> {
topUnreadMessage?.scrollIntoView(); topUnreadMessage?.scrollIntoView();
} }
public scrollToBottom(firstLoad = false) { public scrollToBottom(instant = false) {
// FIXME VINCE: Smooth scrolling that isn't slow@! // FIXME VINCE: Smooth scrolling that isn't slow@!
// this.messagesEndRef.current?.scrollIntoView( // this.messagesEndRef.current?.scrollIntoView(
// { behavior: firstLoad ? 'auto' : 'smooth' } // { behavior: firstLoad ? 'auto' : 'smooth' }

Loading…
Cancel
Save