mirror of
https://github.com/pierre42100/ComunicWeb
synced 2025-06-19 04:15:17 +00:00
Automatically reoopen conversations on page reload
This commit is contained in:
@ -25,6 +25,67 @@ class CallsController {
|
||||
// Create a new window for the conversation
|
||||
const window = new CallWindow(conv);
|
||||
OpenConversations.set(conv.ID, window)
|
||||
this.AddToLocalStorage(conv.ID);
|
||||
|
||||
window.on("close", () => {
|
||||
OpenConversations.delete(conv.ID)
|
||||
this.RemoveFromLocalStorage(conv.ID)
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the conversation to local storage
|
||||
*
|
||||
* @param {number} convID Target conversation ID
|
||||
*/
|
||||
static AddToLocalStorage(convID) {
|
||||
const list = this.GetListLocalStorage();
|
||||
if(!list.includes(convID))
|
||||
list.push(convID)
|
||||
this.SetListLocalStorage(list)
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {number} convID Target conversation ID
|
||||
*/
|
||||
static RemoveFromLocalStorage(convID) {
|
||||
this.SetListLocalStorage(
|
||||
this.GetListLocalStorage().filter(e => e != convID)
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {number[]} The ID of the opened conversations
|
||||
*/
|
||||
static GetListLocalStorage() {
|
||||
const content = localStorage.getItem("calls")
|
||||
if(content == null)
|
||||
return []
|
||||
else
|
||||
return JSON.parse(content).filter(e => e != null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the list of open calls
|
||||
*
|
||||
* @param {number[]} list New list
|
||||
*/
|
||||
static SetListLocalStorage(list) {
|
||||
localStorage.setItem("calls", JSON.stringify(list))
|
||||
}
|
||||
}
|
||||
|
||||
document.addEventListener("wsClosed", () => {
|
||||
// Close all the current conversations
|
||||
OpenConversations.forEach((v) => v.Close(false))
|
||||
|
||||
OpenConversations = new Map();
|
||||
})
|
||||
|
||||
|
||||
document.addEventListener("wsOpen", () => {
|
||||
CallsController.GetListLocalStorage().forEach(async c => {
|
||||
CallsController.Open(await getSingleConversation(c))
|
||||
})
|
||||
})
|
@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
|
||||
class CallWindow {
|
||||
class CallWindow extends CustomEvents {
|
||||
|
||||
/**
|
||||
* Create a new call window
|
||||
@ -13,6 +13,7 @@ class CallWindow {
|
||||
* @param {Conversation} conv Information about the target conversation
|
||||
*/
|
||||
constructor(conv) {
|
||||
super()
|
||||
this.construct(conv);
|
||||
}
|
||||
|
||||
@ -48,8 +49,22 @@ class CallWindow {
|
||||
this.closeButton = createElem2({
|
||||
appendTo: windowHead.querySelector(".pull-right"),
|
||||
type: "a",
|
||||
innerHTML: "<i class='fa fa-cross'></i>"
|
||||
innerHTML: "<i class='fa fa-cross'></i>",
|
||||
onclick: () => this.Close()
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Close this window & cancel the call
|
||||
*
|
||||
* @param {boolean} propagate Set to true to propagate
|
||||
* the event
|
||||
*/
|
||||
Close(propagate = true) {
|
||||
this.rootEl.remove();
|
||||
|
||||
if(propagate)
|
||||
this.emitEvent("closed");
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user