Adding improvements to message request handling.

pull/2000/head
warrickct 3 years ago
parent 2e2941ba9b
commit 9c9a43ee97

@ -447,5 +447,6 @@
"blockAll": "Block All", "blockAll": "Block All",
"messageRequests": "Message Requests", "messageRequests": "Message Requests",
"requestsSubtitle": "Pending Requests", "requestsSubtitle": "Pending Requests",
"requestsPlaceholder": "No requests" "requestsPlaceholder": "No requests",
"messageRequestsDescription": "Enable Message Request Inbox"
} }

@ -34,6 +34,7 @@ const InnerLeftPaneMessageSection = () => {
<LeftPaneMessageSection <LeftPaneMessageSection
conversations={lists?.conversations || []} conversations={lists?.conversations || []}
contacts={lists?.contacts || []} contacts={lists?.contacts || []}
conversationRequests={lists?.conversationRequests}
searchResults={searchResults} searchResults={searchResults}
searchTerm={searchTerm} searchTerm={searchTerm}
/> />

@ -37,6 +37,7 @@ export interface Props {
contacts: Array<ReduxConversationType>; contacts: Array<ReduxConversationType>;
conversations?: Array<ConversationListItemProps>; conversations?: Array<ConversationListItemProps>;
conversationRequests?: Array<ConversationListItemProps>;
searchResults?: SearchResultsProps; searchResults?: SearchResultsProps;
} }
@ -281,13 +282,19 @@ export class LeftPaneMessageSection extends React.Component<Props, State> {
this.handleToggleOverlay(undefined); this.handleToggleOverlay(undefined);
}} }}
onButtonClick={async () => { onButtonClick={async () => {
window?.log?.info('Blocking all conversations');
// TODO: msgrequest iterate all convos and block // TODO: msgrequest iterate all convos and block
// iterate all conversations and set all to approve then // iterate all conversations and set all to approve then
const allConversations = getConversationController().getConversations(); const { conversationRequests } = this.props;
let syncRequired = false; let syncRequired = false;
_.forEach(allConversations, convo => { if (!conversationRequests) {
if (convo.isApproved() !== true) { window?.log?.info('No conversation requests to block.');
return;
}
_.forEach(conversationRequests, convo => {
if (convo.isApproved !== true) {
BlockedNumberController.block(convo.id); BlockedNumberController.block(convo.id);
syncRequired = true; syncRequired = true;
} }

@ -17,11 +17,7 @@ import {
import { shell } from 'electron'; import { shell } from 'electron';
import { mapDispatchToProps } from '../../../state/actions'; import { mapDispatchToProps } from '../../../state/actions';
import { unblockConvoById } from '../../../interactions/conversationInteractions'; import { unblockConvoById } from '../../../interactions/conversationInteractions';
import { import { toggleAudioAutoplay, toggleMessageRequests } from '../../../state/ducks/userConfig';
disableMessageRequests,
enableMessageRequests,
toggleAudioAutoplay,
} from '../../../state/ducks/userConfig';
import { sessionPassword, updateConfirmModal } from '../../../state/ducks/modalDialog'; import { sessionPassword, updateConfirmModal } from '../../../state/ducks/modalDialog';
import { PasswordAction } from '../../dialog/SessionPasswordDialog'; import { PasswordAction } from '../../dialog/SessionPasswordDialog';
import { SessionIconButton } from '../icon'; import { SessionIconButton } from '../icon';
@ -412,22 +408,16 @@ class SettingsViewInner extends React.Component<SettingsViewProps, State> {
}, },
{ {
id: 'message-request-setting', id: 'message-request-setting',
title: 'Message Requests', // TODO: translation title: window.i18n('messageRequests'),
description: 'Enable Message Request Inbox', description: window.i18n('messageRequestsDescription'),
hidden: false, hidden: false,
type: SessionSettingType.Toggle, type: SessionSettingType.Toggle,
category: SessionSettingCategory.Appearance, category: SessionSettingCategory.Appearance,
setFn: () => { setFn: () => {
window.inboxStore?.dispatch(toggleAudioAutoplay()); window.inboxStore?.dispatch(toggleMessageRequests());
if (window.inboxStore?.getState().userConfig.messageRequests) {
window.inboxStore?.dispatch(disableMessageRequests());
} else {
window.inboxStore?.dispatch(enableMessageRequests());
}
}, },
content: { content: {
defaultValue: window.inboxStore?.getState().userConfig.audioAutoplay, defaultValue: window.inboxStore?.getState().userConfig.messageRequests,
}, },
comparisonValue: undefined, comparisonValue: undefined,
onClick: undefined, onClick: undefined,

@ -125,7 +125,7 @@ const handleContactReceived = async (
// updateProfile will do a commit for us // updateProfile will do a commit for us
contactConvo.set('active_at', _.toNumber(envelope.timestamp)); contactConvo.set('active_at', _.toNumber(envelope.timestamp));
if (window.lokiFeatureFlags.useMessageRequests === true) { if (window.lokiFeatureFlags.useMessageRequests === true && window.inboxStore?.getState().userConfig.messageRequests) {
contactConvo.setIsApproved(Boolean(contactReceived.isApproved)); contactConvo.setIsApproved(Boolean(contactReceived.isApproved));
if (contactReceived.isBlocked === true) { if (contactReceived.isBlocked === true) {

@ -26,20 +26,12 @@ const userConfigSlice = createSlice({
disableRecoveryPhrasePrompt: state => { disableRecoveryPhrasePrompt: state => {
state.showRecoveryPhrasePrompt = false; state.showRecoveryPhrasePrompt = false;
}, },
disableMessageRequests: state => { toggleMessageRequests: state => {
state.messageRequests = false; state.messageRequests = !state.messageRequests;
},
enableMessageRequests: state => {
state.messageRequests = false;
}, },
}, },
}); });
const { actions, reducer } = userConfigSlice; const { actions, reducer } = userConfigSlice;
export const { export const { toggleAudioAutoplay, disableRecoveryPhrasePrompt, toggleMessageRequests } = actions;
toggleAudioAutoplay,
disableRecoveryPhrasePrompt,
disableMessageRequests,
enableMessageRequests,
} = actions;
export const userConfigReducer = reducer; export const userConfigReducer = reducer;

@ -304,60 +304,34 @@ export const _getLeftPaneLists = (
}; };
} }
// TODO: if message requests toggle on and msg requesnt enable
const messageRequestsEnabled = const messageRequestsEnabled =
window.inboxStore?.getState().userConfig.messageRequests === true && window.inboxStore?.getState().userConfig.messageRequests === true &&
window?.lokiFeatureFlags?.useMessageRequests === true; window.lokiFeatureFlags?.useMessageRequests === true;
// if (!Boolean(conversation.isApproved) === true && window.lokiFeatureFlags.useMessageRequests) {
// continue;
// }
// Add Open Group to list as soon as the name has been set // Add Open Group to list as soon as the name has been set
// if (conversation.isPublic && (!conversation.name || conversation.name === 'Unknown group')) { if (conversation.isPublic && (!conversation.name || conversation.name === 'Unknown group')) {
// continue; continue;
// }
// if (!conversation.isApproved && !conversation.isBlocked) {
// conversationRequests.push(conversation);
// }
if (shouldShowInRequestList(conversation, messageRequestsEnabled)) {
conversationRequests.push(conversation);
} }
// Remove all invalid conversations and conversatons of devices associated // Remove all invalid conversations and conversatons of devices associated
// with cancelled attempted links // with cancelled attempted links
// if (!conversation.isPublic && !conversation.activeAt) { if (!conversation.isPublic && !conversation.activeAt) {
// continue; continue;
// } }
// if (conversation.activeAt !== undefined && conversation.type === ConversationTypeEnum.PRIVATE) {
// directConversations.push(conversation);
// }
if (shouldShowInContacts(conversation)) { if (conversation.activeAt !== undefined && conversation.type === ConversationTypeEnum.PRIVATE) {
directConversations.push(conversation); directConversations.push(conversation);
} }
if (shouldShowInConversationList(conversation, messageRequestsEnabled)) { if (messageRequestsEnabled) {
conversations.push(conversation); if (!conversation.isApproved && !conversation.isBlocked) {
unreadCount = calculateNewUnreadTotal(unreadCount, conversation); // dont increase unread counter, don't push to convo list.
conversationRequests.push(conversation);
continue;
} }
// if (conversation.isApproved) {
// conversations.push(conversation);
// }
} }
return {
conversations,
contacts: directConversations,
conversationRequests,
unreadCount,
};
};
const calculateNewUnreadTotal = (unreadCount: number, conversation: ReduxConversationType) => {
if ( if (
unreadCount < 9 && unreadCount < 9 &&
conversation.unreadCount && conversation.unreadCount &&
@ -366,73 +340,16 @@ const calculateNewUnreadTotal = (unreadCount: number, conversation: ReduxConvers
) { ) {
unreadCount += conversation.unreadCount; unreadCount += conversation.unreadCount;
} }
return unreadCount;
};
const shouldShowInRequestList = ( conversations.push(conversation);
conversation: ReduxConversationType,
messageRequestsEnabled: boolean
) => {
if (conversation.isPublic || conversation.isBlocked || Boolean(conversation.activeAt) === false) {
return false;
}
if (messageRequestsEnabled) {
if (Boolean(conversation.isApproved || !conversation.isBlocked)) {
return false;
}
}
return true;
};
const shouldShowInContacts = (conversation: ReduxConversationType) => {
// Add Open Group to list as soon as the name has been set
if (conversation.isPublic && (!conversation.name || conversation.name === 'Unknown group')) {
return false;
}
// if (shouldShowInRequestList(conversation)) {
// conversationRequests.push(conversation);
// }
// Remove all invalid conversations and conversatons of devices associated
// with cancelled attempted links
if (!conversation.isPublic && !conversation.activeAt) {
return false;
}
if (conversation.activeAt !== undefined && conversation.type === ConversationTypeEnum.PRIVATE) {
// directConversations.push(conversation);
return true;
} else {
return false;
}
};
const shouldShowInConversationList = (
conversation: ReduxConversationType,
messageRequestsEnabled: boolean
) => {
// // Add Open Group to list as soon as the name has been set
if (conversation.isPublic && (!conversation.name || conversation.name === 'Unknown group')) {
return false;
}
// Remove all invalid conversations and conversatons of devices associated
// with cancelled attempted links
if (!conversation.isPublic && !conversation.activeAt) {
return false;
}
// if (!conversation.activeAt) {
// return false;
// }
if (messageRequestsEnabled && !conversation.isApproved) {
return false;
} }
return true; return {
conversations,
contacts: directConversations,
conversationRequests,
unreadCount,
};
}; };
export const getLeftPaneLists = createSelector( export const getLeftPaneLists = createSelector(

Loading…
Cancel
Save