remove error in console, and search work with unlog user

This commit is contained in:
Xamora 2024-01-14 17:50:34 +01:00
parent 131e599d17
commit 11392c22c4
5 changed files with 42 additions and 16 deletions

View File

@ -107,8 +107,8 @@ class ChatNoticeConsumer(WebsocketConsumer):
def connect(self):
user = self.scope["user"]
if (user.is_anonymous or not user.is_authenticated):
return
#if (user.is_anonymous or not user.is_authenticated):
#return
if (self.channel_layer == None):
return
@ -125,6 +125,18 @@ class ChatNoticeConsumer(WebsocketConsumer):
self.accept()
message_time: int = int(time.time() * 1000)
targets = list(self.channel_layer.users_channels.keys())
for target in targets:
channel = self.channel_layer.users_channels.get(target)
if (channel == None or target == user.pk):
continue
async_to_sync(self.channel_layer.send)(channel, {
'type':"online_users",
'author_id':user.pk,
'time':message_time,
})
def disconnect(self, code):
user = self.scope["user"]
@ -152,8 +164,8 @@ class ChatNoticeConsumer(WebsocketConsumer):
return
user = self.scope["user"]
if (user.is_anonymous or not user.is_authenticated):
return
#if (user.is_anonymous or not user.is_authenticated):
#return
text_data_json = json.loads(text_data)
@ -170,6 +182,8 @@ class ChatNoticeConsumer(WebsocketConsumer):
message_time: int = int(time.time() * 1000)
status = 200;
#print("receive" + str(user.pk))
if targets == "all":
targets = list(self.channel_layer.users_channels.keys())
@ -211,8 +225,10 @@ class ChatNoticeConsumer(WebsocketConsumer):
def online_users(self, event):
user = self.scope["user"]
if (user.is_anonymous or not user.is_authenticated):
return
#if (user.is_anonymous or not user.is_authenticated):
#return
#print("online_users" + str(user.pk))
event['content'] = self.channel_layer.users_channels

View File

@ -1,6 +1,7 @@
class Notice {
constructor(client) {
this.client = client;
this.online_users = {};
this.connect();
}
@ -25,12 +26,10 @@ class Notice {
async disconnect() {
if (this.chatSocket == undefined)
this.chatSocket.close();
return ;
this.chatSocket.close();
this.chatSocket.send(JSON.stringify({
type: "online_users",
targets: "all",
}));
}
async sendInvite(id_inviter, id_inviteds) {
@ -65,6 +64,8 @@ class Notice {
if (this.chatSocket == undefined)
return;
this.online_users = {};
this.chatSocket.send(JSON.stringify({
type: "online_users",
targets: "all",

View File

@ -10,10 +10,7 @@ export default class extends AbstractView {
async wait_get_online_users() {
return new Promise((resolve) => {
const checkInterval = setInterval(() => {
if (client.notice !== undefined &&
client.notice.online_users !== undefined &&
Object.keys(client.notice.online_users).length > 0) {
if (Object.keys(client.notice.online_users).length > 0) {
clearInterval(checkInterval);
resolve();
}
@ -26,6 +23,10 @@ export default class extends AbstractView {
let logged = await client.isAuthentificate();
let profiles = await client.profiles.all();
if (client.notice == undefined || client.notice.online_users == undefined)
return console.log("Error");
await client.notice.getOnlineUser();
await this.wait_get_online_users();
client.notice.rewrite_usernames = this.rewrite_usernames;
@ -121,7 +122,12 @@ export default class extends AbstractView {
}
async rewrite_usernames() {
let search = document.getElementById("input_user").value.toLowerCase();
let search_document = document.getElementById("input_user");
if (search_document == undefined || search_document == null)
return
let search = search_document.value.toLowerCase();
let profiles = await client.profiles.all();

View File

@ -10,6 +10,8 @@ async function login()
let response = await client.login(username, password);
if (response.status == 200) {
await client.notice.disconnect();
await client.notice.connect();
navigateTo("/home");
} else {
let error = await response.json();

View File

@ -9,6 +9,7 @@ export default class extends AbstractAuthentifiedView
async postInit() {
await client.logout();
await client.notice.disconnect();
navigateTo("/login")
}
}