Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<title>LocalChat</title>
</head>
<body>





<script type="module" src="./js/landing-page.js"></script>
</body>
</html>
19 changes: 19 additions & 0 deletions js/models/chat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class Chat{
constructor(userId1,userId2){
this.id=Chat.generateChatId();
this.user1Typing=false;
this.user2Typing=false;
this.messages=[];
}

static generateChatId(userId1,userId2){
if(userId1>userId2){
return userId1+'-'+userId2;
}
else{
return userId1+'-'+userId2;
}
}
}

export default Chat;
Empty file added js/models/group.js
Empty file.
9 changes: 9 additions & 0 deletions js/models/message.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class Message{
constructor(content,senderId,replyTo){
this.id=Math.floor(Math.random()*99999);
this.content=content;
this.senderId=senderId;
this.replyTo=replyTo;
this.timestamp=Date.now();
}
}
23 changes: 23 additions & 0 deletions js/models/user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import LocalStorageService from "../services/local-storage.js";

class User{
constructor(username,password){

this.id=User.generateUserId();
this.username=username;
this.password=password;
this.isLoggedIn=false;
this.isOnline=false;
}

static isUserNameUnique(username){
let users=LocalStorageService.getUsers();
return !(users.find(user=>user.username===username));
}

static generateUserId(){
return LocalStorageService.getUsers().length+1;
}
}

export default User;
13 changes: 10 additions & 3 deletions js/services/local-storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,25 @@ class LocalStorageService{
let users=JSON.parse(localStorage.getItem('users'))||[];
const user=new User(username,password);
users.push(user);
localStorage.setItem(JSON.stringify(users));
localStorage.setItem('users',JSON.stringify(users));
}

static createChat(userId1,userId2){
let chats=JSON.parse(localStorage.getItem('chats'));
let chat=new Chat(userId1,userId2);
chats.push(chat);
localStorage.setItem(JSON.stringify(chats));
localStorage.setItem('chats',JSON.stringify(chats));
}

static createGroup(){

}

}
static getUsers(){
return JSON.parse(localStorage.getItem('users'))||[];
}

}


export default LocalStorageService;
37 changes: 37 additions & 0 deletions js/services/session-manager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import LocalStorageService from "./local-storage.js";

class SessionManager{

static Login(username,password){
let users=LocalStorageService.getUsers();
user=users.find(user=>(user.username===username && user.password===password));
if(user){
user.isLoggedIn=true;
user.isOnline=true;

sessionStorage.setItem('user',JSON.stringify(user));
return user;
}

return false;
}


static Logout(user){
user.isLoggedIn=false;
user.isOnline=false;
sessionStorage.removeItem('user');
}


static setTestValue(){
sessionStorage.setItem('test','test value');
}

static getTestValue(){
console.log(sessionStorage.getItem('test'));
}
}


export default SessionManager;