Advance don't merge

This commit is contained in:
Xamora 2023-12-12 10:04:46 +01:00
parent 9b523f082f
commit bc892bc157
7 changed files with 48 additions and 51 deletions

View File

@ -0,0 +1,9 @@
class Channel {
constructor(id, members, messages) {
this.id = id;
this.members = members;
this.messages = messages;
}
}
export {Channel}

View File

@ -0,0 +1,19 @@
class Channels {
constructor(client) {
this.client = client;
}
async createChannel(users_id) {
console.log(users_id);
let response = await this.client._post("/api/chat/", {
users_id:users_id
});
let data = await response.json();
if (data == "Channel already exist")
return null;
return data;
}
}
export {Channels}

View File

@ -11,7 +11,6 @@ import { Client } from "./api/client.js";
import AbstractRedirectView from "./views/AbstractRedirectView.js"; import AbstractRedirectView from "./views/AbstractRedirectView.js";
import MeView from "./views/MeView.js"; import MeView from "./views/MeView.js";
import ProfilePageView from "./views/profiles/ProfilePageView.js"; import ProfilePageView from "./views/profiles/ProfilePageView.js";
import ProfilesView from "./views/profiles/ProfilesView.js";
let client = new Client(location.protocol + "//" + location.host) let client = new Client(location.protocol + "//" + location.host)
@ -36,7 +35,6 @@ const navigateTo = async (uri) => {
const router = async (uri) => { const router = async (uri) => {
const routes = [ const routes = [
{ path: "/", view: Dashboard }, { path: "/", view: Dashboard },
{ path: "/profiles", view: ProfilesView},
{ path: "/profiles/:id", view: ProfilePageView }, { path: "/profiles/:id", view: ProfilePageView },
{ path: "/settings", view: Settings }, { path: "/settings", view: Settings },
{ path: "/login", view: LoginView }, { path: "/login", view: LoginView },

View File

@ -1,6 +1,6 @@
import AbstractAuthentifiedView from "./AbstractAuthentifiedView.js"; import AbstractView from "./AbstractView.js";
export default class extends AbstractAuthentifiedView { export default class extends AbstractView {
constructor(params) { constructor(params) {
super(params, "Chat"); super(params, "Chat");

View File

@ -19,7 +19,7 @@ export default class extends AbstractView {
let search = document.getElementById("form").value; let search = document.getElementById("form").value;
let logged = client.isAuthentificate(); let logged = await client.isAuthentificate();
let users = await client.profiles.all(); let users = await client.profiles.all();
let list_users = document.getElementById('list_users'); let list_users = document.getElementById('list_users');
@ -38,10 +38,21 @@ export default class extends AbstractView {
new_user.appendChild(document.createTextNode(" ")); new_user.appendChild(document.createTextNode(" "));
// chat // chat
let chat = document.createElement("a"); if (logged) {
chat.href = `/chat` let chat = document.createElement("a");
chat.appendChild(document.createTextNode("Chat")); let array = [
new_user.appendChild(chat); client.me.user_id,
user.user_id,
];
console.log(client.me.id);
chat.addEventListener("click", async function(){
console.log("click");
await client.channels.createChannel([client.me.user_id , user.user_id]);
});
//chat.href = `/chat`
chat.appendChild(document.createTextNode("Chat"));
new_user.appendChild(chat);
}
// break line // break line
new_user.appendChild(document.createElement("br")); new_user.appendChild(document.createElement("br"));
@ -54,7 +65,7 @@ export default class extends AbstractView {
list_users.appendChild(new_user); list_users.appendChild(new_user);
}); });
console.log(list_users); //console.log(list_users);
} }

View File

@ -1,40 +0,0 @@
import AbstractView from "../AbstractView.js";
import { client } from "../../index.js"
export default class extends AbstractView {
constructor(params) {
super(params, "Profiles");
}
async postInit()
{
let profiles = await client.profiles.all()
let profile_list_element = document.getElementById("profile-list")
profiles.forEach((profile) => {
let profile_element = document.createElement("div");
profile_element.className = "item";
let avatar = document.createElement("img");
avatar.src = profile.avatar_url;
let username = document.createElement("a");
username.href = `/profiles/${profile.user_id}`;
username.appendChild(document.createTextNode(profile.username));
profile_element.appendChild(avatar);
profile_element.appendChild(username);
profile_list_element.appendChild(profile_element)
});
}
async getHtml() {
return `
<link rel="stylesheet" href="/static/css/profiles/profiles.css">
<div id="profile-list">
</div>
`;
}
}