@selfcommunity/react-ui 0.7.9-alpha.5 → 0.7.9-alpha.51

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (144) hide show
  1. package/lib/cjs/components/CategoryHeader/Skeleton.js +3 -2
  2. package/lib/cjs/components/ChangeGroupCover/ChangeGroupCover.js +24 -1
  3. package/lib/cjs/components/ChangeGroupPicture/ChangeGroupPicture.js +32 -11
  4. package/lib/cjs/components/Composer/Attributes/Attributes.js +3 -3
  5. package/lib/cjs/components/Composer/Composer.js +3 -5
  6. package/lib/cjs/components/Composer/Content/ContentPost/ContentPost.js +4 -3
  7. package/lib/cjs/components/Composer/Layer/AudienceLayer/AudienceLayer.d.ts +2 -3
  8. package/lib/cjs/components/Composer/Layer/AudienceLayer/AudienceLayer.js +8 -9
  9. package/lib/cjs/components/EditGroupButton/EditGroupButton.js +4 -0
  10. package/lib/cjs/components/FeedObject/FeedObject.d.ts +1 -0
  11. package/lib/cjs/components/FeedObject/FeedObject.js +23 -6
  12. package/lib/cjs/components/FeedUpdatesWidget/FeedUpdatesWidget.js +1 -1
  13. package/lib/cjs/components/Group/Group.d.ts +3 -0
  14. package/lib/cjs/components/Group/Group.js +16 -4
  15. package/lib/cjs/components/GroupAutocomplete/GroupAutocomplete.js +1 -1
  16. package/lib/cjs/components/GroupForm/GroupForm.js +31 -9
  17. package/lib/cjs/components/GroupHeader/GroupHeader.d.ts +6 -5
  18. package/lib/cjs/components/GroupHeader/GroupHeader.js +53 -11
  19. package/lib/cjs/components/GroupHeader/Skeleton.d.ts +2 -4
  20. package/lib/cjs/components/GroupHeader/Skeleton.js +10 -10
  21. package/lib/cjs/components/GroupInfoWidget/GroupInfoWidget.js +40 -7
  22. package/lib/cjs/components/GroupInviteButton/GroupInviteButton.js +33 -46
  23. package/lib/cjs/components/GroupInvitedWidget/GroupInvitedWidget.d.ts +74 -0
  24. package/lib/cjs/components/GroupInvitedWidget/GroupInvitedWidget.js +221 -0
  25. package/lib/cjs/components/GroupInvitedWidget/Skeleton.d.ts +22 -0
  26. package/lib/cjs/components/GroupInvitedWidget/Skeleton.js +38 -0
  27. package/lib/cjs/components/GroupInvitedWidget/constants.d.ts +1 -0
  28. package/lib/cjs/components/GroupInvitedWidget/constants.js +4 -0
  29. package/lib/cjs/components/GroupInvitedWidget/index.d.ts +4 -0
  30. package/lib/cjs/components/GroupInvitedWidget/index.js +8 -0
  31. package/lib/cjs/components/GroupMembersButton/GroupMembersButton.d.ts +5 -0
  32. package/lib/cjs/components/GroupMembersButton/GroupMembersButton.js +7 -2
  33. package/lib/cjs/components/GroupMembersWidget/GroupMembersWidget.js +25 -4
  34. package/lib/cjs/components/GroupRequestsWidget/GroupRequestsWidget.d.ts +11 -5
  35. package/lib/cjs/components/GroupRequestsWidget/GroupRequestsWidget.js +18 -7
  36. package/lib/cjs/components/GroupSettingsIconButton/GroupSettingsIconButton.d.ts +48 -0
  37. package/lib/cjs/components/GroupSettingsIconButton/GroupSettingsIconButton.js +145 -0
  38. package/lib/cjs/components/GroupSettingsIconButton/index.d.ts +3 -0
  39. package/lib/cjs/components/GroupSettingsIconButton/index.js +5 -0
  40. package/lib/cjs/components/GroupSubscribeButton/GroupSubscribeButton.d.ts +8 -3
  41. package/lib/cjs/components/GroupSubscribeButton/GroupSubscribeButton.js +31 -10
  42. package/lib/cjs/components/Groups/Groups.d.ts +19 -16
  43. package/lib/cjs/components/Groups/Groups.js +89 -85
  44. package/lib/cjs/components/Groups/Skeleton.d.ts +4 -0
  45. package/lib/cjs/components/Groups/Skeleton.js +2 -2
  46. package/lib/cjs/components/NavigationMenuIconButton/NavigationMenuIconButton.js +1 -1
  47. package/lib/cjs/components/NavigationToolbarMobile/NavigationToolbarMobile.d.ts +4 -0
  48. package/lib/cjs/components/NavigationToolbarMobile/NavigationToolbarMobile.js +2 -3
  49. package/lib/cjs/components/Notification/Group/Group.d.ts +15 -0
  50. package/lib/cjs/components/Notification/Group/Group.js +78 -0
  51. package/lib/cjs/components/Notification/Group/index.d.ts +3 -0
  52. package/lib/cjs/components/Notification/Group/index.js +5 -0
  53. package/lib/cjs/components/Notification/Notification.js +31 -1
  54. package/lib/cjs/components/Notification/PrivateMessage/PrivateMessage.js +16 -5
  55. package/lib/cjs/components/PrivateMessageComponent/PrivateMessageComponent.d.ts +1 -1
  56. package/lib/cjs/components/PrivateMessageComponent/PrivateMessageComponent.js +12 -7
  57. package/lib/cjs/components/PrivateMessageSnippetItem/PrivateMessageSnippetItem.js +11 -6
  58. package/lib/cjs/components/PrivateMessageSnippets/PrivateMessageSnippets.d.ts +3 -3
  59. package/lib/cjs/components/PrivateMessageSnippets/PrivateMessageSnippets.js +24 -6
  60. package/lib/cjs/components/PrivateMessageThread/PrivateMessageThread.d.ts +6 -1
  61. package/lib/cjs/components/PrivateMessageThread/PrivateMessageThread.js +45 -20
  62. package/lib/cjs/components/PrivateMessageThreadItem/PrivateMessageThreadItem.js +6 -0
  63. package/lib/cjs/components/SearchAutocomplete/SearchAutocomplete.js +22 -5
  64. package/lib/cjs/components/SnippetNotifications/SnippetNotifications.js +7 -0
  65. package/lib/cjs/components/ToastNotifications/ToastNotifications.js +7 -0
  66. package/lib/cjs/components/User/User.d.ts +6 -1
  67. package/lib/cjs/components/User/User.js +5 -4
  68. package/lib/cjs/constants/PubSub.d.ts +28 -0
  69. package/lib/cjs/constants/PubSub.js +22 -0
  70. package/lib/cjs/index.d.ts +5 -2
  71. package/lib/cjs/index.js +12 -4
  72. package/lib/esm/components/CategoryHeader/Skeleton.js +3 -2
  73. package/lib/esm/components/ChangeGroupCover/ChangeGroupCover.js +24 -1
  74. package/lib/esm/components/ChangeGroupPicture/ChangeGroupPicture.js +32 -11
  75. package/lib/esm/components/Composer/Attributes/Attributes.js +3 -3
  76. package/lib/esm/components/Composer/Composer.js +3 -5
  77. package/lib/esm/components/Composer/Content/ContentPost/ContentPost.js +4 -3
  78. package/lib/esm/components/Composer/Layer/AudienceLayer/AudienceLayer.d.ts +2 -3
  79. package/lib/esm/components/Composer/Layer/AudienceLayer/AudienceLayer.js +8 -9
  80. package/lib/esm/components/EditGroupButton/EditGroupButton.js +5 -1
  81. package/lib/esm/components/FeedObject/FeedObject.d.ts +1 -0
  82. package/lib/esm/components/FeedObject/FeedObject.js +24 -7
  83. package/lib/esm/components/FeedUpdatesWidget/FeedUpdatesWidget.js +1 -1
  84. package/lib/esm/components/Group/Group.d.ts +3 -0
  85. package/lib/esm/components/Group/Group.js +18 -6
  86. package/lib/esm/components/GroupAutocomplete/GroupAutocomplete.js +1 -1
  87. package/lib/esm/components/GroupForm/GroupForm.js +31 -9
  88. package/lib/esm/components/GroupHeader/GroupHeader.d.ts +6 -5
  89. package/lib/esm/components/GroupHeader/GroupHeader.js +55 -13
  90. package/lib/esm/components/GroupHeader/Skeleton.d.ts +2 -4
  91. package/lib/esm/components/GroupHeader/Skeleton.js +10 -10
  92. package/lib/esm/components/GroupInfoWidget/GroupInfoWidget.js +40 -7
  93. package/lib/esm/components/GroupInviteButton/GroupInviteButton.js +33 -46
  94. package/lib/esm/components/GroupInvitedWidget/GroupInvitedWidget.d.ts +74 -0
  95. package/lib/esm/components/GroupInvitedWidget/GroupInvitedWidget.js +218 -0
  96. package/lib/esm/components/GroupInvitedWidget/Skeleton.d.ts +22 -0
  97. package/lib/esm/components/GroupInvitedWidget/Skeleton.js +34 -0
  98. package/lib/esm/components/GroupInvitedWidget/constants.d.ts +1 -0
  99. package/lib/esm/components/GroupInvitedWidget/constants.js +1 -0
  100. package/lib/esm/components/GroupInvitedWidget/index.d.ts +4 -0
  101. package/lib/esm/components/GroupInvitedWidget/index.js +4 -0
  102. package/lib/esm/components/GroupMembersButton/GroupMembersButton.d.ts +5 -0
  103. package/lib/esm/components/GroupMembersButton/GroupMembersButton.js +8 -3
  104. package/lib/esm/components/GroupMembersWidget/GroupMembersWidget.js +26 -5
  105. package/lib/esm/components/GroupRequestsWidget/GroupRequestsWidget.d.ts +11 -5
  106. package/lib/esm/components/GroupRequestsWidget/GroupRequestsWidget.js +18 -7
  107. package/lib/esm/components/GroupSettingsIconButton/GroupSettingsIconButton.d.ts +48 -0
  108. package/lib/esm/components/GroupSettingsIconButton/GroupSettingsIconButton.js +142 -0
  109. package/lib/esm/components/GroupSettingsIconButton/index.d.ts +3 -0
  110. package/lib/esm/components/GroupSettingsIconButton/index.js +2 -0
  111. package/lib/esm/components/GroupSubscribeButton/GroupSubscribeButton.d.ts +8 -3
  112. package/lib/esm/components/GroupSubscribeButton/GroupSubscribeButton.js +32 -11
  113. package/lib/esm/components/Groups/Groups.d.ts +19 -16
  114. package/lib/esm/components/Groups/Groups.js +94 -90
  115. package/lib/esm/components/Groups/Skeleton.d.ts +4 -0
  116. package/lib/esm/components/Groups/Skeleton.js +2 -2
  117. package/lib/esm/components/NavigationMenuIconButton/NavigationMenuIconButton.js +1 -1
  118. package/lib/esm/components/NavigationToolbarMobile/NavigationToolbarMobile.d.ts +4 -0
  119. package/lib/esm/components/NavigationToolbarMobile/NavigationToolbarMobile.js +2 -3
  120. package/lib/esm/components/Notification/Group/Group.d.ts +15 -0
  121. package/lib/esm/components/Notification/Group/Group.js +75 -0
  122. package/lib/esm/components/Notification/Group/index.d.ts +3 -0
  123. package/lib/esm/components/Notification/Group/index.js +2 -0
  124. package/lib/esm/components/Notification/Notification.js +31 -1
  125. package/lib/esm/components/Notification/PrivateMessage/PrivateMessage.js +16 -5
  126. package/lib/esm/components/PrivateMessageComponent/PrivateMessageComponent.d.ts +1 -1
  127. package/lib/esm/components/PrivateMessageComponent/PrivateMessageComponent.js +13 -8
  128. package/lib/esm/components/PrivateMessageSnippetItem/PrivateMessageSnippetItem.js +11 -6
  129. package/lib/esm/components/PrivateMessageSnippets/PrivateMessageSnippets.d.ts +3 -3
  130. package/lib/esm/components/PrivateMessageSnippets/PrivateMessageSnippets.js +26 -8
  131. package/lib/esm/components/PrivateMessageThread/PrivateMessageThread.d.ts +6 -1
  132. package/lib/esm/components/PrivateMessageThread/PrivateMessageThread.js +47 -22
  133. package/lib/esm/components/PrivateMessageThreadItem/PrivateMessageThreadItem.js +7 -1
  134. package/lib/esm/components/SearchAutocomplete/SearchAutocomplete.js +22 -5
  135. package/lib/esm/components/SnippetNotifications/SnippetNotifications.js +7 -0
  136. package/lib/esm/components/ToastNotifications/ToastNotifications.js +7 -0
  137. package/lib/esm/components/User/User.d.ts +6 -1
  138. package/lib/esm/components/User/User.js +5 -4
  139. package/lib/esm/constants/PubSub.d.ts +28 -0
  140. package/lib/esm/constants/PubSub.js +19 -0
  141. package/lib/esm/index.d.ts +5 -2
  142. package/lib/esm/index.js +7 -4
  143. package/lib/umd/react-ui.js +1 -1
  144. package/package.json +6 -6
