Skip to content

Commit 2e24186

Browse files
authored
support to search posts on group searching (#1110)
1 parent 0ec8b58 commit 2e24186

File tree

1 file changed

+26
-6
lines changed
  • packages/ringcentral-integration/modules/GlipGroups

1 file changed

+26
-6
lines changed

packages/ringcentral-integration/modules/GlipGroups/index.js

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,24 @@ function getUniqueMemberIds(groups) {
7474
return memberIds;
7575
}
7676

77+
function searchPosts(searchFilter, posts) {
78+
let result = false;
79+
for (const post of posts) {
80+
if (post.text && post.text.toLowerCase().indexOf(searchFilter) > -1) {
81+
result = true;
82+
break;
83+
}
84+
if (post.mentions && post.mentions.length > 0) {
85+
const mentionNames = post.mentions.map(m => m.name).join(' ').toLowerCase();
86+
if (mentionNames.indexOf(searchFilter) > -1) {
87+
result = true;
88+
break;
89+
}
90+
}
91+
}
92+
return result;
93+
}
94+
7795
/**
7896
* @class
7997
* @description Accound info managing module.
@@ -495,10 +513,10 @@ export default class GlipGroups extends Pollable {
495513
@getter
496514
allGroups = createSelector(
497515
() => this.data,
498-
() => (this._glipPersons && this._glipPersons.personsMap) || {},
499-
() => (this._glipPosts && this._glipPosts.postsMap) || {},
516+
() => (this._glipPersons && this._glipPersons.personsMap),
517+
() => (this._glipPosts && this._glipPosts.postsMap),
500518
() => this._auth.ownerId,
501-
(data, personsMap, postsMap, ownerId) => (data || []).map(
519+
(data, personsMap = {}, postsMap = {}, ownerId) => (data || []).map(
502520
group => formatGroup(group, personsMap, postsMap, ownerId)
503521
),
504522
)
@@ -507,7 +525,8 @@ export default class GlipGroups extends Pollable {
507525
filteredGroups = createSelector(
508526
() => this.allGroups,
509527
() => this.searchFilter,
510-
(allGroups, searchFilter) => {
528+
() => (this._glipPosts && this._glipPosts.postsMap),
529+
(allGroups, searchFilter, postsMap = {}) => {
511530
if (isBlank(searchFilter)) {
512531
return allGroups;
513532
}
@@ -520,13 +539,14 @@ export default class GlipGroups extends Pollable {
520539
if (!name) {
521540
const groupUsernames = group.detailMembers
522541
.map(m => `${m.firstName} ${m.lastName}`)
523-
.join(',')
542+
.join(' ')
524543
.toLowerCase();
525544
if (groupUsernames && groupUsernames.indexOf(filterString) > -1) {
526545
return true;
527546
}
528547
}
529-
return false;
548+
const result = searchPosts(filterString, postsMap[group.id] || []);
549+
return result;
530550
});
531551
},
532552
)

0 commit comments

Comments
 (0)