-
Notifications
You must be signed in to change notification settings - Fork 121
Expand file tree
/
Copy pathselectors.js
More file actions
88 lines (74 loc) · 2.6 KB
/
selectors.js
File metadata and controls
88 lines (74 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import {createSelector} from 'reselect';
import moment from 'moment';
import {getActivitiesFromThreadAndNonThreadCollections} from '@webex/redux-module-conversation';
const getShare = (state) => state.share;
const getConversationThreadActivities = (state) => state.conversation.get('threadActivities');
const getConversationNonThreadActivities = (state) => state.conversation.get('sortNonThreadActivities');
/**
* Formats the published date to the format specified for content display
* @param {String} dateString
* @returns {String}
*/
function formatDate(dateString) {
return moment(dateString).format('L');
}
/**
* Creates an array of "content" activities and their data from the share module
* @param {Array} rawActivities An array of conversation activities
* @param {Object} share The redux share module
* @returns {Array}
*/
function getFileShareActivities(rawActivities, share) {
const fileShares = [];
rawActivities.filter((activity) => activity.verb === 'share')
.forEach((activity) => {
if (activity.object.files && activity.object.files.items.length) {
activity.object.files.items.forEach((fileItem) => {
let isFetching = false;
let objectUrl;
if (fileItem.image) {
const thumbnail = fileItem.mimeType === 'image/gif' ? share.getIn(['files', fileItem.url]) : share.getIn(['files', fileItem.image.url]);
if (thumbnail) {
isFetching = thumbnail.get('isFetching');
objectUrl = thumbnail.get('objectUrl');
}
}
const fileShare = {
actor: activity.actor,
activityId: activity.id,
item: {
...fileItem,
isFetching,
objectUrl
},
published: new Date(activity.published),
timestamp: formatDate(activity.published)
};
fileShares.push(fileShare);
});
}
});
return fileShares;
}
/**
* Combines the threaded and non threaded activities by using the convo redux module
* helper function
*/
const getConversationActivities = createSelector(
[
getConversationThreadActivities,
getConversationNonThreadActivities
],
getActivitiesFromThreadAndNonThreadCollections
);
const getFilesWidgetProps = createSelector(
[getConversationActivities, getShare],
(conversationActivities, share) => {
const fileShares = getFileShareActivities(conversationActivities, share);
return {
// Sort by newest content first
fileShares: fileShares.sort((a, b) => b.published - a.published)
};
}
);
export default getFilesWidgetProps;