diff --git a/core/src/components/login-view/login-view.js b/core/src/components/login-view/login-view.js index c29be5ab..24bef336 100644 --- a/core/src/components/login-view/login-view.js +++ b/core/src/components/login-view/login-view.js @@ -15,7 +15,7 @@ import './login-section.js' import '../qort-theme-toggle.js' import settings from '../../functional-components/settings-page.js' -import { addAutoLoadImageChat, removeAutoLoadImageChat, addChatLastSeen, allowQAPPAutoAuth, removeQAPPAutoAuth, removeQAPPAutoLists, allowQAPPAutoLists } from '../../redux/app/app-actions.js' +import { addAutoLoadImageChat, removeAutoLoadImageChat, addChatLastSeen, allowQAPPAutoAuth, removeQAPPAutoAuth, removeQAPPAutoLists, allowQAPPAutoLists, addTabInfo, setTabNotifications, setNewTab } from '../../redux/app/app-actions.js' window.reduxStore = store window.reduxAction = { @@ -25,7 +25,10 @@ window.reduxAction = { allowQAPPAutoAuth: allowQAPPAutoAuth, removeQAPPAutoAuth: removeQAPPAutoAuth, allowQAPPAutoLists: allowQAPPAutoLists, - removeQAPPAutoLists: removeQAPPAutoLists + removeQAPPAutoLists: removeQAPPAutoLists, + addTabInfo: addTabInfo, + setTabNotifications: setTabNotifications, + setNewTab: setNewTab } const animationDuration = 0.7 // Seconds diff --git a/core/src/components/show-plugin.js b/core/src/components/show-plugin.js index 4cf8d729..4f68ffee 100644 --- a/core/src/components/show-plugin.js +++ b/core/src/components/show-plugin.js @@ -6,9 +6,13 @@ import { addPluginRoutes } from '../plugins/addPluginRoutes.js' import { repeat } from 'lit/directives/repeat.js'; import ShortUniqueId from 'short-unique-id'; import { setNewTab } from '../redux/app/app-actions.js' +import localForage from "localforage"; import '@material/mwc-icon' +const chatLastSeen = localForage.createInstance({ + name: "chat-last-seen", +}); class ShowPlugin extends connect(store)(LitElement) { static get properties() { return { @@ -19,7 +23,10 @@ class ShowPlugin extends connect(store)(LitElement) { registeredUrls: { type: Array }, currentTab: { type: Number }, tabs: { type: Array }, - theme: { type: String, reflect: true } + theme: { type: String, reflect: true }, + tabInfo: { type: Object }, + chatLastSeen: { type: Array }, + chatHeads: { type: Array } } } @@ -155,6 +162,20 @@ class ShowPlugin extends connect(store)(LitElement) { color: #999; --mdc-icon-size: 20px; } + + .count { + position: absolute; + background: red; + color: white; + padding: 5px; + font-size: 12px; + border-radius: 50%; + height: 10px; + width: 10px; + display: flex; + justify-content: center; + align-items: center; + } ` } @@ -165,6 +186,9 @@ class ShowPlugin extends connect(store)(LitElement) { this.tabs = [] this.uid = new ShortUniqueId() this.theme = localStorage.getItem('qortalTheme') ? localStorage.getItem('qortalTheme') : 'light' + this.tabInfo = {} + this.chatLastSeen = [] + this.chatHeads = [] } async getUpdateComplete() { @@ -189,9 +213,44 @@ class ShowPlugin extends connect(store)(LitElement) { return myPlug === undefined ? 'about:blank' : `${window.location.origin}/plugin/${myPlug.domain}/${myPlug.page}${this.linkParam}` } + return html`
- ${this.tabs.map((tab, index) => html` + ${this.tabs.map((tab, index) => { + let title = '' + let count = 0 + if (tab.myPlugObj && tab.myPlugObj.title) { + title = tab.myPlugObj.title + } + if (tab.myPlugObj && (tab.myPlugObj.url === 'websites' || tab.myPlugObj.url === 'qapps') && this.tabInfo[tab.id]) { + title = this.tabInfo[tab.id].name + } + if (tab.myPlugObj && (tab.myPlugObj.url === 'websites' || tab.myPlugObj.url === 'qapps') && this.tabInfo[tab.id]) { + count = this.tabInfo[tab.id].count + } + + if (tab.myPlugObj && tab.myPlugObj.url === 'q-chat') { + for (const chat of this.chatHeads) { + + const lastReadMessage = this.chatLastSeen.find((ch) => { + let id + if (chat.groupId === 0) { + id = chat.groupId + } else if (chat.groupId) { + id = chat.groupId + } else { + id = chat.address + } + + return ch.key.includes(id) + }) + if (lastReadMessage && lastReadMessage.timestamp < chat.timestamp) { + count = count + 1 + } + } + + } + return html`
this.currentTab = index} @@ -200,26 +259,31 @@ class ShowPlugin extends connect(store)(LitElement) {
${tab.myPlugObj && tab.myPlugObj.mwcicon}
+ ${count ? html` +
${count}
+ ` : ''} +
       - ${tab.myPlugObj && tab.myPlugObj.title} + ${title}      
{ this.removeTab(index) }}>x
- `)}    + ` + })}    @@ -227,7 +291,7 @@ class ShowPlugin extends connect(store)(LitElement) { ${repeat(this.tabs, (tab) => tab.id, (tab, index) => html`
-