Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions packages/rocketchat-mapview/client/mapview.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { TAPi18n } from 'meteor/tap:i18n';
import { RocketChat } from 'meteor/rocketchat:lib';
import { settings } from 'meteor/rocketchat:settings';
import { callbacks } from 'meteor/rocketchat:callbacks';
/*
* MapView is a named function that will replace geolocation in messages with a Google Static Map
* @param {Object} message - The message object
Expand All @@ -8,7 +9,7 @@ import { RocketChat } from 'meteor/rocketchat:lib';
function MapView(message) {

// get MapView settings
const mv_googlekey = RocketChat.settings.get('MapView_GMapsAPIKey');
const mv_googlekey = settings.get('MapView_GMapsAPIKey');

if (message.location) {

Expand All @@ -26,4 +27,4 @@ function MapView(message) {
return message;
}

RocketChat.callbacks.add('renderMessage', MapView, RocketChat.callbacks.priority.HIGH, 'mapview');
callbacks.add('renderMessage', MapView, callbacks.priority.HIGH, 'mapview');
3 changes: 2 additions & 1 deletion packages/rocketchat-mapview/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ Package.describe({
Package.onUse(function(api) {
api.use([
'ecmascript',
'rocketchat:lib',
'rocketchat:settings',
'rocketchat:callbacks',
'tap:i18n',
]);
api.mainModule('client/index.js', 'client');
Expand Down
6 changes: 3 additions & 3 deletions packages/rocketchat-mapview/server/settings.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Meteor } from 'meteor/meteor';
import { RocketChat } from 'meteor/rocketchat:lib';
import { settings } from 'meteor/rocketchat:settings';

Meteor.startup(function() {
RocketChat.settings.add('MapView_Enabled', false, { type: 'boolean', group: 'Message', section: 'Google Maps', public: true, i18nLabel: 'MapView_Enabled', i18nDescription: 'MapView_Enabled_Description' });
return RocketChat.settings.add('MapView_GMapsAPIKey', '', { type: 'string', group: 'Message', section: 'Google Maps', public: true, i18nLabel: 'MapView_GMapsAPIKey', i18nDescription: 'MapView_GMapsAPIKey_Description' });
settings.add('MapView_Enabled', false, { type: 'boolean', group: 'Message', section: 'Google Maps', public: true, i18nLabel: 'MapView_Enabled', i18nDescription: 'MapView_Enabled_Description' });
return settings.add('MapView_GMapsAPIKey', '', { type: 'string', group: 'Message', section: 'Google Maps', public: true, i18nLabel: 'MapView_GMapsAPIKey', i18nDescription: 'MapView_GMapsAPIKey_Description' });
});
5 changes: 2 additions & 3 deletions packages/rocketchat-mentions-flextab/client/actionButton.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { Meteor } from 'meteor/meteor';
import { Template } from 'meteor/templating';
import { RocketChat } from 'meteor/rocketchat:lib';
import { RoomHistoryManager } from 'meteor/rocketchat:ui';
import { MessageAction, RoomHistoryManager } from 'meteor/rocketchat:ui-utils';

Meteor.startup(function() {
RocketChat.MessageAction.addButton({
MessageAction.addButton({
id: 'jump-to-message',
icon: 'jump',
label: 'Jump_to_message',
Expand Down
4 changes: 2 additions & 2 deletions packages/rocketchat-mentions-flextab/client/tabBar.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Meteor } from 'meteor/meteor';
import { RocketChat } from 'meteor/rocketchat:lib';
import { TabBar } from 'meteor/rocketchat:ui-utils';

Meteor.startup(function() {
return RocketChat.TabBar.addButton({
return TabBar.addButton({
groups: ['channel', 'group'],
id: 'mentions',
i18nTitle: 'Mentions',
Expand Down
3 changes: 2 additions & 1 deletion packages/rocketchat-mentions-flextab/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ Package.onUse(function(api) {
'mongo',
'ecmascript',
'less',
'rocketchat:lib',
'rocketchat:models',
'rocketchat:ui-utils',
'templating',
]);
api.addFiles('client/views/stylesheets/mentionsFlexTab.less', 'client');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { Meteor } from 'meteor/meteor';
import { RocketChat } from 'meteor/rocketchat:lib';
import { Users, Messages } from 'meteor/rocketchat:models';

Meteor.publish('mentionedMessages', function(rid, limit = 50) {
if (!this.userId) {
return this.ready();
}
const publication = this;
const user = RocketChat.models.Users.findOneById(this.userId);
const user = Users.findOneById(this.userId);
if (!user) {
return this.ready();
}
if (!Meteor.call('canAccessRoom', rid, this.userId)) {
return this.ready();
}
const cursorHandle = RocketChat.models.Messages.findVisibleByMentionAndRoomId(user.username, rid, {
const cursorHandle = Messages.findVisibleByMentionAndRoomId(user.username, rid, {
sort: {
ts: -1,
},
Expand Down
11 changes: 6 additions & 5 deletions packages/rocketchat-mentions/client/client.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import { Meteor } from 'meteor/meteor';
import { RocketChat } from 'meteor/rocketchat:lib';
import { callbacks } from 'meteor/rocketchat:callbacks';
import { settings } from 'meteor/rocketchat:settings';
import Mentions from '../lib/Mentions';

const MentionsClient = new Mentions({
pattern() {
return RocketChat.settings.get('UTF8_Names_Validation');
return settings.get('UTF8_Names_Validation');
},
useRealName() {
return RocketChat.settings.get('UI_Use_Real_Name');
return settings.get('UI_Use_Real_Name');
},
me() {
const me = Meteor.user();
return me && me.username;
},
});

RocketChat.callbacks.add('renderMessage', (message) => MentionsClient.parse(message), RocketChat.callbacks.priority.MEDIUM, 'mentions-message');
RocketChat.callbacks.add('renderMentions', (message) => MentionsClient.parse(message), RocketChat.callbacks.priority.MEDIUM, 'mentions-mentions');
callbacks.add('renderMessage', (message) => MentionsClient.parse(message), callbacks.priority.MEDIUM, 'mentions-message');
callbacks.add('renderMentions', (message) => MentionsClient.parse(message), callbacks.priority.MEDIUM, 'mentions-mentions');
5 changes: 4 additions & 1 deletion packages/rocketchat-mentions/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ Package.describe({
Package.onUse(function(api) {
api.use([
'ecmascript',
'rocketchat:lib',
'rocketchat:settings',
'rocketchat:callbacks',
'rocketchat:notifications',
'rocketchat:models',
]);
api.mainModule('client/index.js', 'client');
api.mainModule('server/index.js', 'server');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Meteor } from 'meteor/meteor';
import { check } from 'meteor/check';
import { RocketChat } from 'meteor/rocketchat:lib';
import { Rooms, Users, Messages } from 'meteor/rocketchat:models';

Meteor.methods({
getUserMentionsByChannel({ roomId, options }) {
Expand All @@ -10,14 +10,14 @@ Meteor.methods({
throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'getUserMentionsByChannel' });
}

const room = RocketChat.models.Rooms.findOneById(roomId);
const room = Rooms.findOneById(roomId);

if (!room) {
throw new Meteor.Error('error-invalid-room', 'Invalid room', { method: 'getUserMentionsByChannel' });
}

const user = RocketChat.models.Users.findOneById(Meteor.userId());
const user = Users.findOneById(Meteor.userId());

return RocketChat.models.Messages.findVisibleByMentionAndRoomId(user.username, roomId, options).fetch();
return Messages.findVisibleByMentionAndRoomId(user.username, roomId, options).fetch();
},
});
19 changes: 11 additions & 8 deletions packages/rocketchat-mentions/server/server.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
import { Meteor } from 'meteor/meteor';
import { Random } from 'meteor/random';
import { TAPi18n } from 'meteor/tap:i18n';
import { RocketChat } from 'meteor/rocketchat:lib';
import { settings } from 'meteor/rocketchat:settings';
import { callbacks } from 'meteor/rocketchat:callbacks';
import { Notifications } from 'meteor/rocketchat:notifications';
import { Users, Subscriptions, Rooms } from 'meteor/rocketchat:models';
import _ from 'underscore';
import MentionsServer from './Mentions';

const mention = new MentionsServer({
pattern: () => RocketChat.settings.get('UTF8_Names_Validation'),
messageMaxAll: () => RocketChat.settings.get('Message_MaxAll'),
pattern: () => settings.get('UTF8_Names_Validation'),
messageMaxAll: () => settings.get('Message_MaxAll'),
getUsers: (usernames) => Meteor.users.find({ username: { $in: _.unique(usernames) } }, { fields: { _id: true, username: true, name: 1 } }).fetch(),
getUser: (userId) => RocketChat.models.Users.findOneById(userId),
getTotalChannelMembers: (rid) => RocketChat.models.Subscriptions.findByRoomId(rid).count(),
getChannels: (channels) => RocketChat.models.Rooms.find({ name: { $in: _.unique(channels) }, t: 'c' }, { fields: { _id: 1, name: 1 } }).fetch(),
getUser: (userId) => Users.findOneById(userId),
getTotalChannelMembers: (rid) => Subscriptions.findByRoomId(rid).count(),
getChannels: (channels) => Rooms.find({ name: { $in: _.unique(channels) }, t: 'c' }, { fields: { _id: 1, name: 1 } }).fetch(),
onMaxRoomMembersExceeded({ sender, rid }) {
// Get the language of the user for the error notification.
const { language } = this.getUser(sender._id);
const msg = TAPi18n.__('Group_mentions_disabled_x_members', { total: this.messageMaxAll }, language);

RocketChat.Notifications.notifyUser(sender._id, 'message', {
Notifications.notifyUser(sender._id, 'message', {
_id: Random.id(),
rid,
ts: new Date,
Expand All @@ -32,4 +35,4 @@ const mention = new MentionsServer({
});
},
});
RocketChat.callbacks.add('beforeSaveMessage', (message) => mention.execute(message), RocketChat.callbacks.priority.HIGH, 'mentions');
callbacks.add('beforeSaveMessage', (message) => mention.execute(message), callbacks.priority.HIGH, 'mentions');
1 change: 0 additions & 1 deletion packages/rocketchat-message-action/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ Package.onUse(function(api) {
api.use([
'templating',
'ecmascript',
'rocketchat:lib',
]);
api.addFiles('client/stylesheets/messageAction.css', 'client');
api.mainModule('client/index.js', 'client');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { Meteor } from 'meteor/meteor';
import { DateFormat } from 'meteor/rocketchat:lib';
import { fixCordova } from 'meteor/rocketchat:lazy-load';
import { Template } from 'meteor/templating';
import { RocketChat } from 'meteor/rocketchat:lib';
import { getUserPreference } from 'meteor/rocketchat:utils';
import { Users } from 'meteor/rocketchat:models';
import { renderMessageBody } from 'meteor/rocketchat:ui-utils';

const colors = {
Expand All @@ -28,11 +29,11 @@ Template.messageAttachment.helpers({
},
loadImage() {
if (this.downloadImages !== true) {
const user = RocketChat.models.Users.findOne({ _id: Meteor.userId() }, { fields: { 'settings.autoImageLoad' : 1 } });
if (RocketChat.getUserPreference(user, 'autoImageLoad') === false) {
const user = Users.findOne({ _id: Meteor.userId() }, { fields: { 'settings.autoImageLoad' : 1 } });
if (getUserPreference(user, 'autoImageLoad') === false) {
return false;
}
if (Meteor.Device.isPhone() && RocketChat.getUserPreference(user, 'saveMobileBandwidth') !== true) {
if (Meteor.Device.isPhone() && getUserPreference(user, 'saveMobileBandwidth') !== true) {
return false;
}
}
Expand All @@ -54,7 +55,7 @@ Template.messageAttachment.helpers({
if (this.collapsed != null) {
return this.collapsed;
} else {
return RocketChat.getUserPreference(Meteor.userId(), 'collapseMediaByDefault') === true;
return getUserPreference(Meteor.userId(), 'collapseMediaByDefault') === true;
}
},
time() {
Expand Down
2 changes: 2 additions & 0 deletions packages/rocketchat-message-attachments/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ Package.onUse(function(api) {
'rocketchat:e2e',
'rocketchat:ui-message',
'rocketchat:ui-utils',
'rocketchat:utils',
'rocketchat:models',
]);
api.addFiles('client/stylesheets/messageAttachments.css', 'client');
api.mainModule('client/index.js', 'client');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Meteor } from 'meteor/meteor';
import { FlowRouter } from 'meteor/kadira:flow-router';
import { RocketChat, handleError } from 'meteor/rocketchat:lib';
import { RoomManager, ChatSubscription } from 'meteor/rocketchat:ui';
import { RoomManager, MessageAction } from 'meteor/rocketchat:ui-utils';
import { handleError } from 'meteor/rocketchat:utils';
import { ChatSubscription } from 'meteor/rocketchat:models';

Meteor.startup(() => {
RocketChat.MessageAction.addButton({
MessageAction.addButton({
id: 'mark-message-as-unread',
icon: 'flag',
label: 'Mark_as_unread',
Expand Down
5 changes: 3 additions & 2 deletions packages/rocketchat-message-mark-as-unread/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ Package.describe({
Package.onUse(function(api) {
api.use([
'ecmascript',
'rocketchat:lib',
'rocketchat:logger',
'rocketchat:ui',
'rocketchat:models',
'rocketchat:ui-utils',
'rocketchat:utils',
'templating',
]);
api.mainModule('client/index.js', 'client');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Meteor } from 'meteor/meteor';
import { RocketChat } from 'meteor/rocketchat:lib';
import { Messages, Subscriptions } from 'meteor/rocketchat:models';
import logger from './logger';

Meteor.methods({
Expand All @@ -12,7 +12,7 @@ Meteor.methods({
}

if (room) {
const lastMessage = RocketChat.models.Messages.findVisibleByRoomId(room, { limit: 1, sort: { ts: -1 } }).fetch()[0];
const lastMessage = Messages.findVisibleByRoomId(room, { limit: 1, sort: { ts: -1 } }).fetch()[0];

if (lastMessage == null) {
throw new Meteor.Error('error-action-not-allowed', 'Not allowed', {
Expand All @@ -21,10 +21,10 @@ Meteor.methods({
});
}

return RocketChat.models.Subscriptions.setAsUnreadByRoomIdAndUserId(lastMessage.rid, userId, lastMessage.ts);
return Subscriptions.setAsUnreadByRoomIdAndUserId(lastMessage.rid, userId, lastMessage.ts);
}

const originalMessage = RocketChat.models.Messages.findOneById(firstUnreadMessage._id, {
const originalMessage = Messages.findOneById(firstUnreadMessage._id, {
fields: {
u: 1,
rid: 1,
Expand All @@ -38,11 +38,11 @@ Meteor.methods({
action: 'Unread_messages',
});
}
const lastSeen = RocketChat.models.Subscriptions.findOneByRoomIdAndUserId(originalMessage.rid, userId).ls;
const lastSeen = Subscriptions.findOneByRoomIdAndUserId(originalMessage.rid, userId).ls;
if (firstUnreadMessage.ts >= lastSeen) {
return logger.connection.debug('Provided message is already marked as unread');
}
logger.connection.debug(`Updating unread message of ${ originalMessage.ts } as the first unread`);
return RocketChat.models.Subscriptions.setAsUnreadByRoomIdAndUserId(originalMessage.rid, userId, originalMessage.ts);
return Subscriptions.setAsUnreadByRoomIdAndUserId(originalMessage.rid, userId, originalMessage.ts);
},
});