Skip to content
Merged
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"@babel/preset-typescript": "^7.26.0",
"@babel/runtime": "^7.26.7",
"@ecency/render-helper": "^2.4.25",
"@ecency/sdk": "^2.0.33",
"@ecency/sdk": "^2.0.34",
"@esteemapp/dhive": "0.15.0",
"@esteemapp/react-native-autocomplete-input": "^4.2.1",
"@esteemapp/react-native-multi-slider": "^1.1.0",
Expand Down
5 changes: 3 additions & 2 deletions src/components/comment/view/commentView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const CommentView = ({
onUpvotePress,
handleParaSelection,
onTagPress,
onAuthorPress,
}) => {
const intl = useIntl();

Expand Down Expand Up @@ -314,8 +315,8 @@ const CommentView = ({
customStyle={{ alignItems: 'flex-start', paddingLeft: 12 }}
showDotMenuButton={true}
handleOnDotPress={() => handleOnMenuPress(comment)}
avatarOnPress={handleOnUserPress}
profileOnPress={_openProfilePage}
avatarOnPress={onAuthorPress || handleOnUserPress}
profileOnPress={onAuthorPress || _openProfilePage}
secondaryContentComponent={_renderComment()}
/>
</View>
Expand Down
2 changes: 2 additions & 0 deletions src/components/comments/container/commentsContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const CommentsContainer = ({
postType,
handleCommentDelete,
onTagPress,
onAuthorPress,
}) => {
const navigation = useNavigation();
const postsCachePrimer = postQueries.usePostsCachePrimer();
Expand Down Expand Up @@ -321,6 +322,7 @@ const CommentsContainer = ({
isLoading={isLoading}
postType={postType}
onTagPress={onTagPress}
onAuthorPress={onAuthorPress}
/>
);
};
Expand Down
2 changes: 2 additions & 0 deletions src/components/comments/view/commentsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const CommentsView = ({
isLoading,
postType,
onTagPress,
onAuthorPress,
}) => {
const [selectedComment, setSelectedComment] = useState(null);
const intl = useIntl();
Expand Down Expand Up @@ -142,6 +143,7 @@ const CommentsView = ({
fetchedAt={fetchedAt}
incrementRepliesCount={incrementRepliesCount}
onTagPress={onTagPress}
onAuthorPress={onAuthorPress}
/>
);
};
Expand Down
8 changes: 8 additions & 0 deletions src/providers/chat/mattermost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ export const getChannelUnreadTotal = (channel: any): number => {
return 0;
}

// Channels that have never been viewed (null/undefined last_viewed_at)
// should not count unreads — prevents auto-joined channels from
// inflating the badge with all historical messages.
const lastViewed = channel?.last_viewed_at ?? channel?.last_view_at;
if (lastViewed == null) {
return 0;
}

const unreadMentionValues = [
channel?.unread_mentions,
channel?.mention_count,
Expand Down
4 changes: 3 additions & 1 deletion src/providers/queries/postQueries/wavesQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
getWavesByHostQueryOptions,
getWavesFollowingQueryOptions,
getWavesByTagQueryOptions,
getWavesByAccountQueryOptions,
useDeleteComment,
WaveEntry,
} from '@ecency/sdk';
Expand All @@ -30,7 +31,8 @@ import { useAuthContext } from '../../sdk';
type WavesQueryOptions =
| ReturnType<typeof getWavesByHostQueryOptions>
| ReturnType<typeof getWavesFollowingQueryOptions>
| ReturnType<typeof getWavesByTagQueryOptions>;
| ReturnType<typeof getWavesByTagQueryOptions>
| ReturnType<typeof getWavesByAccountQueryOptions>;

export const useWavesQuery = (sdkQueryOptions: WavesQueryOptions, host: string) => {
const queryClient = useQueryClient();
Expand Down
47 changes: 40 additions & 7 deletions src/screens/chats/container/chatsContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,23 @@ const ChatsContainer = () => {
// ============================================================================

const _getUnreadMeta = useCallback((channel: any) => {
const _zeroUnread = {
unreadMentions: 0,
unreadMessages: 0,
unreadCount: 0,
totalUnread: 0,
};

if (channel?.is_muted) {
return {
unreadMentions: 0,
unreadMessages: 0,
unreadCount: 0,
totalUnread: 0,
};
return _zeroUnread;
}

// Channels that have never been viewed (null/undefined) should
// not show unreads — prevents auto-joined channels from showing
// all historical messages as new
const lastViewed = channel?.last_viewed_at ?? channel?.last_view_at;
if (lastViewed == null) {
return _zeroUnread;
}

const unreadMentionValues = [
Expand Down Expand Up @@ -603,7 +613,27 @@ const ChatsContainer = () => {

const joined = await joinMattermostChannel(channelId);
const joinedId = _getChannelId(joined) || channelId;
const mergedChannel = { ...resolved?.resolvedChannel, ...channel, ...joined };

// Mark channel as viewed immediately after joining so historical
// messages don't inflate the unread count for newly joined users
let viewedSuccessfully = false;
try {
await markMattermostChannelViewed(joinedId);
viewedSuccessfully = true;
} catch {
// non-critical — channel will show unreads until manually opened
}

const mergedChannel = {
...resolved?.resolvedChannel,
...channel,
...joined,
...(viewedSuccessfully && {
unread_messages: 0,
unread_mentions: 0,
mention_count: 0,
}),
};
const communityIdentifier = safeExtractCommunityIdentifier(mergedChannel);

setChannels((prev) => {
Expand All @@ -621,6 +651,9 @@ const ChatsContainer = () => {
return [mergedChannel, ...prev];
});

// Refresh global badge to reflect the mark-as-viewed
_refreshGlobalUnreadChatCount();

navigation.navigate(
ROUTES.SCREENS.CHAT_THREAD as never,
{
Expand Down
27 changes: 21 additions & 6 deletions src/screens/waves/children/wavesHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,35 @@ export type WavesFeedType = 'for-you' | 'following';

interface WavesHeaderProps {
activeTag: string | null;
activeAuthor: string | null;
onClearTag: () => void;
onClearAuthor: () => void;
}

export const WavesHeader = ({ activeTag, onClearTag }: WavesHeaderProps) => {
if (!activeTag) {
export const WavesHeader = ({
activeTag,
activeAuthor,
onClearTag,
onClearAuthor,
}: WavesHeaderProps) => {
if (!activeTag && !activeAuthor) {
return null;
}

return (
<View style={styles.tagChipRow}>
<TouchableOpacity style={styles.tagChip} onPress={onClearTag}>
<Text style={styles.tagChipText}>#{activeTag}</Text>
<Icon iconType="MaterialIcons" name="close" size={16} style={styles.tagChipClose} />
</TouchableOpacity>
{!!activeTag && (
<TouchableOpacity style={styles.tagChip} onPress={onClearTag}>
<Text style={styles.tagChipText}>#{activeTag}</Text>
<Icon iconType="MaterialIcons" name="close" size={16} style={styles.tagChipClose} />
</TouchableOpacity>
)}
{!!activeAuthor && (
<TouchableOpacity style={styles.tagChip} onPress={onClearAuthor}>
<Text style={styles.tagChipText}>@{activeAuthor}</Text>
<Icon iconType="MaterialIcons" name="close" size={16} style={styles.tagChipClose} />
</TouchableOpacity>
)}
</View>
);
};
Expand Down
68 changes: 62 additions & 6 deletions src/screens/waves/screen/wavesScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
getWavesByHostQueryOptions,
getWavesFollowingQueryOptions,
getWavesByTagQueryOptions,
getWavesByAccountQueryOptions,
} from '@ecency/sdk';
import {
Comments,
Expand Down Expand Up @@ -49,6 +50,7 @@ const WavesFeed = ({
queryKey,
listRef,
onTagPress,
onAuthorPress,
onOptionsPress,
onScrollStateChange,
onVisibilityChange,
Expand All @@ -58,6 +60,7 @@ const WavesFeed = ({
queryKey: string;
listRef: React.RefObject<FlatList | null>;
onTagPress: (tag: string) => void;
onAuthorPress: (username: string) => void;
onOptionsPress: (content: any) => void;
onScrollStateChange: (state: { enabled: boolean; offset: number }) => void;
onVisibilityChange?: (api: {
Expand Down Expand Up @@ -136,6 +139,7 @@ const WavesFeed = ({
handleOnOptionsPress={onOptionsPress}
handleCommentDelete={wavesQuery.deleteWave}
onTagPress={onTagPress}
onAuthorPress={onAuthorPress}
flatListProps={{
ref: listRef,
onEndReached: _fetchData,
Expand All @@ -162,9 +166,11 @@ const WavesScreen = () => {
const forYouListRef = useRef<FlatList>(null);
const followingListRef = useRef<FlatList>(null);
const tagListRef = useRef<FlatList>(null);
const authorListRef = useRef<FlatList>(null);

const [feedType, setFeedType] = useState<WavesFeedType>('for-you');
const [activeTag, setActiveTag] = useState<string | null>(null);
const [activeAuthor, setActiveAuthor] = useState<string | null>(null);
const [enableScrollTop, setEnableScrollTop] = useState(false);
const [lazyLoad, setLazyLoad] = useState(false);
const activeDeleteWaveRef = useRef<
Expand All @@ -186,8 +192,14 @@ const WavesScreen = () => {
() => (activeTag ? getWavesByTagQueryOptions(WAVES_HOST, activeTag) : null),
[activeTag],
);
const authorQueryOptions = useMemo(
() => (activeAuthor ? getWavesByAccountQueryOptions(WAVES_HOST, activeAuthor) : null),
[activeAuthor],
);

const activeListRef = activeTag
const activeListRef = activeAuthor
? authorListRef
: activeTag
? tagListRef
: feedType === 'following'
? followingListRef
Expand Down Expand Up @@ -223,14 +235,15 @@ const WavesScreen = () => {
return;
}

if (tab === feedType && !activeTag) {
if (tab === feedType && !activeTag && !activeAuthor) {
activeListRef.current?.scrollToOffset({ offset: 0, animated: false });
setEnableScrollTop(false);
return;
}

if (tab === 'following') {
setActiveTag(null);
setActiveAuthor(null);
}

setEnableScrollTop(false);
Expand All @@ -240,6 +253,7 @@ const WavesScreen = () => {
const _handleTagFilter = useCallback((tag: string) => {
setFeedType((prev) => (prev === 'following' ? 'for-you' : prev));
setEnableScrollTop(false);
setActiveAuthor(null);
setActiveTag(tag);
}, []);

Expand All @@ -248,6 +262,18 @@ const WavesScreen = () => {
setActiveTag(null);
}, []);

const _handleAuthorFilter = useCallback((username: string) => {
setFeedType((prev) => (prev === 'following' ? 'for-you' : prev));
setEnableScrollTop(false);
setActiveTag(null);
setActiveAuthor(username);
}, []);

const _handleClearAuthor = useCallback(() => {
setEnableScrollTop(false);
setActiveAuthor(null);
}, []);

const _handleOnOptionsPress = (content: any) => {
if (postOptionsModalRef.current) {
postOptionsModalRef.current.show(content);
Expand Down Expand Up @@ -278,9 +304,15 @@ const WavesScreen = () => {
setEnableScrollTop(enabled);
};

const _renderTagChip = activeTag ? (
<WavesHeader activeTag={activeTag} onClearTag={_handleClearTag} />
) : null;
const _renderFilterChip =
activeTag || activeAuthor ? (
<WavesHeader
activeTag={activeTag}
activeAuthor={activeAuthor}
onClearTag={_handleClearTag}
onClearAuthor={_handleClearAuthor}
/>
) : null;

const _renderWavesScene = ({ route }: { route: { key: string } }) => {
if (route.key === 'following') {
Expand All @@ -295,6 +327,28 @@ const WavesScreen = () => {
queryKey={`following:${currentAccount?.name}`}
listRef={followingListRef}
onTagPress={_handleTagFilter}
onAuthorPress={_handleAuthorFilter}
onOptionsPress={_handleOnOptionsPress}
onScrollStateChange={_handleScrollStateChange}
onVisibilityChange={({ deleteWave }) => {
activeDeleteWaveRef.current = deleteWave;
}}
isDarkTheme={isDarkTheme}
/>
</View>
);
}

if (activeAuthor && authorQueryOptions) {
return (
<View style={styles.tabScene}>
{_renderFilterChip}
<WavesFeed
queryOptions={authorQueryOptions}
queryKey={`author:${activeAuthor}`}
listRef={authorListRef}
onTagPress={_handleTagFilter}
onAuthorPress={_handleAuthorFilter}
onOptionsPress={_handleOnOptionsPress}
onScrollStateChange={_handleScrollStateChange}
onVisibilityChange={({ deleteWave }) => {
Expand All @@ -309,12 +363,13 @@ const WavesScreen = () => {
if (activeTag && tagQueryOptions) {
return (
<View style={styles.tabScene}>
{_renderTagChip}
{_renderFilterChip}
<WavesFeed
queryOptions={tagQueryOptions}
queryKey={`tag:${activeTag}`}
listRef={tagListRef}
onTagPress={_handleTagFilter}
onAuthorPress={_handleAuthorFilter}
onOptionsPress={_handleOnOptionsPress}
onScrollStateChange={_handleScrollStateChange}
onVisibilityChange={({ deleteWave }) => {
Expand All @@ -333,6 +388,7 @@ const WavesScreen = () => {
queryKey="for-you"
listRef={forYouListRef}
onTagPress={_handleTagFilter}
onAuthorPress={_handleAuthorFilter}
onOptionsPress={_handleOnOptionsPress}
onScrollStateChange={_handleScrollStateChange}
onVisibilityChange={({ deleteWave }) => {
Expand Down
Loading
Loading