patch chat
This commit is contained in:
parent
58d20920ea
commit
478456a199
@ -10,6 +10,7 @@ class ChatChannelModel(models.Model):
|
|||||||
self.save()
|
self.save()
|
||||||
for user_id in users_id:
|
for user_id in users_id:
|
||||||
ChatMemberModel(channel_id = self.pk, member_id = user_id).save()
|
ChatMemberModel(channel_id = self.pk, member_id = user_id).save()
|
||||||
|
return self.pk
|
||||||
|
|
||||||
def get_members_id(self):
|
def get_members_id(self):
|
||||||
return [member_channel.member_id for member_channel in ChatMemberModel.objects.filter(channel_id = self.pk)]
|
return [member_channel.member_id for member_channel in ChatMemberModel.objects.filter(channel_id = self.pk)]
|
||||||
|
@ -28,6 +28,9 @@ class ChannelView(APIView):
|
|||||||
data: dict = serializer.validated_data
|
data: dict = serializer.validated_data
|
||||||
|
|
||||||
members_id = data.get("members_id")
|
members_id = data.get("members_id")
|
||||||
|
if members_id == None:
|
||||||
|
return Response({"detail": "members_id is None."}, status = status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
if self.request.user.pk not in members_id:
|
if self.request.user.pk not in members_id:
|
||||||
return Response({"detail": "You are trying to create a chat group without you."}, status = status.HTTP_400_BAD_REQUEST)
|
return Response({"detail": "You are trying to create a chat group without you."}, status = status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
|
@ -37,7 +37,6 @@ class Channel {
|
|||||||
|
|
||||||
updateMessages(messages)
|
updateMessages(messages)
|
||||||
{
|
{
|
||||||
console.log(messages);
|
|
||||||
messages = JSON.parse(messages);
|
messages = JSON.parse(messages);
|
||||||
let new_messages = [];
|
let new_messages = [];
|
||||||
|
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
import {Channel} from "./channel.js"
|
import {Channel} from "./channel.js"
|
||||||
import {Message} from "./message.js"
|
|
||||||
|
|
||||||
class Channels {
|
class Channels {
|
||||||
constructor(client) {
|
constructor(client) {
|
||||||
this.client = client;
|
this.client = client;
|
||||||
|
this.channel = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
async createChannel(members_id, reload) {
|
async createChannel(members_id, reload) {
|
||||||
@ -29,7 +29,10 @@ class Channels {
|
|||||||
if (exit_code == 200)
|
if (exit_code == 200)
|
||||||
messages = data.messages;
|
messages = data.messages;
|
||||||
|
|
||||||
return new Channel(this.client, data.channel_id, members_id, messages, reload);
|
console.log(response);
|
||||||
|
console.log(data);
|
||||||
|
this.channel = new Channel(this.client, data.channel_id, members_id, messages, reload);
|
||||||
|
return this.channel;
|
||||||
}
|
}
|
||||||
|
|
||||||
async deleteChannel(members_id) {
|
async deleteChannel(members_id) {
|
||||||
|
0
frontend/static/js/api/chat/notice.js
Normal file
0
frontend/static/js/api/chat/notice.js
Normal file
@ -32,7 +32,7 @@ class Profile
|
|||||||
|
|
||||||
let block_response = await this.client._get("/api/profiles/block");
|
let block_response = await this.client._get("/api/profiles/block");
|
||||||
|
|
||||||
if (block_response.status == 404)
|
if (block_response.status != 200)
|
||||||
return
|
return
|
||||||
|
|
||||||
let block_data = await block_response.json();
|
let block_data = await block_response.json();
|
||||||
|
@ -54,22 +54,22 @@ export default class extends AbstractView {
|
|||||||
let add_chat = document.createElement("a");
|
let add_chat = document.createElement("a");
|
||||||
add_chat.id = "add_chat_off";
|
add_chat.id = "add_chat_off";
|
||||||
add_chat.onclick = async () => {
|
add_chat.onclick = async () => {
|
||||||
if (client.channel != undefined) {
|
if (client.channels.channel != undefined) {
|
||||||
client.channel.members_id.forEach((member_id) => {
|
client.channels.channel.members_id.forEach((member_id) => {
|
||||||
if (member_id == user.user_id)
|
if (member_id == user.user_id)
|
||||||
client.channel = undefined;
|
client.channels.channel = undefined;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (client.channel == undefined) {
|
if (client.channels.channel == undefined) {
|
||||||
add_chat.id = "add_chat_off";
|
add_chat.id = "add_chat_off";
|
||||||
this.last_add_chat = undefined;
|
this.last_add_chat = undefined;
|
||||||
return this.hideChat();
|
return await this.hideChat();
|
||||||
}
|
}
|
||||||
|
|
||||||
client.channel.disconnect();
|
await client.channels.channel.disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
client.channel = await client.channels.createChannel([client.me.user_id , user.user_id], this.chat);
|
client.channels.channel = await client.channels.createChannel([client.me.user_id , user.user_id], this.chat);
|
||||||
this.chat();
|
this.chat();
|
||||||
if (this.last_add_chat != undefined)
|
if (this.last_add_chat != undefined)
|
||||||
this.last_add_chat.id = "add_chat_off";
|
this.last_add_chat.id = "add_chat_off";
|
||||||
@ -109,7 +109,7 @@ export default class extends AbstractView {
|
|||||||
document.getElementById(reload).remove();
|
document.getElementById(reload).remove();
|
||||||
});
|
});
|
||||||
|
|
||||||
if (client.channel == undefined || !logged)
|
if (client.channels.channel == undefined || !logged)
|
||||||
return ;
|
return ;
|
||||||
|
|
||||||
let chats = document.getElementById("chats");
|
let chats = document.getElementById("chats");
|
||||||
@ -134,7 +134,7 @@ export default class extends AbstractView {
|
|||||||
|
|
||||||
// les messages, réecriture seulement du dernier
|
// les messages, réecriture seulement du dernier
|
||||||
let i = 0;
|
let i = 0;
|
||||||
client.channel.messages.forEach((message) => {
|
client.channels.channel.messages.forEach((message) => {
|
||||||
if (messages.children[i] == null || message.content != messages.children[i].innerText) {
|
if (messages.children[i] == null || message.content != messages.children[i].innerText) {
|
||||||
let text = document.createElement("p");
|
let text = document.createElement("p");
|
||||||
let date = new Date(message.time);
|
let date = new Date(message.time);
|
||||||
@ -160,16 +160,16 @@ export default class extends AbstractView {
|
|||||||
chat.appendChild(chat_input);
|
chat.appendChild(chat_input);
|
||||||
|
|
||||||
chat_input.onkeydown = async () => {
|
chat_input.onkeydown = async () => {
|
||||||
if (event.keyCode == 13 && client.channel != undefined) {
|
if (event.keyCode == 13 && client.channels.channel != undefined) {
|
||||||
//let chat_input = document.getElementById("input_chat");
|
//let chat_input = document.getElementById("input_chat");
|
||||||
let chat_text = chat_input.value;
|
let chat_text = chat_input.value;
|
||||||
|
|
||||||
let receivers_id = [];
|
let receivers_id = [];
|
||||||
client.channel.members_id.forEach((member_id) => {
|
client.channels.channel.members_id.forEach((member_id) => {
|
||||||
if (member_id != client.me.user_id)
|
if (member_id != client.me.user_id)
|
||||||
receivers_id.push(users.filter(user => user.user_id == member_id)[0].user_id);
|
receivers_id.push(users.filter(user => user.user_id == member_id)[0].user_id);
|
||||||
});
|
});
|
||||||
await client.channel.sendMessageChannel(chat_text, receivers_id)
|
await client.channels.channel.sendMessageChannel(chat_text, receivers_id)
|
||||||
|
|
||||||
// Reset
|
// Reset
|
||||||
chat_input.value = "";
|
chat_input.value = "";
|
||||||
@ -180,7 +180,7 @@ export default class extends AbstractView {
|
|||||||
let members = document.createElement("h2");
|
let members = document.createElement("h2");
|
||||||
members.id = "members";
|
members.id = "members";
|
||||||
let usernames = "";
|
let usernames = "";
|
||||||
client.channel.members_id.forEach((member_id) => {
|
client.channels.channel.members_id.forEach((member_id) => {
|
||||||
if (member_id != client.me.user_id) {
|
if (member_id != client.me.user_id) {
|
||||||
if (usernames.length > 0)
|
if (usernames.length > 0)
|
||||||
usernames += ", ";
|
usernames += ", ";
|
||||||
@ -216,9 +216,9 @@ export default class extends AbstractView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async leavePage() {
|
async leavePage() {
|
||||||
if (client.channel != undefined)
|
if (client.channels.channel != undefined)
|
||||||
client.channel.disconnect();
|
client.channels.channel.disconnect();
|
||||||
client.channel = undefined
|
client.channels.channel = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
async getHtml() {
|
async getHtml() {
|
||||||
|
@ -26,8 +26,7 @@ class BlocksView(APIView):
|
|||||||
blocks = BlockModel.objects.filter(blocker=request.user.pk)
|
blocks = BlockModel.objects.filter(blocker=request.user.pk)
|
||||||
if (blocks):
|
if (blocks):
|
||||||
return Response(serializers.serialize("json", BlockModel.objects.filter(blocker=request.user.pk)), status=status.HTTP_200_OK)
|
return Response(serializers.serialize("json", BlockModel.objects.filter(blocker=request.user.pk)), status=status.HTTP_200_OK)
|
||||||
else:
|
return Response({}, status=status.HTTP_204_NO_CONTENT)
|
||||||
return Response({}, status=status.HTTP_404_NOT_FOUND)
|
|
||||||
|
|
||||||
def post(self, request):
|
def post(self, request):
|
||||||
data: dict = request.data
|
data: dict = request.data
|
||||||
|
Loading…
Reference in New Issue
Block a user