Compare commits
No commits in common. "57ed6165eabef0ad0b958ec4b3256446021c9f88" and "41a7a6dfb8c5581897d5e21c3f3d97e3b96275b5" have entirely different histories.
57ed6165ea
...
41a7a6dfb8
@ -11,9 +11,9 @@ class ChatView(APIView):
|
||||
|
||||
def get(self, request, pk):
|
||||
if (ChannelModel.objects.filter(pk=pk)):
|
||||
return Response({'channel_id': pk}, status=status.HTTP_200_OK)
|
||||
return Response({'channel_id': pk})
|
||||
else:
|
||||
return Response("Channel doesn't exist", status=status.HTTP_404_NOT_FOUND)
|
||||
return Response("Channel doesn't exist")
|
||||
|
||||
def delete(self, request, pk):
|
||||
|
||||
@ -21,7 +21,28 @@ class ChatView(APIView):
|
||||
MessageModel.objects.filter(pk=pk).delete()
|
||||
MemberModel.objects.filter(pk=pk).delete()
|
||||
|
||||
return Response({'channel_id': pk}, status=status.HTTP_200_OK)
|
||||
return Response({'channel_id': pk})
|
||||
|
||||
"""
|
||||
def post(self, request, pk):
|
||||
channel = ChannelModel.objects.filter(pk=pk)
|
||||
message = request.data.get("message", [])
|
||||
print(message)
|
||||
if (message == []):
|
||||
return Response('No message', status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
new_message = MessageModel()
|
||||
new_message.channel_id = message["channel_id"]
|
||||
new_message.author_id = message["author_id"]
|
||||
new_message.content = message["content"]
|
||||
new_message.time = message["time"]
|
||||
new_message.save()
|
||||
|
||||
messages = MessageModel.objects.filter(channel_id=pk)
|
||||
messages = serializers.serialize("json", messages)
|
||||
return Response({'messages':messages}, status=status.HTTP_200_OK)
|
||||
"""
|
||||
|
||||
|
||||
class ChatsView(APIView):
|
||||
def post(self, request):
|
||||
|
@ -1,20 +0,0 @@
|
||||
#app #avatar
|
||||
{
|
||||
height: 100px;
|
||||
width: 100px;
|
||||
}
|
||||
|
||||
#app #username
|
||||
{
|
||||
font-size: 0.8em;
|
||||
}
|
||||
|
||||
#app #block {
|
||||
cursor: pointer;
|
||||
font-size: 0.7em;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
#app {
|
||||
margin-top: 20px;
|
||||
}
|
11
frontend/static/css/profiles/profile.css
Normal file
11
frontend/static/css/profiles/profile.css
Normal file
@ -0,0 +1,11 @@
|
||||
#app #avatar
|
||||
{
|
||||
height: 100px;
|
||||
width: 100px;
|
||||
}
|
||||
|
||||
#app #username
|
||||
{
|
||||
height: 100px;
|
||||
width: 100px;
|
||||
}
|
11
frontend/static/css/profiles/profiles.css
Normal file
11
frontend/static/css/profiles/profiles.css
Normal file
@ -0,0 +1,11 @@
|
||||
#app .item img
|
||||
{
|
||||
height: 100px;
|
||||
width: 100px;
|
||||
}
|
||||
|
||||
#app .item a
|
||||
{
|
||||
height: 100px;
|
||||
width: 100px;
|
||||
}
|
@ -30,7 +30,7 @@
|
||||
|
||||
#app #chat {
|
||||
position: relative;
|
||||
max-height: 100vh;
|
||||
max-height: 86vh;
|
||||
width: 100vh;
|
||||
/*border: 2px solid green;*/
|
||||
overflow: hidden;
|
||||
@ -50,7 +50,7 @@
|
||||
}
|
||||
|
||||
#app #messages {
|
||||
max-height: 60vh;
|
||||
max-height: 40em;
|
||||
overflow: scroll;
|
||||
overflow-y: scroll;
|
||||
overflow-x: hidden;
|
||||
|
@ -31,17 +31,6 @@ class Profiles
|
||||
await profile.init(user_id);
|
||||
return profile;
|
||||
}
|
||||
|
||||
async block(user_id) {
|
||||
|
||||
// blocker & blocked
|
||||
let response = await this.client._post("/api/block/",
|
||||
[this.client.me.user_id, user_id],
|
||||
);
|
||||
|
||||
let data = await response.json();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
export {Profiles}
|
@ -10,9 +10,9 @@ import GameView from "./views/Game.js"
|
||||
|
||||
import PageNotFoundView from './views/PageNotFoundView.js'
|
||||
|
||||
import AbstractRedirectView from "./views/abstracts/AbstractRedirectView.js";
|
||||
import AbstractRedirectView from "./views/AbstractRedirectView.js";
|
||||
import MeView from "./views/MeView.js";
|
||||
import ProfilePageView from "./views/ProfilePageView.js";
|
||||
import ProfilePageView from "./views/profiles/ProfilePageView.js";
|
||||
import MatchMakingView from "./views/MatchMakingView.js";
|
||||
|
||||
let client = new Client(location.protocol + "//" + location.host)
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { client, navigateTo } from "../../index.js";
|
||||
import { client, navigateTo } from "../index.js";
|
||||
import AbstractRedirectView from "./AbstractRedirectView.js";
|
||||
|
||||
export default class extends AbstractRedirectView{
|
@ -1,4 +1,4 @@
|
||||
import { client, navigateTo } from "../../index.js";
|
||||
import { client, navigateTo } from "../index.js";
|
||||
import AbstractRedirectView from "./AbstractRedirectView.js";
|
||||
|
||||
export default class extends AbstractRedirectView{
|
@ -1,4 +1,4 @@
|
||||
import { navigateTo } from "../../index.js";
|
||||
import { navigateTo } from "../index.js";
|
||||
import AbstractView from "./AbstractView.js";
|
||||
|
||||
export default class extends AbstractView{
|
@ -1,4 +1,4 @@
|
||||
import AbstractView from "./abstracts/AbstractView.js";
|
||||
import AbstractView from "./AbstractView.js";
|
||||
|
||||
export default class extends AbstractView {
|
||||
constructor(params) {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import AbstractView from "./abstracts/AbstractView.js";
|
||||
import AbstractView from './AbstractView.js'
|
||||
|
||||
export default class extends AbstractView {
|
||||
constructor(params) {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import AbstractAuthentificateView from "./abstracts/AbstractAuthentifiedView.js";
|
||||
import AbstractAuthentificateView from "./AbstractAuthentifiedView.js";
|
||||
|
||||
export default class extends AbstractAuthentificateView {
|
||||
constructor(params) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { client, navigateTo } from "../index.js";
|
||||
import AbstractView from "./abstracts/AbstractView.js";
|
||||
import AbstractView from "./AbstractView.js";
|
||||
|
||||
function game_found(game_id)
|
||||
{
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { client, navigateTo } from "../index.js";
|
||||
import { clear, fill_errors } from "../utils/formUtils.js";
|
||||
import AbstractAuthentificateView from "./abstracts/AbstractAuthentifiedView.js";
|
||||
import AbstractAuthentificateView from "./AbstractAuthentifiedView.js";
|
||||
|
||||
export default class extends AbstractAuthentificateView
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
import AbstractView from "./abstracts/AbstractView.js";
|
||||
import AbstractView from "./AbstractView.js";
|
||||
|
||||
export default class extends AbstractView {
|
||||
constructor(params) {
|
||||
|
@ -1,48 +0,0 @@
|
||||
import AbstractView from "./abstracts/AbstractView.js";
|
||||
import { client } from "../index.js"
|
||||
|
||||
export default class extends AbstractView {
|
||||
constructor(params) {
|
||||
super(params, "Profile ");
|
||||
this.user_id = params.id;
|
||||
}
|
||||
|
||||
async postInit()
|
||||
{
|
||||
let profile = await client.profiles.getProfile(this.user_id);
|
||||
let info = document.getElementById("info");
|
||||
|
||||
// Username
|
||||
let username = document.createElement("a");
|
||||
username.id = "username";
|
||||
username.appendChild(document.createTextNode(profile.username));
|
||||
info.appendChild(username);
|
||||
|
||||
info.appendChild(document.createElement("br"));
|
||||
|
||||
// Avatar
|
||||
let avatar = document.createElement("img");
|
||||
avatar.id = "avatar";
|
||||
avatar.src = profile.avatar_url;
|
||||
info.appendChild(avatar);
|
||||
|
||||
// Block option
|
||||
let block = document.createElement("a");
|
||||
block.id = "block";
|
||||
block.addEventListener("click", async () => {
|
||||
if (client.me.user_id != user.user_id) {
|
||||
}
|
||||
});
|
||||
block.appendChild(document.createTextNode("Block"));
|
||||
info.appendChild(block);
|
||||
}
|
||||
|
||||
async getHtml() {
|
||||
return `
|
||||
<link rel="stylesheet" href="/static/css/profile.css">
|
||||
<div id="info">
|
||||
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
import AbstractView from "./abstracts/AbstractView.js";
|
||||
import AbstractView from "./AbstractView.js";
|
||||
import {client} from "../index.js";
|
||||
import {Message} from "../api/chat/message.js"
|
||||
|
||||
@ -81,6 +81,13 @@ export default class extends AbstractView {
|
||||
|
||||
new_user.appendChild(document.createTextNode(" "));
|
||||
|
||||
let block = document.createElement("a");
|
||||
block.addEventListener("click", async () => {
|
||||
if (client.me.user_id != user.user_id) {
|
||||
}
|
||||
});
|
||||
block.appendChild(document.createTextNode("Block"));
|
||||
new_user.appendChild(block);
|
||||
}
|
||||
|
||||
// break line
|
||||
@ -101,11 +108,11 @@ export default class extends AbstractView {
|
||||
async chat() {
|
||||
|
||||
let logged = await client.isAuthentificate();
|
||||
/*let reload = document.getElementById("messages");
|
||||
let reload = document.getElementById("messages");
|
||||
if (reload != null)
|
||||
reload.remove();*/
|
||||
reload.remove();
|
||||
|
||||
let reload = document.getElementById("members");
|
||||
reload = document.getElementById("members");
|
||||
if (reload != null)
|
||||
reload.remove();
|
||||
|
||||
@ -120,36 +127,13 @@ export default class extends AbstractView {
|
||||
chats.appendChild(chat);
|
||||
}
|
||||
|
||||
|
||||
// div des messages
|
||||
let messages = document.getElementById("messages");
|
||||
if (messages == null) {
|
||||
messages = document.createElement("div");
|
||||
let messages = document.createElement("div");
|
||||
messages.id = "messages";
|
||||
if (document.getElementById("input_chat") == null)
|
||||
chat.appendChild(messages);
|
||||
else
|
||||
document.getElementById("input_chat").before(messages);
|
||||
}
|
||||
|
||||
// les messages, réecriture seulement du dernier
|
||||
let i = 0;
|
||||
client.channel.messages.forEach((message) => {
|
||||
if (messages.children[i] == null || message.content != messages.children[i].innerText) {
|
||||
console.log(message.content);
|
||||
if (messages.children[i] != null)
|
||||
console.log(messages.children[i].innerText);
|
||||
let text = document.createElement("p");
|
||||
text.appendChild(document.createTextNode(message.content));
|
||||
if (message.author_id == client.me.user_id)
|
||||
text.id = "you";
|
||||
else
|
||||
text.id = "other";
|
||||
|
||||
messages.appendChild(text);
|
||||
}
|
||||
i++;
|
||||
});
|
||||
|
||||
// Input pour rentrer un message
|
||||
if (document.getElementById("input_chat") == null) {
|
||||
@ -189,6 +173,17 @@ export default class extends AbstractView {
|
||||
members.appendChild(document.createTextNode(usernames));
|
||||
messages.before(members);
|
||||
|
||||
// les messages
|
||||
client.channel.messages.forEach((message) => {
|
||||
let text = document.createElement("p");
|
||||
text.appendChild(document.createTextNode(message.content));
|
||||
if (message.author_id == client.me.user_id)
|
||||
text.id = "you";
|
||||
else
|
||||
text.id = "other";
|
||||
|
||||
messages.appendChild(text);
|
||||
});
|
||||
|
||||
// Scroll to the bottom of messages
|
||||
messages.scrollTop = messages.scrollHeight;
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { client, navigateTo } from "../../index.js";
|
||||
import { clear, fill_errors } from "../../utils/formUtils.js";
|
||||
import AbstractNonAuthentifiedView from "../abstracts/AbstractNonAuthentified.js";
|
||||
import AbstractNonAuthentifiedView from "../AbstractNonAuthentified.js";
|
||||
|
||||
async function login()
|
||||
{
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { client, navigateTo } from "../../index.js";
|
||||
import AbstractAuthentifiedView from "../abstracts/AbstractAuthentifiedView.js";
|
||||
import AbstractAuthentifiedView from "../AbstractAuthentifiedView.js";
|
||||
|
||||
export default class extends AbstractAuthentifiedView
|
||||
{
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { client, navigateTo } from "../../index.js";
|
||||
import { clear, fill_errors } from "../../utils/formUtils.js";
|
||||
import AbstractNonAuthentifiedView from "../abstracts/AbstractNonAuthentified.js";
|
||||
import AbstractNonAuthentifiedView from "../AbstractNonAuthentified.js";
|
||||
|
||||
async function register()
|
||||
{
|
||||
|
29
frontend/static/js/views/profiles/ProfilePageView.js
Normal file
29
frontend/static/js/views/profiles/ProfilePageView.js
Normal file
@ -0,0 +1,29 @@
|
||||
import AbstractView from "../AbstractView.js";
|
||||
import { client } from "../../index.js"
|
||||
|
||||
export default class extends AbstractView {
|
||||
constructor(params) {
|
||||
super(params, "Profile ");
|
||||
this.user_id = params.id;
|
||||
}
|
||||
|
||||
async postInit()
|
||||
{
|
||||
let profile = await client.profiles.getProfile(this.user_id);
|
||||
|
||||
let username_element = document.getElementById("username");
|
||||
username_element.href = `/profiles/${this.user_id}`;
|
||||
username_element.appendChild(document.createTextNode(profile.username));
|
||||
|
||||
let avatar_element = document.getElementById("avatar");
|
||||
avatar_element.src = profile.avatar_url;
|
||||
}
|
||||
|
||||
async getHtml() {
|
||||
return `
|
||||
<link rel="stylesheet" href="/static/css/profiles/profile.css">
|
||||
<img id="avatar"/>
|
||||
<a id="username"></a>
|
||||
`;
|
||||
}
|
||||
}
|
@ -4,7 +4,6 @@ from django.contrib.auth.models import User
|
||||
from django.db.models.signals import post_save
|
||||
from django.dispatch import receiver
|
||||
from django.conf import settings
|
||||
from django.db.models import IntegerField
|
||||
|
||||
def upload_to(instance, filename: str):
|
||||
return f"./profiles/static/avatars/{instance.pk}.{filename.split('.')[1]}"
|
||||
@ -19,10 +18,3 @@ def on_user_created(sender, instance, created, **kwargs):
|
||||
if created:
|
||||
profile: ProfileModel = ProfileModel.objects.create(pk = instance.pk, user = instance)
|
||||
profile.save()
|
||||
|
||||
class BlockModel(models.Model):
|
||||
blocker = IntegerField(primary_key=False)
|
||||
blocked = IntegerField(primary_key=False)
|
||||
|
||||
def __str__(self):
|
||||
return "blocker_id: " + str(self.blocker) + ", blocked_id: " + str(self.blocked)
|
||||
|
@ -3,11 +3,9 @@ from django.conf import settings
|
||||
from django.conf.urls.static import static
|
||||
|
||||
from . import viewsets
|
||||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
path("me", viewsets.MyProfileViewSet.as_view({'patch': 'partial_update', 'get': 'retrieve'}), name="my_profile_page"),
|
||||
path("<int:pk>", viewsets.ProfileViewSet.as_view({'get': 'retrieve'}), name="profile_page"),
|
||||
path("", viewsets.ProfileViewSet.as_view({'get': 'list'}), name="profiles_list"),
|
||||
path("block", views.BlockView.as_view(), name="block_page"),
|
||||
] + static("/static/avatars/", document_root="./avatars")
|
@ -1,18 +0,0 @@
|
||||
from rest_framework.views import APIView
|
||||
from rest_framework.response import Response
|
||||
from rest_framework import authentication, permissions, status
|
||||
from rest_framework.authentication import SessionAuthentication
|
||||
from django.core import serializers
|
||||
|
||||
class BlockView(APIView):
|
||||
permission_classes = (permissions.IsAuthenticated,)
|
||||
authentication_classes = (SessionAuthentication,)
|
||||
|
||||
def post(self, request, pk):
|
||||
pass
|
||||
|
||||
def get(self, request, pk):
|
||||
pass
|
||||
|
||||
def delete(self, request, pk):
|
||||
pass
|
Loading…
Reference in New Issue
Block a user