diff --git a/chat/models.py b/chat/models.py index 236c4ee..bc72b90 100644 --- a/chat/models.py +++ b/chat/models.py @@ -20,5 +20,5 @@ class MessageModel(models.Model): content = models.CharField(max_length=255) time = IntegerField(primary_key=False) - def __str__(self): + def __str__(self): return "author_id: " + str(self.author_id) + ", channel_id: " + str(self.channel_id) + ", content: " + self.content diff --git a/chat/views.py b/chat/views.py index 731325f..23e51ea 100644 --- a/chat/views.py +++ b/chat/views.py @@ -11,9 +11,9 @@ class ChatView(APIView): def get(self, request, pk): if (ChannelModel.objects.filter(pk=pk)): - return Response({'channel_id': pk}) + return Response({'channel_id': pk}, status=status.HTTP_200_OK) else: - return Response("Channel doesn't exist") + return Response("Channel doesn't exist", status=status.HTTP_404_NOT_FOUND) def delete(self, request, pk): @@ -21,28 +21,7 @@ class ChatView(APIView): MessageModel.objects.filter(pk=pk).delete() MemberModel.objects.filter(pk=pk).delete() - 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) - """ - + return Response({'channel_id': pk}, status=status.HTTP_200_OK) class ChatsView(APIView): def post(self, request): diff --git a/frontend/static/css/profile.css b/frontend/static/css/profile.css new file mode 100644 index 0000000..e0a5684 --- /dev/null +++ b/frontend/static/css/profile.css @@ -0,0 +1,20 @@ +#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; +} diff --git a/frontend/static/css/profiles/profile.css b/frontend/static/css/profiles/profile.css deleted file mode 100644 index 559ea88..0000000 --- a/frontend/static/css/profiles/profile.css +++ /dev/null @@ -1,11 +0,0 @@ -#app #avatar -{ - height: 100px; - width: 100px; -} - -#app #username -{ - height: 100px; - width: 100px; -} \ No newline at end of file diff --git a/frontend/static/css/profiles/profiles.css b/frontend/static/css/profiles/profiles.css deleted file mode 100644 index 7002c0f..0000000 --- a/frontend/static/css/profiles/profiles.css +++ /dev/null @@ -1,11 +0,0 @@ -#app .item img -{ - height: 100px; - width: 100px; -} - -#app .item a -{ - height: 100px; - width: 100px; -} \ No newline at end of file diff --git a/frontend/static/css/search.css b/frontend/static/css/search.css index ba0dc98..5e1618d 100644 --- a/frontend/static/css/search.css +++ b/frontend/static/css/search.css @@ -30,7 +30,7 @@ #app #chat { position: relative; - max-height: 86vh; + max-height: 100vh; width: 100vh; /*border: 2px solid green;*/ overflow: hidden; @@ -50,7 +50,7 @@ } #app #messages { - max-height: 40em; + max-height: 60vh; overflow: scroll; overflow-y: scroll; overflow-x: hidden; diff --git a/frontend/static/js/api/profiles.js b/frontend/static/js/api/profiles.js index f093c62..b12691f 100644 --- a/frontend/static/js/api/profiles.js +++ b/frontend/static/js/api/profiles.js @@ -31,6 +31,17 @@ 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} \ No newline at end of file +export {Profiles} diff --git a/frontend/static/js/index.js b/frontend/static/js/index.js index b0d3107..346eacb 100644 --- a/frontend/static/js/index.js +++ b/frontend/static/js/index.js @@ -10,9 +10,9 @@ import GameView from "./views/Game.js" import PageNotFoundView from './views/PageNotFoundView.js' -import AbstractRedirectView from "./views/AbstractRedirectView.js"; +import AbstractRedirectView from "./views/abstracts/AbstractRedirectView.js"; import MeView from "./views/MeView.js"; -import ProfilePageView from "./views/profiles/ProfilePageView.js"; +import ProfilePageView from "./views/ProfilePageView.js"; import MatchMakingView from "./views/MatchMakingView.js"; let client = new Client(location.protocol + "//" + location.host) diff --git a/frontend/static/js/views/Dashboard.js b/frontend/static/js/views/Dashboard.js index 698f945..0eba692 100644 --- a/frontend/static/js/views/Dashboard.js +++ b/frontend/static/js/views/Dashboard.js @@ -1,4 +1,4 @@ -import AbstractView from "./AbstractView.js"; +import AbstractView from "./abstracts/AbstractView.js"; export default class extends AbstractView { constructor(params) { @@ -16,4 +16,4 @@ export default class extends AbstractView {

`; } -} \ No newline at end of file +} diff --git a/frontend/static/js/views/Game.js b/frontend/static/js/views/Game.js index 87dd0cb..62c3066 100644 --- a/frontend/static/js/views/Game.js +++ b/frontend/static/js/views/Game.js @@ -1,4 +1,4 @@ -import AbstractView from './AbstractView.js' +import AbstractView from "./abstracts/AbstractView.js"; export default class extends AbstractView { constructor(params) { diff --git a/frontend/static/js/views/HomeView.js b/frontend/static/js/views/HomeView.js index 3569edb..a54ce96 100644 --- a/frontend/static/js/views/HomeView.js +++ b/frontend/static/js/views/HomeView.js @@ -1,4 +1,4 @@ -import AbstractAuthentificateView from "./AbstractAuthentifiedView.js"; +import AbstractAuthentificateView from "./abstracts/AbstractAuthentifiedView.js"; export default class extends AbstractAuthentificateView { constructor(params) { @@ -15,4 +15,4 @@ export default class extends AbstractAuthentificateView { Logout `; } -} \ No newline at end of file +} diff --git a/frontend/static/js/views/MatchMakingView.js b/frontend/static/js/views/MatchMakingView.js index df9cd9a..ca02363 100644 --- a/frontend/static/js/views/MatchMakingView.js +++ b/frontend/static/js/views/MatchMakingView.js @@ -1,5 +1,5 @@ import { client, navigateTo } from "../index.js"; -import AbstractView from "./AbstractView.js"; +import AbstractView from "./abstracts/AbstractView.js"; function game_found(game_id) { @@ -26,4 +26,4 @@ export default class extends AbstractView { { await client.matchmaking.stop(); } -} \ No newline at end of file +} diff --git a/frontend/static/js/views/MeView.js b/frontend/static/js/views/MeView.js index dd44b81..8ca2365 100644 --- a/frontend/static/js/views/MeView.js +++ b/frontend/static/js/views/MeView.js @@ -1,6 +1,6 @@ import { client, navigateTo } from "../index.js"; import { clear, fill_errors } from "../utils/formUtils.js"; -import AbstractAuthentificateView from "./AbstractAuthentifiedView.js"; +import AbstractAuthentificateView from "./abstracts/AbstractAuthentifiedView.js"; export default class extends AbstractAuthentificateView { @@ -102,4 +102,4 @@ export default class extends AbstractAuthentificateView `; } -} \ No newline at end of file +} diff --git a/frontend/static/js/views/PageNotFoundView.js b/frontend/static/js/views/PageNotFoundView.js index cff748e..5d875c3 100644 --- a/frontend/static/js/views/PageNotFoundView.js +++ b/frontend/static/js/views/PageNotFoundView.js @@ -1,4 +1,4 @@ -import AbstractView from "./AbstractView.js"; +import AbstractView from "./abstracts/AbstractView.js"; export default class extends AbstractView { constructor(params) { diff --git a/frontend/static/js/views/ProfilePageView.js b/frontend/static/js/views/ProfilePageView.js new file mode 100644 index 0000000..90c3d4e --- /dev/null +++ b/frontend/static/js/views/ProfilePageView.js @@ -0,0 +1,48 @@ +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 ` + +
+ +
+ `; + } +} diff --git a/frontend/static/js/views/Search.js b/frontend/static/js/views/Search.js index 2b3a011..7a706c7 100644 --- a/frontend/static/js/views/Search.js +++ b/frontend/static/js/views/Search.js @@ -1,4 +1,4 @@ -import AbstractView from "./AbstractView.js"; +import AbstractView from "./abstracts/AbstractView.js"; import {client} from "../index.js"; import {Message} from "../api/chat/message.js" @@ -81,13 +81,6 @@ 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 @@ -108,11 +101,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();*/ - reload = document.getElementById("members"); + let reload = document.getElementById("members"); if (reload != null) reload.remove(); @@ -127,13 +120,33 @@ export default class extends AbstractView { chats.appendChild(chat); } + // div des messages - let messages = document.createElement("div"); - messages.id = "messages"; - if (document.getElementById("input_chat") == null) - chat.appendChild(messages); - else - document.getElementById("input_chat").before(messages); + let messages = document.getElementById("messages"); + if (messages == null) { + 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[i] == null || message != 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) { @@ -173,17 +186,6 @@ 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; diff --git a/frontend/static/js/views/AbstractAuthentifiedView.js b/frontend/static/js/views/abstracts/AbstractAuthentifiedView.js similarity index 86% rename from frontend/static/js/views/AbstractAuthentifiedView.js rename to frontend/static/js/views/abstracts/AbstractAuthentifiedView.js index 191dcb5..eff0e36 100644 --- a/frontend/static/js/views/AbstractAuthentifiedView.js +++ b/frontend/static/js/views/abstracts/AbstractAuthentifiedView.js @@ -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{ diff --git a/frontend/static/js/views/AbstractNonAuthentified.js b/frontend/static/js/views/abstracts/AbstractNonAuthentified.js similarity index 86% rename from frontend/static/js/views/AbstractNonAuthentified.js rename to frontend/static/js/views/abstracts/AbstractNonAuthentified.js index 8c6190c..cf28f45 100644 --- a/frontend/static/js/views/AbstractNonAuthentified.js +++ b/frontend/static/js/views/abstracts/AbstractNonAuthentified.js @@ -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{ diff --git a/frontend/static/js/views/AbstractRedirectView.js b/frontend/static/js/views/abstracts/AbstractRedirectView.js similarity index 85% rename from frontend/static/js/views/AbstractRedirectView.js rename to frontend/static/js/views/abstracts/AbstractRedirectView.js index 6144270..81f1936 100644 --- a/frontend/static/js/views/AbstractRedirectView.js +++ b/frontend/static/js/views/abstracts/AbstractRedirectView.js @@ -1,4 +1,4 @@ -import { navigateTo } from "../index.js"; +import { navigateTo } from "../../index.js"; import AbstractView from "./AbstractView.js"; export default class extends AbstractView{ diff --git a/frontend/static/js/views/AbstractView.js b/frontend/static/js/views/abstracts/AbstractView.js similarity index 100% rename from frontend/static/js/views/AbstractView.js rename to frontend/static/js/views/abstracts/AbstractView.js diff --git a/frontend/static/js/views/accounts/LoginView.js b/frontend/static/js/views/accounts/LoginView.js index 6c81dc6..3e40d0a 100644 --- a/frontend/static/js/views/accounts/LoginView.js +++ b/frontend/static/js/views/accounts/LoginView.js @@ -1,6 +1,6 @@ import { client, navigateTo } from "../../index.js"; import { clear, fill_errors } from "../../utils/formUtils.js"; -import AbstractNonAuthentifiedView from "../AbstractNonAuthentified.js"; +import AbstractNonAuthentifiedView from "../abstracts/AbstractNonAuthentified.js"; async function login() { @@ -44,4 +44,4 @@ export default class extends AbstractNonAuthentifiedView { `; } -} \ No newline at end of file +} diff --git a/frontend/static/js/views/accounts/LogoutView.js b/frontend/static/js/views/accounts/LogoutView.js index 3713d18..6f29745 100644 --- a/frontend/static/js/views/accounts/LogoutView.js +++ b/frontend/static/js/views/accounts/LogoutView.js @@ -1,5 +1,5 @@ import { client, navigateTo } from "../../index.js"; -import AbstractAuthentifiedView from "../AbstractAuthentifiedView.js"; +import AbstractAuthentifiedView from "../abstracts/AbstractAuthentifiedView.js"; export default class extends AbstractAuthentifiedView { @@ -8,4 +8,4 @@ export default class extends AbstractAuthentifiedView client.logout(); navigateTo("/login") } -} \ No newline at end of file +} diff --git a/frontend/static/js/views/accounts/RegisterView.js b/frontend/static/js/views/accounts/RegisterView.js index 7e185e7..f1a4812 100644 --- a/frontend/static/js/views/accounts/RegisterView.js +++ b/frontend/static/js/views/accounts/RegisterView.js @@ -1,6 +1,6 @@ import { client, navigateTo } from "../../index.js"; import { clear, fill_errors } from "../../utils/formUtils.js"; -import AbstractNonAuthentifiedView from "../AbstractNonAuthentified.js"; +import AbstractNonAuthentifiedView from "../abstracts/AbstractNonAuthentified.js"; async function register() { diff --git a/frontend/static/js/views/profiles/ProfilePageView.js b/frontend/static/js/views/profiles/ProfilePageView.js deleted file mode 100644 index 81247a4..0000000 --- a/frontend/static/js/views/profiles/ProfilePageView.js +++ /dev/null @@ -1,29 +0,0 @@ -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 ` - - - - `; - } -} diff --git a/profiles/models.py b/profiles/models.py index 31df212..1362463 100644 --- a/profiles/models.py +++ b/profiles/models.py @@ -4,6 +4,7 @@ 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]}" @@ -17,4 +18,11 @@ class ProfileModel(models.Model): def on_user_created(sender, instance, created, **kwargs): if created: profile: ProfileModel = ProfileModel.objects.create(pk = instance.pk, user = instance) - profile.save() \ No newline at end of file + 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) diff --git a/profiles/urls.py b/profiles/urls.py index db385c2..0218f09 100644 --- a/profiles/urls.py +++ b/profiles/urls.py @@ -3,9 +3,11 @@ 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("", viewsets.ProfileViewSet.as_view({'get': 'retrieve'}), name="profile_page"), path("", viewsets.ProfileViewSet.as_view({'get': 'list'}), name="profiles_list"), -] + static("/static/avatars/", document_root="./avatars") \ No newline at end of file + path("block", views.BlockView.as_view(), name="block_page"), +] + static("/static/avatars/", document_root="./avatars") diff --git a/profiles/views.py b/profiles/views.py new file mode 100644 index 0000000..aeb17f6 --- /dev/null +++ b/profiles/views.py @@ -0,0 +1,18 @@ +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