add database fields

This commit is contained in:
Peter Maquiran
2024-06-14 09:30:14 +01:00
parent f6dc118fe4
commit 3da412eef6
7 changed files with 49 additions and 389 deletions
-15
View File
@@ -157,11 +157,8 @@
[roomId]="roomId"
(backToChat)="backToChat($event)"
(closeAllDesktopComponents)="closeAllDesktopComponents()"
(openGroupContacts)="openGroupContactsPage($event)"
(openEditGroupPage)="openEditGroupPage($event)"
(getGroups)="getGroups($event)"
*ngIf="showNewGroup"
@@ -186,18 +183,6 @@
>
</app-group-contacts>
<app-attendee-modal
[adding]="adding"
[taskParticipants]="taskParticipants"
[taskParticipantsCc]="taskParticipantsCc"
(closeComponent)="openNewEventPage()"
(setIntervenient)="setIntervenient($event)"
(setIntervenientCC)="setIntervenientCC($event)"
(setContact)="setContact($event)"
[style.display]="showAttendees ? 'flex' : 'none'"
[footer]="true"
class=" height-100 flex-column">
</app-attendee-modal>
</div>
</div>
+16 -352
View File
@@ -54,7 +54,6 @@ export class ChatPage implements OnInit {
segment: string = 'Grupos'
allGroups: any[];
privateGroups: any[];
publicGroups: any[];
userConnectedList: any[];
userRooms: any[];
userChannels: any[];
@@ -118,16 +117,11 @@ export class ChatPage implements OnInit {
constructor(
private chatService: ChatService,
private modalController: ModalController,
private authService: AuthService,
private route: Router,
private timeService: TimeService,
public ThemeService: ThemeService,
private dataService: DataService,
private router: Router,
private platform: Platform,
private storageservice: StorageService,
public ChatSystemService: ChatSystemService,
private zone: NgZone,
public RouteService: RouteService,
private store: Store<{ chat: RoomRemoteDataSourceState }>,
private RoomRepositoryService: RoomRepositoryService
@@ -146,13 +140,6 @@ export class ChatPage implements OnInit {
this.segment = 'Grupos'
/* this.eventTriger.getObservable().subscribe((event) => {
if (event.notification == "recive") {
this.onSegmentChange()
}
// console.log(event)
}); */
}
// Fetch all items using useLiveQuery
@@ -162,14 +149,7 @@ export class ChatPage implements OnInit {
this.items$ = this.RoomRepositoryService.getItemsLive()
this.RoomRepositoryService.list();
this.authService.userData$.subscribe((res: any) => {
this.loggedUser = res;
});
this.hideRefreshButton();
this.getChatMembers();
this.router.events.forEach((event) => {
if (event instanceof NavigationEnd && event.url == '/home/chat' ||
@@ -192,12 +172,6 @@ export class ChatPage implements OnInit {
this.routerSubscription?.unsubscribe();
}
reopenWebSocketConnection() {
// Implement your reconnection logic here.
const newWebSocket = new WebSocket(environment.apiWsChatUrl);
// Add event listeners to the newWebSocket.
// Retry connecting or other reconnection logic can be added here.
}
firstEnter = true
@@ -235,16 +209,16 @@ export class ChatPage implements OnInit {
openFailed = 0
openChat(roomId) {
const room = this.ChatSystemService.getRoomById(roomId);
if (room) {
this.openFailed = 0
if (room.isGroup) {
this.segment = 'Grupos'
this.openGroupMessagesPage(roomId)
} else {
this.segment = 'Contactos'
// const room = this.ChatSystemService.getRoomById(roomId);
if (roomId) {
//this.openFailed = 0
//if (room.isGroup) {
// this.segment = 'Grupos'
// this.openGroupMessagesPage(roomId)
//} else {
// this.segment = 'Contactos'
this.openMessagesPage(roomId)
}
//}
} else {
if (this.openFailed <= 3) {
this.openFailed++
@@ -481,11 +455,6 @@ export class ChatPage implements OnInit {
}
onSegmentChange() {
// this.ChatSystemService.getAllRooms();
this.ChatSystemService._dm
}
doRefresh(event) {
setTimeout(() => {
try {
@@ -502,138 +471,6 @@ export class ChatPage implements OnInit {
});
}
// getDirectMessagesDB() {
// if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
// this.storageservice.get("rooms").then((rooms) =>{
// this.userDirectMessages = rooms.sort((a, b) => {
// var dateA = new Date(a._updatedAt).getTime();
// var dateB = new Date(b._updatedAt).getTime();
// return dateB - dateA;
// });
// //
// //
// }).catch((error) => {
// console.error('storage getdirectmessagedb: ',error)
// })
// this.storageservice.get('chatusers').then((users) => {
// this.dmUsers = users.filter(data => data.username != SessionStore.user.UserName);
// }).catch((error) => {
// console.error('storage getchatusers: ',error)
// })
// }
// // else {
// // this.sqlservice.getAllChatRoom().then((rooms: any) => {
// // //
// // let roomsArray = [];
// // rooms.forEach(element => {
// // let roomListDB = {
// // _id: element.Id,
// // uids: this.isJson(element.Uids),
// // usernames: this.isJson(element.Usernames),
// // lastMessage: this.isJson(element.LastMessage),
// // _updatedAt: element.UpdatedAt
// // }
// // if(element.customFields == "undefined") {
// // roomsArray.push(roomListDB)
// // }
// // });
// // this.userDirectMessages = roomsArray.sort((a, b) => {
// // var dateA = new Date(a._updatedAt).getTime();
// // var dateB = new Date(b._updatedAt).getTime();
// // return dateB - dateA;
// // });
// // //
// // //
// // })
// // this.sqlservice.getAllChatUsers().then((userslist: any) => {
// // //
// // let chatusersArray = [];
// // userslist.forEach(element => {
// // let userListDB = {
// // _id: element.Id,
// // name: element.Name,
// // username: element.Username
// // }
// // chatusersArray.push(userListDB);
// // });
// // this.dmUsers = chatusersArray.filter(data => data.username != SessionStore.user.UserName);
// // })
// // }
// }
// transformDataRoomList(data) {
// if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
// let roomsArray = [];
// data.forEach(element => {
// let roomList = {
// _id: element._id,
// uids: element.uids,
// usernames: element.usernames,
// lastMessage: element.lastMessage,
// _updatedAt: element._updatedAt
// }
// //
// roomsArray.push(roomList)
// });
// this.storageservice.remove('rooms');
// this.storageservice.store('rooms', roomsArray);
// } else {
// data.forEach(element => {
// let roomList = {
// id: element._id,
// uids: element.uids,
// usernames: element.usernames,
// lastMessage: element.lastMessage,
// updatedat: element._updatedAt
// }
// //
// // this.sqlservice.addChatListRoom(roomList);
// });
// }
// }
async transformDataUserList(users) {
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
let usersArray = [];
users.forEach(element => {
//
let chatusers = {
_id: element._id,
name: element.name,
username: element.username
}
//
usersArray.push(chatusers);
});
await this.storageservice.remove('chatusers');
await this.storageservice.store('chatusers', usersArray);
} else {
users.forEach(element => {
//
let chatusers = {
id: element._id,
name: element.name,
username: element.username
}
//
// this.sqlservice.addChatListUsers(chatusers);
});
}
}
showDateDuration(start: any) {
return this.timeService.showDateDuration(start);
@@ -643,115 +480,6 @@ export class ChatPage implements OnInit {
return this.timeService.countDownDate(date, roomId);
}
async getChatMembers() {
// this.chatService.getAllUsers().subscribe(res => {
// //
// this.transformDataUserList(res['users'])
// });
}
getGroupsDB() {
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
this.storageservice.get("grouprooms").then((rooms) => {
let k = rooms.sort((a, b) => {
var dateA = new Date(a._updatedAt).getTime();
var dateB = new Date(b._updatedAt).getTime();
return dateB - dateA;
});
this.allGroups = rooms.sort((a, b) => {
var dateA = new Date(a._updatedAt).getTime();
var dateB = new Date(b._updatedAt).getTime();
return dateB - dateA;
});
//
}).catch((error) => {
console.error('storage getGrup Romm db: ', error)
})
this.storageservice.get('chatusers').then((users) => {
this.dmUsers = users.filter(data => data.username != SessionStore.user.UserName);
}).catch((error) => {
console.error('storage getgrupDb: ', error)
})
} else {
// this.sqlservice.getAllChatRoom().then((rooms: any) => {
// let roomsArray = [];
// rooms.forEach(element => {
// let fddf = this.isJson(element.LastMessage);
// let roomListDB = {
// _id: element.Id,
// customFields: this.isJson(element.customFields),
// name: element.name,
// lastMessage: this.isJson(element.LastMessage),
// _updatedAt: element.UpdatedAt
// }
// if(element.customFields != "undefined") {
// roomsArray.push(roomListDB)
// }
// });
// this.allGroups = roomsArray.sort((a, b) => {
// var dateA = new Date(a._updatedAt).getTime();
// var dateB = new Date(b._updatedAt).getTime();
// return dateB - dateA;
// });
// //
// })
}
}
roomDataFileType(roomData) {
return roomData?.lastMessage?.file?.type || null
}
async transformGroups(data) {
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
let groupsArray = [];
data.forEach(element => {
let roomList = {
_id: element._id,
uids: element.uids,
usernames: element.usernames,
name: element.name,
customFields: element.customFields,
lastMessage: element.lastMessage,
_updatedAt: element._updatedAt
}
groupsArray.push(roomList)
});
await this.storageservice.remove('grouprooms');
await this.storageservice.store('grouprooms', groupsArray);
} else {
data.forEach(element => {
let roomList = {
id: element._id,
uids: element.uids,
usernames: element.usernames,
customFields: element.customFields,
name: element.name,
lastMessage: element.lastMessage,
updatedat: element._updatedAt
}
// this.sqlservice.addChatListRoom(roomList);
});
}
}
async emptyTextDescriptionOpen() {
@@ -759,45 +487,6 @@ export class ChatPage implements OnInit {
this.showEmptyComponent = true
}
async getGroups(event?) {
this.result = this.chatService.getAllPrivateGroups().subscribe(async (res: any) => {
//
this.showLoader = false;
if (res.groups != 200) {
this.transformGroups(res.groups);
this.getGroupsDB();
this.privateGroups = res.groups;
if (this.route.url != "/home/chat") {
//
}
else {
//Check if modal is opened
if (this.segment == "Grupos" && this.showGroupMessages != true) {
await new Promise(resolve => setTimeout(resolve, 1000)).catch((error) => {
console.error(error);
});
//await this.getGroups();
}
}
}
else {
//await this.getGroups();
}
});
}
isJson(str) {
try {
JSON.parse(str);
} catch (e) {
return str;
}
return JSON.parse(str);
}
async selectContact() {
const modal = await this.modalController.create({
@@ -862,31 +551,18 @@ export class ChatPage implements OnInit {
backToChat({ roomId }) {
const room = this.ChatSystemService.getRoomById(roomId);
//const room = this.ChatSystemService.getRoomById(roomId);
if (room.isGroup) {
this.segment = "Grupos"
this.openGroupMessagesPage(room.id);
} else {
//if (room.isGroup) {
// this.segment = "Grupos"
// this.openGroupMessagesPage(room.id);
//} else {
this.segment = "Contactos"
this.openMessagesPage(room.id);
}
this.openMessagesPage(roomId);
// }
}
async openChatDebuggingPageModal(roomId?: any) {
const modal = await this.modalController.create({
component: ChatDebuggingPage,
cssClass: 'modal modal-desktop isMessagesChatOpened',
componentProps: {
// roomId: roomId,
},
});
modal.onDidDismiss();
await modal.present();
}
async openGroupMessagesModal(roomId: any) {
@@ -904,17 +580,5 @@ export class ChatPage implements OnInit {
await modal.present();
}
reloadComponent(self: boolean, urlToNavigateTo?: string) {
//skipLocationChange:true means dont update the url to / when navigating
console.log("Current route I am on:", this.router.url);
const url = self ? this.router.url : urlToNavigateTo;
this.zone.run(() => this.router.navigateByUrl('/', { skipLocationChange: true }).then(() => {
this.zone.run(() => this.router.navigate([`/${url}`]).then(() => {
console.log(`After navigation I am on:${this.router.url}`)
}))
}))
}
}
@@ -16,6 +16,7 @@ const tableSchema = z.object({
messageType: z.number(),
canEdit: z.boolean(),
oneShot: z.boolean(),
sentAt: z.string().optional(),
requireUnlock: z.boolean(),
sender: z.object({
wxUserId: z.number(),
@@ -49,7 +50,7 @@ export class MessageLocalDataSourceService {
messageDataSource.message.hook('creating', (primKey, obj, trans) => {
// const newMessage = await trans.table('message').get(primKey);
this.messageSubject.next(obj);
this.messageSubject.next(obj);
// return newMessage
})
}
@@ -103,8 +104,8 @@ export class MessageLocalDataSourceService {
}
}
getItemsLive(roomId: string) {
return liveQuery(() =>
getItemsLive(roomId: string) {
return liveQuery(() =>
messageDataSource.message.where('roomId').equals(roomId).sortBy('id')
)
}
@@ -12,7 +12,7 @@ const tableSchema = z.object({
wxUserId: z.number(),
wxFullName: z.string(),
wxeMail: z.string().email(),
userPhoto: z.string().nullable()// api check
userPhoto: z.string().nullable().optional()// api check
}),
createdAt: z.any(),
expirationDate: z.any(),
@@ -30,6 +30,14 @@ const TableMemberListSchema = z.object({
userPhoto: z.string().nullable(),
}),
joinAt: z.string(),
// lastMessage: z.object({
// sentAt: z.string(),
// message: z.string(),
// sender: z.object({
// wxUserId: z.number(),
// wxFullName: z.string(),
// }).optional(),
// })
})
export type TableRoom = z.infer<typeof tableSchema>
@@ -35,12 +35,12 @@ export class WebSocketService {
this.connect('http://5.180.182.151:8080/')
this.messages$.subscribe(({payload, requestId}) => {
this.messages$.subscribe(({payload, requestId, type}) => {
if(this.callback[requestId]) {
this.callback[requestId]({payload, requestId})
this.callback[requestId]({payload, requestId, type})
delete this.callback[requestId]
}
})
}
@@ -89,7 +89,7 @@ export class WebSocketService {
public sendMessage(message: WebSocketMessage): Observable<any> {
return new Observable<void>(observer => {
if(typeof message == 'object') {
message.requestId = uuidv4()
@@ -107,7 +107,7 @@ export class WebSocketService {
}
}).pipe(
catchError(err => {
console.error('Send message error:', err);
@@ -126,4 +126,4 @@ export class WebSocketService {
public get connectionStatus(): Observable<boolean> {
return this.connectionStatus$.asObservable();
}
}
}
@@ -15,28 +15,27 @@ export class MessageRepositoryService {
private messageLiveDataSourceService: MessageLiveDataSourceService,
private messageLocalDataSourceService: MessageLocalDataSourceService
) {
this.messageLiveDataSourceService.socket.messages$.subscribe(({payload, requestId}) => {
this.messageLiveDataSourceService.socket.messages$.subscribe(({payload, requestId, type}) => {
if(payload.sender == null) {
delete payload.sender
}
if(payload) {
if(type == 'sendMessage') {
let clone: TableMessage = {
...payload,
messageId: payload.id,
}
delete clone.id
try {
if(clone.sender.wxUserId != SessionStore.user.UserId) {
this.messageLocalDataSourceService.createMessage(clone)
}
this.messageLocalDataSourceService.createMessage(clone)
} catch (e) {
//console.log('error', {payload})
}
} else if (type == 'deleteMessage') {
}
@@ -107,6 +106,6 @@ export class MessageRepositoryService {
subscribeToNewMessages(roomId: any) {
return this.messageLocalDataSourceService.subscribeToNewMessage(roomId)
return this.messageLocalDataSourceService.subscribeToNewMessage(roomId)
}
}
@@ -14,6 +14,7 @@ import { RoomUpdateInputDTO } from '../dto/room/roomUpdateInputDTO';
import { SessionStore } from 'src/app/store/session.service';
import { RoomLiveDataSourceService } from '../data-source/room/room-live-data-source.service';
import { isHttpResponse } from 'src/app/services/http.service';
import { value } from '../../../../../../../_________________/src/plugin/src/sql/Operators/args-attributes';
@Injectable({
providedIn: 'root'
@@ -144,12 +145,14 @@ export class RoomRepositoryService {
result.value.data.createdBy = {
wxeMail: SessionStore.user.Email,
wxFullName: SessionStore.user.FullName,
wxUserId: SessionStore.user.UserId
wxUserId: SessionStore.user.UserId,
}
}
this.roomMemoryDataSourceService.dispatch(addRoom(result.value))
this.roomLocalDataSourceService.createRoom(result.value.data)
const localResult = await this.roomLocalDataSourceService.createRoom(result.value.data)
return localResult.map(e => result.value)
}
return result