Calling setting convo isApproved. Removing some unnecessary conditionals.
This commit is contained in:
parent
ffad806366
commit
f5972a5d1c
|
@ -3,11 +3,12 @@ import { useDispatch, useSelector } from 'react-redux';
|
|||
import styled from 'styled-components';
|
||||
import { getMessageCountByType } from '../../data/data';
|
||||
import {
|
||||
acceptConversation,
|
||||
approveConvoAndSendResponse,
|
||||
blockConvoById,
|
||||
declineConversation,
|
||||
} from '../../interactions/conversationInteractions';
|
||||
import { MessageDirection } from '../../models/messageType';
|
||||
import { getConversationController } from '../../session/conversations';
|
||||
import { forceSyncConfigurationNowIfNeeded } from '../../session/utils/syncUtils';
|
||||
import { updateConfirmModal } from '../../state/ducks/modalDialog';
|
||||
import { getSelectedConversation } from '../../state/selectors/conversations';
|
||||
|
@ -67,7 +68,9 @@ export const ConversationMessageRequestButtons = () => {
|
|||
|
||||
const handleAcceptConversationRequest = async () => {
|
||||
const { id } = selectedConversation;
|
||||
await acceptConversation(id, true);
|
||||
const convo = await getConversationController().get(selectedConversation.id);
|
||||
await convo.setDidApproveMe(true);
|
||||
await approveConvoAndSendResponse(id, true);
|
||||
};
|
||||
|
||||
if (!showMsgRequestUI) {
|
||||
|
|
|
@ -120,10 +120,15 @@ export async function unblockConvoById(conversationId: string) {
|
|||
await conversation.commit();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* marks the conversation's approval fields, sends messageRequestResponse, syncs to linked devices
|
||||
*/
|
||||
export const acceptConversation = async (conversationId: string, syncToDevices: boolean = true) => {
|
||||
export const approveConvoAndSendResponse = async (
|
||||
conversationId: string,
|
||||
syncToDevices: boolean = true
|
||||
) => {
|
||||
const convoToApprove = getConversationController().get(conversationId);
|
||||
|
||||
if (!convoToApprove || convoToApprove.isApproved()) {
|
||||
|
@ -132,7 +137,6 @@ export const acceptConversation = async (conversationId: string, syncToDevices:
|
|||
}
|
||||
|
||||
await convoToApprove.setIsApproved(true, false);
|
||||
await convoToApprove.setDidApproveMe(true, false);
|
||||
|
||||
await convoToApprove.commit();
|
||||
await convoToApprove.sendMessageRequestResponse(true);
|
||||
|
|
|
@ -140,30 +140,25 @@ const handleContactReceived = async (
|
|||
contactConvo.set('active_at', _.toNumber(envelope.timestamp));
|
||||
}
|
||||
|
||||
if (window.inboxStore?.getState().userConfig.messageRequests) {
|
||||
if (contactReceived.isApproved) {
|
||||
await contactConvo.setIsApproved(Boolean(contactReceived.isApproved));
|
||||
if (contactReceived.isApproved) {
|
||||
await contactConvo.setIsApproved(Boolean(contactReceived.isApproved));
|
||||
// TODO: add message search in convo for pre-existing msgRequestResponse msg only happens once per convo
|
||||
await contactConvo.addSingleOutgoingMessage({
|
||||
sent_at: _.toNumber(envelope.timestamp),
|
||||
messageRequestResponse: {
|
||||
isApproved: 1,
|
||||
},
|
||||
unread: 1, // 1 means unread
|
||||
expireTimer: 0,
|
||||
});
|
||||
contactConvo.updateLastMessage();
|
||||
await contactConvo.setDidApproveMe(Boolean(contactReceived.didApproveMe));
|
||||
}
|
||||
|
||||
if (contactReceived.didApproveMe) {
|
||||
// TODO: add message search in convo for pre-existing msgRequestResponse msg only happens once per convo
|
||||
await contactConvo.addSingleOutgoingMessage({
|
||||
sent_at: _.toNumber(envelope.timestamp),
|
||||
messageRequestResponse: {
|
||||
isApproved: 1,
|
||||
},
|
||||
unread: 1, // 1 means unread
|
||||
expireTimer: 0,
|
||||
});
|
||||
contactConvo.updateLastMessage();
|
||||
await contactConvo.setDidApproveMe(Boolean(contactReceived.didApproveMe));
|
||||
}
|
||||
}
|
||||
|
||||
if (contactReceived.isBlocked) {
|
||||
await BlockedNumberController.block(contactConvo.id);
|
||||
} else {
|
||||
await BlockedNumberController.unblock(contactConvo.id);
|
||||
}
|
||||
if (contactReceived.isBlocked) {
|
||||
await BlockedNumberController.block(contactConvo.id);
|
||||
} else {
|
||||
await BlockedNumberController.unblock(contactConvo.id);
|
||||
}
|
||||
|
||||
void updateProfileOneAtATime(contactConvo, profile, contactReceived.profileKey);
|
||||
|
|
|
@ -602,7 +602,6 @@ async function handleMessageRequestResponse(
|
|||
return;
|
||||
}
|
||||
|
||||
await conversationToApprove.setIsApproved(isApproved);
|
||||
await conversationToApprove.setDidApproveMe(isApproved);
|
||||
if (isApproved === true) {
|
||||
// Conversation was not approved before so a sync is needed
|
||||
|
|
|
@ -26,6 +26,7 @@ import { hasConversationOutgoingMessage } from '../../../data/data';
|
|||
import { getCallMediaPermissionsSettings } from '../../../components/settings/SessionSettings';
|
||||
import { PnServer } from '../../apis/push_notification_api';
|
||||
import { getNowWithNetworkOffset } from '../../apis/snode_api/SNodeAPI';
|
||||
import { approveConvoAndSendResponse } from '../../../interactions/conversationInteractions';
|
||||
|
||||
// tslint:disable: function-name
|
||||
|
||||
|
@ -504,6 +505,10 @@ export async function USER_callRecipient(recipient: string) {
|
|||
callNotificationType: 'started-call',
|
||||
unread: 0,
|
||||
});
|
||||
|
||||
// initiating a call is analgous to sending a message request
|
||||
await approveConvoAndSendResponse(recipient, true);
|
||||
|
||||
// we do it manually as the sendToPubkeyNonDurably rely on having a message saved to the db for MessageSentSuccess
|
||||
// which is not the case for a pre offer message (the message only exists in memory)
|
||||
const rawMessage = await MessageUtils.toRawMessage(PubKey.cast(recipient), preOfferMsg);
|
||||
|
@ -834,6 +839,10 @@ export async function USER_acceptIncomingCallRequest(fromSender: string) {
|
|||
unread: 0,
|
||||
});
|
||||
await buildAnswerAndSendIt(fromSender);
|
||||
|
||||
// consider the conversation completely approved
|
||||
await callerConvo.setDidApproveMe(true);
|
||||
await approveConvoAndSendResponse(fromSender, true);
|
||||
}
|
||||
|
||||
export async function rejectCallAlreadyAnotherCall(fromSender: string, forcedUUID: string) {
|
||||
|
|
Loading…
Reference in New Issue