@@ -0,0 +1,15 @@
1
+ import { SCNotificationGroupActivityType } from '@selfcommunity/types';
2
+ import { NotificationItemProps } from '../../../shared/NotificationItem';
3
+ export interface NotificationGroupProps extends Pick<NotificationItemProps, Exclude<keyof NotificationItemProps, 'image' | 'disableTypography' | 'primary' | 'primaryTypographyProps' | 'secondary' | 'secondaryTypographyProps' | 'actions' | 'footer' | 'isNew'>> {
4
+ /**
5
+ * Notification obj
6
+ * @default null
7
+ */
8
+ notificationObject: SCNotificationGroupActivityType;
9
+ }
10
+ /**
11
+ * This component render the content of the notification of type group
12
+ * @constructor
13
+ * @param props
14
+ */
15
+ export default function GroupNotification(props: NotificationGroupProps): JSX.Element;
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const react_1 = tslib_1.__importStar(require("react"));
5
+ const styles_1 = require("@mui/material/styles");
6
+ const material_1 = require("@mui/material");
7
+ const react_core_1 = require("@selfcommunity/react-core");
8
+ const types_1 = require("@selfcommunity/types");
9
+ const react_intl_1 = require("react-intl");
10
+ const DateTimeAgo_1 = tslib_1.__importDefault(require("../../../shared/DateTimeAgo"));
11
+ const classnames_1 = tslib_1.__importDefault(require("classnames"));
12
+ const types_2 = require("../../../types");
13
+ const NotificationItem_1 = tslib_1.__importDefault(require("../../../shared/NotificationItem"));
14
+ const lab_1 = require("@mui/lab");
15
+ const UserDeletedSnackBar_1 = tslib_1.__importDefault(require("../../../shared/UserDeletedSnackBar"));
16
+ const UserAvatar_1 = tslib_1.__importDefault(require("../../../shared/UserAvatar"));
17
+ const constants_1 = require("../constants");
18
+ const classes = {
19
+ root: `${constants_1.PREFIX}-group-root`,
20
+ avatar: `${constants_1.PREFIX}-avatar`,
21
+ actions: `${constants_1.PREFIX}-actions`,
22
+ acceptButton: `${constants_1.PREFIX}-reply-button`,
23
+ activeAt: `${constants_1.PREFIX}-active-at`,
24
+ username: `${constants_1.PREFIX}-username`
25
+ };
26
+ const Root = (0, styles_1.styled)(NotificationItem_1.default, {
27
+ name: constants_1.PREFIX,
28
+ slot: 'GroupRoot'
29
+ })(() => ({}));
30
+ /**
31
+ * This component render the content of the notification of type group
32
+ * @constructor
33
+ * @param props
34
+ */
35
+ function GroupNotification(props) {
36
+ // PROPS
37
+ const { notificationObject, id = `n_${props.notificationObject['sid']}`, className, template = types_2.SCNotificationObjectTemplateType.DETAIL } = props, rest = tslib_1.__rest(props, ["notificationObject", "id", "className", "template"]);
38
+ // CONTEXT
39
+ const scRoutingContext = (0, react_core_1.useSCRouting)();
40
+ const scUserContext = (0, react_1.useContext)(react_core_1.SCUserContext);
41
+ const manager = scUserContext.managers.groups;
42
+ // STATE
43
+ const [status, setStatus] = (0, react_1.useState)(null);
44
+ const [openAlert, setOpenAlert] = (0, react_1.useState)(false);
45
+ // CONST
46
+ const isSnippetTemplate = template === types_2.SCNotificationObjectTemplateType.SNIPPET;
47
+ const isToastTemplate = template === types_2.SCNotificationObjectTemplateType.TOAST;
48
+ (0, react_1.useEffect)(() => {
49
+ setStatus(manager.subscriptionStatus(notificationObject.group));
50
+ }, [manager.subscriptionStatus, notificationObject.group]);
51
+ // RENDER
52
+ if (isSnippetTemplate || isToastTemplate) {
53
+ return (react_1.default.createElement(Root, Object.assign({ id: id, className: (0, classnames_1.default)(classes.root, className, `${constants_1.PREFIX}-${template}`), template: template, isNew: notificationObject.is_new, disableTypography: true, image: react_1.default.createElement(react_core_1.Link, Object.assign({}, (!notificationObject.user.deleted && {
54
+ to: scRoutingContext.url(react_core_1.SCRoutes.USER_PROFILE_ROUTE_NAME, notificationObject.user)
55
+ }), { onClick: notificationObject.user.deleted ? () => setOpenAlert(true) : null }),
56
+ react_1.default.createElement(UserAvatar_1.default, { hide: !notificationObject.user.community_badge, smaller: true },
57
+ react_1.default.createElement(material_1.Avatar, { alt: notificationObject.user.username, variant: "circular", src: notificationObject.user.avatar, classes: { root: classes.avatar } }))), primary: react_1.default.createElement(material_1.Box, null,
58
+ react_1.default.createElement(react_core_1.Link, Object.assign({}, (!notificationObject.user.deleted && {
59
+ to: scRoutingContext.url(react_core_1.SCRoutes.USER_PROFILE_ROUTE_NAME, notificationObject.user)
60
+ }), { onClick: notificationObject.user.deleted ? () => setOpenAlert(true) : null, className: classes.username }), notificationObject.user.username),
61
+ ' ',
62
+ react_1.default.createElement(react_intl_1.FormattedMessage, { id: `ui.notification.${notificationObject.type}`, defaultMessage: `ui.notification.${notificationObject.type}`, values: {
63
+ group: notificationObject.group.name,
64
+ link: (...chunks) => react_1.default.createElement(react_core_1.Link, { to: scRoutingContext.url(react_core_1.SCRoutes.GROUP_ROUTE_NAME, notificationObject.group) }, chunks)
65
+ } })), footer: isToastTemplate && (react_1.default.createElement(material_1.Stack, { direction: "row", justifyContent: "space-between", alignItems: "center", spacing: 2 },
66
+ react_1.default.createElement(DateTimeAgo_1.default, { date: notificationObject.active_at }),
67
+ status && status !== types_1.SCGroupSubscriptionStatusType.SUBSCRIBED && (react_1.default.createElement(material_1.Typography, { color: "primary" },
68
+ react_1.default.createElement(react_core_1.Link, { to: scRoutingContext.url(react_core_1.SCRoutes.GROUP_ROUTE_NAME, notificationObject.group) },
69
+ react_1.default.createElement(react_intl_1.FormattedMessage, { id: "ui.groupSubscribeButton.accept", defaultMessage: "ui.groupSubscribeButton.accept" })))))) }, rest)));
70
+ }
71
+ return (react_1.default.createElement(react_1.default.Fragment, null,
72
+ react_1.default.createElement(Root, Object.assign({ id: id, className: (0, classnames_1.default)(classes.root, className, `${constants_1.PREFIX}-${template}`), template: template, isNew: notificationObject.is_new, disableTypography: true, actions: react_1.default.createElement(material_1.Stack, { direction: "row", justifyContent: "space-between", alignItems: "center", spacing: 2 },
73
+ react_1.default.createElement(DateTimeAgo_1.default, { date: notificationObject.active_at, className: classes.activeAt }),
74
+ status && status !== types_1.SCGroupSubscriptionStatusType.SUBSCRIBED && (react_1.default.createElement(lab_1.LoadingButton, { color: 'primary', variant: "outlined", size: "small", classes: { root: classes.acceptButton }, component: react_core_1.Link, loading: scUserContext.user ? status === null || manager.isLoading(notificationObject.group) : null, to: scRoutingContext.url(react_core_1.SCRoutes.GROUP_ROUTE_NAME, notificationObject.group) },
75
+ react_1.default.createElement(react_intl_1.FormattedMessage, { id: "ui.groupSubscribeButton.accept", defaultMessage: "ui.groupSubscribeButton.accept" })))) }, rest)),
76
+ openAlert && react_1.default.createElement(UserDeletedSnackBar_1.default, { open: openAlert, handleClose: () => setOpenAlert(false) })));
77
+ }
78
+ exports.default = GroupNotification;
@@ -0,0 +1,3 @@
1
+ import GroupNotification, { NotificationGroupProps } from './Group';
2
+ export default GroupNotification;
3
+ export { NotificationGroupProps };
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const Group_1 = tslib_1.__importDefault(require("./Group"));
5
+ exports.default = Group_1.default;
@@ -35,6 +35,7 @@ const types_1 = require("@selfcommunity/types");
35
35
  const UserDeletedSnackBar_1 = tslib_1.__importDefault(require("../../shared/UserDeletedSnackBar"));
