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">
|
<div class="chat__content--users">
|
||||||
<ul>
|
<ul>
|
||||||
<transition-group name="fade">
|
<transition-group name="fade">
|
||||||
<li
|
<li v-for="msg in array" :key="msg">
|
||||||
v-for="msg in array"
|
|
||||||
:key="msg"
|
|
||||||
>
|
|
||||||
<div class="card__user">
|
<div class="card__user">
|
||||||
<div class="user__icon">
|
<div class="user__icon">
|
||||||
<img :src="msg.icon">
|
<img :src="msg.icon" />
|
||||||
</div>
|
</div>
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<h1>{{ msg.username }}</h1>
|
<h1>{{ msg.username }}</h1>
|
||||||
@@ -32,54 +29,73 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<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 WritechatComponent from "@/components/WritechatComponent.vue";
|
||||||
import { SendMessageToChat } from "@/assets/js/chat/ChatLogic.js";
|
import { SendMessageToChat } from "@/assets/js/chat/ChatLogic.js";
|
||||||
import {eventBus} from "@/main";
|
import { eventBus } from "@/main";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: { WritechatComponent },
|
components: { WritechatComponent },
|
||||||
inject: [ 'eventBus' ],
|
inject: ["eventBus"],
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
array: [],
|
array: [],
|
||||||
id: 0,
|
id: 0,
|
||||||
}
|
};
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
ClaimDatamsg(msg) {
|
ClaimDatamsg(msg) {
|
||||||
|
|
||||||
SendMessageToChat(msg[0]);
|
SendMessageToChat(msg[0]);
|
||||||
|
|
||||||
// if(this.array.length > 7) {
|
// if(this.array.length > 7) {
|
||||||
// this.array.shift()
|
// this.array.shift()
|
||||||
// }
|
// }
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
eventBus.on('dataChat', (dataFromServer) => {
|
eventBus.on("dataChat", (dataFromServer) => {
|
||||||
try {
|
try {
|
||||||
// Attempt to parse the JSON string
|
// Attempt to parse the JSON string
|
||||||
const dataObject = JSON.parse(dataFromServer);
|
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 = {
|
const MsgUser = {
|
||||||
id: this.id + 1,
|
id: this.id + 1,
|
||||||
msg: dataObject.Message,
|
msg: dataObject.Message,
|
||||||
username: dataObject.SpUserName,
|
username: dataObject.SpUserName,
|
||||||
icon: imageUrl
|
icon: imageUrl,
|
||||||
};
|
};
|
||||||
|
|
||||||
this.array.push(MsgUser);
|
this.array.push(MsgUser);
|
||||||
} catch (error) {
|
} 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>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
Reference in New Issue
Block a user