Page MenuHomePhabricator

[lib] Function to dispatch edit message action
ClosedPublic

Authored by kuba on Mar 22 2023, 6:04 AM.
Tags
None
Referenced Files
Unknown Object (File)
Sat, Nov 23, 3:58 AM
Unknown Object (File)
Sat, Nov 23, 1:16 AM
Unknown Object (File)
Sat, Nov 23, 1:12 AM
Unknown Object (File)
Fri, Nov 22, 9:11 PM
Unknown Object (File)
Sun, Nov 10, 10:20 PM
Unknown Object (File)
Sun, Nov 10, 6:42 PM
Unknown Object (File)
Sun, Nov 10, 4:13 PM
Unknown Object (File)
Sun, Nov 10, 10:15 AM
Subscribers

Details

Summary

Added function to dispatch edit message action. It calls the edit message function, which communicates with the keyserver endpoint.

Test Plan

Called the function from both web and native (iOS), and checked if the keyserver endpoint is called successfully.

Diff Detail

Repository
rCOMM Comm
Lint
No Lint Coverage
Unit
No Test Coverage

Event Timeline

ashoat requested changes to this revision.Mar 22 2023, 3:14 PM
ashoat added inline comments.
lib/shared/edit-messages-utils.js
25

In what scenario will messageID not be set? It would be easier to understand how this function is used if you included it in the same diff where you introduced the first usage

54–55

Why are we doing this? Do we need this info in the reducer?

56

I think you forgot to remove this console.log

This revision now requires changes to proceed.Mar 22 2023, 3:14 PM
kuba marked 3 inline comments as done.

Address review comments

lib/shared/edit-messages-utils.js
25

In what scenario will messageID not be set? It would be easier to understand how this function is used if you included it in the same diff where you introduced the first usage

It is not currently used anywhere, but I use it locally to test it (tooltip-utils.js):

function useMessageEditAction(
  item: ChatMessageInfoItem,
  threadInfo: ThreadInfo,
): ?MessageTooltipAction {
  const { messageInfo } = item;

  const canEditMessage = useCanEditMessage(threadInfo, messageInfo);
  const editMessage = useEditMessage(messageInfo.id);

  return React.useMemo(() => {
    if (!canEditMessage) {
      return null;
    }

    if (item.messageInfoType !== 'composable') {
      return null;
    }

    const buttonContent = (
      <SWMansionIcon icon="edit-1" size={18} disableFill={false} />
    );
    const onClickEdit = () => {
      editMessage('Test ' + new Date().toLocaleString());
    };

    return {
      actionButtonContent: buttonContent,
      onClick: onClickEdit,
      label: 'Edit',
    };
  }, [canEditMessage, editMessage, item]);
}

Scenario: Here sometimes messageInfo.id can be sometimes undefined, and I cannot use condition here, before calling the useEditMessage, because of React Hook "useEditMessage" is called conditionally error.

lib/shared/edit-messages-utils.js
42–44 ↗(On Diff #24061)

Why are we doing this? What does it achieve?

38

Should we instead have an invariant here? From your code snippet, it looks like useCanEditMessage should prevent the callback from being called if !messageID

ashoat requested changes to this revision.Mar 24 2023, 10:54 AM
This revision now requires changes to proceed.Mar 24 2023, 10:54 AM
kuba marked 2 inline comments as done.

Added invariant & removed redundant error catching.

This revision is now accepted and ready to land.Mar 28 2023, 6:01 AM