|
1 | | -import _ from 'underscore'; |
2 | | -import { ReactiveVar } from 'meteor/reactive-var'; |
3 | | -import { Mongo } from 'meteor/mongo'; |
4 | 1 | import { Template } from 'meteor/templating'; |
| 2 | +import { HTML } from 'meteor/htmljs'; |
5 | 3 |
|
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'; |
10 | 5 |
|
11 | 6 | import './DiscussionTabbar.html'; |
12 | 7 |
|
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 | +}); |
14 | 11 |
|
15 | 12 | 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(); |
22 | 17 | }, |
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), |
74 | 18 | }); |
0 commit comments