36
36
  const UserAvatar_1 = tslib_1.__importDefault(require("../../shared/UserAvatar"));
37
37
  const constants_1 = require("./constants");
38
+ const Group_1 = tslib_1.__importDefault(require("./Group"));
38
39
  const messages = (0, react_intl_1.defineMessages)({
39
40
  receivePrivateMessage: {
40
41
  id: 'ui.notification.receivePrivateMessage',
@@ -151,7 +152,7 @@ function UserNotification(inProps) {
151
152
  }
152
153
  /**
153
154
  * Handles vote
154
- * @param comment
155
+ * @param index
155
156
  */
156
157
  const handleVote = (index) => {
157
158
  return (contribution) => {
@@ -196,6 +197,29 @@ function UserNotification(inProps) {
196
197
  b: (...chunks) => react_1.default.createElement("strong", null, chunks)
197
198
  })) }));
198
199
  }
200
+ /**
201
+ * Group notifications header
202
+ */
203
+ if (notificationObject.aggregated &&
204
+ (notificationObject.aggregated[0].type === types_1.SCNotificationTypologyType.USER_INVITED_TO_JOIN_GROUP ||
205
+ notificationObject.aggregated[0].type === types_1.SCNotificationTypologyType.USER_ACCEPTED_TO_JOIN_GROUP ||
206
+ notificationObject.aggregated[0].type === types_1.SCNotificationTypologyType.USER_ADDED_TO_GROUP ||
207
+ notificationObject.aggregated[0].type === types_1.SCNotificationTypologyType.USER_REQUESTED_TO_JOIN_GROUP)) {
208
+ let groupNotification = notificationObject.aggregated[0];
209
+ return (react_1.default.createElement(material_1.CardHeader, { className: classes.header, avatar: react_1.default.createElement(react_core_1.Link, Object.assign({}, (!groupNotification.user.deleted && {
210
+ to: scRoutingContext.url(react_core_1.SCRoutes.USER_PROFILE_ROUTE_NAME, groupNotification.user)
211
+ }), { onClick: groupNotification.user.deleted ? () => setOpenAlert(true) : null }),
212
+ react_1.default.createElement(UserAvatar_1.default, { hide: !groupNotification.user.community_badge, smaller: true },
213
+ react_1.default.createElement(material_1.Avatar, { className: classes.avatar, alt: groupNotification.user.username, variant: "circular", src: groupNotification.user.avatar }))), titleTypographyProps: { className: classes.title, variant: 'subtitle1' }, title: react_1.default.createElement(react_1.default.Fragment, null,
214
+ react_1.default.createElement(react_core_1.Link, Object.assign({}, (!groupNotification.user.deleted && {
215
+ to: scRoutingContext.url(react_core_1.SCRoutes.USER_PROFILE_ROUTE_NAME, groupNotification.user)
216
+ }), { onClick: groupNotification.user.deleted ? () => setOpenAlert(true) : null, className: classes.username }), groupNotification.user.username),
217
+ ' ',
218
+ react_1.default.createElement(react_intl_1.FormattedMessage, { id: `ui.notification.${notificationObject.aggregated[0].type}`, defaultMessage: `ui.notification.${notificationObject.aggregated[0].type}`, values: {
219
+ group: groupNotification.group.name,
220
+ link: (...chunks) => react_1.default.createElement(react_core_1.Link, { to: scRoutingContext.url(react_core_1.SCRoutes.GROUP_ROUTE_NAME, groupNotification.group) }, chunks)
221
+ } })) }));
222
+ }
199
223
  /**
200
224
  * Comment, NestedComment, Follow Contribution header
201
225
  */
