Skip to content

Commit 500b8e3

Browse files
committed
Paid Messages: Follow up (#5823)
1 parent e29302c commit 500b8e3

File tree

8 files changed

+38
-14
lines changed

8 files changed

+38
-14
lines changed

‎src/components/common/Composer.scss

+2
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,8 @@
691691

692692
.placeholder-star-icon {
693693
line-height: 1;
694+
margin-inline-end: 0.0625rem;
695+
margin-inline-start: 0.25rem;
694696
}
695697
.forced-placeholder,
696698
.placeholder-text {

‎src/components/left/settings/PrivacyLockedOption.module.scss

-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,5 @@
1212
}
1313

1414
.checked .lock-icon {
15-
left: 1.25rem;
16-
font-size: 1rem;
1715
color: var(--color-primary);
1816
}

‎src/components/left/settings/PrivacyMessages.tsx

+10-4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import useLang from '../../../hooks/useLang';
2424
import useLastCallback from '../../../hooks/useLastCallback';
2525
import useOldLang from '../../../hooks/useOldLang';
2626

27+
import Icon from '../../common/icons/Icon';
2728
import ListItem from '../../ui/ListItem';
2829
import RadioGroup from '../../ui/RadioGroup';
2930
import RangeSlider from '../../ui/RangeSlider';
@@ -130,8 +131,13 @@ function PrivacyMessages({
130131
}, [setChargeForMessages, updateGlobalPrivacySettingsWithDebounced]);
131132

132133
const renderValueForStarsRange = useCallback((value: number) => {
133-
return formatStarsAsText(lang, value);
134-
}, [lang]);
134+
return (
135+
<span className="settings-range-value">
136+
{!canChangeChargeForMessages && (<Icon name="lock-badge" />)}
137+
{formatStarsAsText(lang, value)}
138+
</span>
139+
);
140+
}, [lang, canChangeChargeForMessages]);
135141

