Skip to content

Commit

Permalink
Chore: Migrate modules related to room template to TypeScript (#25881)
Browse files Browse the repository at this point in the history
  • Loading branch information
tassoevan authored Aug 22, 2022
1 parent 5be9725 commit 8a2899f
Show file tree
Hide file tree
Showing 121 changed files with 3,500 additions and 3,578 deletions.
2 changes: 1 addition & 1 deletion apps/meteor/app/api/server/lib/getServerInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { hasPermissionAsync } from '../../../authorization/server/functions/hasP

type ServerInfo =
| {
info: Info;
info: typeof Info;
}
| {
version: string | undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Meteor.startup(function () {
imperativeModal.open({
component: CreateDiscussion,
props: {
defaultParentRoom: room.prid || room._id,
defaultParentRoom: room?.prid || room?._id,
onClose: imperativeModal.close,
parentMessageId: message._id,
nameSuggestion: message?.msg?.substr(0, 140),
Expand Down
1 change: 1 addition & 0 deletions apps/meteor/app/emoji/lib/rocketchat.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ export const emoji = {
},
},
},
/** @type {Record<string, unknown>} */
list: {},
};
7 changes: 4 additions & 3 deletions apps/meteor/app/livechat/client/views/app/livechatReadOnly.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { FlowRouter } from 'meteor/kadira:flow-router';
import { ChatRoom, CachedChatRoom } from '../../../../models/client';
import { callWithErrorHandling } from '../../../../../client/lib/utils/callWithErrorHandling';
import { APIClient } from '../../../../utils/client';
import { RoomManager } from '../../../../ui-utils/client/lib/RoomManager';
import { inquiryDataStream } from '../../lib/stream/inquiry';
import { dispatchToastMessage } from '../../../../../client/lib/toast';
import './livechatReadOnly.html';
Expand Down Expand Up @@ -91,6 +90,8 @@ Template.livechatReadOnly.onCreated(async function () {
this.inquiry.set(inquiry);
};

this.roomDataStream = new Meteor.Streamer('room-data');

Meteor.call('livechat:getRoutingConfig', (err, config) => {
if (config) {
this.routingConfig.set(config);
Expand All @@ -108,7 +109,7 @@ Template.livechatReadOnly.onCreated(async function () {
const { room } = await APIClient.get(`/v1/rooms.info`, { roomId });
this.room.set(room);
if (room && room._id) {
RoomManager.roomStream.on(roomId, (room) => this.room.set(room));
this.roomDataStream.on(roomId, (room) => this.room.set(room));
}

this.preparing.set(false);
Expand All @@ -124,5 +125,5 @@ Template.livechatReadOnly.onDestroyed(function () {
}

const { rid } = Template.currentData();
RoomManager.roomStream.removeListener(rid);
this.roomDataStream.removeListener(rid);
});
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { settings } from '../../../../../settings';
import { t } from '../../../../../utils';
import { hasRole, hasPermission, hasAtLeastOnePermission } from '../../../../../authorization';
import { APIClient } from '../../../../../utils/client';
import { RoomManager } from '../../../../../ui-utils/client';
import { getCustomFormTemplate } from '../customTemplates/register';
import { Markdown } from '../../../../../markdown/client';
import { formatDateAndTime } from '../../../../../../client/lib/utils/formatDateAndTime';
Expand Down Expand Up @@ -414,8 +413,10 @@ Template.visitorInfo.onCreated(function () {
this.updateRoom(room);
};

this.roomDataStream = new Meteor.Streamer('room-data');

if (rid) {
RoomManager.roomStream.on(rid, this.updateRoom);
this.roomDataStream.on(rid, this.updateRoom);
loadRoomData(rid);
}

Expand All @@ -436,5 +437,5 @@ Template.visitorInfo.onCreated(function () {

Template.visitorInfo.onDestroyed(function () {
const { rid } = Template.currentData();
RoomManager.roomStream.removeListener(rid, this.updateRoom);
this.roomDataStream.removeListener(rid, this.updateRoom);
});
File renamed without changes.
20 changes: 0 additions & 20 deletions apps/meteor/app/models/client/models/ChatMessage.js

This file was deleted.

32 changes: 32 additions & 0 deletions apps/meteor/app/models/client/models/ChatMessage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import type { IMessage, IRoom } from '@rocket.chat/core-typings';
import { Mongo } from 'meteor/mongo';

class ChatMessageCollection extends Mongo.Collection<IMessage & { ignored?: boolean }> {
constructor() {
super(null);
}

setReactions(messageId: IMessage['_id'], reactions: IMessage['reactions']) {
return this.update({ _id: messageId }, { $set: { reactions } });
}

unsetReactions(messageId: IMessage['_id']) {
return this.update({ _id: messageId }, { $unset: { reactions: 1 } });
}

findOneByRoomIdAndMessageId(rid: IRoom['_id'], messageId: IMessage['_id'], options?: Mongo.Options<IMessage>) {
const query = {
rid,
_id: messageId,
};

return this.findOne(query, options);
}
}

// TODO: check if we can dodge these missing typings from Meteor Collection Hooks
export const ChatMessage = new ChatMessageCollection() as unknown as Mongo.Collection<IMessage & { ignored?: boolean }> & {
direct: Mongo.Collection<IMessage, IMessage>;

queries: unknown[];
};
2 changes: 1 addition & 1 deletion apps/meteor/app/models/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Meteor } from 'meteor/meteor';

if (Meteor.isClient) {
module.exports = require('./client/index.js');
module.exports = require('./client/index');
}
if (Meteor.isServer) {
module.exports = require('./server/index');
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/otr/client/OTRRoom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ export class OTRRoom implements IOTRRoom {
}
}

async encrypt(message: IMessage): Promise<string> {
async encrypt(message: Pick<IMessage, '_id' | 'msg'>): Promise<string> {
try {
const data = new TextEncoder().encode(
EJSON.stringify({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { callWithErrorHandling } from '../../../../client/lib/utils/callWithErro
import './messageBoxFollow.html';

Template.messageBoxFollow.events({
'click .js-follow'() {
'click .js-follow'(this: { tmid: string }) {
const { tmid } = this;
callWithErrorHandling('followMessage', { mid: tmid });
},
Expand Down
4 changes: 2 additions & 2 deletions apps/meteor/app/threads/client/flextab/thread.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<div class="dropzone-overlay {{isDropzoneDisabled}} background-transparent-darkest color-content-background-color">{{_ dragAndDropLabel}}</div>
<div class="thread-list js-scroll-thread">
<ul class="thread">
{{# with messageContext}}
{{#with messageContext}}
{{#if isLoading}}
<li class="load-more">
{{> loading}}
Expand All @@ -19,7 +19,7 @@
</div>
{{> messageBox messageBoxData}}
<footer class="thread-footer">
{{# with checkboxData }}
{{#with checkboxData }}
<div style="display: flex;">
{{> Checkbox . }}
</div>
Expand Down
Loading

0 comments on commit 8a2899f

Please sign in to comment.