@@ -278,6 +302,12 @@ function UserNotification(inProps) {
278
302
  else if (n.type === types_1.SCNotificationTypologyType.CONTRIBUTION) {
279
303
  return react_1.default.createElement(Contribution_1.default, { notificationObject: n, key: i, onVote: handleVote(i) });
280
304
  }
305
+ else if (n.type === types_1.SCNotificationTypologyType.USER_ADDED_TO_GROUP ||
306
+ n.type === types_1.SCNotificationTypologyType.USER_INVITED_TO_JOIN_GROUP ||
307
+ n.type === types_1.SCNotificationTypologyType.USER_ACCEPTED_TO_JOIN_GROUP ||
308
+ n.type === types_1.SCNotificationTypologyType.USER_REQUESTED_TO_JOIN_GROUP) {
309
+ return react_1.default.createElement(Group_1.default, { notificationObject: n, key: i });
310
+ }
281
311
  return null;
282
312
  }
283
313
  /**
@@ -41,6 +41,7 @@ const Root = (0, styles_1.styled)(NotificationItem_1.default, {
41
41
  * @param props
42
42
  */
43
43
  function PrivateMessageNotification(props) {
44
+ var _a, _b, _c, _d, _e;
44
45
  // PROPS
45
46
  const { notificationObject, id = `n_${props.notificationObject['sid']}`, className, template = types_1.SCNotificationObjectTemplateType.DETAIL } = props, rest = tslib_1.__rest(props, ["notificationObject", "id", "className", "template"]);
46
47
  // CONTEXT
@@ -91,7 +92,9 @@ function PrivateMessageNotification(props) {
91
92
  react_1.default.createElement(react_intl_1.FormattedMessage, { id: 'ui.userToastNotifications.privateMessage.sentMessage', defaultMessage: 'ui.userToastNotifications.privateMessage.sentMessage' }),
92
93
  ":",
93
94
  react_1.default.createElement(material_1.Box, { className: classes.messageWrap },
94
- react_1.default.createElement(react_core_1.Link, { to: scRoutingContext.url(react_core_1.SCRoutes.USER_PRIVATE_MESSAGES_ROUTE_NAME, notificationObject.message.sender), className: classes.message },
95
+ react_1.default.createElement(react_core_1.Link, { to: ((_a = notificationObject.message) === null || _a === void 0 ? void 0 : _a.group)
96
+ ? scRoutingContext.url(react_core_1.SCRoutes.GROUP_MESSAGES_ROUTE_NAME, notificationObject.message.group)
97
+ : scRoutingContext.url(react_core_1.SCRoutes.USER_PRIVATE_MESSAGES_ROUTE_NAME, notificationObject.message.sender), className: classes.message },
95
98
  react_1.default.createElement(material_1.Typography, { variant: "body2", dangerouslySetInnerHTML: { __html: notificationObject.message.message } }))))),
96
99
  isSnippetTemplate && (react_1.default.createElement(material_1.Box, null,
97
100
  react_1.default.createElement(material_1.Typography, { component: "div", color: "inherit" },
@@ -99,13 +102,17 @@ function PrivateMessageNotification(props) {
99
102
  to: scRoutingContext.url(react_core_1.SCRoutes.USER_PROFILE_ROUTE_NAME, notificationObject.message.sender)
100
103
  }), { onClick: notificationObject.message.sender.deleted ? () => setOpenAlert(true) : null, className: classes.username }), notificationObject.message.sender.username),
101
104
  ' ',
102
- react_1.default.createElement(react_core_1.Link, { to: scRoutingContext.url(react_core_1.SCRoutes.USER_PRIVATE_MESSAGES_ROUTE_NAME, notificationObject.message.sender), className: classes.messageLabel }, intl.formatMessage(messages.receivePrivateMessage, {
105
+ react_1.default.createElement(react_core_1.Link, { to: ((_b = notificationObject.message) === null || _b === void 0 ? void 0 : _b.group)
106
+ ? scRoutingContext.url(react_core_1.SCRoutes.GROUP_MESSAGES_ROUTE_NAME, notificationObject.message.group)
107
+ : scRoutingContext.url(react_core_1.SCRoutes.USER_PRIVATE_MESSAGES_ROUTE_NAME, notificationObject.message.sender), className: classes.messageLabel }, intl.formatMessage(messages.receivePrivateMessage, {
103
108
  total: 1,
104
109
  b: (...chunks) => react_1.default.createElement("strong", null, chunks)
105
110
  })))))), footer: isToastTemplate && (react_1.default.createElement(material_1.Stack, { direction: "row", justifyContent: "space-between", alignItems: "center", spacing: 2 },
106
111
  react_1.default.createElement(DateTimeAgo_1.default, { date: notificationObject.active_at }),
107
112
  react_1.default.createElement(material_1.Typography, { color: "primary" },
108
- react_1.default.createElement(react_core_1.Link, { to: scRoutingContext.url(react_core_1.SCRoutes.USER_PRIVATE_MESSAGES_ROUTE_NAME, notificationObject.message.sender) }, scUserContext.user && follower ? (react_1.default.createElement(react_intl_1.FormattedMessage, { id: "ui.userToastNotifications.replyMessage", defaultMessage: 'ui.userToastNotifications.replyMessage' })) : (react_1.default.createElement(react_intl_1.FormattedMessage, { id: "ui.userToastNotifications.viewMessage", defaultMessage: 'ui.userToastNotifications.viewMessage' })))))) }, rest)));
113
+ react_1.default.createElement(react_core_1.Link, { to: ((_c = notificationObject.message) === null || _c === void 0 ? void 0 : _c.group)
114
+ ? scRoutingContext.url(react_core_1.SCRoutes.GROUP_MESSAGES_ROUTE_NAME, notificationObject.message.group)
115
+ : scRoutingContext.url(react_core_1.SCRoutes.USER_PRIVATE_MESSAGES_ROUTE_NAME, notificationObject.message.sender) }, scUserContext.user && follower ? (react_1.default.createElement(react_intl_1.FormattedMessage, { id: "ui.userToastNotifications.replyMessage", defaultMessage: 'ui.userToastNotifications.replyMessage' })) : (react_1.default.createElement(react_intl_1.FormattedMessage, { id: "ui.userToastNotifications.viewMessage", defaultMessage: 'ui.userToastNotifications.viewMessage' })))))) }, rest)));
109
116
  }
