Started implementing video support.
This commit is contained in:
@@ -49,9 +49,10 @@ export class Dm implements OnInit {
|
||||
fileId: file.fileId,
|
||||
type: file.type,
|
||||
format: file.extension,
|
||||
path: file.preview,
|
||||
path: file.blob,
|
||||
height: file.height,
|
||||
width: file.width,
|
||||
localVideoThumbnail: file.videoThumbnail
|
||||
})
|
||||
})
|
||||
|
||||
@@ -82,46 +83,58 @@ export class Dm implements OnInit {
|
||||
console.log(fileId, allChunks, chunksDone)
|
||||
}
|
||||
|
||||
onWsListen(action: string, message: string) {
|
||||
console.log(action, message)
|
||||
switch (action) {
|
||||
case "newMessage": {
|
||||
this.store.messages.update(messages => [...messages, JSON.parse(message)])
|
||||
// The chatid parameter ensures isolation
|
||||
onWsListen(action: string, message: string, chatid: string) {
|
||||
const data = JSON.parse(message);
|
||||
if (data.chatid === chatid) {
|
||||
const targetStore = this.serviceManager.dmServices()[chatid];
|
||||
if (targetStore) {
|
||||
switch (action) {
|
||||
case "newMessage":
|
||||
targetStore.messages.update(messages => [...messages, data]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.route.params.subscribe(async params => {
|
||||
const chatid = params['chatid']
|
||||
this.chatid = chatid
|
||||
console.log(this.serviceManager.chats())
|
||||
const session = this.serviceManager.currentSession();
|
||||
const chatData = this.serviceManager.chats().find(chat => chat.chatid == chatid)
|
||||
const chatid = params['chatid'];
|
||||
this.chatid = chatid;
|
||||
|
||||
// Setup storage
|
||||
if (!this.serviceManager.dmServices()[chatid] && session != null && chatData != null) {
|
||||
this.serviceManager.dmServices()[chatid] = {
|
||||
service: new DMService(
|
||||
session.userData.userid,
|
||||
session.token,
|
||||
chatid,
|
||||
this.indexedDb.getApi(),
|
||||
(action, data) => {
|
||||
this.onWsListen(action, data)
|
||||
}
|
||||
),
|
||||
chatData: signal<Chat>(chatData),
|
||||
messages: signal<Message[]>([]),
|
||||
messageBox: new MessageBoxViewModel(
|
||||
(msg, files) => this.sendMessage(msg, files),
|
||||
)
|
||||
}
|
||||
const session = this.serviceManager.currentSession();
|
||||
const chatData = this.serviceManager.chats().find(c => c.chatid === chatid);
|
||||
|
||||
if (!session || !chatData) {
|
||||
console.warn(`Initialization deferred for ${chatid}: Session or ChatData missing.`);
|
||||
return;
|
||||
}
|
||||
|
||||
this.store.messages.set(await this.serviceManager.dmServices()[chatid].service.get())
|
||||
console.log(WebSocketHandler.getInstance().connId)
|
||||
await this.store.service.joinWebSocketRoom()
|
||||
})
|
||||
if (!this.serviceManager.dmServices()[chatid]) {
|
||||
const newStore = {
|
||||
chatData: signal<Chat>(chatData),
|
||||
messages: signal<Message[]>([]),
|
||||
messageBox: new MessageBoxViewModel((msg, files) => this.sendMessage(msg, files)),
|
||||
wsListener: (action, data) => this.onWsListen(action, data, chatid),
|
||||
} as DmStorage;
|
||||
|
||||
newStore.service = new DMService(
|
||||
session.userData.userid,
|
||||
session.token,
|
||||
chatid,
|
||||
this.indexedDb.getApi(),
|
||||
(action, data) => newStore.wsListener(action, data)
|
||||
);
|
||||
|
||||
this.serviceManager.dmServices()[chatid] = newStore;
|
||||
|
||||
const currentStore = this.serviceManager.dmServices()[chatid];
|
||||
const history = await currentStore.service.get();
|
||||
currentStore.messages.set(history);
|
||||
|
||||
await currentStore.service.joinWebSocketRoom();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user