mirror of
https://github.com/irislib/iris-messenger.git
synced 2024-10-18 22:23:23 +00:00
fix follows/followers notification
This commit is contained in:
parent
f0247dd9da
commit
ce9cd1959c
@ -14,8 +14,8 @@ let myProfilePhoto;
|
||||
let latestChatLink;
|
||||
let onlineTimeout;
|
||||
let ourActivity;
|
||||
let hasFollowers;
|
||||
let hasFollows;
|
||||
let hasFollowers;
|
||||
let userSearchIndex;
|
||||
const follows = {};
|
||||
const channels = window.channels = {};
|
||||
@ -63,6 +63,8 @@ function addFollow(callback, k, followDistance, follower) {
|
||||
}
|
||||
callback && callback(k, follows[k]);
|
||||
updateUserSearchIndex();
|
||||
updateHasFollows();
|
||||
updateHasFollowers();
|
||||
}
|
||||
|
||||
function removeFollow(k, followDistance, follower) {
|
||||
@ -71,6 +73,8 @@ function removeFollow(k, followDistance, follower) {
|
||||
if (followDistance === 1) {
|
||||
State.local.get('groups').get('follows').get(k).put(false);
|
||||
}
|
||||
updateHasFollows();
|
||||
updateHasFollowers();
|
||||
}
|
||||
}
|
||||
|
||||
@ -98,6 +102,22 @@ 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);
|
||||
}
|
||||
}
|
||||
|
||||
function updateHasFollowers() {
|
||||
const v = follows[key.pub] && (follows[key.pub].followers.size > 0);
|
||||
if (v !== hasFollowers) {
|
||||
hasFollowers = v;
|
||||
State.local.get('hasFollowers').put(hasFollowers);
|
||||
}
|
||||
}
|
||||
|
||||
function getUserSearchIndex() {
|
||||
return userSearchIndex;
|
||||
}
|
||||
@ -138,15 +158,14 @@ function setOurOnlineStatus() {
|
||||
|
||||
function updateGroups() {
|
||||
getExtendedFollows((k, info) => {
|
||||
if (!hasFollows && info.followDistance >= 1) { State.local.get('noFollows').put(false); }
|
||||
if (info.followDistance <= 1) {
|
||||
State.local.get('groups').get('follows').get(k).put(true);
|
||||
} else if (info.followDistance == 2) {
|
||||
State.local.get('groups').get('2ndDegreeFollows').get(k).put(true);
|
||||
}
|
||||
State.local.get('groups').get('everyone').get(k).put(true);
|
||||
if (!hasFollowers && k === getPubKey() && info.followers.size) {
|
||||
State.local.get('noFollowers').put(false);
|
||||
if (k === getPubKey()) {
|
||||
updateHasFollowers();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -1,20 +1,12 @@
|
||||
import Helpers from '../Helpers.js';
|
||||
import { html } from 'htm/preact';
|
||||
import State from '../State.js';
|
||||
import PublicMessageForm from '../components/PublicMessageForm.js';
|
||||
import Identicon from '../components/Identicon.js';
|
||||
import FollowButton from '../components/FollowButton.js';
|
||||
import CopyButton from '../components/CopyButton.js';
|
||||
import MessageFeed from '../components/MessageFeed.js';
|
||||
import Filters from '../components/Filters.js';
|
||||
import Session from '../Session.js';
|
||||
import View from './View.js';
|
||||
import {translate as t} from '../Translation.js';
|
||||
import SubscribeHashtagButton from "../components/SubscribeHashtagButton";
|
||||
import Helmet from 'react-helmet';
|
||||
|
||||
const SUGGESTED_FOLLOW = 'hyECQHwSo7fgr2MVfPyakvayPeixxsaAWVtZ-vbaiSc.TXIp8MnCtrnW6n2MrYquWPcc-DTmZzMBmc2yaGv9gIU';
|
||||
|
||||
class Feed extends View {
|
||||
constructor() {
|
||||
super();
|
||||
@ -42,46 +34,6 @@ class Feed extends View {
|
||||
State.local.get('filters').get('group').put('everyone');
|
||||
}
|
||||
State.local.get('filters').get('group').on(this.inject());
|
||||
State.local.get('noFollows').on(this.inject());
|
||||
State.local.get('noFollowers').on(this.inject());
|
||||
}
|
||||
|
||||
getNotification() {
|
||||
if (this.state.noFollows) {
|
||||
return html`
|
||||
<div class="msg">
|
||||
<div class="msg-content">
|
||||
<p>${t('follow_someone_info')}</p>
|
||||
<div class="profile-link-container">
|
||||
<a href="/profile/${SUGGESTED_FOLLOW}" class="profile-link">
|
||||
<${Identicon} str=${SUGGESTED_FOLLOW} width=40 />
|
||||
<iris-text path="profile/name" user=${SUGGESTED_FOLLOW} placeholder="Suggested follow"/>
|
||||
</a>
|
||||
<${FollowButton} id=${SUGGESTED_FOLLOW} />
|
||||
</div>
|
||||
<p>${t('alternatively')} <a href="/profile/${Session.getPubKey()}">${t('give_your_profile_link_to_someone')}</a>.</p>
|
||||
</div>
|
||||
</div>
|
||||
`
|
||||
}
|
||||
if (this.state.noFollowers) {
|
||||
return html`
|
||||
<div class="msg">
|
||||
<div class="msg-content">
|
||||
<p>${t('no_followers_yet')}</p>
|
||||
<p><${CopyButton} text=${t('copy_link')} copyStr=${Helpers.getProfileLink(Session.getPubKey())}/></p>
|
||||
<p dangerouslySetInnerHTML=${{
|
||||
__html: t(
|
||||
'alternatively_get_sms_verified',
|
||||
`href="https://iris-sms-auth.herokuapp.com/?pub=${Session.getPubKey()}"`
|
||||
)}}>
|
||||
</p>
|
||||
<small>${t('no_followers_yet_info')}</small>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
filter(msg) {
|
||||
@ -115,7 +67,7 @@ class Feed extends View {
|
||||
${s.searchTerm ? html`<h2>Search results for "${s.searchTerm}"</h2>` : html`
|
||||
${this.getNotification()}
|
||||
`}
|
||||
${s.noFollows ? '' : html`<${Filters}/>`}
|
||||
${s.hasFollows ? html`<${Filters}/>` : ''}
|
||||
<${MessageFeed}
|
||||
scrollElement=${this.scrollElement.current}
|
||||
hashtag=${hashtag}
|
||||
|
@ -255,7 +255,6 @@ class Group extends View {
|
||||
}
|
||||
let qrCodeEl = $('#profile-page-qr');
|
||||
qrCodeEl.empty();
|
||||
State.local.get('noFollowers').on(noFollowers => this.setState({noFollowers}));
|
||||
State.local.get('inviteLinksChanged').on(() => this.setState({}));
|
||||
State.local.get('channels').get(this.props.id).get('participants').on(() => {
|
||||
const isAdmin = areWeAdmin(pub);
|
||||
|
@ -50,8 +50,6 @@ class Login extends Component {
|
||||
Session.login(k);
|
||||
State.public.user().get('profile').get('name').put(name);
|
||||
Session.createChatLink();
|
||||
State.local.get('noFollows').put(true);
|
||||
State.local.get('noFollowers').put(true);
|
||||
State.local.get('filters').get('group').put('follows');
|
||||
this.base.style = 'display:none';
|
||||
});
|
||||
|
@ -58,7 +58,7 @@ class Profile extends View {
|
||||
}
|
||||
|
||||
getNotification() {
|
||||
if (this.state.noFollowers && this.followers.has(Session.getPubKey())) {
|
||||
if (!this.state.hasFollowers && 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('noFollowers').on(noFollowers => this.setState({noFollowers}));
|
||||
State.local.get('hasFollowers').on(this.inject());
|
||||
this.getProfileDetails();
|
||||
if (chat) {
|
||||
$(`input[name=notificationPreference][value=${ chat.notificationSetting }]`).attr('checked', 'checked');
|
||||
|
@ -88,36 +88,11 @@ class Store extends View {
|
||||
`;
|
||||
}
|
||||
|
||||
getNotification() {
|
||||
const SUGGESTED_FOLLOW = 'hyECQHwSo7fgr2MVfPyakvayPeixxsaAWVtZ-vbaiSc.TXIp8MnCtrnW6n2MrYquWPcc-DTmZzMBmc2yaGv9gIU';
|
||||
if (this.state.noFollows) {
|
||||
return html`
|
||||
<div class="centered-container">
|
||||
<div class="msg">
|
||||
<div class="msg-content">
|
||||
<p>${t('follow_someone_info')}</p>
|
||||
<div class="profile-link-container">
|
||||
<a href="/profile/${SUGGESTED_FOLLOW}" class="profile-link">
|
||||
<${Identicon} str=${SUGGESTED_FOLLOW} width=40/>
|
||||
<iris-text path="profile/name" user=${SUGGESTED_FOLLOW} placeholder="Suggested follow"/>
|
||||
</a>
|
||||
<${FollowButton} id=${SUGGESTED_FOLLOW}/>
|
||||
</div>
|
||||
<p>${t('alternatively')} <a
|
||||
href="/profile/${Session.getPubKey()}">${t('give_your_profile_link_to_someone')}</a>.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
renderItems() {
|
||||
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.noFollows) ? '' : html`<${Filters}/>`}
|
||||
${(this.props.store || !this.state.hasFollows) ? '' : html`<${Filters}/>`}
|
||||
${cartTotalItems ? html`
|
||||
<p>
|
||||
<button onClick=${() => route('/checkout')}>${t('shopping_cart')}(${cartTotalItems})</button>
|
||||
@ -249,17 +224,6 @@ class Store extends View {
|
||||
this.isMyProfile = Session.getPubKey() === user;
|
||||
this.setState({followedUserCount: 0, followerCount: 0, name: '', photo: '', about: '', totalPrice: 0, items: {}, cart: {}});
|
||||
|
||||
State.local.get('noFollows').on(this.inject());
|
||||
|
||||
State.local.get('groups').get('follows').map().on(this.sub(
|
||||
(isFollowing, user, a, e) => {
|
||||
if (isFollowing && this.state.noFollows && Session.getPubKey() !== user) {
|
||||
State.local.get('noFollows').put(false);
|
||||
e.off();
|
||||
}
|
||||
}
|
||||
));
|
||||
|
||||
if (user) {
|
||||
this.getCartFromUser(user);
|
||||
this.getProductsFromUser(user);
|
||||
|
@ -2,6 +2,15 @@ import Component from '../BaseComponent.js';
|
||||
import { createRef } from 'preact';
|
||||
import Header from '../components/Header.js';
|
||||
import { html } from 'htm/preact';
|
||||
import Session from "../Session";
|
||||
import {translate as t} from "../Translation";
|
||||
import Identicon from "../components/Identicon";
|
||||
import FollowButton from "../components/FollowButton";
|
||||
import CopyButton from "../components/CopyButton";
|
||||
import Helpers from "../Helpers";
|
||||
import State from "../State";
|
||||
|
||||
const SUGGESTED_FOLLOW = 'hyECQHwSo7fgr2MVfPyakvayPeixxsaAWVtZ-vbaiSc.TXIp8MnCtrnW6n2MrYquWPcc-DTmZzMBmc2yaGv9gIU';
|
||||
|
||||
class View extends Component {
|
||||
scrollElement = createRef();
|
||||
@ -14,6 +23,50 @@ class View extends Component {
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
getNotification() {
|
||||
if (!this.followsSubscribed) {
|
||||
this.followsSubscribed = true;
|
||||
State.local.get('hasFollowers').on(this.inject());
|
||||
State.local.get('hasFollows').on(this.inject());
|
||||
}
|
||||
|
||||
if (!this.state.hasFollows) {
|
||||
return html`
|
||||
<div class="msg">
|
||||
<div class="msg-content">
|
||||
<p>${t('follow_someone_info')}</p>
|
||||
<div class="profile-link-container">
|
||||
<a href="/profile/${SUGGESTED_FOLLOW}" class="profile-link">
|
||||
<${Identicon} str=${SUGGESTED_FOLLOW} width=40 />
|
||||
<iris-text path="profile/name" user=${SUGGESTED_FOLLOW} placeholder="Suggested follow"/>
|
||||
</a>
|
||||
<${FollowButton} id=${SUGGESTED_FOLLOW} />
|
||||
</div>
|
||||
<p>${t('alternatively')} <a href="/profile/${Session.getPubKey()}">${t('give_your_profile_link_to_someone')}</a>.</p>
|
||||
</div>
|
||||
</div>
|
||||
`
|
||||
}
|
||||
if (!this.state.hasFollowers) {
|
||||
return html`
|
||||
<div class="msg">
|
||||
<div class="msg-content">
|
||||
<p>${t('no_followers_yet')}</p>
|
||||
<p><${CopyButton} text=${t('copy_link')} copyStr=${Helpers.getProfileLink(Session.getPubKey())}/></p>
|
||||
<p dangerouslySetInnerHTML=${{
|
||||
__html: t(
|
||||
'alternatively_get_sms_verified',
|
||||
`href="https://iris-sms-auth.herokuapp.com/?pub=${Session.getPubKey()}"`
|
||||
)}}>
|
||||
</p>
|
||||
<small>${t('no_followers_yet_info')}</small>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
export default View;
|
||||
|
Loading…
Reference in New Issue
Block a user