110
117
  return (react_1.default.createElement(react_1.default.Fragment, null,
111
118
  react_1.default.createElement(Root, Object.assign({ id: id, className: (0, classnames_1.default)(classes.root, className, `${constants_1.PREFIX}-${template}`), template: template, isNew: notificationObject.is_new, disableTypography: true, actions: react_1.default.createElement(material_1.Stack, { direction: "row", justifyContent: "space-between", alignItems: "center", spacing: 2 },
@@ -114,8 +121,12 @@ function PrivateMessageNotification(props) {
114
121
  ? null
115
122
  : scUserContext.user
116
123
  ? follower === null || manager.isLoading(notificationObject.message.sender)
117
- : null, to: scRoutingContext.url(react_core_1.SCRoutes.USER_PRIVATE_MESSAGES_ROUTE_NAME, notificationObject.message.sender) }, scUserContext.user && follower ? (react_1.default.createElement(react_intl_1.FormattedMessage, { id: "ui.notification.privateMessage.btnReplyLabel", defaultMessage: "ui.notification.privateMessage.btnReplyLabel" })) : (react_1.default.createElement(react_intl_1.FormattedMessage, { id: "ui.notification.privateMessage.btnViewLabel", defaultMessage: "ui.notification.privateMessage.btnViewLabel" })))), primary: react_1.default.createElement(material_1.Box, { className: classes.messageWrap },
118
- react_1.default.createElement(react_core_1.Link, { to: scRoutingContext.url(react_core_1.SCRoutes.USER_PRIVATE_MESSAGES_ROUTE_NAME, notificationObject.message.sender), className: classes.message },
124
+ : null, to: ((_d = notificationObject.message) === null || _d === void 0 ? void 0 : _d.group)
125
+ ? scRoutingContext.url(react_core_1.SCRoutes.GROUP_MESSAGES_ROUTE_NAME, notificationObject.message.group)
126
+ : scRoutingContext.url(react_core_1.SCRoutes.USER_PRIVATE_MESSAGES_ROUTE_NAME, notificationObject.message.sender) }, scUserContext.user && follower ? (react_1.default.createElement(react_intl_1.FormattedMessage, { id: "ui.notification.privateMessage.btnReplyLabel", defaultMessage: "ui.notification.privateMessage.btnReplyLabel" })) : (react_1.default.createElement(react_intl_1.FormattedMessage, { id: "ui.notification.privateMessage.btnViewLabel", defaultMessage: "ui.notification.privateMessage.btnViewLabel" })))), primary: react_1.default.createElement(material_1.Box, { className: classes.messageWrap },
127
+ react_1.default.createElement(react_core_1.Link, { to: ((_e = notificationObject.message) === null || _e === void 0 ? void 0 : _e.group)
128
+ ? scRoutingContext.url(react_core_1.SCRoutes.GROUP_MESSAGES_ROUTE_NAME, notificationObject.message.group)
129
+ : scRoutingContext.url(react_core_1.SCRoutes.USER_PRIVATE_MESSAGES_ROUTE_NAME, notificationObject.message.sender), className: classes.message },
119
130
  react_1.default.createElement(material_1.Typography, { variant: "body2", dangerouslySetInnerHTML: { __html: notificationObject.message.message } }))) }, rest)),
120
131
  openAlert && react_1.default.createElement(UserDeletedSnackBar_1.default, { open: openAlert, handleClose: () => setOpenAlert(false) })));
121
132
  }
@@ -8,7 +8,7 @@ export interface PrivateMessageComponentProps {
8
8
  * Handler on message click
9
9
  * @default null
10
10
  */
11
- onItemClick?: (id: any) => void;
11
+ onItemClick?: (id: any, type: any) => void;
12
12
  /**
13
13
  * Handler on single message open
14
14
  * @default null
@@ -67,6 +67,7 @@ function PrivateMessageComponent(inProps) {
67
67
  const isMobile = (0, material_1.useMediaQuery)(theme.breakpoints.down('md'));
68
68
  const [layout, setLayout] = (0, react_1.useState)('default');
69
69
  const [obj, setObj] = (0, react_1.useState)(id !== null && id !== void 0 ? id : null);
70
+ const [type, setType] = (0, react_1.useState)(null);
70
71
  const isNew = obj && obj === types_1.SCPrivateMessageStatusType.NEW;
71
72
  const [openNewMessage, setOpenNewMessage] = (0, react_1.useState)(isNew !== null && isNew !== void 0 ? isNew : false);
72
73
  const mobileSnippetsView = (layout === 'default' && !obj) || (layout === 'mobile' && !obj);
@@ -88,10 +89,12 @@ function PrivateMessageComponent(inProps) {
88
89
  /**
89
90
  * Handles thread opening on click
90
91
  * @param item
92
+ * @param type
91
93
  */
92
- const handleThreadOpening = (item) => {
93
- onItemClick && onItemClick(messageReceiver(item, authUserId));
94
- setObj(messageReceiver(item, authUserId));
94
+ const handleThreadOpening = (item, type) => {
95
+ onItemClick && onItemClick(item.group ? item.group.id : messageReceiver(item, authUserId), type);
96
+ setType(type);
97
+ setObj(item.group ? item : messageReceiver(item, authUserId));
95
98
  setOpenNewMessage(false);
96
99
  };
97
100
  /**
@@ -107,7 +110,8 @@ function PrivateMessageComponent(inProps) {
107
110
  const handleOpenNewMessage = () => {
108
111
  setOpenNewMessage(!openNewMessage);
109
112
  setObj(types_1.SCPrivateMessageStatusType.NEW);
110
- onItemClick && onItemClick(types_1.SCPrivateMessageStatusType.NEW);
113
+ setType(types_1.SCPrivateMessageType.NEW);
114
+ onItemClick && onItemClick(types_1.SCPrivateMessageStatusType.NEW, types_1.SCPrivateMessageType.NEW);
111
115
  };
112
116
  /**
113
117
  * Handles new messages open from user profile page or notifications section
@@ -123,13 +127,14 @@ function PrivateMessageComponent(inProps) {
123
127
  id && setLayout('mobile');
124
128
  setOpenNewMessage(false);
125
129
  setObj(null);
130
+ setType(null);
126
131
  onThreadBack && onThreadBack();
127
132
  };
128
133
  /**
129
134
  * Handles state update when a new message is sent
130
135
  */
131
136
  const handleOnNewMessageSent = (msg, isOne) => {
132
- onItemClick && onItemClick(isOne ? messageReceiver(msg, authUserId) : '');
137
+ onItemClick && onItemClick(isOne ? messageReceiver(msg, authUserId) : '', msg.group ? types_1.SCPrivateMessageType.GROUP : types_1.SCPrivateMessageType.USER);
133
138
  setObj(isOne ? messageReceiver(msg, authUserId) : null);
134
139
  setOpenNewMessage(false);
135
140
  };
@@ -149,14 +154,14 @@ function PrivateMessageComponent(inProps) {
149
154
  onSnippetClick: handleThreadOpening,
150
155
  onNewMessageClick: handleOpenNewMessage,
151
156
  onDeleteConfirm: handleDeleteThread
152
- }, userObj: obj, clearSearch: clear, elevation: 0 })));
157
+ }, threadObj: obj, clearSearch: clear, elevation: 0 })));
153
158
  }
154
159
  /**
155
160
  * Renders thread section
156
161
  */
157
162
  function renderThread() {
158
163
  return (react_1.default.createElement(material_1.Grid, { item: true, xs: 12, md: 7, className: (0, classnames_1.default)(classes.threadBox, { [classes.hide]: isMobile && mobileSnippetsView }) },
159
- react_1.default.createElement(PrivateMessageThread_1.default, { userObj: obj, openNewMessage: openNewMessage, onNewMessageClose: handleMessageBack, onNewMessageSent: handleOnNewMessageSent, onSingleMessageOpen: handleSingleMessage, elevation: 0 })));
164
+ react_1.default.createElement(PrivateMessageThread_1.default, { threadObj: obj, type: type, openNewMessage: openNewMessage, onNewMessageClose: handleMessageBack, onNewMessageSent: handleOnNewMessageSent, onSingleMessageOpen: handleSingleMessage, elevation: 0 })));
160
165
  }
