Sticker Modal: Check ability to send stickers in current chat (#1466)

This commit is contained in:
Alexander Zinchuk 2021-09-24 14:37:45 +03:00
parent 6dc26233c4
commit a2fe5734e1
3 changed files with 32 additions and 13 deletions

View File

@ -6,10 +6,22 @@
border-radius: var(--border-radius-messages-small); border-radius: var(--border-radius-messages-small);
background: transparent no-repeat center; background: transparent no-repeat center;
background-size: contain; background-size: contain;
cursor: pointer;
transition: background-color .15s ease, opacity .3s ease !important; transition: background-color .15s ease, opacity .3s ease !important;
position: relative; position: relative;
&.interactive {
cursor: pointer;
&:hover {
background-color: var(--color-interactive-element-hover);
.sticker-unfave-button {
opacity: 1;
}
}
}
@media (max-width: 600px) { @media (max-width: 600px) {
margin: 0.25rem; margin: 0.25rem;
} }
@ -52,12 +64,4 @@
opacity: 0; opacity: 0;
} }
&:hover {
background-color: var(--color-interactive-element-hover);
.sticker-unfave-button {
opacity: 1;
}
}
} }

View File

@ -76,6 +76,7 @@ const StickerButton: FC<OwnProps> = ({
const fullClassName = buildClassName( const fullClassName = buildClassName(
'StickerButton', 'StickerButton',
onClick && 'interactive',
sticker.isAnimated && 'animated', sticker.isAnimated && 'animated',
stickerSelector, stickerSelector,
className, className,

View File

@ -8,10 +8,13 @@ import { GlobalActions } from '../../global/types';
import { STICKER_SIZE_MODAL } from '../../config'; import { STICKER_SIZE_MODAL } from '../../config';
import { pick } from '../../util/iteratees'; import { pick } from '../../util/iteratees';
import { selectStickerSet, selectStickerSetByShortName } from '../../modules/selectors'; import {
selectChat, selectCurrentMessageList, selectStickerSet, selectStickerSetByShortName,
} from '../../modules/selectors';
import { useIntersectionObserver } from '../../hooks/useIntersectionObserver'; import { useIntersectionObserver } from '../../hooks/useIntersectionObserver';
import useLang from '../../hooks/useLang'; import useLang from '../../hooks/useLang';
import renderText from './helpers/renderText'; import renderText from './helpers/renderText';
import { getAllowedAttachmentOptions, getCanPostInChat } from '../../modules/helpers';
import Modal from '../ui/Modal'; import Modal from '../ui/Modal';
import Button from '../ui/Button'; import Button from '../ui/Button';
@ -28,6 +31,7 @@ export type OwnProps = {
}; };
type StateProps = { type StateProps = {
canSendStickers?: boolean;
stickerSet?: ApiStickerSet; stickerSet?: ApiStickerSet;
}; };
@ -40,6 +44,7 @@ const StickerSetModal: FC<OwnProps & StateProps & DispatchProps> = ({
fromSticker, fromSticker,
stickerSetShortName, stickerSetShortName,
stickerSet, stickerSet,
canSendStickers,
onClose, onClose,
loadStickers, loadStickers,
toggleStickerSet, toggleStickerSet,
@ -102,7 +107,7 @@ const StickerSetModal: FC<OwnProps & StateProps & DispatchProps> = ({
sticker={sticker} sticker={sticker}
size={STICKER_SIZE_MODAL} size={STICKER_SIZE_MODAL}
observeIntersection={observeIntersection} observeIntersection={observeIntersection}
onClick={handleSelect} onClick={canSendStickers ? handleSelect : undefined}
clickArg={sticker} clickArg={sticker}
/> />
))} ))}
@ -129,9 +134,18 @@ const StickerSetModal: FC<OwnProps & StateProps & DispatchProps> = ({
); );
}; };
export default memo(withGlobal( export default memo(withGlobal<OwnProps>(
(global, { fromSticker, stickerSetShortName }: OwnProps) => { (global, { fromSticker, stickerSetShortName }): StateProps => {
const currentMessageList = selectCurrentMessageList(global);
const { chatId, threadId } = currentMessageList || {};
const chat = chatId && selectChat(global, chatId);
const sendOptions = chat ? getAllowedAttachmentOptions(chat) : undefined;
const canSendStickers = Boolean(
chat && threadId && getCanPostInChat(chat, threadId) && sendOptions?.canSendStickers,
);
return { return {
canSendStickers,
stickerSet: fromSticker stickerSet: fromSticker
? selectStickerSet(global, fromSticker.stickerSetId) ? selectStickerSet(global, fromSticker.stickerSetId)
: stickerSetShortName : stickerSetShortName