Page MenuHomePhabricator

D9537.diff
No OneTemporary

D9537.diff

diff --git a/keyserver/src/fetchers/message-fetchers.js b/keyserver/src/fetchers/message-fetchers.js
--- a/keyserver/src/fetchers/message-fetchers.js
+++ b/keyserver/src/fetchers/message-fetchers.js
@@ -6,6 +6,7 @@
sortMessageInfoList,
shimUnsupportedRawMessageInfos,
isInvalidSidebarSource,
+ isUnableToBeRenderedIndependently,
} from 'lib/shared/message-utils.js';
import { messageSpecs } from 'lib/shared/messages/message-specs.js';
import { getNotifCollapseKey } from 'lib/shared/notif-utils.js';
@@ -890,10 +891,17 @@
>();
for (const message of parsedResults) {
const { rawMessageInfo } = message;
- if (isInvalidSidebarSource(rawMessageInfo)) {
+ if (isUnableToBeRenderedIndependently(rawMessageInfo)) {
continue;
}
invariant(rawMessageInfo.id, 'rawMessageInfo.id should not be null');
+ // Flow fails to refine types correctly since
+ // isUnableToBeRenderedIndependently introspects into a message spec
+ // instead of directly checking message types. We use "continue" to avoid
+ // invalid messages, but Flow doesn't recognize this. The
+ // alternative is to check against every message type, but that defeats
+ // the purpose of a 'single source of truth.'
+ // $FlowFixMe
rawMessageInfoMap.set(rawMessageInfo.id, rawMessageInfo);
}
diff --git a/lib/shared/message-utils.js b/lib/shared/message-utils.js
--- a/lib/shared/message-utils.js
+++ b/lib/shared/message-utils.js
@@ -669,6 +669,12 @@
return !messageSpecs[message.type].canBePinned;
}
+function isUnableToBeRenderedIndependently(
+ message: RawMessageInfo | MessageInfo,
+): boolean {
+ return !messageSpecs[message.type].canBeRenderedIndependently;
+}
+
export {
localIDPrefix,
messageKey,
@@ -700,4 +706,5 @@
useNextLocalID,
isInvalidSidebarSource,
isInvalidPinSource,
+ isUnableToBeRenderedIndependently,
};
diff --git a/lib/shared/message-utils.test.js b/lib/shared/message-utils.test.js
--- a/lib/shared/message-utils.test.js
+++ b/lib/shared/message-utils.test.js
@@ -1,6 +1,10 @@
// @flow
-import { isInvalidSidebarSource, isInvalidPinSource } from './message-utils.js';
+import {
+ isInvalidSidebarSource,
+ isInvalidPinSource,
+ isUnableToBeRenderedIndependently,
+} from './message-utils.js';
import { messageSpecs } from '../shared/messages/message-specs.js';
import { messageTypes } from '../types/message-types-enum.js';
import type { RawSidebarSourceMessageInfo } from '../types/message-types.js';
@@ -730,20 +734,26 @@
expect(canBePinned).toBe(false);
});
- describe('canBeRenderedIndependently', () => {
+ describe('isUnableToBeRenderedIndependently & canBeRenderedIndependently', () => {
it('should return false for RawReactionMessageInfo', () => {
const messageSpec = messageSpecs[messageTypes.REACTION];
+ const shouldBeUnableToBeRenderedIndependently =
+ isUnableToBeRenderedIndependently(reactionMessageInfo);
const canBeRenderedIndependently = messageSpec.canBeRenderedIndependently;
+ expect(shouldBeUnableToBeRenderedIndependently).toBe(true);
expect(canBeRenderedIndependently).toBe(false);
});
it('should return false for RawEditMessageInfo', () => {
const messageSpec = messageSpecs[messageTypes.EDIT_MESSAGE];
+ const shouldBeUnableToBeRenderedIndependently =
+ isUnableToBeRenderedIndependently(editMessageInfo);
const canBeRenderedIndependently = messageSpec.canBeRenderedIndependently;
+ expect(shouldBeUnableToBeRenderedIndependently).toBe(true);
expect(canBeRenderedIndependently).toBe(false);
});
});

File Metadata

Mime Type
text/plain
Expires
Tue, Nov 26, 6:45 PM (21 h, 57 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2585793
Default Alt Text
D9537.diff (3 KB)

Event Timeline