Merge remote-tracking branch 'origin/master'
# Conflicts: # src/views/rooms.vue
This commit is contained in:
commit
433fbac3fa
@ -35,11 +35,11 @@ export default {
|
||||
roomId: String
|
||||
},
|
||||
methods: {
|
||||
async sendMessage(){
|
||||
sendMessage(){
|
||||
let content = this.msg.content;
|
||||
if (!content.body) return;
|
||||
if (!content.body.trim()) return;
|
||||
let msgSend = Object.assign({}, this.msg);
|
||||
await matrix.sendEvent(msgSend, this.roomId);
|
||||
matrix.sendEvent(msgSend, this.roomId);
|
||||
content.body = "";
|
||||
let id = this.$refs.newMessageInput;
|
||||
id.style.height = "1.25rem";
|
||||
@ -88,6 +88,7 @@ export default {
|
||||
position: relative;
|
||||
margin-top: 1.25rem;
|
||||
margin-bottom: 0.75rem;
|
||||
padding: 0;
|
||||
left: 2rem;
|
||||
min-height: 1.5rem;
|
||||
max-height: 10rem;
|
||||
|
14
src/lib/scrollHandler.js
Normal file
14
src/lib/scrollHandler.js
Normal file
@ -0,0 +1,14 @@
|
||||
export default class {
|
||||
constructor(element) {
|
||||
this.element = element
|
||||
}
|
||||
scrollToBottom(){
|
||||
this.setScrollBottom(0);
|
||||
}
|
||||
getScrollBottom(){
|
||||
return this.element.scrollHeight - this.element.scrollTop - this.element.offsetHeight;
|
||||
}
|
||||
setScrollBottom(height){
|
||||
this.element.scrollTop = this.element.scrollHeight - this.element.offsetHeight - height;
|
||||
}
|
||||
}
|
@ -1,12 +1,12 @@
|
||||
<template>
|
||||
<div>
|
||||
<div ref="chatContainer" class="chatContainer">
|
||||
<div @scroll="scrollHandler()" ref="msgContainer" id="messagesContainer" class="messagesContainer">
|
||||
<div @scroll="onScroll()" ref="msgContainer" id="messagesContainer" class="messagesContainer">
|
||||
<div v-if="loadingStatus" @click="loadEvents()" class="loadMore">{{loadingStatus}}</div>
|
||||
<p v-if="room.timeline.length === 0" class="chatInfo">this room is empty</p>
|
||||
<timeline :timeline="room.timeline" :group-timeline="isGroup()" :user="user" :roomId="room.roomId"/>
|
||||
<timeline :timeline="room.timeline" :group-timeline="isGroup()" :user="user" :roomId="room.roomId" />
|
||||
</div>
|
||||
<icon v-if="showScrollBtn" @click.native="scrollToBottom()" id="scrollDown" ic="./sym/expand_more-black-24dp.svg" />
|
||||
<icon v-if="showScrollBtn" @click.native="scroll.scrollToBottom()" id="scrollDown" ic="./sym/expand_more-black-24dp.svg" />
|
||||
</div>
|
||||
<newMessage :onResize="height=>resize(height)" :roomId="room.roomId"/>
|
||||
<topBanner :room="room" :close-chat="()=>closeChat()" :open-chat-info="()=>openChatInfo()"/>
|
||||
@ -20,6 +20,7 @@ import Icon from '@/components/icon';
|
||||
import {matrix} from '@/main';
|
||||
import splitArray from '@/lib/splitArray.js'
|
||||
import timeline from '@/components/timeline';
|
||||
import scrollHandler from "@/lib/scrollHandler";
|
||||
|
||||
export default {
|
||||
name: 'chat',
|
||||
@ -36,13 +37,9 @@ export default {
|
||||
openChatInfo: Function
|
||||
},
|
||||
methods:{
|
||||
scrollToBottom(){
|
||||
this.$refs.msgContainer.scrollTop = this.$refs.msgContainer.scrollHeight;
|
||||
},
|
||||
scrollHandler(){
|
||||
onScroll(){
|
||||
if (this.$refs.msgContainer.scrollTop === 0) this.loadEvents();
|
||||
let msg = this.$refs.msgContainer;
|
||||
this.showScrollBtn = msg.scrollHeight - msg.scrollTop > msg.offsetHeight + 200;
|
||||
this.showScrollBtn = this.scroll.getScrollBottom() > 400;
|
||||
},
|
||||
resize(height){
|
||||
this.$refs.chatContainer.style.height = `calc(100% - ${height}px - 3.5rem)`;
|
||||
@ -51,9 +48,11 @@ export default {
|
||||
return Object.keys(this.room.currentState.members).length > 2;
|
||||
},
|
||||
async loadEvents(){
|
||||
let scrollBottom = this.scroll.getScrollBottom();
|
||||
this.loadingStatus = 'loading ...';
|
||||
await matrix.client.paginateEventTimeline(this.room.getLiveTimeline(), {backwards: true})
|
||||
.then(state => this.loadingStatus = state?'load more':false);
|
||||
this.scroll.setScrollBottom(scrollBottom);
|
||||
},
|
||||
getUser(userId){
|
||||
return matrix.client.getUser(userId);
|
||||
@ -64,14 +63,16 @@ export default {
|
||||
return {
|
||||
showScrollBtn: false,
|
||||
scrollOnUpdate: true,
|
||||
loadingStatus: 'load more'
|
||||
loadingStatus: 'load more',
|
||||
scroll: ()=>{}
|
||||
}
|
||||
},
|
||||
updated(){
|
||||
//this.scrollToBottom();
|
||||
if(this.scroll.getScrollBottom() < 400) this.scroll.scrollToBottom();
|
||||
},
|
||||
mounted(){
|
||||
//this.scrollToBottom();
|
||||
this.scroll = new scrollHandler(this.$refs.msgContainer);
|
||||
this.scroll.scrollToBottom();
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
@ -8,7 +8,7 @@
|
||||
<input v-model="search" class="input" type="text" maxlength="50" placeholder="search"><br>
|
||||
<div v-for="room in matrix.rooms" :key="room.roomId" @click="openChat(room)" >
|
||||
<room-list-element
|
||||
v-if="!search || room.name.toLowerCase().includes(search.toLowerCase())"
|
||||
v-if="!search || room.name.toLowerCase().includes(search.toLowerCase().trim())"
|
||||
:room="room"
|
||||
class="roomListElement"
|
||||
/>
|
||||
@ -45,10 +45,11 @@ export default {
|
||||
},
|
||||
methods:{
|
||||
openChat(room){
|
||||
this.currentRoom = undefined
|
||||
this.$nextTick(() => this.currentRoom = room);
|
||||
this.showChatInfo = false;
|
||||
this.currentRoom = room;
|
||||
this.$router.push(`/rooms/${room.roomId}`);
|
||||
this.$forceUpdate();
|
||||
this.search = '';
|
||||
},
|
||||
getMxcFromRoom
|
||||
|
Loading…
Reference in New Issue
Block a user