161
166
  /**
162
167
  * Renders the component (if not hidden by autoHide prop)
@@ -74,10 +74,12 @@ function PrivateMessageSnippetItem(inProps) {
74
74
  // STATE
75
75
  const hasBadge = () => {
76
76
  var _a;
77
- if ((message === null || message === void 0 ? void 0 : message.receiver.id) !== ((_a = scUserContext === null || scUserContext === void 0 ? void 0 : scUserContext.user) === null || _a === void 0 ? void 0 : _a.id)) {
78
- return message === null || message === void 0 ? void 0 : message.receiver.community_badge;
77
+ if (message.receiver) {
78
+ if ((message === null || message === void 0 ? void 0 : message.receiver.id) !== ((_a = scUserContext === null || scUserContext === void 0 ? void 0 : scUserContext.user) === null || _a === void 0 ? void 0 : _a.id)) {
79
+ return message === null || message === void 0 ? void 0 : message.receiver.community_badge;
80
+ }
81
+ return message === null || message === void 0 ? void 0 : message.sender.community_badge;
79
82
  }
80
- return message === null || message === void 0 ? void 0 : message.sender.community_badge;
81
83
  };
82
84
  if (!message) {
83
85
  return react_1.default.createElement(Skeleton_1.default, { elevation: 0 });
@@ -88,10 +90,13 @@ function PrivateMessageSnippetItem(inProps) {
88
90
  return (react_1.default.createElement(Root, Object.assign({ className: (0, classnames_1.default)(classes.root, className) }, rest, { secondaryAction: secondaryAction, disablePadding: true }),
89
91
  react_1.default.createElement(material_1.ListItemButton, { onClick: onItemClick, classes: { root: (0, classnames_1.default)({ [classes.unread]: message.thread_status === types_1.SCPrivateMessageStatusType.NEW }) } },
90
92
  react_1.default.createElement(material_1.ListItemAvatar, null,
91
- react_1.default.createElement(UserAvatar_1.default, { hide: !hasBadge() },
92
- react_1.default.createElement(material_1.Avatar, { alt: ((_a = scUserContext === null || scUserContext === void 0 ? void 0 : scUserContext.user) === null || _a === void 0 ? void 0 : _a.username) === message.receiver.username ? message.sender.username : message.receiver.username, src: ((_b = scUserContext === null || scUserContext === void 0 ? void 0 : scUserContext.user) === null || _b === void 0 ? void 0 : _b.username) === message.receiver.username ? message.sender.avatar : message.receiver.avatar }))),
93
+ react_1.default.createElement(UserAvatar_1.default, { hide: !hasBadge() }, message.group ? (react_1.default.createElement(material_1.Avatar, { alt: message.group.name, src: message.group.image_big })) : (react_1.default.createElement(material_1.Avatar, { alt: ((_a = scUserContext === null || scUserContext === void 0 ? void 0 : scUserContext.user) === null || _a === void 0 ? void 0 : _a.username) === message.receiver.username ? message.sender.username : message.receiver.username, src: ((_b = scUserContext === null || scUserContext === void 0 ? void 0 : scUserContext.user) === null || _b === void 0 ? void 0 : _b.username) === message.receiver.username ? message.sender.avatar : message.receiver.avatar })))),
93
94
  react_1.default.createElement(material_1.ListItemText, { primary: react_1.default.createElement(react_1.default.Fragment, null,
94
- react_1.default.createElement(material_1.Typography, { component: "span", className: classes.username }, ((_c = scUserContext === null || scUserContext === void 0 ? void 0 : scUserContext.user) === null || _c === void 0 ? void 0 : _c.username) === message.receiver.username ? message.sender.username : message.receiver.username),
95
+ react_1.default.createElement(material_1.Typography, { component: "span", className: classes.username }, message.group
96
+ ? message.group.name
97
+ : ((_c = scUserContext === null || scUserContext === void 0 ? void 0 : scUserContext.user) === null || _c === void 0 ? void 0 : _c.username) === message.receiver.username
98
+ ? message.sender.username
99
+ : message.receiver.username),
95
100
  hasBadge() && preferences && (react_1.default.createElement(material_1.Chip, { component: "span", className: classes.badgeLabel, size: "small", label: preferences[react_core_1.SCPreferences.STAFF_STAFF_BADGE_LABEL] })),
96
101
  react_1.default.createElement(material_1.Typography, { color: "secondary", className: classes.time, component: "span" }, `${intl.formatDate(message.last_message_at, {
97
102
  day: '2-digit',
@@ -20,7 +20,7 @@ export interface PrivateMessageSnippetsProps extends CardProps {
20
20
  *
21
21
  */
22
22
  snippetActions?: {
23
- onSnippetClick?: (msg: any) => void;
23
+ onSnippetClick?: (msg: any, type: any) => void;
24
24
  onNewMessageClick?: () => void;
25
25
  onDeleteConfirm?: (msg: any) => void;
26
26
  };
@@ -29,10 +29,10 @@ export interface PrivateMessageSnippetsProps extends CardProps {
29
29
  */
30
30
  [p: string]: any;
31
31
  /**
32
- * thread user object
32
+ * thread user/ group object
33
33
  * @default null
34
34
  */
35
- userObj?: any;
35
+ threadObj?: any;
36
36
  }
37
37
  /**
38
38
  * > API documentation for the Community-JS PrivateMessageSnippets component. Learn about the available props and the CSS API.
@@ -71,25 +71,30 @@ function PrivateMessageSnippets(inProps) {
71
71
  props: inProps,
72
72
  name: constants_1.PREFIX
73
73
  });
74
- const { className = null, userObj = null, snippetActions, clearSearch } = props, rest = tslib_1.__rest(props, ["className", "userObj", "snippetActions", "clearSearch"]);
74
+ const { className = null, threadObj = null, snippetActions, clearSearch } = props, rest = tslib_1.__rest(props, ["className", "threadObj", "snippetActions", "clearSearch"]);
75
75
  // STATE
76
76
  const theme = (0, material_1.useTheme)();
77
77
  const isMobile = (0, useMediaQuery_1.default)(theme.breakpoints.down('md'));
78
78
  const { data, updateSnippets } = (0, react_core_1.useSCFetchPrivateMessageSnippets)({ cacheStrategy: utils_1.CacheStrategies.CACHE_FIRST });
79
79
  const [search, setSearch] = (0, react_1.useState)('');
80
- const isObj = typeof userObj === 'object';
80
+ const isObj = typeof threadObj === 'object';
81
81
  const scUserContext = (0, react_1.useContext)(react_core_1.SCUserContext);
82
82
  const authUserId = scUserContext.user ? scUserContext.user.id : null;
83
+ const [type, setType] = (0, react_1.useState)(null);
83
84
  // INTL
84
85
  const intl = (0, react_intl_1.useIntl)();
85
86
  // REFS
86
87
  const refreshSubscription = (0, react_1.useRef)(null);
87
88
  // CONST
88
89
  const filteredSnippets = data.snippets.filter((el) => {
90
+ var _a;
89
91
  if (search === '') {
90
92
  return el;
91
93
  }
92
- else if (el.receiver.id === authUserId) {
94
+ else if (el.group) {
95
+ return el.group.slug.includes(search.toLowerCase());
96
+ }
97
+ else if (((_a = el === null || el === void 0 ? void 0 : el.receiver) === null || _a === void 0 ? void 0 : _a.id) === authUserId) {
93
98
  return el.sender.username.includes(search.toLowerCase());
94
99
  }
95
100
  return el.receiver.username.includes(search.toLowerCase());
@@ -101,6 +106,18 @@ function PrivateMessageSnippets(inProps) {
101
106
  }
102
107
  return ((_b = item === null || item === void 0 ? void 0 : item.receiver) === null || _b === void 0 ? void 0 : _b.id) !== loggedUserId ? (_c = item === null || item === void 0 ? void 0 : item.receiver) === null || _c === void 0 ? void 0 : _c.id : (_d = item === null || item === void 0 ? void 0 : item.sender) === null || _d === void 0 ? void 0 : _d.id;
103
108
  };
109
+ const isSelected = (0, react_1.useMemo)(() => {
110
+ return (message) => {
111
+ var _a, _b;
112
+ if (threadObj && type === types_1.SCPrivateMessageType.GROUP) {
113
+ return ((_a = message === null || message === void 0 ? void 0 : message.group) === null || _a === void 0 ? void 0 : _a.id) === (isObj ? (_b = threadObj === null || threadObj === void 0 ? void 0 : threadObj.group) === null || _b === void 0 ? void 0 : _b.id : threadObj);
114
+ }
115
+ else if (threadObj && type === types_1.SCPrivateMessageType.USER) {
116
+ return messageReceiver(message, authUserId) === (isObj ? messageReceiver(threadObj, authUserId) : threadObj);
117
+ }
118
+ return null;
119
+ };
120
+ }, [threadObj, authUserId, type]);
104
121
  //HANDLERS
105
122
  const handleChange = (event) => {
106
123
  setSearch(event.target.value);
@@ -116,7 +133,9 @@ function PrivateMessageSnippets(inProps) {
116
133
  snippetActions && snippetActions.onDeleteConfirm(msg);
117
134
  };
118
135
  function handleOpenThread(msg) {
119
- snippetActions && snippetActions.onSnippetClick(msg);
136
+ const _type = msg.group !== null ? types_1.SCPrivateMessageType.GROUP : types_1.SCPrivateMessageType.USER;
137
+ setType(_type);
138
+ snippetActions && snippetActions.onSnippetClick(msg, _type);
120
139
  handleClear();
121
140
  updateSnippetsParams(msg.id, 'seen');
122
141
  }
@@ -221,7 +240,6 @@ function PrivateMessageSnippets(inProps) {
221
240
  } }),
222
241
  react_1.default.createElement(material_1.List, null, filteredSnippets.map((message) => (react_1.default.createElement(PrivateMessageSnippetItem_1.default, { message: message, key: message.id, onItemClick: () => handleOpenThread(message), secondaryAction: react_1.default.createElement(react_1.default.Fragment, null,
223
242
  message.thread_status === types_1.SCPrivateMessageStatusType.NEW && (react_1.default.createElement(material_1.Icon, { fontSize: "small", color: "secondary" }, "fiber_manual_record")),
224
- !isMobile && (react_1.default.createElement(PrivateMessageSettingsIconButton_1.default, { threadToDelete: messageReceiver(message, authUserId), onItemDeleteConfirm: () => handleDeleteConversation(messageReceiver(message, authUserId)), user: messageReceiver(message, authUserId, true) }))), selected: userObj !== types_1.SCPrivateMessageStatusType.NEW &&
225
- messageReceiver(message, authUserId) === (isObj ? messageReceiver(userObj, authUserId) : userObj) })))))))));
243
+ !isMobile && (react_1.default.createElement(PrivateMessageSettingsIconButton_1.default, { threadToDelete: messageReceiver(message, authUserId), onItemDeleteConfirm: () => handleDeleteConversation(messageReceiver(message, authUserId)), user: messageReceiver(message, authUserId, true) }))), selected: isSelected(message) })))))))));
226
244
  }
227
245
  exports.default = PrivateMessageSnippets;
@@ -1,10 +1,11 @@
1
+ import { SCPrivateMessageType } from '@selfcommunity/types';
1
2
  import { CardProps } from '@mui/material';
2
3
  export interface PrivateMessageThreadProps extends CardProps {
3
4
  /**
4
5
  * Thread object or thread id
5
6
  * default null
6
7
  */
