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)
Thu, Dec 5, 1:57 AM
Unknown Object (File)
Thu, Dec 5, 1:57 AM
Unknown Object (File)
Wed, Dec 4, 3:22 AM
Unknown Object (File)
Wed, Dec 4, 3:22 AM
Unknown Object (File)
Wed, Dec 4, 3:22 AM
Unknown Object (File)
Wed, Dec 4, 3:22 AM
Unknown Object (File)
Sun, Dec 1, 1:25 AM
Unknown Object (File)
Tue, Nov 26, 7:29 PM
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 ↗(On Diff #23991)

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 ↗(On Diff #23991)

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

56 ↗(On Diff #23991)

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 ↗(On Diff #23991)

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

Why are we doing this? What does it achieve?

38 ↗(On Diff #23991)

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