Remove getIsConversationEmptySelector in favor of messageCount
This commit is contained in:
parent
c9ffb7c014
commit
9e2411ce30
6 changed files with 18 additions and 97 deletions
|
@ -1336,6 +1336,7 @@ export class ConversationModel extends window.Backbone.Model<
|
|||
markedUnread: this.get('markedUnread')!,
|
||||
membersCount: this.getMembersCount(),
|
||||
memberships: this.getMemberships(),
|
||||
messageCount: this.get('messageCount') || 0,
|
||||
pendingMemberships: this.getPendingMemberships(),
|
||||
pendingApprovalMemberships: this.getPendingApprovalMemberships(),
|
||||
messageRequestsEnabled,
|
||||
|
|
|
@ -91,6 +91,7 @@ export type ConversationType = {
|
|||
markedUnread?: boolean;
|
||||
phoneNumber?: string;
|
||||
membersCount?: number;
|
||||
messageCount?: number;
|
||||
accessControlAddFromInviteLink?: number;
|
||||
accessControlAttributes?: number;
|
||||
accessControlMembers?: number;
|
||||
|
|
|
@ -181,20 +181,6 @@ export const getMessagesByConversation = createSelector(
|
|||
}
|
||||
);
|
||||
|
||||
export const getIsConversationEmptySelector = createSelector(
|
||||
getMessagesByConversation,
|
||||
(messagesByConversation: MessagesByConversationType) => (
|
||||
conversationId: string
|
||||
): boolean => {
|
||||
const messages = getOwn(messagesByConversation, conversationId);
|
||||
if (!messages) {
|
||||
assert(false, 'Could not find conversation with this ID');
|
||||
return true;
|
||||
}
|
||||
return messages.messageIds.length === 0;
|
||||
}
|
||||
);
|
||||
|
||||
const collator = new Intl.Collator();
|
||||
|
||||
// Note: we will probably want to put i18n and regionCode back when we are formatting
|
||||
|
|
|
@ -10,10 +10,7 @@ import { StateType } from '../reducer';
|
|||
|
||||
import { isShortName } from '../../components/emoji/lib';
|
||||
import { getIntl } from '../selectors/user';
|
||||
import {
|
||||
getConversationSelector,
|
||||
getIsConversationEmptySelector,
|
||||
} from '../selectors/conversations';
|
||||
import { getConversationSelector } from '../selectors/conversations';
|
||||
import {
|
||||
getBlessedStickerPacks,
|
||||
getInstalledStickerPacks,
|
||||
|
@ -81,10 +78,14 @@ const mapStateToProps = (state: StateType, props: ExternalProps) => {
|
|||
// Message Requests
|
||||
...conversation,
|
||||
conversationType: conversation.type,
|
||||
isMissingMandatoryProfileSharing:
|
||||
isMissingMandatoryProfileSharing: Boolean(
|
||||
!conversation.profileSharing &&
|
||||
window.Signal.RemoteConfig.isEnabled('desktop.mandatoryProfileSharing') &&
|
||||
!getIsConversationEmptySelector(state)(id),
|
||||
window.Signal.RemoteConfig.isEnabled(
|
||||
'desktop.mandatoryProfileSharing'
|
||||
) &&
|
||||
conversation.messageCount &&
|
||||
conversation.messageCount > 0
|
||||
),
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -7,10 +7,7 @@ import {
|
|||
ConversationHeader,
|
||||
OutgoingCallButtonStyle,
|
||||
} from '../../components/conversation/ConversationHeader';
|
||||
import {
|
||||
getConversationSelector,
|
||||
getIsConversationEmptySelector,
|
||||
} from '../selectors/conversations';
|
||||
import { getConversationSelector } from '../selectors/conversations';
|
||||
import { StateType } from '../reducer';
|
||||
import { CallMode } from '../../types/Calling';
|
||||
import {
|
||||
|
@ -110,10 +107,14 @@ const mapStateToProps = (state: StateType, ownProps: OwnProps) => {
|
|||
'groupVersion',
|
||||
]),
|
||||
conversationTitle: state.conversations.selectedConversationTitle,
|
||||
isMissingMandatoryProfileSharing:
|
||||
isMissingMandatoryProfileSharing: Boolean(
|
||||
!conversation.profileSharing &&
|
||||
window.Signal.RemoteConfig.isEnabled('desktop.mandatoryProfileSharing') &&
|
||||
!getIsConversationEmptySelector(state)(id),
|
||||
window.Signal.RemoteConfig.isEnabled(
|
||||
'desktop.mandatoryProfileSharing'
|
||||
) &&
|
||||
conversation.messageCount &&
|
||||
conversation.messageCount > 0
|
||||
),
|
||||
i18n: getIntl(state),
|
||||
showBackButton: state.conversations.selectedConversationPanelDepth > 0,
|
||||
outgoingCallButtonStyle: getOutgoingCallButtonStyle(conversation, state),
|
||||
|
|
|
@ -23,7 +23,6 @@ import {
|
|||
getComposerStep,
|
||||
getConversationSelector,
|
||||
getInvitedContactsForNewlyCreatedGroup,
|
||||
getIsConversationEmptySelector,
|
||||
getMaximumGroupSizeModalState,
|
||||
getPlaceholderContact,
|
||||
getRecommendedGroupSizeModalState,
|
||||
|
@ -257,74 +256,6 @@ describe('both/state/selectors/conversations', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('#getIsConversationEmptySelector', () => {
|
||||
it('returns a selector that returns true for conversations that have no messages', () => {
|
||||
const state = {
|
||||
...getEmptyRootState(),
|
||||
conversations: {
|
||||
...getEmptyState(),
|
||||
messagesByConversation: {
|
||||
abc123: {
|
||||
heightChangeMessageIds: [],
|
||||
isLoadingMessages: false,
|
||||
messageIds: [],
|
||||
metrics: { totalUnread: 0 },
|
||||
resetCounter: 0,
|
||||
scrollToMessageCounter: 0,
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
const selector = getIsConversationEmptySelector(state);
|
||||
|
||||
assert.isTrue(selector('abc123'));
|
||||
});
|
||||
|
||||
it('returns a selector that returns true for conversations that have no messages, even if loading', () => {
|
||||
const state = {
|
||||
...getEmptyRootState(),
|
||||
conversations: {
|
||||
...getEmptyState(),
|
||||
messagesByConversation: {
|
||||
abc123: {
|
||||
heightChangeMessageIds: [],
|
||||
isLoadingMessages: true,
|
||||
messageIds: [],
|
||||
metrics: { totalUnread: 0 },
|
||||
resetCounter: 0,
|
||||
scrollToMessageCounter: 0,
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
const selector = getIsConversationEmptySelector(state);
|
||||
|
||||
assert.isTrue(selector('abc123'));
|
||||
});
|
||||
|
||||
it('returns a selector that returns false for conversations that have messages', () => {
|
||||
const state = {
|
||||
...getEmptyRootState(),
|
||||
conversations: {
|
||||
...getEmptyState(),
|
||||
messagesByConversation: {
|
||||
abc123: {
|
||||
heightChangeMessageIds: [],
|
||||
isLoadingMessages: false,
|
||||
messageIds: ['xyz'],
|
||||
metrics: { totalUnread: 0 },
|
||||
resetCounter: 0,
|
||||
scrollToMessageCounter: 0,
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
const selector = getIsConversationEmptySelector(state);
|
||||
|
||||
assert.isFalse(selector('abc123'));
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getComposerStep', () => {
|
||||
it("returns undefined if the composer isn't open", () => {
|
||||
const state = getEmptyRootState();
|
||||
|
|
Loading…
Reference in a new issue