136142
function renderSectionStarsAmountForPaidMessages() {
137143
return (
@@ -146,6 +152,7 @@ function PrivacyMessages({
146152
value={chargeForMessages}
147153
onChange={handleChargeForMessagesChange}
148154
renderValue={renderValueForStarsRange}
155+
readOnly={!canChangeChargeForMessages}
149156
/>
150157
<p className="settings-item-description-larger" dir={oldLang.isRtl ? 'rtl' : undefined}>
151158
{lang('SectionDescriptionStarsForForMessages', {
@@ -219,8 +226,7 @@ function PrivacyMessages({
219226
{privacyDescription}
220227
</p>
221228
</div>
222-
{canChangeChargeForMessages
223-
&& selectedValue === 'charge_for_messages' && renderSectionStarsAmountForPaidMessages()}
229+
{selectedValue === 'charge_for_messages' && renderSectionStarsAmountForPaidMessages()}
224230
{canChangeChargeForMessages && selectedValue === 'charge_for_messages' && renderSectionNoPaidMessagesForUsers()}
225231
{!isCurrentUserPremium && <PremiumStatusItem premiumSection="message_privacy" />}
226232
</>

‎src/components/left/settings/Settings.scss

+6
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,12 @@
121121
}
122122
}
123123

124+
.settings-range-value {
125+
color: var(--color-primary);
126+
display: inline-flex;
127+
align-items: center;
128+
}
129+
124130
.settings-item-simple,
125131
.settings-item {
126132
text-align: initial;

‎src/components/middle/MessageList.tsx

+9-4
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,10 @@ const MessageList: FC<OwnProps & StateProps> = ({
226226

227227
const areMessagesLoaded = Boolean(messageIds);
228228

229+
const isPrivate = isUserId(chatId);
230+
const withUsers = Boolean((!isPrivate && !isChannelChat)
231+
|| isChatWithSelf || isSystemBotChat || isAnonymousForwards || isChannelWithAvatars);
232+
229233
useSyncEffect(() => {
230234
// We only need it first time when message list appears
231235
if (areMessagesLoaded) {
@@ -329,9 +333,13 @@ const MessageList: FC<OwnProps & StateProps> = ({
329333
memoUnreadDividerBeforeIdRef.current,
330334
!isForum ? Number(threadId) : undefined,
331335
isChatWithSelf,
336+
withUsers,
332337
)
333338
: undefined;
334-
}, [messageIds, messagesById, type, isServiceNotificationsChat, isForum, threadId, isChatWithSelf, channelJoinInfo]);
339+
}, [withUsers,
340+
messageIds, messagesById, type,
341+
isServiceNotificationsChat, isForum,
342+
threadId, isChatWithSelf, channelJoinInfo]);
335343

336344
useInterval(() => {
337345
if (!messageIds || !messagesById || type === 'scheduled') return;
@@ -635,9 +643,6 @@ const MessageList: FC<OwnProps & StateProps> = ({
635643
}
636644
}, [isSelectModeActive]);
637645

638-
const isPrivate = isUserId(chatId);
639-
const withUsers = Boolean((!isPrivate && !isChannelChat)
640-
|| isChatWithSelf || isSystemBotChat || isAnonymousForwards || isChannelWithAvatars);
641646
const noAvatars = Boolean(!withUsers || (isChannelChat && !isChannelWithAvatars));
642647
const shouldRenderGreeting = isUserId(chatId) && !isChatWithSelf && !isBot && !isAnonymousForwards
643648
&& type === 'thread'

‎src/components/middle/helpers/groupMessages.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export function isAlbum(messageOrAlbum: ApiMessage | IAlbum): messageOrAlbum is
1919
}
2020

2121
export function groupMessages(
22-
messages: ApiMessage[], firstUnreadId?: number, topMessageId?: number, isChatWithSelf?: boolean,
22+
messages: ApiMessage[], firstUnreadId?: number, topMessageId?: number, isChatWithSelf?: boolean, withUsers?: boolean,
2323
) {
2424
const initDateGroup: MessageDateGroup = {
2525
originalDate: messages[0].date,
@@ -90,7 +90,7 @@ export function groupMessages(
9090
} else if (
9191
nextMessage.id === firstUnreadId
9292
|| message.senderId !== nextMessage.senderId
93-
|| message.paidMessageStars
93+
|| (!withUsers && message.paidMessageStars)
9494
|| message.isOutgoing !== nextMessage.isOutgoing
9595
|| message.postAuthorTitle !== nextMessage.postAuthorTitle
9696
|| (isActionMessage(message) && message.content.action?.type !== 'phoneCall')

‎src/components/ui/RangeSlider.scss

+4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
--slider-color: var(--color-text-secondary);
2626
}
2727

28+
&.readOnly {
29+
pointer-events: none;
30+
}
31+
2832
.slider-top-row {
2933
display: flex;
3034
justify-content: space-between;

‎src/components/ui/RangeSlider.tsx

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { ChangeEvent } from 'react';
2-
import type { FC } from '../../lib/teact/teact';
2+
import type { FC, TeactNode } from '../../lib/teact/teact';
33
import React, { memo, useCallback, useMemo } from '../../lib/teact/teact';
44

55
import buildClassName from '../../util/buildClassName';
@@ -16,9 +16,10 @@ type OwnProps = {
1616
label?: string;
1717
value: number;
1818
disabled?: boolean;
19+
readOnly?: boolean;
1920
bold?: boolean;
2021
className?: string;
21-
renderValue?: (value: number) => string;
22+
renderValue?: (value: number) => TeactNode;
2223
onChange: (value: number) => void;
2324
isCenteredLayout?: boolean;
2425
};
@@ -31,6 +32,7 @@ const RangeSlider: FC<OwnProps> = ({
3132
label,
3233
value,
3334
disabled,
35+
readOnly,
3436
bold,
3537
className,
3638
renderValue,
@@ -46,6 +48,7 @@ const RangeSlider: FC<OwnProps> = ({
4648
className,
4749
'RangeSlider',
4850
disabled && 'disabled',
51+
readOnly && 'readOnly',
4952
bold && 'bold',
5053
);
5154

0 commit comments

Comments
 (0)