refactoring
This commit is contained in:
parent
5437433232
commit
08ba24c3c9
|
@ -73,6 +73,7 @@ export const ConversationMessageRequestButtons = () => {
|
|||
const { id } = selectedConversation;
|
||||
const convo = getConversationController().get(selectedConversation.id);
|
||||
await convo.setDidApproveMe(true);
|
||||
await convo.addOutgoingApprovalMessage(Date.now());
|
||||
await approveConvoAndSendResponse(id, true);
|
||||
};
|
||||
|
||||
|
|
|
@ -633,16 +633,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
|
|||
await this.setIsApproved(true);
|
||||
if (hasIncomingMessages) {
|
||||
// have to manually add approval for local client here as DB conditional approval check in config msg handling will prevent this from running
|
||||
await this.addSingleOutgoingMessage({
|
||||
sent_at: Date.now(),
|
||||
messageRequestResponse: {
|
||||
isApproved: 1,
|
||||
},
|
||||
unread: 1, // 1 means unread
|
||||
expireTimer: 0,
|
||||
});
|
||||
this.updateLastMessage();
|
||||
|
||||
await this.addOutgoingApprovalMessage(Date.now());
|
||||
if (!this.didApproveMe()) {
|
||||
await this.setDidApproveMe(true);
|
||||
}
|
||||
|
@ -729,6 +720,39 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param timestamp for determining the order for this message to appear like a regular message
|
||||
*/
|
||||
public async addOutgoingApprovalMessage(timestamp: number) {
|
||||
await this.addSingleOutgoingMessage({
|
||||
sent_at: timestamp,
|
||||
messageRequestResponse: {
|
||||
isApproved: 1,
|
||||
},
|
||||
unread: 1, // 1 means unread
|
||||
expireTimer: 0,
|
||||
});
|
||||
|
||||
this.updateLastMessage();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param timestamp For determining message order in conversation
|
||||
* @param source For determining the conversation name used in the message.
|
||||
*/
|
||||
public async addIncomingApprovalMessage(timestamp: number, source: string) {
|
||||
await this.addSingleIncomingMessage({
|
||||
sent_at: timestamp, // TODO: maybe add timestamp to messageRequestResponse? confirm it doesn't exist first
|
||||
source,
|
||||
messageRequestResponse: {
|
||||
isApproved: 1,
|
||||
},
|
||||
unread: 1, // 1 means unread
|
||||
expireTimer: 0,
|
||||
});
|
||||
this.updateLastMessage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to evalute if a convo contains the right values
|
||||
* @param values Required properties to evaluate if this is a message request
|
||||
|
|
|
@ -57,8 +57,6 @@ async function handleGroupsAndContactsFromConfigMessage(
|
|||
) {
|
||||
const lastConfigUpdate = await getItemById(hasSyncedInitialConfigurationItem);
|
||||
const lastConfigTimestamp = lastConfigUpdate?.timestamp;
|
||||
console.warn({ lastConfigUpdate });
|
||||
console.warn({ lastConfigTimestamp });
|
||||
const isNewerConfig = lastConfigTimestamp && lastConfigTimestamp < _.toNumber(envelope.timestamp);
|
||||
|
||||
// const didWeHandleAConfigurationMessageAlready =
|
||||
|
@ -158,15 +156,7 @@ const handleContactReceived = async (
|
|||
if (!contactConvo.isApproved()) {
|
||||
// TODO: add message search in convo for pre-existing msgRequestResponse msg only happens once per convo
|
||||
await contactConvo.setIsApproved(Boolean(contactReceived.isApproved));
|
||||
await contactConvo.addSingleOutgoingMessage({
|
||||
sent_at: _.toNumber(envelope.timestamp),
|
||||
messageRequestResponse: {
|
||||
isApproved: 1,
|
||||
},
|
||||
unread: 1, // 1 means unread
|
||||
expireTimer: 0,
|
||||
});
|
||||
contactConvo.updateLastMessage();
|
||||
await contactConvo.addOutgoingApprovalMessage(_.toNumber(envelope.timestamp));
|
||||
}
|
||||
|
||||
if (contactReceived.didApproveMe === true) {
|
||||
|
|
|
@ -605,16 +605,10 @@ async function handleMessageRequestResponse(
|
|||
await conversationToApprove.setDidApproveMe(isApproved);
|
||||
if (isApproved === true) {
|
||||
// Conversation was not approved before so a sync is needed
|
||||
await conversationToApprove.addSingleIncomingMessage({
|
||||
sent_at: _.toNumber(envelope.timestamp), // TODO: maybe add timestamp to messageRequestResponse? confirm it doesn't exist first
|
||||
source: envelope.source,
|
||||
messageRequestResponse: {
|
||||
isApproved: 1,
|
||||
},
|
||||
unread: 1, // 1 means unread
|
||||
expireTimer: 0,
|
||||
});
|
||||
conversationToApprove.updateLastMessage();
|
||||
await conversationToApprove.addIncomingApprovalMessage(
|
||||
_.toNumber(envelope.timestamp),
|
||||
envelope.source
|
||||
);
|
||||
}
|
||||
|
||||
await removeFromCache(envelope);
|
||||
|
|
Loading…
Reference in New Issue