dont flash the notifications

This commit is contained in:
Martti Malmi 2021-08-20 11:43:51 +03:00
parent ce9cd1959c
commit c33f2e096d
6 changed files with 29 additions and 29 deletions

View File

@ -14,8 +14,8 @@ let myProfilePhoto;
let latestChatLink;
let onlineTimeout;
let ourActivity;
let hasFollows;
let hasFollowers;
let noFollows;
let noFollowers;
let userSearchIndex;
const follows = {};
const channels = window.channels = {};
@ -63,8 +63,8 @@ function addFollow(callback, k, followDistance, follower) {
}
callback && callback(k, follows[k]);
updateUserSearchIndex();
updateHasFollows();
updateHasFollowers();
updateNoFollows();
updateNoFollowers();
}
function removeFollow(k, followDistance, follower) {
@ -73,8 +73,8 @@ function removeFollow(k, followDistance, follower) {
if (followDistance === 1) {
State.local.get('groups').get('follows').get(k).put(false);
}
updateHasFollows();
updateHasFollowers();
updateNoFollows();
updateNoFollowers();
}
}
@ -102,21 +102,21 @@ function getExtendedFollows(callback, k, maxDepth = 3, currentDepth = 1) {
return follows;
}
function updateHasFollows() {
const v = Object.keys(follows).length > 1;
if (v !== hasFollows) {
hasFollows = v;
State.local.get('hasFollows').put(hasFollows);
const updateNoFollows = _.debounce(() => {
const v = !(Object.keys(follows).length > 1);
if (v !== noFollows) {
noFollows = v;
State.local.get('noFollows').put(noFollows);
}
}
}, 1000);
function updateHasFollowers() {
const v = follows[key.pub] && (follows[key.pub].followers.size > 0);
if (v !== hasFollowers) {
hasFollowers = v;
State.local.get('hasFollowers').put(hasFollowers);
const updateNoFollowers = _.debounce(() => {
const v = !(follows[key.pub] && (follows[key.pub].followers.size > 0));
if (v !== noFollowers) {
noFollowers = v;
State.local.get('noFollowers').put(noFollowers);
}
}
}, 1000);
function getUserSearchIndex() {
return userSearchIndex;
@ -165,7 +165,7 @@ function updateGroups() {
}
State.local.get('groups').get('everyone').get(k).put(true);
if (k === getPubKey()) {
updateHasFollowers();
updateNoFollowers();
}
});
}

View File

@ -32,7 +32,7 @@ class SearchBox extends Component {
componentDidMount() {
State.local.get('groups').get('everyone').map().on(this.sub(
() => {
this.hasFollows = this.hasFollows || Object.keys(Session.getFollows()).length > 1;
this.noFollows = this.noFollows || Object.keys(Session.getFollows()).length > 1;
}
));
State.local.get('activeRoute').on(this.sub(
@ -147,7 +147,7 @@ class SearchBox extends Component {
</a>
`;
})}
${this.state.query && !this.hasFollows ? html`
${this.state.query && !this.noFollows ? html`
<a class="follow-someone">Follow someone to see more search results!</a>
<a href="/profile/${suggestedFollow}" class="suggested">
<${Identicon} str=${suggestedFollow} width=40/>

View File

@ -67,7 +67,7 @@ class Feed extends View {
${s.searchTerm ? html`<h2>Search results for "${s.searchTerm}"</h2>` : html`
${this.getNotification()}
`}
${s.hasFollows ? html`<${Filters}/>` : ''}
${!s.noFollows ? html`<${Filters}/>` : ''}
<${MessageFeed}
scrollElement=${this.scrollElement.current}
hashtag=${hashtag}

View File

@ -58,7 +58,7 @@ class Profile extends View {
}
getNotification() {
if (!this.state.hasFollowers && this.followers.has(Session.getPubKey())) {
if (this.state.noFollowers && this.followers.has(Session.getPubKey())) {
return html`
<div class="msg">
<div class="msg-content">
@ -296,7 +296,7 @@ class Profile extends View {
}
let qrCodeEl = $(this.qrRef.current);
qrCodeEl.empty();
State.local.get('hasFollowers').on(this.inject());
State.local.get('noFollowers').on(this.inject());
this.getProfileDetails();
if (chat) {
$(`input[name=notificationPreference][value=${ chat.notificationSetting }]`).attr('checked', 'checked');

View File

@ -92,7 +92,7 @@ class Store extends View {
const cartTotalItems = Object.keys(this.cart).reduce((sum, k) => sum + this.cart[k], 0);
const keys = Object.keys(this.state.items);
return html`
${(this.props.store || !this.state.hasFollows) ? '' : html`<${Filters}/>`}
${(this.props.store || this.state.noFollows) ? '' : html`<${Filters}/>`}
${cartTotalItems ? html`
<p>
<button onClick=${() => route('/checkout')}>${t('shopping_cart')}(${cartTotalItems})</button>

View File

@ -27,11 +27,11 @@ class View extends Component {
getNotification() {
if (!this.followsSubscribed) {
this.followsSubscribed = true;
State.local.get('hasFollowers').on(this.inject());
State.local.get('hasFollows').on(this.inject());
State.local.get('noFollowers').on(this.inject());
State.local.get('noFollows').on(this.inject());
}
if (!this.state.hasFollows) {
if (this.state.noFollows) {
return html`
<div class="msg">
<div class="msg-content">
@ -48,7 +48,7 @@ class View extends Component {
</div>
`
}
if (!this.state.hasFollowers) {
if (this.state.noFollowers) {
return html`
<div class="msg">
<div class="msg-content">