7
- userObj?: any;
8
+ threadObj?: any;
8
9
  /**
9
10
  * Overrides or extends the styles applied to the component.
10
11
  * @default null
@@ -30,6 +31,10 @@ export interface PrivateMessageThreadProps extends CardProps {
30
31
  * @default null
31
32
  */
32
33
  onSingleMessageOpen?: (open: boolean) => void;
34
+ /**
35
+ * The Thread type
36
+ */
37
+ type?: SCPrivateMessageType;
33
38
  /**
34
39
  * Any other properties
35
40
  */
@@ -43,6 +43,8 @@ const classes = {
43
43
  newMessageContent: `${constants_1.PREFIX}-new-message-content`,
44
44
  sender: `${constants_1.PREFIX}-sender`,
45
45
  receiver: `${constants_1.PREFIX}-receiver`,
46
+ avatar: `${constants_1.PREFIX}-avatar`,
47
+ item: `${constants_1.PREFIX}-item`,
46
48
  autocomplete: `${constants_1.PREFIX}-autocomplete`,
47
49
  autocompleteDialog: `${constants_1.PREFIX}-autocomplete-dialog`,
48
50
  editor: `${constants_1.PREFIX}-editor`
@@ -95,7 +97,7 @@ function PrivateMessageThread(inProps) {
95
97
  props: inProps,
96
98
  name: constants_1.PREFIX
97
99
  });
98
- const { userObj, openNewMessage = false, onNewMessageClose = null, onNewMessageSent = null, onSingleMessageOpen = null, className } = props, rest = tslib_1.__rest(props, ["userObj", "openNewMessage", "onNewMessageClose", "onNewMessageSent", "onSingleMessageOpen", "className"]);
100
+ const { threadObj, openNewMessage = false, onNewMessageClose = null, onNewMessageSent = null, onSingleMessageOpen = null, className, type } = props, rest = tslib_1.__rest(props, ["threadObj", "openNewMessage", "onNewMessageClose", "onNewMessageSent", "onSingleMessageOpen", "className", "type"]);
99
101
  // CONTEXT
100
102
  const scUserContext = (0, react_1.useContext)(react_core_1.SCUserContext);
101
103
  // STATE
