Skip to content

Commit

Permalink
IV fix crash
Browse files Browse the repository at this point in the history
Fix scroll position when a new message arrives
  • Loading branch information
evgeny-nadymov committed Oct 4, 2019
1 parent 9065d7f commit 6d1e2cf
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"homepage": "http://evgeny-nadymov.github.io/telegram-react",
"name": "telegram_react",
"version": "0.0.437",
"version": "0.0.439",
"private": true,
"dependencies": {
"@material-ui/core": "^3.9.2",
Expand Down
4 changes: 2 additions & 2 deletions service-worker.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,14 @@ self.addEventListener('fetch', function(event) {

// If shouldRespond was set to true at any point, then call
// event.respondWith(), using the appropriate cache key.
console.log("[SW] fetch url " + url, shouldRespond);
// console.log("[SW] fetch url " + url, shouldRespond);
if (shouldRespond) {
event.respondWith(
caches.open(cacheName).then(function(cache) {
return cache.match(urlsToCacheKeys.get(url)).then(function(response) {
if (response) {
let url = event.request.url;
console.log("[SW] found cached url " + url);
// console.log("[SW] found cached url " + url);
/*if (url.indexOf(".wasm") > -1) {
console.log("[SW] wasm not modified");
let responseInit = {
Expand Down
8 changes: 7 additions & 1 deletion src/Components/ColumnMiddle/MessagesList.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,13 @@ class MessagesList extends React.Component {
const { chatId } = this.props;
if (chatId !== message.chat_id) return;

const scrollBehavior = message.is_outgoing ? ScrollBehaviorEnum.SCROLL_TO_BOTTOM : ScrollBehaviorEnum.NONE;
const list = this.listRef.current;

let scrollBehavior = message.is_outgoing ? ScrollBehaviorEnum.SCROLL_TO_BOTTOM : ScrollBehaviorEnum.NONE;
if (list.scrollTop + list.offsetHeight >= list.scrollHeight) {
scrollBehavior = ScrollBehaviorEnum.SCROLL_TO_BOTTOM;
}

const newState = message.is_outgoing ? { scrollDownVisible: false } : {};

const history = [message];
Expand Down
4 changes: 4 additions & 0 deletions src/Components/InstantView/InstantViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ class InstantViewer extends React.Component {
}

componentDidMount() {
this.mounted = true;
this.handleScroll();

document.addEventListener('keydown', this.onKeyDown, false);
Expand All @@ -114,6 +115,7 @@ class InstantViewer extends React.Component {
}

componentWillUnmount() {
this.mounted = false;
document.removeEventListener('keydown', this.onKeyDown, false);
InstantViewStore.removeListener('clientUpdateInstantViewUrl', this.onClientUpdateInstantViewUrl);
InstantViewStore.removeListener(
Expand Down Expand Up @@ -290,6 +292,8 @@ class InstantViewer extends React.Component {
};

updateItemsInView() {
if (!this.mounted) return;

const { instantView } = this.props;
if (!instantView) return;

Expand Down
2 changes: 1 addition & 1 deletion src/Components/Viewer/InstantViewMediaViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ import MediaViewerButton from './MediaViewerButton';
import MediaViewerFooterText from './MediaViewerFooterText';
import MediaViewerFooterButton from './MediaViewerFooterButton';
import MediaViewerDownloadButton from './MediaViewerDownloadButton';
import { getBlockCaption, getBlockMedia, getBlockUrl, getValidMediaBlocks } from '../../Utils/InstantView';
import { getViewerFile, saveMedia } from '../../Utils/File';
import { setInstantViewViewerContent } from '../../Actions/Client';
import TdLibController from '../../Controllers/TdLibController';
import './InstantViewMediaViewer.css';
import { getBlockCaption, getBlockMedia, getBlockUrl, getValidMediaBlocks } from '../../Utils/InstantView';

const forwardIconStyle = {
padding: 20,
Expand Down

0 comments on commit 6d1e2cf

Please sign in to comment.