From 36ca2a767ce946d0386647286128ea67f49e4dd6 Mon Sep 17 00:00:00 2001 From: warrickct Date: Fri, 11 Feb 2022 12:14:58 +1100 Subject: [PATCH] Adding PR changes --- _locales/en/messages.json | 2 +- stylesheets/_session.scss | 10 +----- .../conversation/SessionConversation.tsx | 27 ++++++++------- .../composition/CompositionBox.tsx | 33 +++++++++++-------- .../message-item/MessageRequestResponse.tsx | 24 +++++++------- ts/models/conversation.ts | 13 +------- ts/receiver/contentMessage.ts | 2 -- .../controlMessage/MessageRequestResponse.ts | 5 +-- ts/session/sending/MessageQueue.ts | 4 +-- ts/state/ducks/SessionTheme.tsx | 6 ++-- ts/state/selectors/conversations.ts | 1 - ts/types/LocalizerKeys.ts | 2 +- 12 files changed, 56 insertions(+), 73 deletions(-) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 75f08e706..02cb08761 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -466,10 +466,10 @@ "trimDatabase": "Trim Database", "trimDatabaseDescription": "Reduces your message database size to your last 10,000 messages.", "trimDatabaseConfirmationBody": "Are you sure you want to delete your $deleteAmount$ oldest received messages?", - "reportAsSpam": "REPORT AS SPAM", "messageRequestPending": "Your message request is currently pending", "messageRequestAccepted": "Your message request has been accepted", "messageRequestAcceptedOurs": "You have accepted $name$'s message request", + "messageRequestAcceptedOursNoName": "You have accepted the message request", "declineRequestMessage": "Are you sure you want to decline this message request?", "respondingToRequestWarning": "Sending a message to this user will automatically accept their message request and reveal your Session ID." } diff --git a/stylesheets/_session.scss b/stylesheets/_session.scss index e215a0b62..c1e1b3082 100644 --- a/stylesheets/_session.scss +++ b/stylesheets/_session.scss @@ -219,12 +219,6 @@ textarea { & > *:hover:not(svg) { filter: brightness(80%); } - - &.simple { - &.danger { - color: var(--color-destructive); - } - } } .session-label { @@ -232,9 +226,7 @@ textarea { padding: $session-margin-sm; width: 100%; border-radius: 2px; - text-align: centere - ; - + text-align: center; &.primary { background-color: $session-color-primary; } diff --git a/ts/components/conversation/SessionConversation.tsx b/ts/components/conversation/SessionConversation.tsx index 30e8c17f9..12456edc5 100644 --- a/ts/components/conversation/SessionConversation.tsx +++ b/ts/components/conversation/SessionConversation.tsx @@ -228,8 +228,7 @@ export class SessionConversation extends React.Component { return ; } - const conversation = getConversationController().get(selectedConversation.id); - const isApproved = conversation.isApproved(); + const isApproved = selectedConversation.isApproved; const selectionMode = selectedMessages.length > 0; const useMsgRequests = window.lokiFeatureFlags.useMessageRequests && @@ -243,9 +242,9 @@ export class SessionConversation extends React.Component { cancelText: window.i18n('cancel'), message: window.i18n('declineRequestMessage'), onClickOk: async () => { - declineConversation(selectedConversation.id, false); - blockConvoById(selectedConversation.id); - forceSyncConfigurationNowIfNeeded(); + await declineConversation(selectedConversation.id, false); + await blockConvoById(selectedConversation.id); + await forceSyncConfigurationNowIfNeeded(); }, onClickCancel: () => { window.inboxStore?.dispatch(updateConfirmModal(null)); @@ -282,7 +281,7 @@ export class SessionConversation extends React.Component {
{showMsgRequestUI && ( -
+ { text={window.i18n('decline')} onClick={handleDeclineConversationRequest} /> -
- {/* - Disabling for now until report as spam is added in - */} +
)} { return null; } + const makeMessagePlaceHolderText = () => { + if (isApproved && !didApproveMe && isPrivate) { + return i18n('messageRequestPending'); + } + if (isKickedFromGroup) { + return i18n('youGotKickedFromGroup'); + } + if (left) { + return i18n('youLeftTheGroup'); + } + if (isBlocked && isPrivate) { + return i18n('unblockToSend'); + } + if (isBlocked && !isPrivate) { + return i18n('unblockGroupToSend'); + } + return i18n('sendMessage'); + }; + const { isKickedFromGroup, left, @@ -432,19 +451,7 @@ class CompositionBoxInner extends React.Component { didApproveMe, isApproved, } = this.props.selectedConversation; - const messagePlaceHolder = - // isApproved && !didApproveMe && isPrivate - isApproved && !didApproveMe && isPrivate - ? i18n('messageRequestPending') - : isKickedFromGroup - ? i18n('youGotKickedFromGroup') - : left - ? i18n('youLeftTheGroup') - : isBlocked && isPrivate - ? i18n('unblockToSend') - : isBlocked && !isPrivate - ? i18n('unblockGroupToSend') - : i18n('sendMessage'); + const messagePlaceHolder = makeMessagePlaceHolderText(); const { typingEnabled } = this.props; return ( diff --git a/ts/components/conversation/message/message-item/MessageRequestResponse.tsx b/ts/components/conversation/message/message-item/MessageRequestResponse.tsx index db876a14d..bd97b18fe 100644 --- a/ts/components/conversation/message/message-item/MessageRequestResponse.tsx +++ b/ts/components/conversation/message/message-item/MessageRequestResponse.tsx @@ -1,25 +1,25 @@ import React from 'react'; +import { useConversationUsername } from '../../../../hooks/useParamSelector'; import { PropsForMessageRequestResponse } from '../../../../models/messageType'; -import { getConversationController } from '../../../../session/conversations'; import { UserUtils } from '../../../../session/utils'; import { Flex } from '../../../basic/Flex'; import { SpacerSM, Text } from '../../../basic/Text'; import { ReadableMessage } from './ReadableMessage'; export const MessageRequestResponse = (props: PropsForMessageRequestResponse) => { - const { messageId, isUnread, receivedAt, conversationId, source } = props; + const { messageId, isUnread, receivedAt, conversationId } = props; - let profileName = ''; - if (conversationId) { - profileName = - getConversationController() - .get(conversationId) - .getProfileName() + ''; - } - const msgText = - profileName && props.source === UserUtils.getOurPubKeyStrFromCache() + const profileName = useConversationUsername(conversationId); + const isFromSync = props.source === UserUtils.getOurPubKeyStrFromCache(); + + let msgText = ''; + if (isFromSync) { + msgText = profileName ? window.i18n('messageRequestAcceptedOurs', [profileName]) - : window.i18n('messageRequestAccepted'); + : window.i18n('messageRequestAcceptedOursNoName'); + } else { + msgText = window.i18n('messageRequestAccepted'); + } return ( { } public async sendMessageRequestResponse(isApproved: boolean) { - const publicKey = fromHexToArray(getOurPubKeyStrFromCache()); - // const msgRequestResponseParams: + const publicKey = getOurPubKeyStrFromCache(); const timestamp = Date.now(); const messageRequestResponseParams = { @@ -745,21 +744,11 @@ export class ConversationModel extends Backbone.Model { const messageRequestResponse = new MessageRequestResponse(messageRequestResponseParams); if (this.isPrivate()) { - // 1-1 conversations const pubkeyForSending = new PubKey(this.id); await getMessageQueue() .sendToPubKey(pubkeyForSending, messageRequestResponse) .catch(window?.log?.error); } - // TODO: may be removable as group invites are implied to be friends. - // else if (this.isClosedGroup()) { - // // group conversations - // await getMessageQueue() - // .sendToGroup(messageRequestResponse, undefined, new PubKey(this.id)) - // .catch(window?.log?.error); - // } - - console.warn('Sent message request response', isApproved); } public async sendMessage(msg: SendMessageType) { diff --git a/ts/receiver/contentMessage.ts b/ts/receiver/contentMessage.ts index f57338e98..49a8456b2 100644 --- a/ts/receiver/contentMessage.ts +++ b/ts/receiver/contentMessage.ts @@ -574,8 +574,6 @@ async function handleMessageRequestResponse( conversationToApprove.updateLastMessage(); } - // await forceSyncConfigurationNowIfNeeded(); - await removeFromCache(envelope); } diff --git a/ts/session/messages/outgoing/controlMessage/MessageRequestResponse.ts b/ts/session/messages/outgoing/controlMessage/MessageRequestResponse.ts index be8192a2b..c5b2b3f49 100644 --- a/ts/session/messages/outgoing/controlMessage/MessageRequestResponse.ts +++ b/ts/session/messages/outgoing/controlMessage/MessageRequestResponse.ts @@ -1,9 +1,10 @@ import { SignalService } from '../../../../protobuf'; +import { fromHexToArray } from '../../../utils/String'; import { ContentMessage } from '../ContentMessage'; import { MessageParams } from '../Message'; interface MessageRequestResponseParams extends MessageParams { - publicKey: Uint8Array; + publicKey: string; isApproved: boolean; } @@ -17,7 +18,7 @@ export class MessageRequestResponse extends ContentMessage { publicKey: params.publicKey, isApproved: params.isApproved, } as MessageRequestResponseParams); - this.publicKey = params.publicKey; + this.publicKey = fromHexToArray(params.publicKey); this.isApproved = params.isApproved; } diff --git a/ts/session/sending/MessageQueue.ts b/ts/session/sending/MessageQueue.ts index 174323a42..6b212e0c1 100644 --- a/ts/session/sending/MessageQueue.ts +++ b/ts/session/sending/MessageQueue.ts @@ -22,7 +22,6 @@ import { OpenGroupRequestCommonType } from '../apis/open_group_api/opengroupV2/A import { OpenGroupVisibleMessage } from '../messages/outgoing/visibleMessage/OpenGroupVisibleMessage'; import { UnsendMessage } from '../messages/outgoing/controlMessage/UnsendMessage'; import { CallMessage } from '../messages/outgoing/controlMessage/CallMessage'; -import { MessageRequestResponse } from '../messages/outgoing/controlMessage/MessageRequestResponse'; type ClosedGroupMessageType = | ClosedGroupVisibleMessage @@ -33,8 +32,7 @@ type ClosedGroupMessageType = | ExpirationTimerUpdateMessage | ClosedGroupEncryptionPairMessage | UnsendMessage - | ClosedGroupEncryptionPairRequestMessage - | MessageRequestResponse; + | ClosedGroupEncryptionPairRequestMessage; // ClosedGroupEncryptionPairReplyMessage must be sent to a user pubkey. Not a group. diff --git a/ts/state/ducks/SessionTheme.tsx b/ts/state/ducks/SessionTheme.tsx index 84b7f69a8..34b5da2c0 100644 --- a/ts/state/ducks/SessionTheme.tsx +++ b/ts/state/ducks/SessionTheme.tsx @@ -57,7 +57,7 @@ const darkButtonGreen = accentDarkTheme; const darkModalBackground = '#101011'; const grey67 = '#434343'; -const darkMessageRequestBannerBackground = '#2c2c2c'; +const darkMessageRequestBannerBackground = darkConversationItemHasUnread; const darkMessageRequestBannerIconBackground = grey67; const darkMessageRequestBannerUnreadBackground = grey67; const darkMessageRequestBannerIcon = '#adadad'; @@ -208,9 +208,9 @@ const lightBackgroundPrimary = '#272726'; const lightButtonGreen = '#272726'; const lightModalBackground = '#fcfcfc'; -const lightMessageRequestBannerBackground = '#f0f0f0'; +const lightMessageRequestBannerBackground = lightColorQuoteBottomBarBg; const lightMessageRequestBannerIconBackground = '#585858'; -const lightMessageRequestBannerUnreadBackground = '#dfdfdf'; +const lightMessageRequestBannerUnreadBackground = lightColorClickableHovered; const lightMessageRequestBannerIcon = white; export const switchHtmlToLightTheme = () => { diff --git a/ts/state/selectors/conversations.ts b/ts/state/selectors/conversations.ts index 7ea1f5037..5a40e99bf 100644 --- a/ts/state/selectors/conversations.ts +++ b/ts/state/selectors/conversations.ts @@ -437,7 +437,6 @@ const _getConversationRequests = ( const pushToMessageRequests = isMessageRequestEnabled && window?.lokiFeatureFlags?.useMessageRequests; return _.filter(sortedConversations, conversation => { - console.warn({ conversation }); return ( pushToMessageRequests && !conversation.isApproved && diff --git a/ts/types/LocalizerKeys.ts b/ts/types/LocalizerKeys.ts index 457c9fce7..aa034d2fa 100644 --- a/ts/types/LocalizerKeys.ts +++ b/ts/types/LocalizerKeys.ts @@ -465,10 +465,10 @@ export type LocalizerKeys = | 'trimDatabase' | 'trimDatabaseDescription' | 'trimDatabaseConfirmationBody' - | 'reportAsSpam' | 'respondingToRequestWarning' | 'messageRequestPending' | 'messageRequestAccepted' | 'messageRequestAcceptedOurs' + | 'messageRequestAcceptedOursNoName' | 'declineRequestMessage' | 'reportIssue';