Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow the user to control whether messages from blocked users are filtered from open groups. #2395

Open
wants to merge 4 commits into
base: clearnet
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions _locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@
"noteToSelf": "Note to Self",
"hideMenuBarTitle": "Hide Menu Bar",
"hideMenuBarDescription": "Toggle system menu bar visibility",
"filterBlockedFromOpenGroupsTitle": "Filter Open Groups",
"filterBlockedFromOpenGroupsDescription": "Filter messages from blocked users from open groups",
"startConversation": "Start New Conversation",
"invalidNumberError": "Invalid Session ID or ONS Name",
"failedResolveOns": "Failed to resolve ONS name",
Expand Down
13 changes: 9 additions & 4 deletions ts/components/search/SearchResults.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
MemoConversationListItemWithDetails,
} from '../leftpane/conversation-list-item/ConversationListItem';
import { MessageResultProps, MessageSearchResult } from './MessageSearchResults';
import { BlockedNumberController } from '../../util';

export type SearchResultsProps = {
contactsAndGroups: Array<ConversationListItemProps>;
Expand Down Expand Up @@ -42,7 +43,11 @@ export const SearchResults = (props: SearchResultsProps) => {
const { contactsAndGroups, messages, searchTerm } = props;

const haveContactsAndGroup = Boolean(contactsAndGroups?.length);
const haveMessages = Boolean(messages?.length);
const filteredMessages = messages.filter(message =>
!window.getSettingValue('filter-open-groups') ||
!BlockedNumberController.isBlocked(message.source)
)
const haveMessages = Boolean(filteredMessages?.length);
const noResults = !haveContactsAndGroup && !haveMessages;

return (
Expand All @@ -55,7 +60,7 @@ export const SearchResults = (props: SearchResultsProps) => {
<MemoConversationListItemWithDetails
{...contactOrGroup}
mentionedUs={false}
isBlocked={false}
isBlocked={BlockedNumberController.isBlocked(contactOrGroup.id)}
key={`search-result-convo-${contactOrGroup.id}`}
/>
))}
Expand All @@ -65,9 +70,9 @@ export const SearchResults = (props: SearchResultsProps) => {
{haveMessages && (
<>
<StyledSeparatorSection>
{`${window.i18n('messagesHeader')}: ${messages.length}`}
{`${window.i18n('messagesHeader')}: ${filteredMessages.length}`}
</StyledSeparatorSection>
{messages.map(message => (
{filteredMessages.map(message => (
<MessageSearchResult key={`search-result-message-${message.id}`} {...message} />
))}
</>
Expand Down
14 changes: 14 additions & 0 deletions ts/components/settings/section/CategoryAppearance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ export const SettingsCategoryAppearance = (props: { hasPassword: boolean | null
? true
: window.getSettingValue(SettingsKey.settingsMenuBar);

const isFilterOpenGroupsActive =
window.getSettingValue(SettingsKey.settingsFilterOpenGroups) === undefined
? true
: window.getSettingValue(SettingsKey.settingsFilterOpenGroups);

const isSpellCheckActive =
window.getSettingValue(SettingsKey.settingsSpellCheck) === undefined
? true
Expand All @@ -79,6 +84,15 @@ export const SettingsCategoryAppearance = (props: { hasPassword: boolean | null
/>
)}
<SessionToggleWithDescription
onClickToggle={() => {
window.toggleFilterOpenGroups();
forceUpdate();
}}
title={window.i18n('filterBlockedFromOpenGroupsTitle')}
description={window.i18n('filterBlockedFromOpenGroupsDescription')}
active={isFilterOpenGroupsActive}
/>
<SessionToggleWithDescription
onClickToggle={() => {
window.toggleSpellCheck();
forceUpdate();
Expand Down
3 changes: 3 additions & 0 deletions ts/data/settings-key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const settingsLinkPreview = 'link-preview-setting';
const settingsStartInTray = 'start-in-tray-setting';
const settingsOpengroupPruning = 'prune-setting';

const settingsFilterOpenGroups = 'filter-open-groups';

export const SettingsKey = {
settingsReadReceipt,
settingsTypingIndicator,
Expand All @@ -17,4 +19,5 @@ export const SettingsKey = {
settingsLinkPreview,
settingsStartInTray,
settingsOpengroupPruning,
settingsFilterOpenGroups
};
11 changes: 11 additions & 0 deletions ts/mains/main_renderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ Storage.onready(async () => {
window.setMenuBarVisibility(!value);
},

getFilterOpenGroups: () => Storage.get('filter-open-groups', true),
setFilterOpenGroups: async (value: boolean) => {
await Storage.put('filter-open-groups', value);
},

getSpellCheck: () => Storage.get('spell-check', true),
setSpellCheck: async (value: boolean) => {
await Storage.put('spell-check', value);
Expand Down Expand Up @@ -291,6 +296,12 @@ async function start() {
window.Events.setHideMenuBar(!current);
};

window.toggleFilterOpenGroups = () => {
const currentValue = window.getSettingValue('filter-open-groups');
const newValue = currentValue !== undefined ? !currentValue : false;
window.Events.setFilterOpenGroups(newValue);
};

window.toggleSpellCheck = () => {
const currentValue = window.getSettingValue('spell-check');
// if undefined, it means 'default' so true. but we have to toggle it, so false
Expand Down
7 changes: 1 addition & 6 deletions ts/session/apis/open_group_api/opengroupV2/ApiUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
updateDefaultRooms,
updateDefaultRoomsInProgress,
} from '../../../../state/ducks/defaultRooms';
import { BlockedNumberController } from '../../../../util';
import { getCompleteUrlFromRoom } from '../utils/OpenGroupUtils';
import { parseOpenGroupV2 } from './JoinOpenGroupV2';
import { getAllRoomInfos } from './OpenGroupAPIV2';
Expand Down Expand Up @@ -96,11 +95,7 @@ export const parseMessages = async (
.filter(m => signatureValidEncodedData.includes(m.opengroupv2Message.base64EncodedData))
.map(m => m.opengroupv2Message);

return _.compact(
parsedMessages.map(m =>
m && m.sender && !BlockedNumberController.isBlocked(m.sender) ? m : null
)
).sort((a, b) => (a.serverId || 0) - (b.serverId || 0));
return _.compact(parsedMessages).sort((a, b) => (a.serverId || 0) - (b.serverId || 0));
};

// tslint:disable: no-http-string
Expand Down
6 changes: 5 additions & 1 deletion ts/state/selectors/conversations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,11 @@ export const getSortedMessagesOfSelectedConversation = createSelector(
}

const isPublic = convo.isPublic() || false;
const sortedMessage = sortMessages(messages, isPublic);
const sortedMessage = sortMessages(messages.filter(msg =>
!window.getSettingValue('filter-open-groups') ||
!BlockedNumberController.isBlocked(msg.propsForMessage.sender)
), isPublic
)

return updateFirstMessageOfSeries(sortedMessage);
}
Expand Down
2 changes: 2 additions & 0 deletions ts/types/LocalizerKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export type LocalizerKeys =
| 'fileSizeWarning'
| 'openGroupURL'
| 'hideMenuBarDescription'
| 'filterBlockedFromOpenGroupsDescription'
| 'pickClosedGroupMember'
| 'ByUsingThisService...'
| 'startConversation'
Expand Down Expand Up @@ -246,6 +247,7 @@ export type LocalizerKeys =
| 'setPassword'
| 'editMenuDeleteContact'
| 'hideMenuBarTitle'
| 'filterBlockedFromOpenGroupsTitle'
| 'imageCaptionIconAlt'
| 'sendRecoveryPhraseTitle'
| 'multipleJoinedTheGroup'
Expand Down
3 changes: 3 additions & 0 deletions ts/util/accountManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ async function createAccount(identityKeyPair: any) {
await Storage.put(SettingsKey.settingsOpengroupPruning, true);
await window.setOpengroupPruning(true);

// Enable open group filtering by default.
await Storage.put(SettingsKey.settingsFilterOpenGroups, true);

await setLocalPubKey(pubKeyString);
}

Expand Down
1 change: 1 addition & 0 deletions ts/window.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ declare global {
toggleCallMediaPermissionsTo: (enabled: boolean) => Promise<void>;
getCallMediaPermissions: () => boolean;
toggleMenuBar: () => void;
toggleFilterOpenGroups: () => void;
toggleSpellCheck: any;
setTheme: (newTheme: string) => any;
isDev?: () => boolean;
Expand Down