remove error in console, and search work with unlog user
This commit is contained in:
parent
131e599d17
commit
11392c22c4
@ -107,8 +107,8 @@ class ChatNoticeConsumer(WebsocketConsumer):
|
|||||||
def connect(self):
|
def connect(self):
|
||||||
|
|
||||||
user = self.scope["user"]
|
user = self.scope["user"]
|
||||||
if (user.is_anonymous or not user.is_authenticated):
|
#if (user.is_anonymous or not user.is_authenticated):
|
||||||
return
|
#return
|
||||||
|
|
||||||
if (self.channel_layer == None):
|
if (self.channel_layer == None):
|
||||||
return
|
return
|
||||||
@ -125,6 +125,18 @@ class ChatNoticeConsumer(WebsocketConsumer):
|
|||||||
|
|
||||||
self.accept()
|
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):
|
def disconnect(self, code):
|
||||||
|
|
||||||
user = self.scope["user"]
|
user = self.scope["user"]
|
||||||
@ -152,8 +164,8 @@ class ChatNoticeConsumer(WebsocketConsumer):
|
|||||||
return
|
return
|
||||||
|
|
||||||
user = self.scope["user"]
|
user = self.scope["user"]
|
||||||
if (user.is_anonymous or not user.is_authenticated):
|
#if (user.is_anonymous or not user.is_authenticated):
|
||||||
return
|
#return
|
||||||
|
|
||||||
text_data_json = json.loads(text_data)
|
text_data_json = json.loads(text_data)
|
||||||
|
|
||||||
@ -170,6 +182,8 @@ class ChatNoticeConsumer(WebsocketConsumer):
|
|||||||
message_time: int = int(time.time() * 1000)
|
message_time: int = int(time.time() * 1000)
|
||||||
status = 200;
|
status = 200;
|
||||||
|
|
||||||
|
#print("receive" + str(user.pk))
|
||||||
|
|
||||||
|
|
||||||
if targets == "all":
|
if targets == "all":
|
||||||
targets = list(self.channel_layer.users_channels.keys())
|
targets = list(self.channel_layer.users_channels.keys())
|
||||||
@ -211,8 +225,10 @@ class ChatNoticeConsumer(WebsocketConsumer):
|
|||||||
def online_users(self, event):
|
def online_users(self, event):
|
||||||
|
|
||||||
user = self.scope["user"]
|
user = self.scope["user"]
|
||||||
if (user.is_anonymous or not user.is_authenticated):
|
#if (user.is_anonymous or not user.is_authenticated):
|
||||||
return
|
#return
|
||||||
|
|
||||||
|
#print("online_users" + str(user.pk))
|
||||||
|
|
||||||
event['content'] = self.channel_layer.users_channels
|
event['content'] = self.channel_layer.users_channels
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
class Notice {
|
class Notice {
|
||||||
constructor(client) {
|
constructor(client) {
|
||||||
this.client = client;
|
this.client = client;
|
||||||
|
this.online_users = {};
|
||||||
this.connect();
|
this.connect();
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -25,12 +26,10 @@ class Notice {
|
|||||||
|
|
||||||
async disconnect() {
|
async disconnect() {
|
||||||
if (this.chatSocket == undefined)
|
if (this.chatSocket == undefined)
|
||||||
|
return ;
|
||||||
|
|
||||||
this.chatSocket.close();
|
this.chatSocket.close();
|
||||||
|
|
||||||
this.chatSocket.send(JSON.stringify({
|
|
||||||
type: "online_users",
|
|
||||||
targets: "all",
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async sendInvite(id_inviter, id_inviteds) {
|
async sendInvite(id_inviter, id_inviteds) {
|
||||||
@ -65,6 +64,8 @@ class Notice {
|
|||||||
if (this.chatSocket == undefined)
|
if (this.chatSocket == undefined)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
this.online_users = {};
|
||||||
|
|
||||||
this.chatSocket.send(JSON.stringify({
|
this.chatSocket.send(JSON.stringify({
|
||||||
type: "online_users",
|
type: "online_users",
|
||||||
targets: "all",
|
targets: "all",
|
||||||
|
@ -10,10 +10,7 @@ export default class extends AbstractView {
|
|||||||
async wait_get_online_users() {
|
async wait_get_online_users() {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
const checkInterval = setInterval(() => {
|
const checkInterval = setInterval(() => {
|
||||||
if (client.notice !== undefined &&
|
if (Object.keys(client.notice.online_users).length > 0) {
|
||||||
client.notice.online_users !== undefined &&
|
|
||||||
Object.keys(client.notice.online_users).length > 0) {
|
|
||||||
|
|
||||||
clearInterval(checkInterval);
|
clearInterval(checkInterval);
|
||||||
resolve();
|
resolve();
|
||||||
}
|
}
|
||||||
@ -26,6 +23,10 @@ export default class extends AbstractView {
|
|||||||
let logged = await client.isAuthentificate();
|
let logged = await client.isAuthentificate();
|
||||||
let profiles = await client.profiles.all();
|
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();
|
await this.wait_get_online_users();
|
||||||
client.notice.rewrite_usernames = this.rewrite_usernames;
|
client.notice.rewrite_usernames = this.rewrite_usernames;
|
||||||
|
|
||||||
@ -121,7 +122,12 @@ export default class extends AbstractView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async rewrite_usernames() {
|
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();
|
let profiles = await client.profiles.all();
|
||||||
|
|
||||||
|
@ -10,6 +10,8 @@ async function login()
|
|||||||
let response = await client.login(username, password);
|
let response = await client.login(username, password);
|
||||||
|
|
||||||
if (response.status == 200) {
|
if (response.status == 200) {
|
||||||
|
await client.notice.disconnect();
|
||||||
|
await client.notice.connect();
|
||||||
navigateTo("/home");
|
navigateTo("/home");
|
||||||
} else {
|
} else {
|
||||||
let error = await response.json();
|
let error = await response.json();
|
||||||
|
@ -9,6 +9,7 @@ export default class extends AbstractAuthentifiedView
|
|||||||
|
|
||||||
async postInit() {
|
async postInit() {
|
||||||
await client.logout();
|
await client.logout();
|
||||||
|
await client.notice.disconnect();
|
||||||
navigateTo("/login")
|
navigateTo("/login")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user