фикс багов, рабочий анпин, все дела

This commit is contained in:
uniknow 2024-07-16 20:04:42 +04:00
parent 435afb5414
commit 8e3cc37cc2
8 changed files with 130 additions and 29 deletions

View file

@ -92,10 +92,18 @@ export async function getLastMessages(chatId,msgLoaded){
})
if(response.ok){
let data = await response.json();
return data.allowed_chats
}
else{
console.log(response, "ты еблан")
data = data.allowed_chats
console.log(data)
if(data == null)
return []
else
return data
} else if(response.status == 409){
return false //если пользователь не подтвердил почту
} else {
console.log(response)
}
}
@ -111,8 +119,7 @@ export async function getLastMessages(chatId,msgLoaded){
if(response.ok){
const data = await response.json()
return data.pinned_messages
}
else{
} else {
console.log(response.status)
}
}
@ -128,9 +135,8 @@ export async function getLastMessages(chatId,msgLoaded){
if(response.ok){
const data = await response.json()
return data.pinned_message
}
else
console.log(response.status)
} else
console.log(response.status)
}

View file

@ -26,12 +26,13 @@ export async function checkExsistingUser(username, email) {
}
}
export async function VerificationEmail(Code){
export async function VerificationEmail(token, Code){
const response = await fetch('https://docs.black-phoenix.ru/api/users/email_verification',{
method:'POST',
credentials:'include',
headers:{
'Content-Type' : 'application/json'
'Content-Type' : 'application/json',
'Authorization': token
},
body: JSON.stringify({
"user_code": Code
@ -39,11 +40,11 @@ export async function VerificationEmail(Code){
})
if(response.status === 200){
window.location.href = '/'
return ""
window.location.href = '/chat'
return true
}
else if(response.status === 422){
return "Неправильный код"
else{
return false
}
}

View file

@ -5,10 +5,6 @@
</script>
<Header />
<style>

View file

@ -41,6 +41,8 @@
let pickedChatName = ""
let pickedChatImg = ""
let warningMessage = ""
let inputArea //объект textarea
onMount(async () => {
@ -51,6 +53,10 @@
window.addEventListener('keydown', onEnterPress);
chats = await getAllChats()
if(chats == false){
chats = []
warningMessage = "чтобы пользоваться чатом, подтверди почту"
}
createNewChatButton = true
//console.log(chats, " чаты")
@ -62,6 +68,9 @@
//console.log(chatId, " chatId")
currentChat = chats.find(chat => chat.chat_id == chatId)
if(currentChat == undefined){
window.location.href = '/chat'
}
//console.log(currentChat, " текущий чат")
pickedChatName = currentChat.chat_name
pickedChatImg = currentChat.avatar_image
@ -70,9 +79,6 @@
msgLoaded += 15
pinnedMsg = await getPinnedMsg(chatId)
console.log(pinnedMsg, " pinned")
//console.log(messages, " сообщения")
token = localStorage.getItem('BPChat')
const websocketUrl = `wss://docs.black-phoenix.ru/api/chat/ws/${chatId}`
@ -80,7 +86,6 @@
if (socket)
socket = null
socket = createWebSocket(websocketUrl, token, async (message) => {
console.log(message, "сообщение!!!!!")
@ -100,7 +105,10 @@
} else if(message.flag === "unpin"){
console.log(message)
const indexOfMassive = pinnedMsg.findIndex(msg => msg.id == message.id)
console.log(indexOfMassive)
pinnedMsg.splice(indexOfMassive, 1)
pinnedMsg = pinnedMsg
} else {
@ -131,6 +139,8 @@
if((messageText != "") || image != null){
console.log(`${messageText} - текст, ${image} - картинка`)
if(messageText == "жопа")
messageText = "жопа съела трусы O.O"
socket.send(JSON.stringify({flag: flag,
message: messageText,
@ -423,7 +433,7 @@ let pinOrNot = false
<div class="newChatInputDiv">
<h3>Название чата</h3>
<input class="newChatName" bind:value={newChatName} type="text">
<input class="newChatName" bind:value={newChatName} type="text">
<h4 class="newChatText">заблокируйте доступ к чату одному из пользователей</h4>
<input placeholder="Введите ник для поиска" type="text" class="nameToFind" on:input={lisinerNameToFine} name="nameToFind">
@ -445,7 +455,7 @@ let pinOrNot = false
</div>
<div class="newChatButtonDiv">
<button disabled={selectedUserId == ""} on:click={submtiCreateNewChat}>Создать</button>
<button disabled={((selectedUserId == "") || (newChatName == ""))} on:click={submtiCreateNewChat}>Создать</button>
<button on:click={cancelCreateNewChat}>Отменить</button>
</div>
@ -490,7 +500,7 @@ let pinOrNot = false
<div class="gradient">
{#if msgTimeShow == true}
<div class="msgTime" transition:fade={{ duration: 100 }}>
<div class="msgTime" transition:fade={{ duration: 100 }}>
<h3>{msgTime}</h3>
</div>
{/if}
@ -515,12 +525,17 @@ let pinOrNot = false
</div>
{/if}
{#if warningMessage.length != 0}
<div class="warningMessage">
<h2 transition:fly={{y:1000, delay:200, duration:500}}>{warningMessage}</h2>
</div>
{/if}
{#if ((chatId != null) && (messages.length === 0))}
<div class="noMsgDiv">
<h2 class="noMsg1">В этом чате еще нет сообщений.</h2>
<h3 class="noMsg2">Крыски, начните обсуждать <br> прям за ее спиной</h3>
<h3 class="noMsg2">Кто же напишет первый?</h3>
</div>
{/if}
@ -653,6 +668,15 @@ let pinOrNot = false
<style lang="scss">
.warningMessage{
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
text-align: center;
height: 100%;
}
.chatName{
width: 100%;
}
@ -692,6 +716,7 @@ let pinOrNot = false
flex-wrap: wrap;
overflow: scroll;
overflow-x: hidden;
height: 100%;
padding-top: 5px;

View file

@ -108,7 +108,9 @@
code = event.target.value
if(code.length == 6){
codeError = await VerificationEmail(code)
let verfcode = await VerificationEmail(code)
if(verfcode == false)
codeError = "Неправильный код"
}
}

View file

@ -0,0 +1,71 @@
<script>
import { blur, fly } from 'svelte/transition';
import { cubicOut } from 'svelte/easing';
import { onMount } from "svelte";
import { VerificationEmail } from '$lib/register';
let token
let codeExist
let code
let verifAnswer
onMount(async () => {
token = localStorage.getItem('BPChat')
codeExist = window.location.hash.startsWith('#code=')
if(codeExist == true){
code = window.location.hash.slice(6);
console.log(code)
verifAnswer = await VerificationEmail(token, code)
console.log(verifAnswer)
if(verifAnswer == false){
}
}
})
</script>
<body>
{#if codeExist == true}
{#if verifAnswer == false}
<img src="/image/somethingWrong.jpg" alt="dsa" transition:blur={{duration:727, delay:100}}>
{:else if verifAnswer == true}
<h2 transition:fly={{y:1000, delay:200, duration:500, easing:cubicOut}}>Отличная работа. <br/> А ты не плохо подтверждаешь почты</h2>
{/if}
{:else if codeExist == false}
<h2 class="brokeUrl">ты, помоему что то перепутал</h2>
{/if}
</body>
<style lang="scss">
body{
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
text-align: center;
}
h2{
margin-top: 5px;
padding: 2px;
}
.brokeUrl{
background-color: red;
margin-bottom: auto;
width: 100%;
}
img{
width: 300px;
height: auto;
border-radius: 15px;
}
</style>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 83 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 114 KiB