diff --git a/src/app/services/chat/room.service.ts b/src/app/services/chat/room.service.ts
index aada27c11..5ff6b23be 100644
--- a/src/app/services/chat/room.service.ts
+++ b/src/app/services/chat/room.service.ts
@@ -6,6 +6,8 @@ import { showDateDuration } from 'src/plugin/showDateDuration'
import { ToastsService } from '../toast.service';
import { chatHistory, ChatMessage } from 'src/app/models/chatMethod'
import { Storage } from '@ionic/storage';
+import { Platform } from '@ionic/angular';
+import { SqliteService } from 'src/app/services/sqlite.service';
@Injectable({
providedIn: 'root'
})
@@ -33,6 +35,8 @@ export class RoomService {
public WsChatService: WsChatService,
private MessageService: MessageService,
private storage: Storage,
+ private platform: Platform,
+ private sqlservice: SqliteService,
) { }
setData({ customFields, id, name, t, lastMessage, _updatedAt }) {
@@ -85,10 +89,55 @@ export class RoomService {
this.WsChatService.send(this.id, msg)
}
+ getMsgFromDBMobile() {
+ console.log('ALL MSG DBBB', this.id)
+ this.sqlservice.getAllChatMSG(this.id).then((msg: any = []) => {
+ let ad = [];
+ ad = msg
+ console.log('ALL MSG DBBB', ad.length)
+ msg.map(element => {
+ console.log('CHANNEL ELEMENT', element)
+ let msgChat = {
+ _id: element.Id,
+ attachments: this.isJson(element.Attachments),
+ channels: this.isJson(element.Channels),
+ file: {
+ guid: this.isJson(element.File).guid,
+ image_url: this.isJson(element.image_url),
+ type: this.isJson(element.File).type
+
+ },
+ mentions: this.isJson(element.Mentions),
+ msg: element.Msg,
+ rid: element.Rid,
+ ts: element.Ts,
+ u: this.isJson(element.U),
+ _updatedAt: this.isJson(element.UpdatedAt),
+ }
+
+ let mmessage = this.fix_updatedAt(msgChat)
+ console.log('FROM DB WEB', mmessage)
+ const wewMessage = new MessageService()
+ wewMessage.setData(mmessage)
+ this.massages.push(wewMessage)
+ console.log('loadHistory 222', this.massages)
+ });
+ });
+ }
+
+ isJson(str) {
+ try {
+ JSON.parse(str);
+ } catch (e) {
+ return "";
+ }
+ return JSON.parse(str);
+ }
+
getMsgFromDB() {
-
+
this.storage.get('chatmsg' + this.id).then((message) => {
-
+
message.forEach(message => {
if (message.file) {
@@ -110,37 +159,45 @@ export class RoomService {
})
}
+
+
// runs onces only
loadHistory(limit = 100) {
if (this.hasLoadHistory) { return false }
- // ionic store
+ /* this.WsChatService.loadHistory(this.id, limit).then((chatHistory:chatHistory) => {
+ console.log('loadHistory', chatHistory)
-
- // websocket
- this.WsChatService.loadHistory(this.id, limit).then(async (chatHistory: chatHistory) => {
-
- //await this.transformData(chatHistory.result.messages.reverse());
- //console.log('loadHistory 111', chatHistory.result.messages.reverse())
- const mgsArray = chatHistory.result.messages.reverse();
- await this.storage.remove('chatmsg' + this.id).then(() => {
- console.log('MSG REMOVE ON STORAGE')
- })
- await this.storage.set('chatmsg' + this.id, mgsArray).then((value) => {
- console.log('MSG SAVED ON STORAGE', value)
- this.getMsgFromDB()
- });
-
- /* chatHistory.result.messages.reverse().forEach(message => {
+ chatHistory.result.messages.reverse().forEach(message => {
message = this.fix_updatedAt(message)
- console.log('loadHistory', message)
- this.storageMessage.push(message)
const wewMessage = new MessageService()
wewMessage.setData(message)
this.massages.push(wewMessage)
- }); */
+ });
+
+
+ }) */
+
+ this.WsChatService.loadHistory(this.id, limit).then(async (chatHistory: chatHistory) => {
+
+ const mgsArray = chatHistory.result.messages.reverse();
+ if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
+ await this.storage.remove('chatmsg' + this.id).then(() => {
+ console.log('MSG REMOVE ON STORAGE')
+ })
+ await this.storage.set('chatmsg' + this.id, mgsArray).then((value) => {
+ console.log('MSG SAVED ON STORAGE', value)
+ this.getMsgFromDB()
+ });
+ } else {
+ mgsArray.forEach((element) => {
+ console.log('SQLITE WEBSOCKET', element)
+ this.sqlservice.addChatMSG(element)
+ })
+ this.getMsgFromDBMobile()
+ }
})
diff --git a/src/app/services/chat/ws-chat-methods.service.ts b/src/app/services/chat/ws-chat-methods.service.ts
index 1636585c3..70625d0af 100644
--- a/src/app/services/chat/ws-chat-methods.service.ts
+++ b/src/app/services/chat/ws-chat-methods.service.ts
@@ -6,6 +6,8 @@ import { SessionStore } from 'src/app/store/session.service';
import { capitalizeTxt } from 'src/plugin/text'
import { Rooms, Update as room } from 'src/app/models/chatMethod';
import { Storage } from '@ionic/storage';
+import { Platform } from '@ionic/angular';
+import { SqliteService } from 'src/app/services/sqlite.service';
@Injectable({
providedIn: 'root'
@@ -24,7 +26,9 @@ export class WsChatMethodsService {
constructor(
private WsChatService: WsChatService,
- private storage: Storage
+ private storage: Storage,
+ private platform: Platform,
+ private sqlservice: SqliteService,
) {
(async()=>{
await this.getAllRooms();
@@ -47,7 +51,7 @@ export class WsChatMethodsService {
//console.log(roomData);
- room = new RoomService(this.WsChatService, new MessageService(), this.storage)
+ room = new RoomService(this.WsChatService, new MessageService(), this.storage, this.platform, this.sqlservice)
room.setData({
customFields: roomData.customFields,
id: this.getRoomId(roomData),
diff --git a/src/app/services/events/edit-event/edit-event.page.html b/src/app/services/events/edit-event/edit-event.page.html
index 401201dbc..50a9723c8 100644
--- a/src/app/services/events/edit-event/edit-event.page.html
+++ b/src/app/services/events/edit-event/edit-event.page.html
@@ -51,13 +51,13 @@
Data Início
Data Fim
diff --git a/src/app/services/events/event-detail-modal/event-detail-modal.page.html b/src/app/services/events/event-detail-modal/event-detail-modal.page.html
index 35866cd52..565af41d2 100644
--- a/src/app/services/events/event-detail-modal/event-detail-modal.page.html
+++ b/src/app/services/events/event-detail-modal/event-detail-modal.page.html
@@ -53,13 +53,13 @@
Data Início
Data Fim
diff --git a/src/app/services/events/event-detail/event-detail.page.html b/src/app/services/events/event-detail/event-detail.page.html
index 3f8023e69..15f9c7920 100644
--- a/src/app/services/events/event-detail/event-detail.page.html
+++ b/src/app/services/events/event-detail/event-detail.page.html
@@ -53,13 +53,13 @@
Data Início
Data Fim
diff --git a/src/app/services/sqlite.service.ts b/src/app/services/sqlite.service.ts
index 2457f5fb0..37638c4c0 100644
--- a/src/app/services/sqlite.service.ts
+++ b/src/app/services/sqlite.service.ts
@@ -280,7 +280,7 @@ export class SqliteService {
console.log('INSIDE DB CHAT MSG',data,)
this.dbInstance.executeSql(`
INSERT OR IGNORE 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}')`, [])
+ 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)}','${JSON.stringify(data._updatedAt)}')`, [])
.then(() => {
console.log("chat msg add with Success");
diff --git a/src/app/shared/agenda/edit-event-to-approve/edit-event-to-approve.page.html b/src/app/shared/agenda/edit-event-to-approve/edit-event-to-approve.page.html
index 7ccf43a4b..4dd30336a 100644
--- a/src/app/shared/agenda/edit-event-to-approve/edit-event-to-approve.page.html
+++ b/src/app/shared/agenda/edit-event-to-approve/edit-event-to-approve.page.html
@@ -17,7 +17,7 @@
-
+
@@ -37,7 +37,7 @@
-
+
@@ -93,7 +93,7 @@