diff --git a/src/api/gramjs/apiBuilders/messages.ts b/src/api/gramjs/apiBuilders/messages.ts index 84382c8e1..47ba60b78 100644 --- a/src/api/gramjs/apiBuilders/messages.ts +++ b/src/api/gramjs/apiBuilders/messages.ts @@ -437,7 +437,7 @@ export function buildLocalMessage( }), date: scheduledAt || Math.round(Date.now() / 1000) + getServerTimeOffset(), isOutgoing: !isChannel, - senderId: sendAs?.id || currentUserId, + senderId: chat.type !== 'chatTypePrivate' ? (sendAs?.id || currentUserId) : undefined, replyInfo: resultReplyInfo, ...(groupedId && { groupedId, @@ -529,7 +529,7 @@ export function buildLocalForwardedMessage({ content: updatedContent, date: scheduledAt || Math.round(Date.now() / 1000) + getServerTimeOffset(), isOutgoing: !asIncomingInChatWithSelf && toChat.type !== 'chatTypeChannel', - senderId: sendAs?.id || currentUserId, + senderId: toChat.type !== 'chatTypePrivate' ? (sendAs?.id || currentUserId) : undefined, sendingState: 'messageSendingStatePending', groupedId, isInAlbum, diff --git a/src/global/actions/apiUpdaters/chats.ts b/src/global/actions/apiUpdaters/chats.ts index 46e24b3fd..0554ffc81 100644 --- a/src/global/actions/apiUpdaters/chats.ts +++ b/src/global/actions/apiUpdaters/chats.ts @@ -171,7 +171,8 @@ addActionHandler('apiUpdate', (global, actions, update): ActionReturnType => { case 'newMessage': { const { message } = update; - if (message.senderId === global.currentUserId && !message.isFromScheduled) { + const isOur = message.senderId ? message.senderId === global.currentUserId : message.isOutgoing; + if (isOur && !message.isFromScheduled) { return undefined; } diff --git a/src/util/notifications.tsx b/src/util/notifications.tsx index 229fe4371..c92e5dae5 100644 --- a/src/util/notifications.tsx +++ b/src/util/notifications.tsx @@ -13,19 +13,18 @@ import { getMessageRecentReaction, getPrivateChatUserId, getUserFullName, - isChatChannel, } from '../global/helpers'; import { getIsChatMuted, getIsChatSilent, getShouldShowMessagePreview } from '../global/helpers/notifications'; import { getMessageSenderName } from '../global/helpers/peers'; import { - selectChat, selectCurrentMessageList, selectIsChatWithSelf, selectNotifyDefaults, selectNotifyException, + selectPeer, + selectSender, selectSettingsKeys, selectTopicFromMessage, - selectUser, } from '../global/selectors'; import { callApi } from '../api/gramjs'; import { IS_ELECTRON, IS_SERVICE_WORKER_SUPPORTED, IS_TOUCH_ENV } from './browser/windowEnvironment'; @@ -298,15 +297,13 @@ function checkIfShouldNotify(chat: ApiChat, message: Partial) { function getNotificationContent(chat: ApiChat, message: ApiMessage, reaction?: ApiPeerReaction) { const global = getGlobal(); - let { - senderId, - } = message; + let sender = selectSender(global, message); const hasReaction = Boolean(reaction); - if (hasReaction) senderId = reaction.peerId; + if (hasReaction) { + sender = selectPeer(global, reaction.peerId); + } const { isScreenLocked } = global.passcode; - const messageSenderChat = senderId ? selectChat(global, senderId) : undefined; - const messageSenderUser = senderId ? selectUser(global, senderId) : undefined; const privateChatUserId = getPrivateChatUserId(chat); const isSelf = privateChatUserId === global.currentUserId; @@ -315,10 +312,6 @@ function getNotificationContent(chat: ApiChat, message: ApiMessage, reaction?: A !isScreenLocked && getShouldShowMessagePreview(chat, selectNotifyDefaults(global), selectNotifyException(global, chat.id)) ) { - const isChat = chat && (isChatChannel(chat) || message.senderId === message.chatId); - - // TODO[forums] Support ApiChat - const sender = isChat ? messageSenderChat : messageSenderUser; const senderName = sender ? getMessageSenderName(oldTranslate, chat.id, sender) : undefined; let summary = jsxToHtml()[0].textContent || '';