Reactions: Fix reacting to document groups and local messages (#1700)
This commit is contained in:
parent
a1ff730765
commit
5648fbcabc
@ -15,7 +15,7 @@ import {
|
|||||||
} from '../../../modules/selectors';
|
} from '../../../modules/selectors';
|
||||||
import {
|
import {
|
||||||
isActionMessage, isChatChannel,
|
isActionMessage, isChatChannel,
|
||||||
isChatGroup, isOwnMessage, areReactionsEmpty, isUserId,
|
isChatGroup, isOwnMessage, areReactionsEmpty, isUserId, isMessageLocal,
|
||||||
} from '../../../modules/helpers';
|
} from '../../../modules/helpers';
|
||||||
import { SERVICE_NOTIFICATIONS_USER_ID } from '../../../config';
|
import { SERVICE_NOTIFICATIONS_USER_ID } from '../../../config';
|
||||||
import { getDayStartAt } from '../../../util/dateFormat';
|
import { getDayStartAt } from '../../../util/dateFormat';
|
||||||
@ -429,6 +429,7 @@ export default memo(withGlobal<OwnProps>(
|
|||||||
const isPinned = messageListType === 'pinned';
|
const isPinned = messageListType === 'pinned';
|
||||||
const isScheduled = messageListType === 'scheduled';
|
const isScheduled = messageListType === 'scheduled';
|
||||||
const isChannel = chat && isChatChannel(chat);
|
const isChannel = chat && isChatChannel(chat);
|
||||||
|
const isLocal = isMessageLocal(message);
|
||||||
const canShowSeenBy = Boolean(chat
|
const canShowSeenBy = Boolean(chat
|
||||||
&& seenByMaxChatMembers
|
&& seenByMaxChatMembers
|
||||||
&& seenByExpiresAt
|
&& seenByExpiresAt
|
||||||
@ -440,7 +441,7 @@ export default memo(withGlobal<OwnProps>(
|
|||||||
&& message.date > Date.now() / 1000 - seenByExpiresAt);
|
&& message.date > Date.now() / 1000 - seenByExpiresAt);
|
||||||
const isPrivate = chat && isUserId(chat.id);
|
const isPrivate = chat && isUserId(chat.id);
|
||||||
const isAction = isActionMessage(message);
|
const isAction = isActionMessage(message);
|
||||||
const canShowReactionsCount = !isChannel && !isScheduled && !isAction && !isPrivate && message.reactions
|
const canShowReactionsCount = !isLocal && !isChannel && !isScheduled && !isAction && !isPrivate && message.reactions
|
||||||
&& !areReactionsEmpty(message.reactions) && message.reactions.canSeeList;
|
&& !areReactionsEmpty(message.reactions) && message.reactions.canSeeList;
|
||||||
const canRemoveReaction = isPrivate && message.reactions?.results?.some((l) => l.isChosen);
|
const canRemoveReaction = isPrivate && message.reactions?.results?.some((l) => l.isChosen);
|
||||||
const isProtected = selectIsMessageProtected(global, message);
|
const isProtected = selectIsMessageProtected(global, message);
|
||||||
@ -469,7 +470,7 @@ export default memo(withGlobal<OwnProps>(
|
|||||||
isPrivate,
|
isPrivate,
|
||||||
hasFullInfo: Boolean(chat?.fullInfo),
|
hasFullInfo: Boolean(chat?.fullInfo),
|
||||||
canShowReactionsCount,
|
canShowReactionsCount,
|
||||||
canShowReactionList: !isAction && !isScheduled && chat?.id !== SERVICE_NOTIFICATIONS_USER_ID,
|
canShowReactionList: !isLocal && !isAction && !isScheduled && chat?.id !== SERVICE_NOTIFICATIONS_USER_ID,
|
||||||
canRemoveReaction,
|
canRemoveReaction,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|||||||
@ -565,6 +565,7 @@ const Message: FC<OwnProps & StateProps> = ({
|
|||||||
const meta = (
|
const meta = (
|
||||||
<MessageMeta
|
<MessageMeta
|
||||||
message={message}
|
message={message}
|
||||||
|
reactionMessage={reactionMessage}
|
||||||
outgoingStatus={outgoingStatus}
|
outgoingStatus={outgoingStatus}
|
||||||
signature={signature}
|
signature={signature}
|
||||||
withReactions={reactionsPosition === 'in-meta'}
|
withReactions={reactionsPosition === 'in-meta'}
|
||||||
@ -1054,8 +1055,8 @@ export default memo(withGlobal<OwnProps>(
|
|||||||
shouldLoopStickers: selectShouldLoopStickers(global),
|
shouldLoopStickers: selectShouldLoopStickers(global),
|
||||||
threadInfo: actualThreadInfo,
|
threadInfo: actualThreadInfo,
|
||||||
availableReactions: global.availableReactions,
|
availableReactions: global.availableReactions,
|
||||||
defaultReaction: selectDefaultReaction(global, chatId),
|
defaultReaction: isMessageLocal(message) ? undefined : selectDefaultReaction(global, chatId),
|
||||||
activeReaction: global.activeReactions[id],
|
activeReaction: reactionMessage && global.activeReactions[reactionMessage.id],
|
||||||
activeEmojiInteraction: global.activeEmojiInteraction,
|
activeEmojiInteraction: global.activeEmojiInteraction,
|
||||||
...(isOutgoing && { outgoingStatus: selectOutgoingStatus(global, message, messageListType === 'scheduled') }),
|
...(isOutgoing && { outgoingStatus: selectOutgoingStatus(global, message, messageListType === 'scheduled') }),
|
||||||
...(typeof uploadProgress === 'number' && { uploadProgress }),
|
...(typeof uploadProgress === 'number' && { uploadProgress }),
|
||||||
|
|||||||
@ -20,6 +20,7 @@ import './MessageMeta.scss';
|
|||||||
|
|
||||||
type OwnProps = {
|
type OwnProps = {
|
||||||
message: ApiMessage;
|
message: ApiMessage;
|
||||||
|
reactionMessage?: ApiMessage;
|
||||||
withReactions?: boolean;
|
withReactions?: boolean;
|
||||||
withReactionOffset?: boolean;
|
withReactionOffset?: boolean;
|
||||||
outgoingStatus?: ApiMessageOutgoingStatus;
|
outgoingStatus?: ApiMessageOutgoingStatus;
|
||||||
@ -32,11 +33,12 @@ type OwnProps = {
|
|||||||
const MessageMeta: FC<OwnProps> = ({
|
const MessageMeta: FC<OwnProps> = ({
|
||||||
message, outgoingStatus, signature, onClick, withReactions,
|
message, outgoingStatus, signature, onClick, withReactions,
|
||||||
activeReaction, withReactionOffset, availableReactions,
|
activeReaction, withReactionOffset, availableReactions,
|
||||||
|
reactionMessage,
|
||||||
}) => {
|
}) => {
|
||||||
const lang = useLang();
|
const lang = useLang();
|
||||||
const [isActivated, markActivated] = useFlag();
|
const [isActivated, markActivated] = useFlag();
|
||||||
|
|
||||||
const reactions = withReactions && message.reactions?.results.filter((l) => l.count > 0);
|
const reactions = withReactions && reactionMessage?.reactions?.results.filter((l) => l.count > 0);
|
||||||
|
|
||||||
const title = useMemo(() => {
|
const title = useMemo(() => {
|
||||||
if (!isActivated) return undefined;
|
if (!isActivated) return undefined;
|
||||||
|
|||||||
@ -7,11 +7,13 @@ import {
|
|||||||
selectChatMessage,
|
selectChatMessage,
|
||||||
selectDefaultReaction,
|
selectDefaultReaction,
|
||||||
selectLocalAnimatedEmojiEffectByName,
|
selectLocalAnimatedEmojiEffectByName,
|
||||||
|
selectMessageIdsByGroupId,
|
||||||
} from '../../selectors';
|
} from '../../selectors';
|
||||||
import { addMessageReaction, subtractXForEmojiInteraction } from '../../reducers/reactions';
|
import { addMessageReaction, subtractXForEmojiInteraction } from '../../reducers/reactions';
|
||||||
import { addUsers, updateChatMessage } from '../../reducers';
|
import { addUsers, updateChatMessage } from '../../reducers';
|
||||||
import { buildCollectionByKey, omit } from '../../../util/iteratees';
|
import { buildCollectionByKey, omit } from '../../../util/iteratees';
|
||||||
import { ANIMATION_LEVEL_MAX } from '../../../config';
|
import { ANIMATION_LEVEL_MAX } from '../../../config';
|
||||||
|
import { isMessageLocal } from '../../helpers';
|
||||||
|
|
||||||
addReducer('loadAvailableReactions', () => {
|
addReducer('loadAvailableReactions', () => {
|
||||||
(async () => {
|
(async () => {
|
||||||
@ -94,8 +96,9 @@ addReducer('sendDefaultReaction', (global, actions, payload) => {
|
|||||||
chatId, messageId, x, y,
|
chatId, messageId, x, y,
|
||||||
} = payload;
|
} = payload;
|
||||||
const reaction = selectDefaultReaction(global, chatId);
|
const reaction = selectDefaultReaction(global, chatId);
|
||||||
|
const message = selectChatMessage(global, chatId, messageId);
|
||||||
|
|
||||||
if (!reaction) return;
|
if (!reaction || !message || isMessageLocal(message)) return;
|
||||||
|
|
||||||
actions.sendReaction({
|
actions.sendReaction({
|
||||||
chatId,
|
chatId,
|
||||||
@ -108,18 +111,28 @@ addReducer('sendDefaultReaction', (global, actions, payload) => {
|
|||||||
|
|
||||||
addReducer('sendReaction', (global, actions, payload) => {
|
addReducer('sendReaction', (global, actions, payload) => {
|
||||||
const {
|
const {
|
||||||
chatId, messageId,
|
chatId,
|
||||||
}: { messageId: number; chatId: string } = payload;
|
}: { chatId: string } = payload;
|
||||||
|
let { messageId } = payload;
|
||||||
|
|
||||||
let { reaction } = payload;
|
let { reaction } = payload;
|
||||||
|
|
||||||
const chat = selectChat(global, chatId);
|
const chat = selectChat(global, chatId);
|
||||||
const message = selectChatMessage(global, chatId, messageId);
|
let message = selectChatMessage(global, chatId, messageId);
|
||||||
|
|
||||||
if (!chat || !message) {
|
if (!chat || !message) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const isInDocumentGroup = Boolean(message.groupedId) && !message.isInAlbum;
|
||||||
|
const documentGroupFirstMessageId = isInDocumentGroup
|
||||||
|
? selectMessageIdsByGroupId(global, chatId, message.groupedId!)![0]
|
||||||
|
: undefined;
|
||||||
|
message = isInDocumentGroup
|
||||||
|
? selectChatMessage(global, chatId, documentGroupFirstMessageId!) || message
|
||||||
|
: message;
|
||||||
|
messageId = message?.id || messageId;
|
||||||
|
|
||||||
if (message.reactions?.results?.some((l) => l.reaction === reaction && l.isChosen)) {
|
if (message.reactions?.results?.some((l) => l.reaction === reaction && l.isChosen)) {
|
||||||
reaction = undefined;
|
reaction = undefined;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user