Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3178830
D12746.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D12746.diff
View Options
diff --git a/lib/handlers/db-ops-handler.react.js b/lib/handlers/db-ops-handler.react.js
--- a/lib/handlers/db-ops-handler.react.js
+++ b/lib/handlers/db-ops-handler.react.js
@@ -41,7 +41,10 @@
if (ops) {
await processDBStoreOperations(ops);
if (ops.outboundP2PMessages && ops.outboundP2PMessages.length > 0) {
- processOutboundMessages();
+ const messageIDs = ops.outboundP2PMessages.map(
+ message => message.messageID,
+ );
+ processOutboundMessages(messageIDs);
}
}
dispatch({
diff --git a/lib/tunnelbroker/peer-to-peer-context.js b/lib/tunnelbroker/peer-to-peer-context.js
--- a/lib/tunnelbroker/peer-to-peer-context.js
+++ b/lib/tunnelbroker/peer-to-peer-context.js
@@ -24,7 +24,7 @@
import { getMessageForException } from '../utils/errors.js';
type PeerToPeerContextType = {
- +processOutboundMessages: () => void,
+ +processOutboundMessages: (messageIDs?: $ReadOnlyArray<string>) => void,
};
const PeerToPeerContext: React.Context<?PeerToPeerContextType> =
@@ -40,6 +40,7 @@
messageID: ?string,
) => Promise<void>,
identityContext: IdentityClientContextType,
+ messageIDs: ?$ReadOnlyArray<string>,
): Promise<void> {
const authMetadata = await identityContext.getAuthMetadata();
if (!authMetadata.deviceID || !authMetadata.userID || !authMetadata.userID) {
@@ -48,7 +49,12 @@
const { olmAPI, sqliteAPI } = getConfig();
await olmAPI.initializeCryptoAccount();
- const messages = await sqliteAPI.getAllOutboundP2PMessage();
+ let messages;
+ if (messageIDs) {
+ messages = await sqliteAPI.getOutboundP2PMessagesByID(messageIDs);
+ } else {
+ messages = await sqliteAPI.getAllOutboundP2PMessage();
+ }
const devicesMap: { [deviceID: string]: OutboundP2PMessage[] } = {};
for (const message: OutboundP2PMessage of messages) {
@@ -136,35 +142,41 @@
function PeerToPeerProvider(props: Props): React.Node {
const { children } = props;
- const restartPromise = React.useRef<boolean>(false);
+ const processingQueue = React.useRef<Array<?$ReadOnlyArray<string>>>([]);
const promiseRunning = React.useRef<boolean>(false);
const { sendMessage } = useTunnelbroker();
const identityContext = React.useContext(IdentityClientContext);
invariant(identityContext, 'Identity context should be set');
- const processOutboundMessages = React.useCallback(() => {
- if (!promiseRunning.current) {
- promiseRunning.current = true;
- void (async () => {
- do {
- restartPromise.current = false;
- try {
- await processOutboundP2PMessages(sendMessage, identityContext);
- } catch (e) {
- console.log(
- `Error processing outbound P2P messages: ${
- getMessageForException(e) ?? 'unknown'
- }`,
- );
- }
- } while (restartPromise.current);
- promiseRunning.current = false;
- })();
- } else {
- restartPromise.current = true;
- }
- }, [identityContext, sendMessage]);
+ const processOutboundMessages = React.useCallback(
+ (messageIDs?: $ReadOnlyArray<string>) => {
+ processingQueue.current.push(messageIDs);
+ if (!promiseRunning.current) {
+ promiseRunning.current = true;
+ void (async () => {
+ do {
+ const nextMessageIDs = processingQueue.current.shift();
+ try {
+ await processOutboundP2PMessages(
+ sendMessage,
+ identityContext,
+ nextMessageIDs,
+ );
+ } catch (e) {
+ console.log(
+ `Error processing outbound P2P messages: ${
+ getMessageForException(e) ?? 'unknown'
+ }`,
+ );
+ }
+ } while (processingQueue.current.length > 0);
+ promiseRunning.current = false;
+ })();
+ }
+ },
+ [identityContext, sendMessage],
+ );
const value: PeerToPeerContextType = React.useMemo(
() => ({
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Nov 9, 2:24 AM (18 h, 17 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2447632
Default Alt Text
D12746.diff (3 KB)
Attached To
Mode
D12746: [lib] Disable automatic retries of all messages and enable manual retries
Attached
Detach File
Event Timeline
Log In to Comment