mirror of
https://github.com/oxen-io/session-desktop.git
synced 2023-12-14 02:12:57 +01:00
PR changes
This commit is contained in:
parent
4576f3cb32
commit
e32f20d8bc
9 changed files with 66 additions and 88 deletions
|
@ -11,6 +11,7 @@ import { useSelector } from 'react-redux';
|
|||
import { getLeftPaneLists } from '../state/selectors/conversations';
|
||||
import { getQuery, getSearchResults, isSearching } from '../state/selectors/search';
|
||||
import { SectionType } from '../state/ducks/section';
|
||||
import { getIsMessageRequestsEnabled } from '../state/selectors/userConfig';
|
||||
|
||||
// from https://github.com/bvaughn/react-virtualized/blob/fb3484ed5dcc41bffae8eab029126c0fb8f7abc0/source/List/types.js#L5
|
||||
export type RowRendererParamsType = {
|
||||
|
@ -29,14 +30,15 @@ const InnerLeftPaneMessageSection = () => {
|
|||
const searchResults = showSearch ? useSelector(getSearchResults) : undefined;
|
||||
|
||||
const lists = showSearch ? undefined : useSelector(getLeftPaneLists);
|
||||
const messageRequestsEnabled = useSelector(getIsMessageRequestsEnabled);
|
||||
|
||||
// tslint:disable: use-simple-attributes
|
||||
return (
|
||||
<LeftPaneMessageSection
|
||||
conversations={lists?.conversations || []}
|
||||
contacts={lists?.contacts || []}
|
||||
searchResults={searchResults}
|
||||
searchTerm={searchTerm}
|
||||
messageRequestsEnabled={messageRequestsEnabled}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
|
|
@ -38,6 +38,8 @@ export interface Props {
|
|||
contacts: Array<ReduxConversationType>;
|
||||
conversations?: Array<ConversationListItemProps>;
|
||||
searchResults?: SearchResultsProps;
|
||||
|
||||
messageRequestsEnabled?: boolean;
|
||||
}
|
||||
|
||||
export enum SessionComposeToType {
|
||||
|
@ -84,7 +86,7 @@ export class LeftPaneMessageSection extends React.Component<Props, State> {
|
|||
|
||||
const conversation = conversations[index];
|
||||
if (!conversation) {
|
||||
window?.log?.info('No conversation found at index');
|
||||
throw new Error('renderRow: conversations selector returned element containing falsy value.');
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -222,12 +224,9 @@ export class LeftPaneMessageSection extends React.Component<Props, State> {
|
|||
* @returns void
|
||||
*/
|
||||
private async handleBlockAllRequestsClick() {
|
||||
let messageRequestsEnabled = false;
|
||||
if (window?.inboxStore?.getState()) {
|
||||
messageRequestsEnabled =
|
||||
window.inboxStore?.getState().userConfig.messageRequests === true &&
|
||||
window.lokiFeatureFlags?.useMessageRequests === true;
|
||||
}
|
||||
const messageRequestsEnabled =
|
||||
this.props.messageRequestsEnabled && window?.lokiFeatureFlags?.useMessageRequests;
|
||||
|
||||
if (!messageRequestsEnabled) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -11,10 +11,7 @@ import { SessionJoinableRooms } from './SessionJoinableDefaultRooms';
|
|||
import { SpacerLG, SpacerMD } from '../basic/Text';
|
||||
import { useSelector } from 'react-redux';
|
||||
import { getConversationRequests } from '../../state/selectors/conversations';
|
||||
import {
|
||||
ConversationListItemProps,
|
||||
MemoConversationListItemWithDetails,
|
||||
} from '../ConversationListItem';
|
||||
import { MemoConversationListItemWithDetails } from '../ConversationListItem';
|
||||
|
||||
export enum SessionClosableOverlayType {
|
||||
Message = 'message',
|
||||
|
@ -299,13 +296,14 @@ const MessageRequestList = () => {
|
|||
return (
|
||||
<div className="message-request-list__container">
|
||||
{conversationRequests.map(conversation => {
|
||||
return <MessageRequestListItem key={conversation.id} conversation={conversation} />;
|
||||
return (
|
||||
<MemoConversationListItemWithDetails
|
||||
key={conversation.id}
|
||||
isMessageRequest={true}
|
||||
{...conversation}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const MessageRequestListItem = (props: { conversation: ConversationListItemProps }) => {
|
||||
const { conversation } = props;
|
||||
return <MemoConversationListItemWithDetails isMessageRequest={true} {...conversation} />;
|
||||
};
|
||||
|
|
|
@ -122,8 +122,17 @@ export async function unblockConvoById(conversationId: string) {
|
|||
*/
|
||||
export const approveConversation = async (conversationId: string) => {
|
||||
const conversationToApprove = await getConversationById(conversationId);
|
||||
|
||||
if (!conversationToApprove || conversationToApprove.isApproved()) {
|
||||
window?.log?.info('Conversation is already approved.');
|
||||
return;
|
||||
}
|
||||
|
||||
await conversationToApprove?.setIsApproved(true);
|
||||
await forceSyncConfigurationNowIfNeeded();
|
||||
|
||||
if (conversationToApprove?.isApproved() === true) {
|
||||
await forceSyncConfigurationNowIfNeeded();
|
||||
}
|
||||
};
|
||||
|
||||
export async function showUpdateGroupNameByConvoId(conversationId: string) {
|
||||
|
|
|
@ -738,7 +738,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
|
|||
!this.isApproved() && (this.isPrivate() || this.isMediumGroup() || this.isClosedGroup());
|
||||
if (updateApprovalNeeded) {
|
||||
await this.setIsApproved(true);
|
||||
await forceSyncConfigurationNowIfNeeded();
|
||||
void forceSyncConfigurationNowIfNeeded();
|
||||
}
|
||||
|
||||
if (this.isOpenGroupV2()) {
|
||||
|
|
|
@ -2,7 +2,7 @@ import _ from 'lodash';
|
|||
import { SignalService } from '../protobuf';
|
||||
import { TTL_DEFAULT } from '../session/constants';
|
||||
import { SNodeAPI } from '../session/snode_api';
|
||||
import { CallManager } from '../session/utils';
|
||||
import { CallManager, UserUtils } from '../session/utils';
|
||||
import { removeFromCache } from './cache';
|
||||
import { EnvelopePlus } from './types';
|
||||
|
||||
|
|
|
@ -54,11 +54,6 @@ async function handleGroupsAndContactsFromConfigMessage(
|
|||
envelope: EnvelopePlus,
|
||||
configMessage: SignalService.ConfigurationMessage
|
||||
) {
|
||||
await createOrUpdateItem({
|
||||
id: 'hasSyncedInitialConfigurationItem',
|
||||
value: true,
|
||||
});
|
||||
|
||||
const didWeHandleAConfigurationMessageAlready =
|
||||
(await getItemById(hasSyncedInitialConfigurationItem))?.value || false;
|
||||
if (didWeHandleAConfigurationMessageAlready) {
|
||||
|
@ -71,6 +66,11 @@ async function handleGroupsAndContactsFromConfigMessage(
|
|||
return;
|
||||
}
|
||||
|
||||
await createOrUpdateItem({
|
||||
id: 'hasSyncedInitialConfigurationItem',
|
||||
value: true,
|
||||
});
|
||||
|
||||
const numberClosedGroup = configMessage.closedGroups?.length || 0;
|
||||
|
||||
window?.log?.info(
|
||||
|
@ -152,7 +152,7 @@ const handleContactReceived = async (
|
|||
}
|
||||
}
|
||||
|
||||
await updateProfileOneAtATime(contactConvo, profile, contactReceived.profileKey);
|
||||
void updateProfileOneAtATime(contactConvo, profile, contactReceived.profileKey);
|
||||
} catch (e) {
|
||||
window?.log?.warn('failed to handle a new closed group from configuration message');
|
||||
}
|
||||
|
|
|
@ -331,54 +331,21 @@ export const getConversationComparator = createSelector(getIntl, _getConversatio
|
|||
// export only because we use it in some of our tests
|
||||
// tslint:disable-next-line: cyclomatic-complexity
|
||||
export const _getLeftPaneLists = (
|
||||
lookup: ConversationLookupType,
|
||||
comparator: (left: ReduxConversationType, right: ReduxConversationType) => number,
|
||||
isMessageRequestEnabled?: boolean,
|
||||
selectedConversation?: string
|
||||
sortedConversations: Array<ReduxConversationType>,
|
||||
isMessageRequestEnabled?: boolean
|
||||
): {
|
||||
conversations: Array<ReduxConversationType>;
|
||||
contacts: Array<ReduxConversationType>;
|
||||
unreadCount: number;
|
||||
} => {
|
||||
const values = Object.values(lookup);
|
||||
const sorted = values.sort(comparator);
|
||||
|
||||
const conversations: Array<ReduxConversationType> = [];
|
||||
const directConversations: Array<ReduxConversationType> = [];
|
||||
|
||||
let unreadCount = 0;
|
||||
for (let conversation of sorted) {
|
||||
if (selectedConversation === conversation.id) {
|
||||
conversation = {
|
||||
...conversation,
|
||||
isSelected: true,
|
||||
};
|
||||
}
|
||||
const isBlocked =
|
||||
BlockedNumberController.isBlocked(conversation.id) ||
|
||||
BlockedNumberController.isGroupBlocked(conversation.id);
|
||||
|
||||
if (isBlocked) {
|
||||
conversation = {
|
||||
...conversation,
|
||||
isBlocked: true,
|
||||
};
|
||||
}
|
||||
|
||||
for (const conversation of sortedConversations) {
|
||||
const excludeUnapproved =
|
||||
isMessageRequestEnabled && window.lokiFeatureFlags?.useMessageRequests;
|
||||
|
||||
// Add Open Group to list as soon as the name has been set
|
||||
if (conversation.isPublic && (!conversation.name || conversation.name === 'Unknown group')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Remove all invalid conversations and conversatons of devices associated
|
||||
// with cancelled attempted links
|
||||
if (!conversation.isPublic && !conversation.activeAt) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (conversation.activeAt !== undefined && conversation.type === ConversationTypeEnum.PRIVATE) {
|
||||
directConversations.push(conversation);
|
||||
}
|
||||
|
@ -407,7 +374,7 @@ export const _getLeftPaneLists = (
|
|||
};
|
||||
};
|
||||
|
||||
export const _getConversationRequests = (
|
||||
export const _getSortedConversations = (
|
||||
lookup: ConversationLookupType,
|
||||
comparator: (left: ReduxConversationType, right: ReduxConversationType) => number,
|
||||
selectedConversation?: string
|
||||
|
@ -415,7 +382,7 @@ export const _getConversationRequests = (
|
|||
const values = Object.values(lookup);
|
||||
const sorted = values.sort(comparator);
|
||||
|
||||
const conversationRequests: Array<ReduxConversationType> = [];
|
||||
const sortedConversations: Array<ReduxConversationType> = [];
|
||||
|
||||
for (let conversation of sorted) {
|
||||
if (selectedConversation === conversation.id) {
|
||||
|
@ -436,14 +403,6 @@ export const _getConversationRequests = (
|
|||
};
|
||||
}
|
||||
|
||||
let messageRequestsEnabled = false;
|
||||
|
||||
if (window?.inboxStore?.getState()) {
|
||||
messageRequestsEnabled =
|
||||
window.inboxStore?.getState().userConfig.messageRequests === true &&
|
||||
window.lokiFeatureFlags?.useMessageRequests === true;
|
||||
}
|
||||
|
||||
// Add Open Group to list as soon as the name has been set
|
||||
if (conversation.isPublic && (!conversation.name || conversation.name === 'Unknown group')) {
|
||||
continue;
|
||||
|
@ -455,28 +414,39 @@ export const _getConversationRequests = (
|
|||
continue;
|
||||
}
|
||||
|
||||
if (messageRequestsEnabled && !conversation.isApproved && !conversation.isBlocked) {
|
||||
// dont increase unread counter, don't push to convo list.
|
||||
conversationRequests.push(conversation);
|
||||
continue;
|
||||
}
|
||||
sortedConversations.push(conversation);
|
||||
}
|
||||
|
||||
return conversationRequests;
|
||||
return sortedConversations;
|
||||
};
|
||||
|
||||
export const getConversationRequests = createSelector(
|
||||
export const getSortedConversations = createSelector(
|
||||
getConversationLookup,
|
||||
getConversationComparator,
|
||||
getSelectedConversationKey,
|
||||
_getSortedConversations
|
||||
);
|
||||
|
||||
export const _getConversationRequests = (
|
||||
sortedConversations: Array<ReduxConversationType>,
|
||||
isMessageRequestEnabled?: boolean
|
||||
): Array<ReduxConversationType> => {
|
||||
const pushToMessageRequests =
|
||||
isMessageRequestEnabled && window.lokiFeatureFlags?.useMessageRequests;
|
||||
return _.filter(sortedConversations, conversation => {
|
||||
return pushToMessageRequests && !conversation.isApproved && !conversation.isBlocked;
|
||||
});
|
||||
};
|
||||
|
||||
export const getConversationRequests = createSelector(
|
||||
getSortedConversations,
|
||||
getIsMessageRequestsEnabled,
|
||||
_getConversationRequests
|
||||
);
|
||||
|
||||
export const getLeftPaneLists = createSelector(
|
||||
getConversationLookup,
|
||||
getConversationComparator,
|
||||
getSortedConversations,
|
||||
getIsMessageRequestsEnabled,
|
||||
getSelectedConversationKey,
|
||||
_getLeftPaneLists
|
||||
);
|
||||
|
||||
|
|
|
@ -4,11 +4,11 @@ import { ConversationTypeEnum } from '../../../../models/conversation';
|
|||
import { ConversationLookupType } from '../../../../state/ducks/conversations';
|
||||
import {
|
||||
_getConversationComparator,
|
||||
_getLeftPaneLists,
|
||||
_getSortedConversations,
|
||||
} from '../../../../state/selectors/conversations';
|
||||
|
||||
describe('state/selectors/conversations', () => {
|
||||
describe('#getLeftPaneList', () => {
|
||||
describe('#getSortedConversationsList', () => {
|
||||
// tslint:disable-next-line: max-func-body-length
|
||||
it('sorts conversations based on timestamp then by intl-friendly title', () => {
|
||||
const i18n = (key: string) => key;
|
||||
|
@ -160,7 +160,7 @@ describe('state/selectors/conversations', () => {
|
|||
},
|
||||
};
|
||||
const comparator = _getConversationComparator(i18n);
|
||||
const { conversations } = _getLeftPaneLists(data, comparator);
|
||||
const conversations = _getSortedConversations(data, comparator);
|
||||
|
||||
assert.strictEqual(conversations[0].name, 'First!');
|
||||
assert.strictEqual(conversations[1].name, 'Á');
|
||||
|
@ -169,7 +169,7 @@ describe('state/selectors/conversations', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('#getLeftPaneListWithPinned', () => {
|
||||
describe('#getSortedConversationsWithPinned', () => {
|
||||
// tslint:disable-next-line: max-func-body-length
|
||||
it('sorts conversations based on pin, timestamp then by intl-friendly title', () => {
|
||||
const i18n = (key: string) => key;
|
||||
|
@ -325,7 +325,7 @@ describe('state/selectors/conversations', () => {
|
|||
},
|
||||
};
|
||||
const comparator = _getConversationComparator(i18n);
|
||||
const { conversations } = _getLeftPaneLists(data, comparator);
|
||||
const conversations = _getSortedConversations(data, comparator);
|
||||
|
||||
assert.strictEqual(conversations[0].name, 'Á');
|
||||
assert.strictEqual(conversations[1].name, 'C');
|
||||
|
|
Loading…
Reference in a new issue