rename request evaluating function for clarity. Prevent disappearing messsages from being activated by request recipient before the request has been accepted.

pull/2174/head
warrickct 3 years ago
parent 7315651c63
commit e4f4328232

@ -41,7 +41,7 @@ export const ConversationMessageRequestButtons = () => {
} }
const convoModel = getConversationController().get(selectedConversation.id); const convoModel = getConversationController().get(selectedConversation.id);
const showMsgRequestUI = convoModel && convoModel.isRequest(); const showMsgRequestUI = convoModel && convoModel.isIncomingRequest();
const handleDeclineConversationRequest = () => { const handleDeclineConversationRequest = () => {
declineConversationWithConfirm(selectedConversation.id, true); declineConversationWithConfirm(selectedConversation.id, true);

@ -10,7 +10,7 @@ export const ConversationRequestinfo = () => {
const selectedConversation = useSelector(getSelectedConversation); const selectedConversation = useSelector(getSelectedConversation);
const convoModel = const convoModel =
selectedConversation && getConversationController().get(selectedConversation.id); selectedConversation && getConversationController().get(selectedConversation.id);
const showMsgRequestUI = selectedConversation && convoModel && convoModel.isRequest(); const showMsgRequestUI = selectedConversation && convoModel && convoModel.isIncomingRequest();
const [hasIncomingMessages, setHasIncomingMessages] = useState(false); const [hasIncomingMessages, setHasIncomingMessages] = useState(false);
const [incomingChecked, setIncomingChecked] = useState(false); const [incomingChecked, setIncomingChecked] = useState(false);

@ -128,7 +128,7 @@ export function useIsRequest(convoId: string) {
const convoProps = useConversationPropsById(convoId); const convoProps = useConversationPropsById(convoId);
return Boolean( return Boolean(
convoProps && convoProps &&
ConversationModel.hasValidRequestValues({ ConversationModel.hasValidIncomingRequestValues({
isMe: convoProps.isMe, isMe: convoProps.isMe,
isApproved: convoProps.isApproved, isApproved: convoProps.isApproved,
isPrivate: convoProps.isPrivate, isPrivate: convoProps.isPrivate,

@ -358,7 +358,9 @@ export async function setDisappearingMessagesByConvoId(
) { ) {
const conversation = getConversationController().get(conversationId); const conversation = getConversationController().get(conversationId);
if (!conversation.didApproveMe() && conversation.isPrivate()) { const canSetDisappearing = !conversation.isOutgoingRequest() && !conversation.isIncomingRequest();
if (!canSetDisappearing) {
ToastUtils.pushMustBeApproved(); ToastUtils.pushMustBeApproved();
return; return;
} }

@ -246,7 +246,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
* Method to evalute if a convo contains the right values * Method to evalute if a convo contains the right values
* @param values Required properties to evaluate if this is a message request * @param values Required properties to evaluate if this is a message request
*/ */
public static hasValidRequestValues({ public static hasValidIncomingRequestValues({
isMe, isMe,
isApproved, isApproved,
isBlocked, isBlocked,
@ -260,6 +260,22 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
return Boolean(!isMe && !isApproved && isPrivate && !isBlocked); return Boolean(!isMe && !isApproved && isPrivate && !isBlocked);
} }
public static hasValidOutgoingRequestValues({
isMe,
didApproveMe,
isApproved,
isBlocked,
isPrivate,
}: {
isMe?: boolean;
isApproved?: boolean;
didApproveMe?: boolean;
isBlocked?: boolean;
isPrivate?: boolean;
}): boolean {
return Boolean(!isMe && isApproved && isPrivate && !isBlocked && !didApproveMe);
}
public idForLogging() { public idForLogging() {
if (this.isPrivate()) { if (this.isPrivate()) {
return this.id; return this.id;
@ -728,10 +744,23 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
/** /**
* Does this conversation contain the properties to be considered a message request * Does this conversation contain the properties to be considered a message request
*/ */
public isRequest(): boolean { public isIncomingRequest(): boolean {
return ConversationModel.hasValidRequestValues({ return ConversationModel.hasValidIncomingRequestValues({
isMe: this.isMe(),
isApproved: this.isApproved(),
isBlocked: this.isBlocked(),
isPrivate: this.isPrivate(),
});
}
/**
* Is this conversation an outgoing message request
*/
public isOutgoingRequest(): boolean {
return ConversationModel.hasValidOutgoingRequestValues({
isMe: this.isMe(), isMe: this.isMe(),
isApproved: this.isApproved(), isApproved: this.isApproved(),
didApproveMe: this.didApproveMe(),
isBlocked: this.isBlocked(), isBlocked: this.isBlocked(),
isPrivate: this.isPrivate(), isPrivate: this.isPrivate(),
}); });
@ -1123,7 +1152,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
`Sending ${read.length} read receipts?`, `Sending ${read.length} read receipts?`,
window.storage.get(SettingsKey.settingsReadReceipt) || false window.storage.get(SettingsKey.settingsReadReceipt) || false
); );
const dontSendReceipt = this.isBlocked() || this.isRequest(); const dontSendReceipt = this.isBlocked() || this.isIncomingRequest();
if (window.storage.get(SettingsKey.settingsReadReceipt) && !dontSendReceipt) { if (window.storage.get(SettingsKey.settingsReadReceipt) && !dontSendReceipt) {
const timestamps = _.map(read, 'timestamp').filter(t => !!t) as Array<number>; const timestamps = _.map(read, 'timestamp').filter(t => !!t) as Array<number>;
const receiptMessage = new ReadReceiptMessage({ const receiptMessage = new ReadReceiptMessage({

@ -167,7 +167,7 @@ const handleContactReceived = async (
// only set for explicit true/false values incase outdated sender doesn't have the fields // only set for explicit true/false values incase outdated sender doesn't have the fields
if (contactReceived.isBlocked === true) { if (contactReceived.isBlocked === true) {
if (contactConvo.isRequest()) { if (contactConvo.isIncomingRequest()) {
// handling case where restored device's declined message requests were getting restored // handling case where restored device's declined message requests were getting restored
await ConversationInteraction.deleteAllMessagesByConvoIdNoConfirmation(contactConvo.id); await ConversationInteraction.deleteAllMessagesByConvoIdNoConfirmation(contactConvo.id);
} }

@ -259,7 +259,7 @@ async function handleRegularMessage(
); );
const isFirstRequestMessage = incomingMessageCount < 2; const isFirstRequestMessage = incomingMessageCount < 2;
if ( if (
conversation.isRequest() && conversation.isIncomingRequest() &&
isFirstRequestMessage && isFirstRequestMessage &&
window.inboxStore?.getState().userConfig.hideMessageRequests window.inboxStore?.getState().userConfig.hideMessageRequests
) { ) {

@ -445,7 +445,7 @@ const _getConversationRequests = (
): Array<ReduxConversationType> => { ): Array<ReduxConversationType> => {
return _.filter(sortedConversations, conversation => { return _.filter(sortedConversations, conversation => {
const { isApproved, isBlocked, isPrivate, isMe } = conversation; const { isApproved, isBlocked, isPrivate, isMe } = conversation;
const isRequest = ConversationModel.hasValidRequestValues({ const isRequest = ConversationModel.hasValidIncomingRequestValues({
isApproved, isApproved,
isBlocked, isBlocked,
isPrivate, isPrivate,

Loading…
Cancel
Save