Browse Source

fix bug that when a user clicks on a notification and goes back to the app it correctly show the chat page. before it would have an infinite spinner

q-apps
Phillip 2 years ago
parent
commit
648db552e7
  1. 5
      qortal-ui-core/src/notifications/notification-actions/new-message.js
  2. 39
      qortal-ui-plugins/plugins/core/messaging/q-chat/q-chat.src.js

5
qortal-ui-core/src/notifications/notification-actions/new-message.js

@ -2,7 +2,6 @@ import { store } from '../../store.js'
import { doPageUrl } from '../../redux/app/app-actions.js' import { doPageUrl } from '../../redux/app/app-actions.js'
export const newMessage = (data) => { export const newMessage = (data) => {
const alert = playSound(data.sound) const alert = playSound(data.sound)
// Should I show notification ? // Should I show notification ?
@ -18,7 +17,7 @@ export const newMessage = (data) => {
} }
notify.onclick = (e) => { notify.onclick = (e) => {
const pageUrl = `/app/q-chat/${data.req.url}` const pageUrl = `/app/q-chat/?chat=${data.req.url}`
store.dispatch(doPageUrl(pageUrl)) store.dispatch(doPageUrl(pageUrl))
} }
} else { } else {
@ -26,7 +25,7 @@ export const newMessage = (data) => {
const notify = new Notification(data.title, data.options) const notify = new Notification(data.title, data.options)
notify.onclick = (e) => { notify.onclick = (e) => {
const pageUrl = `/app/q-chat/${data.req.url}` const pageUrl = `/app/q-chat/?chat=${data.req.url}`
store.dispatch(doPageUrl(pageUrl)) store.dispatch(doPageUrl(pageUrl))
} }
} }

39
qortal-ui-plugins/plugins/core/messaging/q-chat/q-chat.src.js

@ -29,7 +29,7 @@ import StarterKit from '@tiptap/starter-kit'
import Underline from '@tiptap/extension-underline'; import Underline from '@tiptap/extension-underline';
import Placeholder from '@tiptap/extension-placeholder' import Placeholder from '@tiptap/extension-placeholder'
import { Editor, Extension } from '@tiptap/core' import { Editor, Extension } from '@tiptap/core'
import Highlight from '@tiptap/extension-highlight'
const parentEpml = new Epml({ type: 'WINDOW', source: window.parent }) const parentEpml = new Epml({ type: 'WINDOW', source: window.parent })
class Chat extends LitElement { class Chat extends LitElement {
@ -55,7 +55,7 @@ class Chat extends LitElement {
userFoundModalOpen: { type: Boolean }, userFoundModalOpen: { type: Boolean },
userSelected: { type: Object }, userSelected: { type: Object },
editor: {type: Object}, editor: {type: Object},
groupInvites: { type: Array } groupInvites: { type: Array },
} }
} }
@ -118,6 +118,7 @@ class Chat extends LitElement {
} }
async connectedCallback() { async connectedCallback() {
super.connectedCallback(); super.connectedCallback();
await this.getUpdateCompleteTextEditor(); await this.getUpdateCompleteTextEditor();
@ -147,15 +148,36 @@ class Chat extends LitElement {
}}) }})
] ]
}) })
this.unsubscribeStore = window.parent.reduxStore.subscribe(() => {
try {
if(window.parent.location && window.parent.location.search){
const queryString = window.parent.location.search;
const params = new URLSearchParams(queryString);
const chat = params.get("chat")
if(chat && chat !== this.activeChatHeadUrl){
let url = window.parent.location.href;
let newUrl = url.split("?")[0];
window.parent.history.pushState({}, "", newUrl);
this.setActiveChatHeadUrl(chat)
}
}
} catch (error) {
console.error(error)
}
});
} }
disconnectedCallback() { disconnectedCallback() {
super.disconnectedCallback(); super.disconnectedCallback();
this.editor.destroy() this.editor.destroy();
this.unsubscribeStore();
} }
updatePlaceholder(editor, text){ updatePlaceholder(editor, text){
editor.extensionManager.extensions.forEach((extension) => { editor.extensionManager.extensions.forEach((extension) => {
if (extension.name === "placeholder") { if (extension.name === "placeholder") {
@ -215,7 +237,7 @@ class Chat extends LitElement {
</div> </div>
<div class="chat-history"> <div class="chat-history">
${window.parent.location.pathname !== "/app/q-chat" || this.activeChatHeadUrl ? html`${this.renderChatPage(this.chatId)}` : html`${this.renderChatWelcomePage()}`} ${this.activeChatHeadUrl ? html`${this.renderChatPage()}` : html`${this.renderChatWelcomePage()}`}
</div> </div>
</div> </div>
<!-- Start Chatting Dialog --> <!-- Start Chatting Dialog -->
@ -367,6 +389,8 @@ class Chat extends LitElement {
` `
} }
async firstUpdated() { async firstUpdated() {
this.changeLanguage(); this.changeLanguage();
this.changeTheme(); this.changeTheme();
@ -482,8 +506,11 @@ class Chat extends LitElement {
}) })
}) })
parentEpml.imReady() parentEpml.imReady()
} }
setOpenPrivateMessage(props) { setOpenPrivateMessage(props) {
this.openPrivateMessage = props.open; this.openPrivateMessage = props.open;
this.shadowRoot.getElementById("sendTo").value = props.name this.shadowRoot.getElementById("sendTo").value = props.name
@ -839,7 +866,7 @@ class Chat extends LitElement {
}) })
} }
renderChatPage(chatId) { renderChatPage() {
// Check for the chat ID from and render chat messages // Check for the chat ID from and render chat messages
// Else render Welcome to Q-CHat // Else render Welcome to Q-CHat

Loading…
Cancel
Save