Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/components/comment/view/commentView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ const CommentView = ({
);

const activeVotes = comment?.active_votes || [];
const _totalVotes = comment.stats?.total_votes || 0;

const [isOpeningReplies, setIsOpeningReplies] = useState(false);

const childCount = comment.children;
Expand Down Expand Up @@ -165,11 +167,9 @@ const CommentView = ({
iconType="MaterialCommunityIcons"
isClickable
onPress={() =>
handleOnVotersPress &&
activeVotes.length > 0 &&
handleOnVotersPress(activeVotes, comment)
handleOnVotersPress && _totalVotes > 0 && handleOnVotersPress(activeVotes, comment)
}
text={activeVotes.length}
text={_totalVotes}
textStyle={styles.voteCountText}
/>

Expand All @@ -194,7 +194,7 @@ const CommentView = ({
onPress={() => handleOnEditPress && handleOnEditPress(comment)}
iconType="MaterialIcons"
/>
{!childCount && !activeVotes.length && comment.isDeletable && (
{!childCount && !_totalVotes && comment.isDeletable && (
<IconButton
size={20}
iconStyle={styles.leftIcon}
Expand Down
4 changes: 1 addition & 3 deletions src/components/postCard/children/postCardActionsPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ interface Props {
}

export const PostCardActionsPanel = ({ content, handleCardInteraction }: Props) => {
const activeVotes = content?.active_votes || [];

const _onVotersPress = () => {
handleCardInteraction(PostCardActionIds.NAVIGATE, {
name: ROUTES.SCREENS.VOTERS,
Expand Down Expand Up @@ -67,7 +65,7 @@ export const PostCardActionsPanel = ({ content, handleCardInteraction }: Props)
iconStyle={styles.commentIcon}
iconType="MaterialCommunityIcons"
isClickable
text={activeVotes.length}
text={content.stats?.total_votes || 0}
/>
</TouchableOpacity>
</View>
Expand Down
8 changes: 6 additions & 2 deletions src/containers/profileContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ class ProfileContainer extends Component {

_getReplies = async (query) => {
const { isOwnProfile, comments } = this.state;
const {
currentAccount: { name: currentUsername },
} = this.props;

this.setState({ isProfileLoading: true });
let repliesAction;

Expand All @@ -104,7 +108,7 @@ class ProfileContainer extends Component {
query.start_permlink = query.permlink;
}
query.limit = 5;
query.observer = '';
query.observer = currentUsername || ''; // TODO: add current account username here
query.sort = 'comments';
}
} else {
Expand All @@ -116,7 +120,7 @@ class ProfileContainer extends Component {
query.start_permlink = query.permlink;
}
query.limit = 5;
query.observer = '';
query.observer = currentUsername || ''; // TODO: add current account username here
query.sort = 'replies';
}
}
Expand Down
75 changes: 71 additions & 4 deletions src/providers/hive/dhive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import AUTH_TYPE from '../../constants/authType';
import { SERVER_LIST } from '../../constants/options/api';
import { b64uEnc } from '../../utils/b64';
import TransferTypes from '../../constants/transferTypes';
import { Vote } from './hive.types';

interface LocalAccount {
authType: string;
Expand Down Expand Up @@ -723,6 +724,44 @@ export const getProposalsVoted = async (username) => {
}
};

/**
* checks if post is voted by user
* it usefull if voters count goes beyond 1000 limit of get_active_votes api
* @param username
* @param author
* @param permlink
* @returns vote object or null
*/
export const getUserPostVote = async (author: string, permlink: string, username: string) => {
try {
if (!username) {
throw new Error('invalid parameters');
}

console.log('Getting post vote status:', username);

const _limit = 1;
const _sort = 'by_voter_comment';

const rawResult = await client.call('database_api', 'list_votes', [
[username, author, permlink],
_limit,
_sort,
]);

if (!Array.isArray(rawResult?.votes)) {
throw new Error('invalid data');
}

const _votes: Vote[] = rawResult.votes;
return _votes.length ? _votes[0] : null; // since we are fetching with limit 1
} catch (error) {
Sentry.captureException(error);
console.warn('Failed to get post vote status', error);
return null;
}
};

export const getActiveVotes = (author, permlink) =>
new Promise((resolve, reject) => {
try {
Expand Down Expand Up @@ -762,7 +801,7 @@ export const getPostReblogs = async (author, permlink) => {
}
};

export const getRankedPosts = async (query, currentUserName, filterNsfw) => {
export const getRankedPosts = async (query: any, currentUserName: string, filterNsfw: string) => {
try {
console.log('Getting ranked posts:', query);

Expand All @@ -787,7 +826,11 @@ export const getRankedPosts = async (query, currentUserName, filterNsfw) => {
}
};

export const getAccountPosts = async (query, currentUserName: string, filterNsfw: string) => {
export const getAccountPosts = async (
query: any,
currentUserName?: string,
filterNsfw?: string,
) => {
try {
console.log('Getting account posts: ', query);
let posts = await client.call('bridge', 'get_account_posts', query);
Expand Down Expand Up @@ -833,7 +876,8 @@ export const getPost = async (author, permlink, currentUserName = null, isPromot
console.log('Getting post: ', author, permlink);
const post = await client.call('bridge', 'get_post', { author, permlink });
console.log('post fetched', post?.post_id);
// TODO check for cross post, resolve it

// check for cross post, resolve it
return post ? await resolvePost(post, currentUserName, isPromoted) : null;
} catch (error) {
console.warn(error);
Expand Down Expand Up @@ -963,7 +1007,30 @@ const resolvePost = async (

return originalPost;
} else {
return parsePost(post, currentUsername, isPromoted, false, isList, discardBody);
// check post vote count and vote status is needed
if (post.stats.total_votes > 1000) {
// get user vote index
const existingVoteIndex = post.active_votes.findIndex(
(vote) => vote.voter === currentUsername,
);

// no need to fetch vote status if it is already present
if (existingVoteIndex < 0) {
// fetch user vote status
const userVote = currentUsername
? await getUserPostVote(post.author, post.permlink, currentUsername)
: null;
post.active_votes = post.active_votes || [];
if (userVote) {
post.active_votes.push({
voter: userVote.voter,
rshares: userVote.rshares,
});
}
}
}

return parsePost(post, currentUsername, isPromoted, isList, discardBody);
}
}
return null;
Expand Down
4 changes: 2 additions & 2 deletions src/providers/queries/postQueries/feedQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export const useFeedQuery = ({

let func = getAccountPosts;
const options: any = {
observer: feedUsername || '',
observer: currentAccount.username || '', // TOOD: add current account username here
start_author: startAuthor,
start_permlink: startPermlink,
limit: POSTS_FETCH_COUNT,
Expand Down Expand Up @@ -129,7 +129,7 @@ export const useFeedQuery = ({
}

// fetching posts
const response: any[] = await func(options, feedUsername, nsfw);
const response: any[] = await func(options, currentAccount.username, nsfw); // TODO: which username to add here

if (!Array.isArray(response) || response.length == 0) {
return [];
Expand Down
5 changes: 2 additions & 3 deletions src/screens/application/container/applicationContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ class ApplicationContainer extends Component {
};

_logout = async (username) => {
const {currentAccount, otherAccounts, dispatch, intl } = this.props;
const { currentAccount, otherAccounts, dispatch, intl } = this.props;

try {
const response = await removeUserData(username);
Expand Down Expand Up @@ -647,7 +647,6 @@ class ApplicationContainer extends Component {
};

_enableNotification = async (username, isEnable, settings = null, encAccesstoken = null) => {

const accessToken = encAccesstoken ? decryptKey(encAccesstoken, Config.DEFAULT_PIN) : null;

// compile notify_types
Expand Down Expand Up @@ -679,7 +678,7 @@ class ApplicationContainer extends Component {
setPushToken(
{
username,
token: token,
token,
system: `fcm-${Platform.OS}`,
allows_notify: Number(isEnable),
notify_types,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const PostsResultsContainer = ({ children, searchValue }) => {
sort: 'blog',
};

return getAccountPosts(options);
return getAccountPosts(options, currentAccountUsername || '');
};

// Component Functions
Expand Down
13 changes: 5 additions & 8 deletions src/screens/settings/container/settingsContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import THEME_OPTIONS from '../../../constants/options/theme';

// Realm
import {
getExistUser,
setCurrency as setCurrency2DB,
setServer,
setNotificationSettings,
Expand Down Expand Up @@ -360,23 +359,20 @@ class SettingsContainer extends Component {
const { isLoggedIn, otherAccounts = [] } = this.props;

if (isLoggedIn) {

otherAccounts.forEach(async (item) => {
const token = await getMessaging().getToken()
const token = await getMessaging().getToken();
console.log('FCM Token:', token);

const data = {
username: item.username,
token,
system: `fcm-${Platform.OS}`,
allows_notify: enabled ? 1 : 0 ,
allows_notify: enabled ? 1 : 0,
notify_types: notifyTypes,
};

setPushToken(data);

});

}
};

Expand All @@ -385,8 +381,9 @@ class SettingsContainer extends Component {
let message;

const deviceName = await DeviceInfo.getDeviceName();
const platform = `${deviceName} - ${Platform.OS === 'ios' ? 'iOS' : 'Android'} ${Platform.Version
}`;
const platform = `${deviceName} - ${Platform.OS === 'ios' ? 'iOS' : 'Android'} ${
Platform.Version
}`;
const appVersion = `${DeviceInfo.getVersion()} (${DeviceInfo.getBuildNumber()})`;
const username = currentAccount?.username || 'Unknown User';

Expand Down
2 changes: 1 addition & 1 deletion src/utils/filterNsfwPost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface Post {
[key: string]: any;
}

const filterNsfwPost = (posts: Post[], option: string): Post[] => {
const filterNsfwPost = (posts: Post[], option?: string): Post[] => {
const updatedPosts: Post[] = [];

switch (option) {
Expand Down