|
|
|
@ -82,7 +82,8 @@
|
|
|
|
|
</template>
|
|
|
|
|
<script>
|
|
|
|
|
// import RecycleScroller from 'vue-virtual-scroller';
|
|
|
|
|
|
|
|
|
|
// import * as SockJS from 'sockjs-client';
|
|
|
|
|
// import { Stomp } from "stompjs/lib/stomp.js";
|
|
|
|
|
import HonneyBtn from './HonneyBtn.vue';
|
|
|
|
|
import ChatCard from './ChatCard.vue';
|
|
|
|
|
import ChatList from './ChatList.vue';
|
|
|
|
@ -177,6 +178,7 @@ export default {
|
|
|
|
|
|
|
|
|
|
this.get_friendsInfoList()
|
|
|
|
|
this.long_poll_serve()
|
|
|
|
|
// this.websocket_serve()
|
|
|
|
|
},
|
|
|
|
|
components:{
|
|
|
|
|
HonneyBtn,
|
|
|
|
@ -185,6 +187,25 @@ export default {
|
|
|
|
|
ChatList
|
|
|
|
|
},
|
|
|
|
|
methods:{
|
|
|
|
|
// async websocket_serve(){
|
|
|
|
|
// const socket = new SockJS('https://911fb0525ms3.vicp.fun//loveforest/ws');
|
|
|
|
|
// const stompClient = Stomp.over(socket);
|
|
|
|
|
// const userId = getUserId()
|
|
|
|
|
|
|
|
|
|
// stompClient.connect({}, function (frame) {
|
|
|
|
|
// console.log('Connected: ' + frame);
|
|
|
|
|
|
|
|
|
|
// // 假设 receiverId 是当前用户的 ID
|
|
|
|
|
// const receiverId = userId; // 替换为当前用户的 ID
|
|
|
|
|
|
|
|
|
|
// // 订阅用户特定的未读消息队列
|
|
|
|
|
// stompClient.subscribe('/user/' + receiverId + '/queue/unread-messages', function (message) {
|
|
|
|
|
// const unreadMessage = JSON.parse(message.body);
|
|
|
|
|
// console.log('New unread message: ', unreadMessage);
|
|
|
|
|
// // 这里可以更新用户界面来显示未读消息
|
|
|
|
|
// });
|
|
|
|
|
// });
|
|
|
|
|
// },
|
|
|
|
|
async long_poll_serve(){
|
|
|
|
|
try{
|
|
|
|
|
const UserId = getUserId()
|
|
|
|
@ -200,14 +221,18 @@ export default {
|
|
|
|
|
console.log(senderId)
|
|
|
|
|
for(let i = 0;i<this.friendsInfoList.length;i++){
|
|
|
|
|
if(this.friendsInfoList[i].id == senderId){
|
|
|
|
|
let response2 = await axios.get(`/messages/chat/${UserId}/${senderId}`,{
|
|
|
|
|
headers:{Authorization : token}
|
|
|
|
|
})
|
|
|
|
|
if(this.friendsInfoList[i].chatHistory.slice(-1)[0].time == response2.data[response2.data.length-1].timestamp.replace('T',' ')){
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
console.log(this.friendsInfoList[i].chatHistory.slice(-1),response2.data[response2.data.length-1].timestamp.replace('T',' '))
|
|
|
|
|
if(this.chatWith != this.friendsInfoList[i].name){
|
|
|
|
|
this.friendsInfoList[i].unreading_num += 1
|
|
|
|
|
this.new_msg_nums += 1
|
|
|
|
|
}
|
|
|
|
|
let tempt_chat = {name:'',content:'',time:''}
|
|
|
|
|
let response2 = await axios.get(`/messages/chat/${UserId}/${senderId}`,{
|
|
|
|
|
headers:{Authorization : token}
|
|
|
|
|
})
|
|
|
|
|
tempt_chat.name = this.friendsInfoList[i].name
|
|
|
|
|
tempt_chat.content = response2.data[response2.data.length-1].content
|
|
|
|
|
tempt_chat.time = response2.data[response2.data.length-1].timestamp.replace('T',' ')
|
|
|
|
|