adding pr changes

pull/2222/head
warrickct 3 years ago
parent 0db3c76756
commit efa482b002

@ -1347,41 +1347,6 @@ function updateToLokiSchemaVersion20(currentVersion, db) {
return; return;
} }
console.log(`updateToLokiSchemaVersion${targetVersion}: starting...`); 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(() => { db.transaction(() => {
// looking for all private conversations, with a nickname set // looking for all private conversations, with a nickname set
@ -1408,9 +1373,44 @@ function updateToLokiSchemaVersion21(currentVersion, db) {
} }
writeLokiSchemaVersion(targetVersion, 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) { function writeLokiSchemaVersion(newVersion, db) {
@ -2311,16 +2311,15 @@ function getUnreadCountByConversation(conversationId) {
return row['count(*)']; return row['count(*)'];
} }
function getIncomingMessagesCountByConversation(conversationId, type = '%') { function getIncomingMessagesCountByConversation(conversationId) {
const row = globalInstance const row = globalInstance
.prepare( .prepare(
`SELECT count(*) from ${MESSAGES_TABLE} `SELECT count(*) from ${MESSAGES_TABLE}
WHERE conversationId = $conversationId WHERE conversationId = $conversationId
AND type = $type;` AND type = "incoming";`
) )
.get({ .get({
conversationId, conversationId,
type,
}); });
if (!row) { if (!row) {
@ -3121,13 +3120,13 @@ function getMessagesCountByConversation(instance, conversationId) {
return row ? row['count(*)'] : 0; return row ? row['count(*)'] : 0;
} }
function getAllClosedGroupConversations(instance, order = true) { function getAllClosedGroupConversations(instance) {
const rows = (globalInstance || instance) const rows = (globalInstance || instance)
.prepare( .prepare(
`SELECT json FROM ${CONVERSATIONS_TABLE} WHERE `SELECT json FROM ${CONVERSATIONS_TABLE} WHERE
type = 'group' AND type = 'group' AND
id NOT LIKE 'publicChat:%' id NOT LIKE 'publicChat:%'
${order ? 'ORDER BY id ASC' : ''};` ORDER BY id ASC;`
) )
.all(); .all();

@ -1,4 +1,5 @@
import React from 'react'; import React from 'react';
import { useDispatch, useSelector } from 'react-redux';
import styled from 'styled-components'; import styled from 'styled-components';
import { import {
acceptConversation, acceptConversation,
@ -8,14 +9,19 @@ import {
import { forceSyncConfigurationNowIfNeeded } from '../../session/utils/syncUtils'; import { forceSyncConfigurationNowIfNeeded } from '../../session/utils/syncUtils';
import { ReduxConversationType } from '../../state/ducks/conversations'; import { ReduxConversationType } from '../../state/ducks/conversations';
import { updateConfirmModal } from '../../state/ducks/modalDialog'; import { updateConfirmModal } from '../../state/ducks/modalDialog';
import { getSelectedConversation } from '../../state/selectors/conversations';
import { SessionButton, SessionButtonColor, SessionButtonType } from '../basic/SessionButton'; import { SessionButton, SessionButtonColor, SessionButtonType } from '../basic/SessionButton';
export const ConversationMessageRequestButtons = (props: { export const ConversationMessageRequestButtons = () => {
selectedConversation: ReduxConversationType; const selectedConversation = useSelector(getSelectedConversation);
}) => {
const { selectedConversation } = props; if (!selectedConversation) {
const { isApproved, type } = selectedConversation; return null;
const showMsgRequestUI = !isApproved && type === 'private'; }
const showMsgRequestUI =
!selectedConversation.isApproved && selectedConversation.type === 'private';
const dispatch = useDispatch();
const handleDeclineConversationRequest = () => { const handleDeclineConversationRequest = () => {
window.inboxStore?.dispatch( window.inboxStore?.dispatch(
@ -29,10 +35,10 @@ export const ConversationMessageRequestButtons = (props: {
await forceSyncConfigurationNowIfNeeded(); await forceSyncConfigurationNowIfNeeded();
}, },
onClickCancel: () => { onClickCancel: () => {
window.inboxStore?.dispatch(updateConfirmModal(null)); dispatch(updateConfirmModal(null));
}, },
onClickClose: () => { onClickClose: () => {
window.inboxStore?.dispatch(updateConfirmModal(null)); dispatch(updateConfirmModal(null));
}, },
}) })
); );

@ -1,11 +1,12 @@
import React from 'react'; import React from 'react';
import { useSelector } from 'react-redux';
import styled from 'styled-components'; import styled from 'styled-components';
import { ReduxConversationType } from '../../state/ducks/conversations'; import { getSelectedConversation } from '../../state/selectors/conversations';
export const ConversationRequestinfo = (props: { selectedConversation: ReduxConversationType }) => { export const ConversationRequestinfo = () => {
const { selectedConversation } = props; const selectedConversation = useSelector(getSelectedConversation);
const { isApproved, type } = selectedConversation; const showMsgRequestUI =
const showMsgRequestUI = !isApproved && type === 'private'; !selectedConversation?.isApproved && selectedConversation?.type === 'private';
if (!showMsgRequestUI) { if (!showMsgRequestUI) {
return null; return null;

@ -241,7 +241,7 @@ export class SessionConversation extends React.Component<Props, State> {
{lightBoxOptions?.media && this.renderLightBox(lightBoxOptions)} {lightBoxOptions?.media && this.renderLightBox(lightBoxOptions)}
<div className="conversation-messages"> <div className="conversation-messages">
<ConversationMessageRequestButtons selectedConversation={selectedConversation} /> <ConversationMessageRequestButtons />
<SplitViewContainer <SplitViewContainer
top={<InConversationCallContainer />} top={<InConversationCallContainer />}
bottom={ bottom={
@ -256,7 +256,7 @@ export class SessionConversation extends React.Component<Props, State> {
{isDraggingFile && <SessionFileDropzone />} {isDraggingFile && <SessionFileDropzone />}
</div> </div>
<ConversationRequestinfo selectedConversation={selectedConversation} /> <ConversationRequestinfo />
<CompositionBox <CompositionBox
sendMessage={this.sendMessageFn} sendMessage={this.sendMessageFn}
stagedAttachments={this.props.stagedAttachments} stagedAttachments={this.props.stagedAttachments}

@ -626,11 +626,11 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
}; };
const shouldApprove = !this.isApproved() && this.isPrivate(); const shouldApprove = !this.isApproved() && this.isPrivate();
const incomingMessages = await getIncomingMessagesCountByConversation( const incomingMessageCount = await getIncomingMessagesCountByConversation(
this.id, this.id,
MessageDirection.incoming MessageDirection.incoming
); );
const hasIncomingMessages = incomingMessages > 0; const hasIncomingMessages = incomingMessageCount > 0;
if (shouldApprove) { if (shouldApprove) {
await this.setIsApproved(true); await this.setIsApproved(true);
if (!this.didApproveMe() && hasIncomingMessages) { if (!this.didApproveMe() && hasIncomingMessages) {
@ -1542,13 +1542,6 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
) { ) {
return false; 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')); return Boolean(this.get('isApproved'));
} }

@ -461,7 +461,6 @@ export async function innerHandleSwarmContentMessage(
await handleCallMessage(envelope, content.callMessage as SignalService.CallMessage); await handleCallMessage(envelope, content.callMessage as SignalService.CallMessage);
} }
if (content.messageRequestResponse) { if (content.messageRequestResponse) {
console.warn('received message request response');
await handleMessageRequestResponse( await handleMessageRequestResponse(
envelope, envelope,
content.messageRequestResponse as SignalService.MessageRequestResponse content.messageRequestResponse as SignalService.MessageRequestResponse

Loading…
Cancel
Save