Chat data saved on localstorage

This commit is contained in:
Eudes Inácio
2021-12-08 19:36:41 +01:00
parent 1b8bec0afb
commit 17dcecc13e
4 changed files with 501 additions and 198 deletions
+140
View File
@@ -14,11 +14,17 @@ export class SqliteService {
readonly allprocess: string = "ALLPROCESS";
readonly actions: string = "ACTIONS";
readonly publications: string = "PUBLICATIONS";
readonly chatlistroom: string = "CHATLISTROOM";
readonly chatlistUsers: string = "CHATLISTUSERS";
readonly chatmsg: string = "CHATMSG";
EVENTS: Array<any>;
EXPEDIENTES: Array<any>;
ALLPROCESS: Array<any>;
PROCESS: Array<any>;
ALLACTIONS: Array<any>;
ALLChatROOM: Array<any>;
ALLChatUSERs: Array<any>;
ALLCHATMSG: Array<any>;
constructor(private platform: Platform,
private sqlite: SQLite) {
@@ -127,8 +133,55 @@ export class SqliteService {
console.log("Sucess action Table created: ", res)
})
.catch((error) => console.log(JSON.stringify(error)));
await sqLite.executeSql(`
CREATE TABLE IF NOT EXISTS ${this.chatlistroom} (
Id varchar(255) PRIMARY KEY,
Uids Text,
Usernames Text,
LastMessage Text,
UpdatedAt varchar(255)
)`, [])
.then((res) => {
console.log("Sucess chat list room Table created: ", res)
})
.catch((error) => console.log(JSON.stringify(error)));
await sqLite.executeSql(`
CREATE TABLE IF NOT EXISTS ${this.chatlistUsers} (
Id varchar(255) PRIMARY KEY,
Name varchar(255),
Username varchar(255)
)`, [])
.then((res) => {
console.log("Sucess chat list users Table created: ", res)
})
.catch((error) => console.log(JSON.stringify(error)));
await sqLite.executeSql(`
CREATE TABLE IF NOT EXISTS ${this.chatmsg} (
Id varchar(255) PRIMARY KEY,
Attachments Text,
Channels Text,
File Text,
Mentions Text,
Msg varchar(255),
Rid varchar(255),
Ts varchar(255),
U Text,
UpdatedAt varchar(255)
)`, [])
.then((res) => {
console.log("Sucess chat msg Table created: ", res)
})
.catch((error) => console.log(JSON.stringify(error)));
})
.catch((error) => console.log(JSON.stringify(error)));
}).catch((error) => {
console.log('Platform ready error', error)
});
@@ -191,6 +244,48 @@ export class SqliteService {
});
}
//chatlistroom
public addChatListRoom(data) {
console.log('INSIDE DB CHAT LIST ROOM',data,)
this.dbInstance.executeSql(`
INSERT OR REPLACE INTO ${this.chatlistroom} (Id,Uids,Usernames,LastMessage,UpdatedAt)
VALUES ('${data.id}','${JSON.stringify(data.uids)}','${JSON.stringify(data.usernames)}','${JSON.stringify(data.lastMessage)}','${data.updatedat}')`, [])
.then(() => {
console.log("chat room add with Success");
}, (e) => {
console.log(JSON.stringify(e.err));
});
}
//chatlistusers
public addChatListUsers(data) {
console.log('INSIDE DB CHAT LIST ROOM',data,)
this.dbInstance.executeSql(`
INSERT OR REPLACE INTO ${this.chatlistUsers} (Id,Name,Username)
VALUES ('${data.id}','${data.name}','${data.username}')`, [])
.then(() => {
console.log("chat users add with Success");
}, (e) => {
console.log(JSON.stringify(e.err));
});
}
//chatlistusers
public addChatMSG(data) {
console.log('INSIDE DB CHAT MSG',data,)
this.dbInstance.executeSql(`
INSERT OR REPLACE INTO ${this.chatmsg} (Id,Attachments,Channels,File,Mentions,Msg,Rid, Ts ,U, UpdatedAt)
VALUES ('${data._id}','${JSON.stringify(data.attachments)}','${JSON.stringify(data.channels)}','${JSON.stringify(data.file)}','${JSON.stringify(data.mentions)}','${data.msg}','${data.rid}','${data.ts}','${JSON.stringify(data.u)}','${data._updatedAt}')`, [])
.then(() => {
console.log("chat msg add with Success");
}, (e) => {
console.log(JSON.stringify(e.err));
});
}
//updateevent
public updateEvent(data) {
this.dbInstance.executeSql(`
@@ -348,6 +443,51 @@ export class SqliteService {
console.log(" Get all actions error", JSON.stringify(e));
});
}
//getAllChatRoom
getAllChatRoom() {
return this.dbInstance.executeSql(`SELECT * FROM ${this.chatlistroom}`, []).then((res) => {
this.ALLChatROOM = [];
if (res.rows.length > 0) {
for (var i = 0; i < res.rows.length; i++) {
this.ALLChatROOM.push(res.rows.item(i));
}
return this.ALLChatROOM;
}
}, (e) => {
console.log(" Get all chat room error", JSON.stringify(e));
});
}
//getAllChatUsers
getAllChatUsers() {
return this.dbInstance.executeSql(`SELECT * FROM ${this.chatlistUsers}`, []).then((res) => {
this.ALLChatUSERs = [];
if (res.rows.length > 0) {
for (var i = 0; i < res.rows.length; i++) {
this.ALLChatUSERs.push(res.rows.item(i));
}
return this.ALLChatUSERs;
}
}, (e) => {
console.log(" Get all chat users error", JSON.stringify(e));
});
}
//getAllChatMSG
getAllChatMSG(roomId) {
return this.dbInstance.executeSql(`SELECT * FROM ${this.chatmsg} WHERE Rid = ?`, [roomId]).then((res) => {
this.ALLCHATMSG = [];
if (res.rows.length > 0) {
for (var i = 0; i < res.rows.length; i++) {
this.ALLCHATMSG.push(res.rows.item(i));
}
return this.ALLCHATMSG;
}
}, (e) => {
console.log(" Get all chat users error", JSON.stringify(e));
});
}
//getlistOfEventAprove
getListOfEventAprove(process, type) {
return this.dbInstance.executeSql(`SELECT * FROM ${this.allprocess} WHERE workflowDisplayName = ? OR workflowDisplayName = ? `, [process, type]).then((res) => {