Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 15 additions & 31 deletions app/ui/client/views/app/room.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ Template.roomOld.helpers({
},

messageboxData() {
const { sendToBottomIfNecessaryDebounced, subscription } = Template.instance();
const { sendToBottomIfNecessary, subscription } = Template.instance();
const { _id: rid } = this;
const isEmbedded = Layout.isEmbedded();
const showFormattingTips = settings.get('Message_ShowFormattingTips');
Expand All @@ -286,7 +286,7 @@ Template.roomOld.helpers({

chatMessages[rid].initializeInput(input, { rid });
},
onResize: () => sendToBottomIfNecessaryDebounced && sendToBottomIfNecessaryDebounced(),
onResize: () => sendToBottomIfNecessary && sendToBottomIfNecessary(),
onKeyUp: (...args) => chatMessages[rid] && chatMessages[rid].keyup.apply(chatMessages[rid], args),
onKeyDown: (...args) => chatMessages[rid] && chatMessages[rid].keydown.apply(chatMessages[rid], args),
onSend: (...args) => chatMessages[rid] && chatMessages[rid].send.apply(chatMessages[rid], args),
Expand Down Expand Up @@ -432,9 +432,6 @@ Template.roomOld.helpers({
},
});

let lastScrollTop;


export const dropzoneEvents = {
'dragenter .dropzone'(e) {
const types = e.originalEvent && e.originalEvent.dataTransfer && e.originalEvent.dataTransfer.types;
Expand Down Expand Up @@ -552,15 +549,15 @@ Meteor.startup(() => {
RoomHistoryManager.clear(template && template.data && template.data._id);
},
'load .gallery-item'(e, template) {
template.sendToBottomIfNecessaryDebounced();
template.sendToBottomIfNecessary();
},

'rendered .js-block-wrapper'(e, template) {
template.sendToBottomIfNecessaryDebounced();
template.sendToBottomIfNecessary();
},
'click .new-message'(event, instance) {
instance.atBottom = true;
instance.sendToBottomIfNecessaryDebounced();
instance.sendToBottomIfNecessary();
chatMessages[RoomManager.openedRoom].input.focus();
},
'click .upload-progress-close'(e) {
Expand All @@ -584,26 +581,26 @@ Meteor.startup(() => {
'scroll .wrapper': _.throttle(function(e, t) {
const $roomLeader = $('.room-leader');
if ($roomLeader.length) {
if (e.target.scrollTop < lastScrollTop) {
if (e.target.scrollTop < t.lastScrollTop) {
t.hideLeaderHeader.set(false);
} else if (t.isAtBottom(100) === false && e.target.scrollTop > $roomLeader.height()) {
t.hideLeaderHeader.set(true);
}
}
lastScrollTop = e.target.scrollTop;
t.lastScrollTop = e.target.scrollTop;
const height = e.target.clientHeight;
const isLoading = RoomHistoryManager.isLoading(this._id);
const hasMore = RoomHistoryManager.hasMore(this._id);
const hasMoreNext = RoomHistoryManager.hasMoreNext(this._id);

if ((isLoading === false && hasMore === true) || hasMoreNext === true) {
if (hasMore === true && lastScrollTop <= height / 3) {
if (hasMore === true && t.lastScrollTop <= height / 3) {
RoomHistoryManager.getMore(this._id);
} else if (hasMoreNext === true && Math.ceil(lastScrollTop) >= e.target.scrollHeight - height) {
} else if (hasMoreNext === true && Math.ceil(t.lastScrollTop) >= e.target.scrollHeight - height) {
RoomHistoryManager.getMoreNext(this._id);
}
}
}, 300),
}, 100),

'click .time a'(e) {
e.preventDefault();
Expand Down Expand Up @@ -765,8 +762,6 @@ Meteor.startup(() => {
this.sendToBottom();
}
};

this.sendToBottomIfNecessaryDebounced = _.debounce(this.sendToBottomIfNecessary, 10);
}); // Update message to re-render DOM

Template.roomOld.onDestroyed(function() {
Expand Down Expand Up @@ -812,30 +807,22 @@ Meteor.startup(() => {
};

template.sendToBottom = function() {
wrapper.scrollTop = wrapper.scrollHeight - wrapper.clientHeight;
wrapper.scrollTo(30, wrapper.scrollHeight);
newMessage.className = 'new-message background-primary-action-color color-content-background-color not';
};

template.checkIfScrollIsAtBottom = function() {
template.atBottom = template.isAtBottom(100);
};

template.observer = new ResizeObserver(() => template.sendToBottomIfNecessary());

if (window.MutationObserver) {
template.observer = new MutationObserver(() => template.sendToBottomIfNecessaryDebounced());

template.observer.observe(wrapperUl, { childList: true });
} else {
wrapperUl.addEventListener('DOMSubtreeModified', () => template.sendToBottomIfNecessaryDebounced());
}

template.onWindowResize = () => template.sendToBottomIfNecessaryDebounced();

window.addEventListener('resize', template.onWindowResize);
template.observer.observe(wrapperUl);

const wheelHandler = _.throttle(function() {
template.checkIfScrollIsAtBottom();
}, 100);

wrapper.addEventListener('mousewheel', wheelHandler);

wrapper.addEventListener('wheel', wheelHandler);
Expand All @@ -853,7 +840,7 @@ Meteor.startup(() => {
wrapper.addEventListener('scroll', wheelHandler);
});

lastScrollTop = $('.messages-box .wrapper').scrollTop();
this.lastScrollTop = $('.messages-box .wrapper').scrollTop();

const rtl = $('html').hasClass('rtl');

Expand Down Expand Up @@ -983,9 +970,6 @@ Meteor.startup(() => {
return FlowRouter.go('home');
}
});

const observer = new ResizeObserver(template.sendToBottomIfNecessary);
observer.observe(this.firstNode.querySelector('.wrapper ul'));
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const InviteUsers = ({
{onClickClose && <VerticalBar.Close onClick={onClickClose} />}
</VerticalBar.Header>

<VerticalBar.ScrollableContent>
<VerticalBar.Content>
<Field>
<Field.Label flexGrow={0}>{t('Invite_Link')}</Field.Label>
<Field.Row>
Expand All @@ -45,7 +45,7 @@ export const InviteUsers = ({
<Box pb='x16'>
{onClickEdit && <Button onClick={onClickEdit}>{t('Edit_Invite')}</Button>}
</Box>
</VerticalBar.ScrollableContent>
</VerticalBar.Content>
</Box>
);
};
Expand Down