Blocking, accepting on click and accepting on msg send

working across clients.
pull/2000/head
Warrick Corfe-Tan 3 years ago
parent 87235641cb
commit 6a62437c3e

@ -1622,10 +1622,6 @@ function updateConversation(data) {
profileName,
} = data;
// TODO: msgreq - remove
console.log({ usrData: data });
console.log('usrData@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@');
globalInstance
.prepare(
`UPDATE ${CONVERSATIONS_TABLE} SET

@ -30,7 +30,7 @@ import { ConversationNotificationSettingType } from '../models/conversation';
import { Flex } from './basic/Flex';
import { SessionButton, SessionButtonColor } from './session/SessionButton';
import { getConversationById } from '../data/data';
import { syncConfigurationIfNeeded } from '../session/utils/syncUtils';
import { forceSyncConfigurationNowIfNeeded } from '../session/utils/syncUtils';
import { BlockedNumberController } from '../util';
// tslint:disable-next-line: no-empty-interface
@ -294,7 +294,7 @@ const ConversationListItem = (props: Props) => {
window?.log?.error('Unable to find conversation to be blocked.');
}
await BlockedNumberController.block(convoToBlock?.id);
await syncConfigurationIfNeeded(true);
await forceSyncConfigurationNowIfNeeded();
};
/**
@ -306,7 +306,8 @@ const ConversationListItem = (props: Props) => {
console.warn({ convoAfterSetIsApproved: conversationToApprove });
// TODO: Send sync message to other devices. Using config message
await syncConfigurationIfNeeded(true);
// await syncConfigurationIfNeeded(true);
await forceSyncConfigurationNowIfNeeded();
};
return (

@ -30,6 +30,7 @@ import { clearSearch, search, updateSearchTerm } from '../../state/ducks/search'
import _ from 'lodash';
import { MessageRequestsBanner } from './MessageRequestsBanner';
import { BlockedNumberController } from '../../util';
import { forceSyncConfigurationNowIfNeeded } from '../../session/utils/syncUtils';
export interface Props {
searchTerm: string;
@ -305,7 +306,20 @@ export class LeftPaneMessageSection extends React.Component<Props, State> {
}}
onButtonClick={async () => {
// TODO: msgrequest iterate all convos and block
console.warn('Test');
// iterate all conversations and set all to approve then
const allConversations = getConversationController().getConversations();
let syncRequired = false;
_.forEach(allConversations, convo => {
if (convo.isApproved() !== true) {
convo.setIsApproved(true);
syncRequired = true;
}
});
if (syncRequired) {
// syncConfigurationIfNeeded(true);
await forceSyncConfigurationNowIfNeeded();
}
}}
searchTerm={searchTerm}
searchResults={searchResults}

@ -1161,6 +1161,11 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
public async addSingleMessage(messageAttributes: MessageAttributesOptionals, setToExpire = true) {
const model = new MessageModel(messageAttributes);
const isMe = messageAttributes.source === UserUtils.getOurPubKeyStrFromCache();
if (isMe) {
await this.setIsApproved(true);
}
// no need to trigger a UI update now, we trigger a messageAdded just below
const messageId = await model.commit(false);
model.set({ id: messageId });

@ -152,6 +152,7 @@ export async function handleConfigurationMessage(
envelope: EnvelopePlus,
configurationMessage: SignalService.ConfigurationMessage
): Promise<void> {
window?.log?.info('Handling configuration message');
const ourPubkey = UserUtils.getOurPubKeyStrFromCache();
if (!ourPubkey) {
return;

@ -377,7 +377,6 @@ export async function innerHandleContentMessage(
}
if (content.configurationMessage) {
// this one can be quite long (downloads profilePictures and everything, is do not block)
console.warn('@@config message received. contentmessage.ts');
void handleConfigurationMessage(
envelope,
content.configurationMessage as SignalService.ConfigurationMessage

@ -32,11 +32,14 @@ export async function updateProfileOneAtATime(
}
const oneAtaTimeStr = `updateProfileOneAtATime:${conversation.id}`;
return allowOnlyOneAtATime(oneAtaTimeStr, async () => {
return updateProfile(conversation, profile, profileKey);
return createOrUpdateProfile(conversation, profile, profileKey);
});
}
async function updateProfile(
/**
* Creates a new profile from the profile provided. Creates the profile if it doesn't exist.
*/
async function createOrUpdateProfile(
conversation: ConversationModel,
profile: SignalService.DataMessage.ILokiProfile,
profileKey?: Uint8Array | null // was any
@ -400,6 +403,7 @@ export async function isMessageDuplicate({
return false;
}
const filteredResult = [result].filter((m: any) => m.attributes.body === message.body);
console.warn({ filteredResult });
return filteredResult.some(m => isDuplicate(m, message, source));
} catch (error) {
window?.log?.error('isMessageDuplicate error:', Errors.toLogFormat(error));
@ -420,6 +424,7 @@ export const isDuplicate = (
Math.abs(m.attributes.sent_at - testedMessage.timestamp) <=
PUBLICCHAT_MIN_TIME_BETWEEN_DUPLICATE_MESSAGES;
debugger;
return sameUsername && sameText && timestampsSimilar;
};

@ -313,6 +313,9 @@ async function handleRegularMessage(
if (type === 'outgoing') {
handleSyncedReceipts(message, conversation);
// TODO: Can we assume sync receipts are always from linked device outgoings?
if (dataMessage.body !== 'unapprove') conversation.setIsApproved(true);
}
const conversationActiveAt = conversation.get('active_at');

@ -161,12 +161,11 @@ export function handleRequest(body: any, options: ReqOptions, messageHash: strin
incomingMessagePromises.push(promise);
}
// tslint:enable:cyclomatic-complexity max-func-body-length */
// ***********************************************************************
// ***********************************************************************
// ***********************************************************************
// tslint:enable:cyclomatic-complexity max-func-body-length */
/**
* Used in background.js
*/
export async function queueAllCached() {
const items = await getAllFromCache();
items.forEach(async item => {

@ -70,8 +70,9 @@ export const syncConfigurationIfNeeded = async (force: boolean = false) => {
};
export const forceSyncConfigurationNowIfNeeded = async (waitForMessageSent = false) =>
new Promise(resolve => {
const allConvos = getConversationController().getConversations();
new Promise(async resolve => {
// const allConvos = getConversationController().getConversations();
const allConvos = (await getAllConversations()).models;
// if we hang for more than 10sec, force resolve this promise.
setTimeout(() => {
@ -88,6 +89,7 @@ export const forceSyncConfigurationNowIfNeeded = async (waitForMessageSent = fal
resolve(true);
}
: undefined;
console.warn({configMessage});
void getMessageQueue().sendSyncMessage(configMessage, callback as any);
// either we resolve from the callback if we need to wait for it,
// or we don't want to wait, we resolve it here.

Loading…
Cancel
Save