rename request evaluating function for clarity. Prevent disappearing messsages from being activated by request recipient before the request has been accepted.
This commit is contained in:
parent
7315651c63
commit
e4f4328232
|
@ -41,7 +41,7 @@ export const ConversationMessageRequestButtons = () => {
|
|||
}
|
||||
|
||||
const convoModel = getConversationController().get(selectedConversation.id);
|
||||
const showMsgRequestUI = convoModel && convoModel.isRequest();
|
||||
const showMsgRequestUI = convoModel && convoModel.isIncomingRequest();
|
||||
|
||||
const handleDeclineConversationRequest = () => {
|
||||
declineConversationWithConfirm(selectedConversation.id, true);
|
||||
|
|
|
@ -10,7 +10,7 @@ export const ConversationRequestinfo = () => {
|
|||
const selectedConversation = useSelector(getSelectedConversation);
|
||||
const convoModel =
|
||||
selectedConversation && getConversationController().get(selectedConversation.id);
|
||||
const showMsgRequestUI = selectedConversation && convoModel && convoModel.isRequest();
|
||||
const showMsgRequestUI = selectedConversation && convoModel && convoModel.isIncomingRequest();
|
||||
const [hasIncomingMessages, setHasIncomingMessages] = useState(false);
|
||||
const [incomingChecked, setIncomingChecked] = useState(false);
|
||||
|
||||
|
|
|
@ -128,7 +128,7 @@ export function useIsRequest(convoId: string) {
|
|||
const convoProps = useConversationPropsById(convoId);
|
||||
return Boolean(
|
||||
convoProps &&
|
||||
ConversationModel.hasValidRequestValues({
|
||||
ConversationModel.hasValidIncomingRequestValues({
|
||||
isMe: convoProps.isMe,
|
||||
isApproved: convoProps.isApproved,
|
||||
isPrivate: convoProps.isPrivate,
|
||||
|
|
|
@ -358,7 +358,9 @@ export async function setDisappearingMessagesByConvoId(
|
|||
) {
|
||||
const conversation = getConversationController().get(conversationId);
|
||||
|
||||
if (!conversation.didApproveMe() && conversation.isPrivate()) {
|
||||
const canSetDisappearing = !conversation.isOutgoingRequest() && !conversation.isIncomingRequest();
|
||||
|
||||
if (!canSetDisappearing) {
|
||||
ToastUtils.pushMustBeApproved();
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -246,7 +246,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
|
|||
* Method to evalute if a convo contains the right values
|
||||
* @param values Required properties to evaluate if this is a message request
|
||||
*/
|
||||
public static hasValidRequestValues({
|
||||
public static hasValidIncomingRequestValues({
|
||||
isMe,
|
||||
isApproved,
|
||||
isBlocked,
|
||||
|
@ -260,6 +260,22 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
|
|||
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() {
|
||||
if (this.isPrivate()) {
|
||||
return this.id;
|
||||
|
@ -728,8 +744,8 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
|
|||
/**
|
||||
* Does this conversation contain the properties to be considered a message request
|
||||
*/
|
||||
public isRequest(): boolean {
|
||||
return ConversationModel.hasValidRequestValues({
|
||||
public isIncomingRequest(): boolean {
|
||||
return ConversationModel.hasValidIncomingRequestValues({
|
||||
isMe: this.isMe(),
|
||||
isApproved: this.isApproved(),
|
||||
isBlocked: this.isBlocked(),
|
||||
|
@ -737,6 +753,19 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this conversation an outgoing message request
|
||||
*/
|
||||
public isOutgoingRequest(): boolean {
|
||||
return ConversationModel.hasValidOutgoingRequestValues({
|
||||
isMe: this.isMe(),
|
||||
isApproved: this.isApproved(),
|
||||
didApproveMe: this.didApproveMe(),
|
||||
isBlocked: this.isBlocked(),
|
||||
isPrivate: this.isPrivate(),
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* When you have accepted another users message request
|
||||
* @param timestamp for determining the order for this message to appear like a regular message
|
||||
|
@ -1123,7 +1152,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
|
|||
`Sending ${read.length} read receipts?`,
|
||||
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) {
|
||||
const timestamps = _.map(read, 'timestamp').filter(t => !!t) as Array<number>;
|
||||
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
|
||||
if (contactReceived.isBlocked === true) {
|
||||
if (contactConvo.isRequest()) {
|
||||
if (contactConvo.isIncomingRequest()) {
|
||||
// handling case where restored device's declined message requests were getting restored
|
||||
await ConversationInteraction.deleteAllMessagesByConvoIdNoConfirmation(contactConvo.id);
|
||||
}
|
||||
|
|
|
@ -259,7 +259,7 @@ async function handleRegularMessage(
|
|||
);
|
||||
const isFirstRequestMessage = incomingMessageCount < 2;
|
||||
if (
|
||||
conversation.isRequest() &&
|
||||
conversation.isIncomingRequest() &&
|
||||
isFirstRequestMessage &&
|
||||
window.inboxStore?.getState().userConfig.hideMessageRequests
|
||||
) {
|
||||
|
|
|
@ -445,7 +445,7 @@ const _getConversationRequests = (
|
|||
): Array<ReduxConversationType> => {
|
||||
return _.filter(sortedConversations, conversation => {
|
||||
const { isApproved, isBlocked, isPrivate, isMe } = conversation;
|
||||
const isRequest = ConversationModel.hasValidRequestValues({
|
||||
const isRequest = ConversationModel.hasValidIncomingRequestValues({
|
||||
isApproved,
|
||||
isBlocked,
|
||||
isPrivate,
|
||||
|
|
Loading…
Reference in New Issue