|
|
@ -2,6 +2,7 @@
|
|
|
|
<div>
|
|
|
|
<div>
|
|
|
|
<div ref="chatContainer" class="chatContainer">
|
|
|
|
<div ref="chatContainer" class="chatContainer">
|
|
|
|
<div @scroll="scrollHandler()" ref="msgContainer" id="messagesContainer" class="messagesContainer">
|
|
|
|
<div @scroll="scrollHandler()" ref="msgContainer" id="messagesContainer" class="messagesContainer">
|
|
|
|
|
|
|
|
<div v-if="loadingStatus" @click="loadEvents()" class="loadMore">{{loadingStatus}}</div>
|
|
|
|
<div id="messages" class="messages" ref="messages">
|
|
|
|
<div id="messages" class="messages" ref="messages">
|
|
|
|
<p v-if="room.timeline.length === 0" class="chatInfo">this room is empty</p>
|
|
|
|
<p v-if="room.timeline.length === 0" class="chatInfo">this room is empty</p>
|
|
|
|
<div class="timeGroup" v-for="timeGroup in splitArray(room.timeline,
|
|
|
|
<div class="timeGroup" v-for="timeGroup in splitArray(room.timeline,
|
|
|
@ -30,7 +31,7 @@
|
|
|
|
<icon v-if="showScrollBtn" @click.native="scrollToBottom()" id="scrollDown" ic="./sym/expand_more-black-24dp.svg" />
|
|
|
|
<icon v-if="showScrollBtn" @click.native="scrollToBottom()" id="scrollDown" ic="./sym/expand_more-black-24dp.svg" />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<newMessage :onResize="height=>resize(height)" :roomId="room.roomId"/>
|
|
|
|
<newMessage :onResize="height=>resize(height)" :roomId="room.roomId"/>
|
|
|
|
<topBanner :room="room" :close-chat="()=>closeChat()" />
|
|
|
|
<topBanner :room="room" :close-chat="()=>closeChat()" :open-chat-info="()=>openChatInfo()"/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
@ -38,8 +39,9 @@
|
|
|
|
import message from '@/components/message.vue';
|
|
|
|
import message from '@/components/message.vue';
|
|
|
|
import newMessage from '@/components/newMessage.vue';
|
|
|
|
import newMessage from '@/components/newMessage.vue';
|
|
|
|
import topBanner from '@/components/topBanner.vue';
|
|
|
|
import topBanner from '@/components/topBanner.vue';
|
|
|
|
import Icon from "@/components/icon";
|
|
|
|
import Icon from '@/components/icon';
|
|
|
|
import userThumbnail from '@/components/userThumbnail';
|
|
|
|
import userThumbnail from '@/components/userThumbnail';
|
|
|
|
|
|
|
|
import {matrix} from '@/main';
|
|
|
|
|
|
|
|
|
|
|
|
export default {
|
|
|
|
export default {
|
|
|
|
name: 'chat',
|
|
|
|
name: 'chat',
|
|
|
@ -53,7 +55,8 @@ export default {
|
|
|
|
props: {
|
|
|
|
props: {
|
|
|
|
room: [Object, undefined],
|
|
|
|
room: [Object, undefined],
|
|
|
|
user: String,
|
|
|
|
user: String,
|
|
|
|
closeChat: Function
|
|
|
|
closeChat: Function,
|
|
|
|
|
|
|
|
openChatInfo: Function
|
|
|
|
},
|
|
|
|
},
|
|
|
|
methods:{
|
|
|
|
methods:{
|
|
|
|
scrollToBottom(){
|
|
|
|
scrollToBottom(){
|
|
|
@ -61,17 +64,15 @@ export default {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
getTime(time){
|
|
|
|
getTime(time){
|
|
|
|
let date = new Date(time);
|
|
|
|
let date = new Date(time);
|
|
|
|
return `${date.getHours()}:${(date.getMinutes()<10)?"0":""}${date.getMinutes()}`;
|
|
|
|
return `${date.getHours()}:${(date.getMinutes()<10)?'0':''}${date.getMinutes()}`;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
getDate(time){
|
|
|
|
getDate(time){
|
|
|
|
let months = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
|
|
|
|
let months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
|
|
|
|
let date = new Date(time);
|
|
|
|
let date = new Date(time);
|
|
|
|
return `${date.getDate()} ${months[date.getMonth()]} ${date.getFullYear()}`;
|
|
|
|
return `${date.getDate()} ${months[date.getMonth()]} ${date.getFullYear()}`;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
scrollHandler(){
|
|
|
|
scrollHandler(){
|
|
|
|
if (this.$refs.msgContainer.scrollTop === 0){
|
|
|
|
if (this.$refs.msgContainer.scrollTop === 0) this.loadEvents();
|
|
|
|
console.log("load messages")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
let msg = this.$refs.msgContainer;
|
|
|
|
let msg = this.$refs.msgContainer;
|
|
|
|
this.showScrollBtn = msg.scrollHeight - msg.scrollTop > msg.offsetHeight + 200;
|
|
|
|
this.showScrollBtn = msg.scrollHeight - msg.scrollTop > msg.offsetHeight + 200;
|
|
|
|
},
|
|
|
|
},
|
|
|
@ -90,6 +91,11 @@ export default {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
isGroup(){
|
|
|
|
isGroup(){
|
|
|
|
return Object.keys(this.room.currentState.members).length > 2;
|
|
|
|
return Object.keys(this.room.currentState.members).length > 2;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
async loadEvents(){
|
|
|
|
|
|
|
|
this.loadingStatus = 'loading ...';
|
|
|
|
|
|
|
|
await matrix.client.paginateEventTimeline(this.room.getLiveTimeline(), {backwards: true})
|
|
|
|
|
|
|
|
.then(state => this.loadingStatus = state?'load more':false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
data(){
|
|
|
|
data(){
|
|
|
@ -101,7 +107,8 @@ export default {
|
|
|
|
join: 'joined the room',
|
|
|
|
join: 'joined the room',
|
|
|
|
leave: 'left the room',
|
|
|
|
leave: 'left the room',
|
|
|
|
ban: 'was banned'
|
|
|
|
ban: 'was banned'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
loadingStatus: 'load more'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
updated(){
|
|
|
|
updated(){
|
|
|
@ -191,4 +198,15 @@ export default {
|
|
|
|
.username{
|
|
|
|
.username{
|
|
|
|
margin-left: 1rem;
|
|
|
|
margin-left: 1rem;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.loadMore{
|
|
|
|
|
|
|
|
position: relative;
|
|
|
|
|
|
|
|
background-color: #2d2d2d;
|
|
|
|
|
|
|
|
padding: 0.5rem;
|
|
|
|
|
|
|
|
border-radius: 0.5rem;
|
|
|
|
|
|
|
|
width: fit-content;
|
|
|
|
|
|
|
|
left: 50%;
|
|
|
|
|
|
|
|
transform: translate(-50%,0);
|
|
|
|
|
|
|
|
margin-top: 0.5rem;
|
|
|
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
</style>
|
|
|
|