Discussions: Fix missing reactions and Send As feature (#1662)

This commit is contained in:
Alexander Zinchuk 2022-01-25 03:24:31 +01:00
parent b43cde120d
commit b2d06ff289

View File

@ -225,6 +225,7 @@ const Composer: FC<OwnProps & StateProps> = ({
addRecentEmoji, addRecentEmoji,
sendInlineBotResult, sendInlineBotResult,
loadSendAs, loadSendAs,
loadFullChat,
} = getDispatch(); } = getDispatch();
const lang = useLang(); const lang = useLang();
@ -240,6 +241,7 @@ const Composer: FC<OwnProps & StateProps> = ({
] = useState<GlobalState['messages']['contentToBeScheduled'] | undefined>(); ] = useState<GlobalState['messages']['contentToBeScheduled'] | undefined>();
const { width: windowWidth } = windowSize.get(); const { width: windowWidth } = windowSize.get();
const sendAsIds = chat?.sendAsIds; const sendAsIds = chat?.sendAsIds;
const canShowSendAs = sendAsIds && (sendAsIds.length > 1 || !sendAsIds.includes(currentUserId!));
const sendMessageAction = useSendMessageAction(chatId, threadId); const sendMessageAction = useSendMessageAction(chatId, threadId);
useEffect(() => { useEffect(() => {
@ -258,6 +260,12 @@ const Composer: FC<OwnProps & StateProps> = ({
} }
}, [chat, chatId, isReady, lastSyncTime, loadSendAs, sendAsIds]); }, [chat, chatId, isReady, lastSyncTime, loadSendAs, sendAsIds]);
useEffect(() => {
if (chatId && chat && lastSyncTime && !chat.fullInfo && isReady && isChatSuperGroup(chat)) {
loadFullChat({ chatId });
}
}, [chat, chatId, isReady, lastSyncTime, loadFullChat]);
const shouldAnimateSendAsButtonRef = useRef(false); const shouldAnimateSendAsButtonRef = useRef(false);
useOnChange(([prevChatId, prevSendAsIds]) => { useOnChange(([prevChatId, prevSendAsIds]) => {
// We only animate send-as button if `sendAsIds` was missing when opening the chat // We only animate send-as button if `sendAsIds` was missing when opening the chat
@ -920,7 +928,7 @@ const Composer: FC<OwnProps & StateProps> = ({
<i className="icon-bot-commands-filled" /> <i className="icon-bot-commands-filled" />
</ResponsiveHoverButton> </ResponsiveHoverButton>
)} )}
{!!sendAsIds?.length && (sendAsUser || sendAsChat) && ( {canShowSendAs && (sendAsUser || sendAsChat) && (
<Button <Button
round round
color="translucent" color="translucent"
@ -1137,7 +1145,10 @@ export default memo(withGlobal<OwnProps>(
const botKeyboardMessageId = messageWithActualBotKeyboard ? messageWithActualBotKeyboard.id : undefined; const botKeyboardMessageId = messageWithActualBotKeyboard ? messageWithActualBotKeyboard.id : undefined;
const keyboardMessage = botKeyboardMessageId ? selectChatMessage(global, chatId, botKeyboardMessageId) : undefined; const keyboardMessage = botKeyboardMessageId ? selectChatMessage(global, chatId, botKeyboardMessageId) : undefined;
const { currentUserId } = global; const { currentUserId } = global;
const sendAsId = chat?.fullInfo ? chat?.fullInfo?.sendAsId || currentUserId : undefined; const defaultSendAsId = chat?.fullInfo ? chat?.fullInfo?.sendAsId || currentUserId : undefined;
const sendAsId = chat?.sendAsIds && defaultSendAsId && chat.sendAsIds.includes(defaultSendAsId)
? defaultSendAsId
: (chat?.adminRights?.anonymous ? chat?.id : undefined);
const sendAsUser = sendAsId ? selectUser(global, sendAsId) : undefined; const sendAsUser = sendAsId ? selectUser(global, sendAsId) : undefined;
const sendAsChat = !sendAsUser && sendAsId ? selectChat(global, sendAsId) : undefined; const sendAsChat = !sendAsUser && sendAsId ? selectChat(global, sendAsId) : undefined;