mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-21 05:45:50 +00:00
update list on create room event
This commit is contained in:
@@ -34,6 +34,7 @@ import { RoomRemoteDataSourceState } from 'src/app/services/Repositorys/chat/dat
|
||||
import { RoomRepositoryService } from 'src/app/services/Repositorys/chat/repository/room-repository.service'
|
||||
import { RoomListOutPutDTO } from 'src/app/services/Repositorys/chat/dto/room/roomListOutputDTO';
|
||||
import { Observable as DexieObservable } from 'Dexie';
|
||||
import { MessageLiveDataSourceService } from 'src/app/services/Repositorys/chat/data-source/message/message-live-data-source.service';
|
||||
|
||||
|
||||
@Component({
|
||||
@@ -124,9 +125,22 @@ export class ChatPage implements OnInit {
|
||||
public ChatSystemService: ChatSystemService,
|
||||
public RouteService: RouteService,
|
||||
private store: Store<{ chat: RoomRemoteDataSourceState }>,
|
||||
private RoomRepositoryService: RoomRepositoryService
|
||||
private RoomRepositoryService: RoomRepositoryService,
|
||||
private messageLiveDataSourceService: MessageLiveDataSourceService,
|
||||
) {
|
||||
|
||||
|
||||
this.messageLiveDataSourceService.socket.messages$.subscribe(({payload, requestId, type}) => {
|
||||
if(payload.sender == null) {
|
||||
delete payload.sender
|
||||
}
|
||||
|
||||
if(type == 'createRoom') {
|
||||
this.RoomRepositoryService.list();
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
this.count$ = store.select('chat');
|
||||
|
||||
this.headers = new HttpHeaders();
|
||||
@@ -161,6 +175,7 @@ export class ChatPage implements OnInit {
|
||||
this.routerSubscription = this.router.events.subscribe((event) => {
|
||||
if (event instanceof NavigationEnd && event.url.startsWith('/home/chat')) {
|
||||
this.routeCheck()
|
||||
this.RoomRepositoryService.list();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
<!-- <ion-content class="main " ng-controller="AppController"> -->
|
||||
<ion-content ng-controller="AppController">
|
||||
<div>Current Count: {{ count$ | async }}</div>
|
||||
|
||||
|
||||
<ion-refresher slot="fixed" (ionRefresh)="doRefresh($event)">
|
||||
|
||||
+11
-11
@@ -16,7 +16,15 @@ const tableSchema = z.object({
|
||||
}),
|
||||
createdAt: z.any(),
|
||||
expirationDate: z.any(),
|
||||
roomType: z.any()
|
||||
roomType: z.any(),
|
||||
// lastMessage: z.object({
|
||||
// sentAt: z.string(),
|
||||
// message: z.string(),
|
||||
// sender: z.object({
|
||||
// wxUserId: z.any(),
|
||||
// wxFullName: z.any(),
|
||||
// }).optional(),s
|
||||
// })
|
||||
})
|
||||
|
||||
const TableMemberListSchema = z.object({
|
||||
@@ -29,15 +37,7 @@ const TableMemberListSchema = z.object({
|
||||
wxeMail: z.string(),
|
||||
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(),
|
||||
// })
|
||||
joinAt: z.string()
|
||||
})
|
||||
|
||||
export type TableRoom = z.infer<typeof tableSchema>
|
||||
@@ -50,7 +50,7 @@ export const roomDataSource = new Dexie('FriendDatabase') as Dexie & {
|
||||
};
|
||||
|
||||
roomDataSource.version(1).stores({
|
||||
room: 'id, createdBy, roomName, roomType, expirationDate',
|
||||
room: 'id, createdBy, roomName, roomType, expirationDate, lastMessage',
|
||||
memberList: '$roomIdUserId, id, user, joinAt, roomId',
|
||||
});
|
||||
|
||||
|
||||
@@ -14,8 +14,26 @@ 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';
|
||||
import { TableMessage } from '../data-source/message/message-local-data-source.service';
|
||||
import { MessageLiveDataSourceService } from '../data-source/message/message-live-data-source.service';
|
||||
|
||||
|
||||
function date(isoDateString) {
|
||||
let date = new Date(isoDateString);
|
||||
|
||||
const tzOffset = -date.getTimezoneOffset(); // in minutes
|
||||
const diff = tzOffset >= 0 ? '+' : '-';
|
||||
const pad = (n: number) => (n < 10 ? '0' : '') + n;
|
||||
|
||||
return date.getFullYear() +
|
||||
'-' + pad(date.getMonth() + 1) +
|
||||
'-' + pad(date.getDate()) +
|
||||
'T' + pad(date.getHours()) +
|
||||
':' + pad(date.getMinutes()) +
|
||||
':' + pad(date.getSeconds()) +
|
||||
diff + pad(Math.floor(Math.abs(tzOffset) / 60)) +
|
||||
':' + pad(Math.abs(tzOffset) % 60);
|
||||
}
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
@@ -25,8 +43,28 @@ export class RoomRepositoryService {
|
||||
private roomRemoteDataSourceService: RoomRemoteDataSourceService,
|
||||
private roomMemoryDataSourceService: Store<RoomRemoteDataSourceState>,
|
||||
private roomLocalDataSourceService: RoomLocalDataSourceService,
|
||||
private roomLiveDataSourceService: RoomLiveDataSourceService
|
||||
) { }
|
||||
private roomLiveDataSourceService: RoomLiveDataSourceService,
|
||||
private messageLiveDataSourceService: MessageLiveDataSourceService,
|
||||
) {
|
||||
|
||||
// this.messageLiveDataSourceService.socket.messages$.subscribe(({payload, requestId, type}) => {
|
||||
// if(payload.sender == null) {
|
||||
// delete payload.sender
|
||||
// }
|
||||
|
||||
// if(type == 'sendMessage') {
|
||||
// let clone: TableMessage = {
|
||||
// ...payload,
|
||||
// messageId: payload.id,
|
||||
// }
|
||||
|
||||
// this.roomLocalDataSourceService.updateRoom({lastMessage: clone})
|
||||
|
||||
// }
|
||||
|
||||
// })
|
||||
|
||||
}
|
||||
|
||||
@captureAndReraiseAsync('RoomRepositoryService/list')
|
||||
async list() {
|
||||
@@ -38,14 +76,44 @@ export class RoomRepositoryService {
|
||||
const { roomsToDelete, roomsToInsert, roomsToUpdate } = roomListDetermineChanges(result.value.data, localList)
|
||||
|
||||
for( const roomData of roomsToInsert) {
|
||||
|
||||
// roomData["lastMessage"] = {
|
||||
// sentAt: date(roomData.createdAt),
|
||||
// message: "",
|
||||
// sender: {
|
||||
// wxUserId: "",
|
||||
// wxFullName: "",
|
||||
// },
|
||||
// }
|
||||
|
||||
this.roomLocalDataSourceService.createRoom(roomData)
|
||||
}
|
||||
|
||||
for( const roomData of roomsToUpdate) {
|
||||
|
||||
// roomData["lastMessage"] = {
|
||||
// sentAt: date(roomData.createdAt),
|
||||
// message: "",
|
||||
// sender: {
|
||||
// wxUserId: "",
|
||||
// wxFullName: "",
|
||||
// },
|
||||
// }
|
||||
|
||||
this.roomLocalDataSourceService.updateRoom(roomData)
|
||||
}
|
||||
|
||||
for( const roomData of roomsToDelete) {
|
||||
|
||||
// roomData["lastMessage"] = {
|
||||
// sentAt: date(roomData.createdAt),
|
||||
// message: "",
|
||||
// sender: {
|
||||
// wxUserId: 0,
|
||||
// wxFullName: "",
|
||||
// },
|
||||
// }
|
||||
|
||||
this.roomLocalDataSourceService.deleteRoomById(roomData.id)
|
||||
}
|
||||
}
|
||||
@@ -142,16 +210,34 @@ export class RoomRepositoryService {
|
||||
if(result.isOk()) {
|
||||
|
||||
if(!result.value.data.createdBy) {
|
||||
|
||||
let dataObject;
|
||||
|
||||
result.value.data.createdBy = {
|
||||
wxeMail: SessionStore.user.Email,
|
||||
wxFullName: SessionStore.user.FullName,
|
||||
wxUserId: SessionStore.user.UserId,
|
||||
}
|
||||
|
||||
dataObject = result.value.data
|
||||
dataObject.lastMessage = {
|
||||
sentAt: date(new Date()),
|
||||
message: "",
|
||||
sender: {
|
||||
wxUserId: "",
|
||||
wxFullName: "",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
this.roomMemoryDataSourceService.dispatch(addRoom(result.value))
|
||||
const localResult = await this.roomLocalDataSourceService.createRoom(result.value.data)
|
||||
|
||||
this.messageLiveDataSourceService.sendMessage({
|
||||
type: 'createRoom',
|
||||
payload: {a: '5'}
|
||||
})
|
||||
|
||||
return localResult.map(e => result.value)
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<div class="middle">
|
||||
<ion-label class="title">Alterar assunto</ion-label>
|
||||
</div>
|
||||
<app-btn-seguinte (click)="changeGroupName()"></app-btn-seguinte>..1
|
||||
<app-btn-seguinte (click)="changeGroupName()"></app-btn-seguinte>
|
||||
</div>
|
||||
</div>
|
||||
</ion-toolbar>
|
||||
|
||||
@@ -111,7 +111,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
userName = "";
|
||||
room: any = new Array();
|
||||
roomName: any;
|
||||
isAdmin = false;
|
||||
isAdmin = true;
|
||||
roomCountDownDate: string;
|
||||
|
||||
textField = ''
|
||||
@@ -120,7 +120,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
roomMessage$: DexieObservable<TableMessage[]>
|
||||
roomMembers$: DexieObservable<TableMemberList[] | undefined>
|
||||
|
||||
newMessagesStream!: Subscription
|
||||
newMessagesStream!: Subscription
|
||||
|
||||
constructor(
|
||||
public popoverController: PopoverController,
|
||||
@@ -158,14 +158,14 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
|
||||
this.newMessagesStream?.unsubscribe()
|
||||
this.newMessagesStream = this.messageRepositoryService.subscribeToNewMessages(this.roomId).subscribe((e) => {
|
||||
|
||||
|
||||
setTimeout(() => {
|
||||
this.scrollToBottomClicked()
|
||||
}, 10)
|
||||
setTimeout(() => {
|
||||
this.scrollToBottomClicked()
|
||||
}, 200)
|
||||
|
||||
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
@@ -133,7 +133,7 @@ export class ChatPopoverPage implements OnInit {
|
||||
}
|
||||
|
||||
this.showLoader = false
|
||||
|
||||
|
||||
}
|
||||
|
||||
async openChangeGroupName(){
|
||||
|
||||
Reference in New Issue
Block a user