mirror of
https://github.com/yawaflua/LuckyDiamond.git
synced 2025-12-10 04:09:29 +02:00
Add getting chat history logic
This commit is contained in:
@@ -49,6 +49,26 @@ export async function GetCurrentMoney(authToken, searchToken) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export async function GetChatHistory() {
|
||||
|
||||
try {
|
||||
const response = await fetch(`${BackendApiUrl}/ChatHistory/GetChatHistory`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: "",
|
||||
redirect: "follow"
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
console.log("Fetch error:", response.status);
|
||||
}
|
||||
|
||||
return await response.json();
|
||||
} catch (error) {
|
||||
console.log("Fetch error:", error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -10,13 +10,10 @@
|
||||
<div class="chat__content--users">
|
||||
<ul>
|
||||
<transition-group name="fade">
|
||||
<li
|
||||
v-for="msg in array"
|
||||
:key="msg"
|
||||
>
|
||||
<li v-for="msg in array" :key="msg">
|
||||
<div class="card__user">
|
||||
<div class="user__icon">
|
||||
<img :src="msg.icon">
|
||||
<img :src="msg.icon" />
|
||||
</div>
|
||||
<div class="content">
|
||||
<h1>{{ msg.username }}</h1>
|
||||
@@ -32,54 +29,73 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import '@/assets/css/ComponentsStyles/chat.css'
|
||||
import "@/assets/css/ComponentsStyles/chat.css";
|
||||
import { GetChatHistory } from "@/assets/js/rest/RestMethods.js";
|
||||
|
||||
import WritechatComponent from "@/components/WritechatComponent.vue";
|
||||
import { SendMessageToChat } from "@/assets/js/chat/ChatLogic.js";
|
||||
import {eventBus} from "@/main";
|
||||
import { eventBus } from "@/main";
|
||||
|
||||
export default {
|
||||
components: { WritechatComponent },
|
||||
inject: [ 'eventBus' ],
|
||||
inject: ["eventBus"],
|
||||
data() {
|
||||
return {
|
||||
array: [],
|
||||
id: 0,
|
||||
}
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
ClaimDatamsg(msg) {
|
||||
|
||||
SendMessageToChat(msg[0]);
|
||||
|
||||
// if(this.array.length > 7) {
|
||||
// this.array.shift()
|
||||
// }
|
||||
}
|
||||
},
|
||||
},
|
||||
mounted() {
|
||||
eventBus.on('dataChat', (dataFromServer) => {
|
||||
eventBus.on("dataChat", (dataFromServer) => {
|
||||
try {
|
||||
// Attempt to parse the JSON string
|
||||
const dataObject = JSON.parse(dataFromServer);
|
||||
let imageUrl = "https://avatar.spworlds.ru/face/55/" + dataObject.SpUserName;
|
||||
let imageUrl =
|
||||
"https://avatar.spworlds.ru/face/55/" + dataObject.SpUserName;
|
||||
|
||||
const MsgUser = {
|
||||
id: this.id + 1,
|
||||
msg: dataObject.Message,
|
||||
username: dataObject.SpUserName,
|
||||
icon: imageUrl
|
||||
icon: imageUrl,
|
||||
};
|
||||
|
||||
this.array.push(MsgUser);
|
||||
} catch (error) {
|
||||
console.error('Error parsing JSON data:', error);
|
||||
console.error("Error parsing JSON data:", error);
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
created() {
|
||||
GetChatHistory().then((response) => {
|
||||
response.forEach((element) => {
|
||||
let imageUrl =
|
||||
"https://avatar.spworlds.ru/face/55/" + element.userName;
|
||||
|
||||
const MsgUser = {
|
||||
id: this.id + 1,
|
||||
msg: element.message,
|
||||
username: element.userName,
|
||||
icon: imageUrl,
|
||||
};
|
||||
|
||||
this.array.push(MsgUser);
|
||||
});
|
||||
|
||||
this.balance = response.currentMoney;
|
||||
});
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
</style>
|
||||
Reference in New Issue
Block a user