You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

functions.ts 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import { IStore } from '../app/types';
  2. import { updateSettings } from '../base/settings/actions';
  3. /**
  4. * Appends a suffix to the display name.
  5. *
  6. * @param {string} displayName - The display name.
  7. * @param {string} suffix - Suffix that will be appended.
  8. * @returns {string} The formatted display name.
  9. */
  10. export function appendSuffix(displayName: string, suffix = ''): string {
  11. return `${displayName || suffix}${
  12. displayName && suffix && displayName !== suffix ? ` (${suffix})` : ''}`;
  13. }
  14. /**
  15. * Dispatches an action to update the local participant's display name. A
  16. * name must be entered for the action to dispatch.
  17. *
  18. * It returns a boolean to comply the Dialog behaviour:
  19. * {@code true} - the dialog should be closed.
  20. * {@code false} - the dialog should be left open.
  21. *
  22. * @param {Function} dispatch - Redux dispatch function.
  23. * @param {Function} onPostSubmit - Function to be invoked after a successful display name change.
  24. * @param {string} displayName - The display name to save.
  25. * @returns {boolean}
  26. */
  27. export function onSetDisplayName(dispatch: IStore['dispatch'], onPostSubmit?: Function) {
  28. return function(displayName: string) {
  29. if (!displayName?.trim()) {
  30. return false;
  31. }
  32. // Store display name in settings
  33. dispatch(updateSettings({
  34. displayName
  35. }));
  36. onPostSubmit?.();
  37. return true;
  38. };
  39. }