@@ -106,7 +108,7 @@ function PrivateMessageThread(inProps) {
106
108
  const [loading, setLoading] = (0, react_1.useState)(false);
107
109
  const [isHovered, setIsHovered] = (0, react_1.useState)({});
108
110
  const [followers, setFollowers] = (0, react_1.useState)([]);
109
- const isNew = userObj && userObj === types_1.SCPrivateMessageStatusType.NEW;
111
+ const isNew = threadObj && threadObj === types_1.SCPrivateMessageStatusType.NEW;
110
112
  const authUserId = scUserContext.user ? scUserContext.user.id : null;
111
113
  const [singleMessageUser, setSingleMessageUser] = (0, react_1.useState)(null);
112
114
  const [receiver, setReceiver] = (0, react_1.useState)(null);
@@ -115,7 +117,7 @@ function PrivateMessageThread(inProps) {
115
117
  const [openDeleteMessageDialog, setOpenDeleteMessageDialog] = (0, react_1.useState)(false);
116
118
  const [recipients, setRecipients] = (0, react_1.useState)([]);
117
119
  const { enqueueSnackbar, closeSnackbar } = (0, notistack_1.useSnackbar)();
118
- const isNumber = typeof userObj === 'number';
120
+ const isNumber = typeof threadObj === 'number';
119
121
  const messageReceiver = (item, loggedUserId) => {
120
122
  var _a, _b, _c;
121
123
  return ((_a = item === null || item === void 0 ? void 0 : item.receiver) === null || _a === void 0 ? void 0 : _a.id) !== loggedUserId ? (_b = item === null || item === void 0 ? void 0 : item.receiver) === null || _b === void 0 ? void 0 : _b.id : (_c = item === null || item === void 0 ? void 0 : item.sender) === null || _c === void 0 ? void 0 : _c.id;
@@ -128,7 +130,7 @@ function PrivateMessageThread(inProps) {
128
130
  // HOOKS
129
131
  // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
130
132
  // @ts-ignore
131
- const { scUser } = (0, react_core_1.useSCFetchUser)({ id: userObj, userObj });
133
+ const { scUser } = (0, react_core_1.useSCFetchUser)({ id: threadObj, threadObj });
132
134
  const messagesEndRef = (0, react_1.useRef)(null);
133
135
  const scrollToBottom = () => {
134
136
  var _a;
@@ -256,9 +258,9 @@ function PrivateMessageThread(inProps) {
256
258
  * Fetches thread
257
259
  */
258
260
  function fetchThread() {
259
- if (userObj && typeof userObj !== 'string') {
261
+ if (threadObj && typeof threadObj !== 'string' && type !== types_1.SCPrivateMessageType.GROUP) {
260
262
  setLoadingMessageObjs(true);
261
- const _userObjId = isNumber ? userObj : messageReceiver(userObj, authUserId);
263
+ const _userObjId = isNumber ? threadObj : messageReceiver(threadObj, authUserId);
262
264
  api_services_1.PrivateMessageService.getAThread({ user: _userObjId, limit: 10 })
263
265
  .then((res) => {
264
266
  setMessageObjs(res.results);
@@ -291,6 +293,19 @@ function PrivateMessageThread(inProps) {
291
293
  utils_1.Logger.error(Errors_1.SCOPE_SC_UI, { error });
292
294
  });
293
295
  }
296
+ else if (type === types_1.SCPrivateMessageType.GROUP) {
297
+ api_services_1.PrivateMessageService.getAThread({ group: isNumber ? threadObj : threadObj.group.id, limit: 10 })
298
+ .then((res) => {
299
+ setMessageObjs(res.results);
300
+ setPrevious(res.next && updateAndDeleteURLParameters(res.next, 'before_message', res.results[0].id, 'offset'));
301
+ setLoadingMessageObjs(false);
302
+ })
303
+ .catch((error) => {
304
+ setLoadingMessageObjs(false);
305
+ console.log(error);
306
+ utils_1.Logger.error(Errors_1.SCOPE_SC_UI, { error });
307
+ });
308
+ }
294
309
  }
295
310
  const isNewerThan60Seconds = (creationTime) => {
296
311
  const date = new Date(creationTime);
@@ -355,11 +370,15 @@ function PrivateMessageThread(inProps) {
355
370
  .request({
356
371
  url: api_services_1.Endpoints.SendMessage.url(),
357
372
  method: api_services_1.Endpoints.SendMessage.method,
358
- data: {
359
- recipients: openNewMessage || isNew || singleMessageThread ? ids : [isNumber && userObj ? userObj : messageReceiver(userObj, authUserId)],
360
- message: message,
361
- file_uuid: file && !message ? file : null
362
- }
373
+ data: Object.assign(Object.assign({}, (type === types_1.SCPrivateMessageType.GROUP
374
+ ? { group: isNumber ? threadObj : threadObj.group.id }
375
+ : {
376
+ recipients: openNewMessage || isNew || singleMessageThread
377
+ ? ids
378
+ : [isNumber && threadObj ? threadObj : messageReceiver(threadObj, authUserId)]
379
+ })), {
380
+ // recipients: openNewMessage || isNew || singleMessageThread ? ids : [isNumber && threadObj ? threadObj : messageReceiver(threadObj, authUserId)],
381
+ message: message, file_uuid: file && !message ? file : null })
363
382
  })
364
383
  .then((res) => {
365
384
  const isOne = res.data.length <= 1;
@@ -405,13 +424,13 @@ function PrivateMessageThread(inProps) {
405
424
  if (!authUserId) {
406
425
  return;
407
426
  }
408
- if (userObj) {
427
+ if (threadObj) {
409
428
  fetchThread();
410
429
  }
411
430
  else {
412
431
  reset();
413
432
  }
414
- }, [userObj, authUserId, scUser]);
433
+ }, [threadObj, authUserId, scUser]);
415
434
  /**
416
435
  * Notification subscriber
417
436
  */
@@ -426,7 +445,7 @@ function PrivateMessageThread(inProps) {
426
445
  if (index !== -1) {
427
446
  setMessageObjs((prev) => [...prev, res.notification_obj.message]);
428
447
  }
429
- if (isNumber ? userObj === res.thread_id : userObj.id === res.thread_id) {
448
+ if (isNumber ? threadObj === res.thread_id : threadObj.id === res.thread_id) {
430
449
  scrollToBottom();
431
450
  }
432
451
  };
@@ -453,11 +472,17 @@ function PrivateMessageThread(inProps) {
453
472
  react_1.default.createElement("ul", null,
454
473
  react_1.default.createElement(material_1.ListSubheader, null,
455
474
  react_1.default.createElement(material_1.Typography, { align: "center", className: classes.subHeader }, key)),
456
- formattedMessages[key].map((msg) => (react_1.default.createElement(PrivateMessageThreadItem_1.default, { className: authUserId === msg.sender.id ? classes.sender : classes.receiver, message: msg, key: msg.id, mouseEvents: {
457
- onMouseEnter: () => handleMouseEnter(msg.id),
458
- onMouseLeave: () => handleMouseLeave(msg.id)
459
- }, isHovering: isHovered[msg.id], showMenuIcon: authUserId === msg.sender.id, onMenuIconClick: () => handleOpenDeleteMessageDialog(msg) }))))))))),
460
- react_1.default.createElement(PrivateMessageEditor_1.default, { className: classes.editor, send: handleSend, autoHide: !(scUser === null || scUser === void 0 ? void 0 : scUser.can_send_pm_to), autoHideDeletion: (receiver === null || receiver === void 0 ? void 0 : receiver.deleted) || (scUser === null || scUser === void 0 ? void 0 : scUser.deleted), onThreadChangeId: isNumber ? userObj : userObj.receiver.id, error: error, onErrorRemove: () => setError(false) }),
475
+ formattedMessages[key].map((msg) => {
476
+ var _a;
477
+ return (react_1.default.createElement(material_1.Box, { className: classes.item, key: msg.id },
478
+ msg.group && ((_a = scUserContext === null || scUserContext === void 0 ? void 0 : scUserContext.user) === null || _a === void 0 ? void 0 : _a.username) !== msg.sender.username && (react_1.default.createElement(material_1.ListItemAvatar, null,
479
+ react_1.default.createElement(material_1.Avatar, { alt: msg.sender.username, src: msg.sender.avatar, className: classes.avatar }))),
480
+ react_1.default.createElement(PrivateMessageThreadItem_1.default, { className: authUserId === msg.sender.id ? classes.sender : classes.receiver, message: msg, key: msg.id, mouseEvents: {
481
+ onMouseEnter: () => handleMouseEnter(msg.id),
482
+ onMouseLeave: () => handleMouseLeave(msg.id)
483
+ }, isHovering: isHovered[msg.id], showMenuIcon: authUserId === msg.sender.id, onMenuIconClick: () => handleOpenDeleteMessageDialog(msg) })));
484
+ }))))))),
485
+ react_1.default.createElement(PrivateMessageEditor_1.default, { className: classes.editor, send: handleSend, autoHide: type !== types_1.SCPrivateMessageType.GROUP && !(scUser === null || scUser === void 0 ? void 0 : scUser.can_send_pm_to), autoHideDeletion: type === types_1.SCPrivateMessageType.USER && ((receiver === null || receiver === void 0 ? void 0 : receiver.deleted) || (scUser === null || scUser === void 0 ? void 0 : scUser.deleted)), onThreadChangeId: isNumber ? threadObj : type === types_1.SCPrivateMessageType.USER ? threadObj.receiver.id : threadObj.group.id, error: error, onErrorRemove: () => setError(false) }),
461
486
  openDeleteMessageDialog && (react_1.default.createElement(ConfirmDialog_1.default, { open: openDeleteMessageDialog, title: react_1.default.createElement(react_intl_1.FormattedMessage, { id: "ui.privateMessage.component.delete.message.dialog.msg", defaultMessage: "ui.privateMessage.component.delete.message.dialog.msg" }), btnConfirm: react_1.default.createElement(react_intl_1.FormattedMessage, { id: "ui.privateMessage.component.delete.message.dialog.confirm", defaultMessage: "ui.privateMessage.component.delete.message.dialog.confirm" }), onConfirm: handleDeleteMessage, onClose: handleCloseDeleteMessageDialog }))));
462
487
  }
463
488
  /**
@@ -485,6 +510,6 @@ function PrivateMessageThread(inProps) {
485
510
  /**
486
511
  * Renders the component
487
512
  */
488
- return (react_1.default.createElement(Root, Object.assign({}, rest, { className: (0, classnames_1.default)(classes.root, className) }), userObj !== null && !isNew && !singleMessageThread ? renderThread() : renderNewOrNoMessageBox()));
513
+ return (react_1.default.createElement(Root, Object.assign({}, rest, { className: (0, classnames_1.default)(classes.root, className) }), threadObj !== null && !isNew && !singleMessageThread ? renderThread() : renderNewOrNoMessageBox()));
489
514
  }
490
515
  exports.default = PrivateMessageThread;