From efa482b002a93093b49f3459aecec68ba9343c7e Mon Sep 17 00:00:00 2001 From: warrickct Date: Tue, 15 Feb 2022 14:42:39 +1100 Subject: [PATCH] adding pr changes --- app/sql.js | 83 +++++++++---------- .../ConversationRequestButtons.tsx | 22 +++-- .../conversation/ConversationRequestInfo.tsx | 11 +-- .../conversation/SessionConversation.tsx | 4 +- ts/models/conversation.ts | 11 +-- ts/receiver/contentMessage.ts | 1 - 6 files changed, 65 insertions(+), 67 deletions(-) diff --git a/app/sql.js b/app/sql.js index 80988770d..8df33bc3e 100644 --- a/app/sql.js +++ b/app/sql.js @@ -1347,41 +1347,6 @@ function updateToLokiSchemaVersion20(currentVersion, db) { return; } console.log(`updateToLokiSchemaVersion${targetVersion}: starting...`); - db.transaction(() => { - db.exec(` - UPDATE ${CONVERSATIONS_TABLE} SET - json = json_set(json, '$.didApproveMe', 1, '$.isApproved', 1) - WHERE type = 'private'; - `); - - // all closed group admins - const closedGroupRows = getAllClosedGroupConversations(db, false) || []; - - const adminIds = closedGroupRows.map(json => jsonToObject(json).groupAdmins); - forEach(adminIds, id => { - db.exec( - ` - UPDATE ${CONVERSATIONS_TABLE} SET - json = json_set(json, '$.didApproveMe', 1, '$.isApproved', 1) - WHERE type = id - values ($id); - ` - ).run({ - id, - }); - }); - - writeLokiSchemaVersion(targetVersion, db); - })(); - console.log(`updateToLokiSchemaVersion${targetVersion}: success!`); -} - -function updateToLokiSchemaVersion21(currentVersion, db) { - const targetVersion = 21; - if (currentVersion >= targetVersion) { - return; - } - console.log(`updateToLokiSchemaVersion${targetVersion}: starting...`); db.transaction(() => { // looking for all private conversations, with a nickname set @@ -1408,9 +1373,44 @@ function updateToLokiSchemaVersion21(currentVersion, db) { } writeLokiSchemaVersion(targetVersion, db); })(); - - console.log(`updateToLokiSchemaVersion${targetVersion}: success!`); }); + console.log(`updateToLokiSchemaVersion${targetVersion}: success!`); +} + +function updateToLokiSchemaVersion21(currentVersion, db) { + const targetVersion = 21; + if (currentVersion >= targetVersion) { + return; + } + console.log(`updateToLokiSchemaVersion${targetVersion}: starting...`); + + db.transaction(() => { + db.exec(` + UPDATE ${CONVERSATIONS_TABLE} SET + json = json_set(json, '$.didApproveMe', 1, '$.isApproved', 1) + WHERE type = 'private'; + `); + + // all closed group admins + const closedGroupRows = getAllClosedGroupConversations(db) || []; + + const adminIds = closedGroupRows.map(json => jsonToObject(json).groupAdmins); + forEach(adminIds, id => { + db.exec( + ` + UPDATE ${CONVERSATIONS_TABLE} SET + json = json_set(json, '$.didApproveMe', 1, '$.isApproved', 1) + WHERE type = id + values ($id); + ` + ).run({ + id, + }); + }); + + writeLokiSchemaVersion(targetVersion, db); + })(); + console.log(`updateToLokiSchemaVersion${targetVersion}: success!`); } function writeLokiSchemaVersion(newVersion, db) { @@ -2311,16 +2311,15 @@ function getUnreadCountByConversation(conversationId) { return row['count(*)']; } -function getIncomingMessagesCountByConversation(conversationId, type = '%') { +function getIncomingMessagesCountByConversation(conversationId) { const row = globalInstance .prepare( `SELECT count(*) from ${MESSAGES_TABLE} WHERE conversationId = $conversationId - AND type = $type;` + AND type = "incoming";` ) .get({ conversationId, - type, }); if (!row) { @@ -3121,13 +3120,13 @@ function getMessagesCountByConversation(instance, conversationId) { return row ? row['count(*)'] : 0; } -function getAllClosedGroupConversations(instance, order = true) { +function getAllClosedGroupConversations(instance) { const rows = (globalInstance || instance) .prepare( `SELECT json FROM ${CONVERSATIONS_TABLE} WHERE type = 'group' AND id NOT LIKE 'publicChat:%' - ${order ? 'ORDER BY id ASC' : ''};` + ORDER BY id ASC;` ) .all(); diff --git a/ts/components/conversation/ConversationRequestButtons.tsx b/ts/components/conversation/ConversationRequestButtons.tsx index 334687aeb..d0115f0d0 100644 --- a/ts/components/conversation/ConversationRequestButtons.tsx +++ b/ts/components/conversation/ConversationRequestButtons.tsx @@ -1,4 +1,5 @@ import React from 'react'; +import { useDispatch, useSelector } from 'react-redux'; import styled from 'styled-components'; import { acceptConversation, @@ -8,14 +9,19 @@ import { import { forceSyncConfigurationNowIfNeeded } from '../../session/utils/syncUtils'; import { ReduxConversationType } from '../../state/ducks/conversations'; import { updateConfirmModal } from '../../state/ducks/modalDialog'; +import { getSelectedConversation } from '../../state/selectors/conversations'; import { SessionButton, SessionButtonColor, SessionButtonType } from '../basic/SessionButton'; -export const ConversationMessageRequestButtons = (props: { - selectedConversation: ReduxConversationType; -}) => { - const { selectedConversation } = props; - const { isApproved, type } = selectedConversation; - const showMsgRequestUI = !isApproved && type === 'private'; +export const ConversationMessageRequestButtons = () => { + const selectedConversation = useSelector(getSelectedConversation); + + if (!selectedConversation) { + return null; + } + + const showMsgRequestUI = + !selectedConversation.isApproved && selectedConversation.type === 'private'; + const dispatch = useDispatch(); const handleDeclineConversationRequest = () => { window.inboxStore?.dispatch( @@ -29,10 +35,10 @@ export const ConversationMessageRequestButtons = (props: { await forceSyncConfigurationNowIfNeeded(); }, onClickCancel: () => { - window.inboxStore?.dispatch(updateConfirmModal(null)); + dispatch(updateConfirmModal(null)); }, onClickClose: () => { - window.inboxStore?.dispatch(updateConfirmModal(null)); + dispatch(updateConfirmModal(null)); }, }) ); diff --git a/ts/components/conversation/ConversationRequestInfo.tsx b/ts/components/conversation/ConversationRequestInfo.tsx index 7d00439a6..d180a13ff 100644 --- a/ts/components/conversation/ConversationRequestInfo.tsx +++ b/ts/components/conversation/ConversationRequestInfo.tsx @@ -1,11 +1,12 @@ import React from 'react'; +import { useSelector } from 'react-redux'; import styled from 'styled-components'; -import { ReduxConversationType } from '../../state/ducks/conversations'; +import { getSelectedConversation } from '../../state/selectors/conversations'; -export const ConversationRequestinfo = (props: { selectedConversation: ReduxConversationType }) => { - const { selectedConversation } = props; - const { isApproved, type } = selectedConversation; - const showMsgRequestUI = !isApproved && type === 'private'; +export const ConversationRequestinfo = () => { + const selectedConversation = useSelector(getSelectedConversation); + const showMsgRequestUI = + !selectedConversation?.isApproved && selectedConversation?.type === 'private'; if (!showMsgRequestUI) { return null; diff --git a/ts/components/conversation/SessionConversation.tsx b/ts/components/conversation/SessionConversation.tsx index 067204aaa..cc02b2862 100644 --- a/ts/components/conversation/SessionConversation.tsx +++ b/ts/components/conversation/SessionConversation.tsx @@ -241,7 +241,7 @@ export class SessionConversation extends React.Component { {lightBoxOptions?.media && this.renderLightBox(lightBoxOptions)}
- + } bottom={ @@ -256,7 +256,7 @@ export class SessionConversation extends React.Component { {isDraggingFile && }
- + { }; const shouldApprove = !this.isApproved() && this.isPrivate(); - const incomingMessages = await getIncomingMessagesCountByConversation( + const incomingMessageCount = await getIncomingMessagesCountByConversation( this.id, MessageDirection.incoming ); - const hasIncomingMessages = incomingMessages > 0; + const hasIncomingMessages = incomingMessageCount > 0; if (shouldApprove) { await this.setIsApproved(true); if (!this.didApproveMe() && hasIncomingMessages) { @@ -1542,13 +1542,6 @@ export class ConversationModel extends Backbone.Model { ) { return false; } - const msgRequestsEnabled = window.inboxStore?.getState().userConfig.messageRequests; - - // if msg requests are unused, we have to send typing (this is already a private active unblocked convo) - if (!msgRequestsEnabled) { - return true; - } - // with message requests in use, we just need to check for isApproved return Boolean(this.get('isApproved')); } diff --git a/ts/receiver/contentMessage.ts b/ts/receiver/contentMessage.ts index 7961b9ab2..3914e0ed2 100644 --- a/ts/receiver/contentMessage.ts +++ b/ts/receiver/contentMessage.ts @@ -461,7 +461,6 @@ export async function innerHandleSwarmContentMessage( await handleCallMessage(envelope, content.callMessage as SignalService.CallMessage); } if (content.messageRequestResponse) { - console.warn('received message request response'); await handleMessageRequestResponse( envelope, content.messageRequestResponse as SignalService.MessageRequestResponse