Skip to content

Commit fae16fe

Browse files
committed
Contextual bar Discussions List Moved to React
1 parent d92539e commit fae16fe

File tree

14 files changed

+314
-137
lines changed

14 files changed

+314
-137
lines changed

app/api/server/lib/messages.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,14 @@ export async function findSnippetedMessages({ uid, roomId, pagination: { offset,
116116
};
117117
}
118118

119-
export async function findDiscussionsFromRoom({ uid, roomId, pagination: { offset, count, sort } }) {
119+
export async function findDiscussionsFromRoom({ uid, roomId, text, pagination: { offset, count, sort } }) {
120120
const room = await Rooms.findOneById(roomId);
121121

122122
if (!await canAccessRoomAsync(room, { _id: uid })) {
123123
throw new Error('error-not-allowed');
124124
}
125125

126-
const cursor = Messages.findDiscussionsByRoom(roomId, {
126+
const cursor = Messages.findDiscussionsByRoomAndText(roomId, text, {
127127
sort: sort || { ts: -1 },
128128
skip: offset,
129129
limit: count,

app/api/server/v1/chat.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ API.v1.addRoute('chat.getSnippetedMessages', { authRequired: true }, {
697697

698698
API.v1.addRoute('chat.getDiscussions', { authRequired: true }, {
699699
get() {
700-
const { roomId } = this.queryParams;
700+
const { roomId, text } = this.queryParams;
701701
const { sort } = this.parseJsonQuery();
702702
const { offset, count } = this.getPaginationItems();
703703

@@ -707,6 +707,7 @@ API.v1.addRoute('chat.getDiscussions', { authRequired: true }, {
707707
const messages = Promise.await(findDiscussionsFromRoom({
708708
uid: this.userId,
709709
roomId,
710+
text,
710711
pagination: {
711712
offset,
712713
count,

app/discussion/client/tabBar.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Meteor.startup(function() {
1010
i18nTitle: 'Discussions',
1111
icon: 'discussion',
1212
template: 'discussionsTabbar',
13+
full: true,
1314
order: 1,
1415
condition: () => settings.get('Discussion_enabled'),
1516
});
Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,3 @@
11
<template name="discussionsTabbar">
2-
{{#if Template.subscriptionsReady}}
3-
{{#unless hasMessages}}
4-
<div class="list-view discussions-list flex-tab__header">
5-
<h2>{{_ "No_discussions_yet"}}</h2>
6-
</div>
7-
{{/unless}}
8-
{{/if}}
9-
<div class="flex-tab__result discussions-list js-list">
10-
<ul class="list clearfix">
11-
{{# with messageContext}}
12-
{{#each msg in messages}}
13-
{{> message msg=msg room=room subscription=subscription groupable=false settings=settings u=u}}
14-
{{/each}}
15-
{{/with}}
16-
</ul>
17-
18-
{{#if hasMore}}
19-
<div class="load-more">
20-
{{> loading}}
21-
</div>
22-
{{/if}}
23-
</div>
2+
{{ > DiscussionMessageList rid=rid onClose=close}}
243
</template>
Lines changed: 9 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,18 @@
1-
import _ from 'underscore';
2-
import { ReactiveVar } from 'meteor/reactive-var';
3-
import { Mongo } from 'meteor/mongo';
41
import { Template } from 'meteor/templating';
2+
import { HTML } from 'meteor/htmljs';
53

6-
import { messageContext } from '../../../ui-utils/client/lib/messageContext';
7-
import { Messages } from '../../../models/client';
8-
import { APIClient } from '../../../utils/client';
9-
import { upsertMessageBulk } from '../../../ui-utils/client/lib/RoomHistoryManager';
4+
import { createTemplateForComponent } from '../../../../client/reactAdapters';
105

116
import './DiscussionTabbar.html';
127

13-
const LIMIT_DEFAULT = 50;
8+
createTemplateForComponent('DiscussionMessageList', () => import('../../../../client/Channel/Discussions/ContextualBar/List'), {
9+
renderContainerView: () => HTML.DIV({ class: 'contextual-bar' }), // eslint-disable-line new-cap
10+
});
1411

1512
Template.discussionsTabbar.helpers({
16-
hasMessages() {
17-
return Template.instance().messages.find().count();
18-
},
19-
messages() {
20-
const instance = Template.instance();
21-
return instance.messages.find({}, { limit: instance.limit.get(), sort: { ts: -1 } });
13+
close() {
14+
const { data } = Template.instance();
15+
const { tabBar } = data;
16+
return () => tabBar.close();
2217
},
23-
hasMore() {
24-
return Template.instance().hasMore.get();
25-
},
26-
messageContext,
27-
});
28-
29-
Template.discussionsTabbar.onCreated(function() {
30-
this.rid = this.data.rid;
31-
this.messages = new Mongo.Collection(null);
32-
this.hasMore = new ReactiveVar(true);
33-
this.limit = new ReactiveVar(LIMIT_DEFAULT);
34-
35-
this.autorun(() => {
36-
const query = {
37-
rid: this.rid,
38-
drid: { $exists: true },
39-
};
40-
41-
this.cursor && this.cursor.stop();
42-
43-
this.limit.set(LIMIT_DEFAULT);
44-
45-
this.cursor = Messages.find(query).observe({
46-
added: ({ _id, ...message }) => {
47-
this.messages.upsert({ _id }, message);
48-
},
49-
changed: ({ _id, ...message }) => {
50-
this.messages.upsert({ _id }, message);
51-
},
52-
removed: ({ _id }) => {
53-
this.messages.remove({ _id });
54-
},
55-
});
56-
});
57-
58-
this.autorun(async () => {
59-
const limit = this.limit.get();
60-
const { messages, total } = await APIClient.v1.get(`chat.getDiscussions?roomId=${ this.rid }&count=${ limit }`);
61-
62-
upsertMessageBulk({ msgs: messages }, this.messages);
63-
64-
this.hasMore.set(total > limit);
65-
});
66-
});
67-
68-
Template.discussionsTabbar.events({
69-
'scroll .js-list': _.throttle(function(e, instance) {
70-
if (e.target.scrollTop >= e.target.scrollHeight - e.target.clientHeight - 10 && instance.hasMore.get()) {
71-
instance.limit.set(instance.limit.get() + LIMIT_DEFAULT);
72-
}
73-
}, 200),
7418
});

app/models/server/raw/Messages.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,20 @@ export class MessagesRaw extends BaseRaw {
4848
return this.find(query, options);
4949
}
5050

51+
findDiscussionsByRoomAndText(rid, text, options) {
52+
const query = {
53+
rid,
54+
drid: { $exists: true },
55+
...text && {
56+
$text: {
57+
$search: text,
58+
},
59+
},
60+
};
61+
62+
return this.find(query, options);
63+
}
64+
5165
findAllNumberOfTransferredRooms({ start, end, departmentId, onlyCount = false, options = {} }) {
5266
const match = {
5367
$match: {

app/threads/client/components/ThreadComponent.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { roomTypes, APIClient } from '../../../utils/client';
1111
import { call } from '../../../ui-utils/client';
1212
import { useTranslation } from '../../../../client/contexts/TranslationContext';
1313
import VerticalBar from '../../../../client/components/basic/VerticalBar';
14-
import { useLocalStorage } from './hooks/useLocalstorage';
14+
import { useLocalStorage } from '../../../../client/Channel/hooks/useLocalstorage';
1515
import { normalizeThreadTitle } from '../lib/normalizeThreadTitle';
1616

1717
export default function ThreadComponent({ mid, rid, jump, room, ...props }) {

app/threads/client/flextab/threads.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import '../threads.css';
77
import { createTemplateForComponent } from '../../../../client/reactAdapters';
88

99

10-
createTemplateForComponent('ThreadsList', () => import('../../../../client/Channel/Threads/ContextualBar/ThreadList'), {
10+
createTemplateForComponent('ThreadsList', () => import('../../../../client/Channel/Threads/ContextualBar/List'), {
1111
renderContainerView: () => HTML.DIV({ class: 'contextual-bar' }), // eslint-disable-line new-cap
1212
});
1313

0 commit comments

Comments
 (0)