This commit is contained in:
Peter Maquiran
2022-09-26 18:15:41 +01:00
parent bf60b355fe
commit de3a4583dc
5 changed files with 156 additions and 61 deletions
@@ -4,7 +4,7 @@ import { WsChatService } from 'src/app/services/chat/ws-chat.service';
import { MessageService } from 'src/app/services/chat/message.service';
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 { 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';
@@ -139,6 +139,14 @@ export class WsChatMethodsService {
}
getRoomById(roomId) {
if(this.getDmRoom(roomId)) {
return this.getDmRoom(roomId)
} else if(this.getGroupRoom(roomId)) {
return this.getGroupRoom(roomId)
}
}
async restoreRooms() {
try {
@@ -167,10 +175,13 @@ export class WsChatMethodsService {
try {
await this.storage.remove('Rooms');
} catch(e) {}
try {
await rooms.result.update.forEach( async (roomData: room, index) => {
console.log(rooms,'=========!+!+!++!+=====')
let index = 0
if(rooms?.result?.update) {
for (let roomData of rooms.result.update) {
const roomId = this.getRoomId(roomData);
if(roomData.t == 'd') {
@@ -203,16 +214,15 @@ export class WsChatMethodsService {
}
}
});
await this.storage.set('Rooms', rooms);
} catch (e) {
console.log(e, "error");
index++;
}
}
await this.storage.set('Rooms', rooms);
console.log('done get rooms')
setTimeout(() => {
this.sortRoomList()
}, 1000)
@@ -223,13 +233,12 @@ export class WsChatMethodsService {
}, 10000)
this.loadingWholeList = false
}
/**
* @description sort room list by last message date
*/
sortRoomList =() => {
sortRoomList = () => {
this._dm = this.sortService.sortDate(this._dm,'_updatedAt').reverse()
this._group = this.sortService.sortDate(this._group,'_updatedAt').reverse()
@@ -240,6 +249,8 @@ export class WsChatMethodsService {
*/
subscribeToRoom() {
console.log('defaultSubtribe', this.dm)
for (const id in this.dm) {
this.defaultSubtribe(id)
}
@@ -248,6 +259,8 @@ export class WsChatMethodsService {
this.defaultSubtribe(id)
}
console.log("Done subcribe");
this.WsChatService.streamNotifyLogged().then((subscription=>{
}))
@@ -274,14 +287,33 @@ export class WsChatMethodsService {
* @param id room id
*/
private defaultSubtribe(id: any) {
this.WsChatService.streamRoomMessages(id).then((subscription)=>{
console.log(id, this._dm);
this.WsChatService.streamRoomMessages(id).then((subscription) => {
const room = this.getRoomById(id);
room.status.receive.message = true;
console.log(subscription, "subscription");
})
this.WsChatService.subStreamNotifyRoom(id, 'typing', false).then((subscription) => {
const room = this.getRoomById(id);
room.status.receive.typing = true;
console.log(subscription, "subStreamNotifyRoom");
//
})
this.WsChatService.subStreamNotifyRoom(id, 'typing', false)
this.WsChatService.subStreamNotifyRoom(id, 'readMessage', false)
this.WsChatService.subStreamNotifyRoom(id, 'readMessage', false).then((subscription) => {
const room = this.getRoomById(id);
room.status.receive.readMessage = true;
console.log(subscription, "subStreamNotifyRoom");
//
})
this.WsChatService.streamNotifyRoomDeleteMessage(id).then((subscription)=>{
this.WsChatService.streamNotifyRoomDeleteMessage(id).then((subscription) => {
const room = this.getRoomById(id);
room.status.receive.deleteMessage = true;
console.log(subscription);
//
})
}
@@ -323,43 +355,46 @@ export class WsChatMethodsService {
let roomId = this.getRoomId(roomData);
// create room
if(!this.roomExist(roomId)) {
let room:RoomService = new RoomService(this.WsChatService, new MessageService(this.storage, this.NfService, this.WsChatService, this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService, this.NetworkServiceService), this.storage, this.platform, this.sqlservice, this.NativeNotificationService, this.sortService, this.ChatService, this.NfService , this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService, this.NetworkServiceService, this)
room.setData(setData)
room.receiveMessage()
room.getAllUsers = this.getUsers
room.receiveMessageDelete();
room.sortRoomList = this.sortRoomList
if (setData.name != 'Rocket Cat') {
// create room
if(!this.roomExist(roomId)) {
let room:RoomService = new RoomService(this.WsChatService, new MessageService(this.storage, this.NfService, this.WsChatService, this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService, this.NetworkServiceService), this.storage, this.platform, this.sqlservice, this.NativeNotificationService, this.sortService, this.ChatService, this.NfService , this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService, this.NetworkServiceService, this)
room.setData(setData)
room.receiveMessage()
room.getAllUsers = this.getUsers
room.receiveMessageDelete();
room.sortRoomList = this.sortRoomList
// create individual room
// create individual room
if(this.isIndividual(roomData)) {
if(this.isIndividual(roomData)) {
this.dm[roomId] = room
this._dm.push(room)
// console.log(this._dm)
this.dmCount++
this.dm[roomId] = room
this._dm.push(room)
// console.log(this._dm)
this.dmCount++
} else {
// create group room
this.group[roomId] = room
this._group.push(room)
this.groupCount++
}
} else {
// create group room
// in this case room is already present, therefor it will only be necessary,
// to redefine
this.group[roomId] = room
this._group.push(room)
this.groupCount++
if(this.dm[roomId]) {
this.dm[roomId].setData(setData)
} else if(this.group[roomId]) {
this.group[roomId].setData(setData)
}
}
} else {
// in this case room is already present, therefor it will only be necessary,
// to redefine
if(this.dm[roomId]) {
this.dm[roomId].setData(setData)
} else if(this.group[roomId]) {
this.group[roomId].setData(setData)
}
}
}
@@ -486,7 +521,7 @@ export class WsChatMethodsService {
} catch(e) {}
}
getRoomName(roomData: room) {
getRoomName(roomData: room): string {
if(this.isIndividual(roomData)) {
const names: String[] = roomData.usernames
const roomName = names.filter((name, index)=>{