@ -4,36 +4,52 @@ import { Random } from 'meteor/random';
import { Tracker } from 'meteor/tracker' ;
import { Blaze } from 'meteor/blaze' ;
import { FlowRouter } from 'meteor/kadira:flow-router' ;
import { RocketChatTabBar } from 'meteor/rocketchat:lib' ;
import { Session } from 'meteor/session' ;
import { Template } from 'meteor/templating' ;
import { t } from 'meteor/rocketchat:utils' ;
import { t , roomTypes , getUserPreference , handleError } from 'meteor/rocketchat:utils' ;
import { WebRTC } from 'meteor/rocketchat:webrtc' ;
import { ChatSubscription , ChatMessage , RoomRoles , Users , Subscriptions , Rooms } from 'meteor/rocketchat:models' ;
import {
fireGlobalEvent ,
RoomHistoryManager ,
RoomManager ,
readMessage ,
popover ,
modal ,
Layout ,
MessageAction ,
RocketChatTabBar ,
} from 'meteor/rocketchat:ui-utils' ;
import { settings } from 'meteor/rocketchat:settings' ;
import { callbacks } from 'meteor/rocketchat:callbacks' ;
import { promises } from 'meteor/rocketchat:promises' ;
import { hasAllPermission , hasRole } from 'meteor/rocketchat:authorization' ;
import _ from 'underscore' ;
import moment from 'moment' ;
import mime from 'mime-type/with-db' ;
import Clipboard from 'clipboard' ;
import { lazyloadtick } from 'meteor/rocketchat:lazy-load' ;
import { ChatMessages } from '../../lib/chatMessages' ;
import { fileUpload } from '../../lib/fileUpload' ;
chatMessages = { } ;
const isSubscribed = ( _id ) => ChatSubscription . find ( { rid : _id } ) . count ( ) > 0 ;
const favoritesEnabled = ( ) => RocketChat . settings . get ( 'Favorite_Rooms' ) ;
const favoritesEnabled = ( ) => settings . get ( 'Favorite_Rooms' ) ;
const userCanDrop = ( _id ) => ! RocketChat . roomTypes . readOnly ( _id , Meteor . user ( ) ) ;
const userCanDrop = ( _id ) => ! roomTypes . readOnly ( _id , Meteor . user ( ) ) ;
const openProfileTab = ( e , instance , username ) => {
const roomData = Session . get ( ` roomData ${ Session . get ( 'openedRoom' ) } ` ) ;
if ( RocketChat . Layout . isEmbedded ( ) ) {
if ( Layout . isEmbedded ( ) ) {
fireGlobalEvent ( 'click-user-card-message' , { username } ) ;
e . preventDefault ( ) ;
e . stopPropagation ( ) ;
return ;
}
if ( RocketChat . roomTypes . roomTypes [ roomData . t ] . enableMembersListProfile ( ) ) {
if ( roomTypes . roomTypes [ roomData . t ] . enableMembersListProfile ( ) ) {
instance . setUserDetail ( username ) ;
}
@ -42,7 +58,7 @@ const openProfileTab = (e, instance, username) => {
} ;
const openProfileTabOrOpenDM = ( e , instance , username ) => {
if ( RocketChat . settings . get ( 'UI_Click_Direct_Message' ) ) {
if ( settings . get ( 'UI_Click_Direct_Message' ) ) {
Meteor . call ( 'createDirectMessage' , username , ( error , result ) => {
if ( error ) {
if ( error . isClientSafe ) {
@ -70,7 +86,7 @@ const mountPopover = (e, i, outerContext) => {
const [ , message ] = outerContext . _arguments ;
let menuItems = RocketChat . MessageAction . getButtons ( message , context , 'menu' ) . map ( ( item ) => ( {
let menuItems = MessageAction . getButtons ( message , context , 'menu' ) . map ( ( item ) => ( {
icon : item . icon ,
name : t ( item . label ) ,
type : 'message-action' ,
@ -79,7 +95,7 @@ const mountPopover = (e, i, outerContext) => {
} ) ) ;
if ( window . matchMedia ( '(max-width: 500px)' ) . matches ) {
const messageItems = RocketChat . MessageAction . getButtons ( message , context , 'message' ) . map ( ( item ) => ( {
const messageItems = MessageAction . getButtons ( message , context , 'message' ) . map ( ( item ) => ( {
icon : item . icon ,
name : t ( item . label ) ,
type : 'message-action' ,
@ -136,23 +152,23 @@ const wipeFailedUploads = () => {
} ;
function roomHasGlobalPurge ( room ) {
if ( ! RocketChat . settings . get ( 'RetentionPolicy_Enabled' ) ) {
if ( ! settings . get ( 'RetentionPolicy_Enabled' ) ) {
return false ;
}
switch ( room . t ) {
case 'c' :
return RocketChat . settings . get ( 'RetentionPolicy_AppliesToChannels' ) ;
return settings . get ( 'RetentionPolicy_AppliesToChannels' ) ;
case 'p' :
return RocketChat . settings . get ( 'RetentionPolicy_AppliesToGroups' ) ;
return settings . get ( 'RetentionPolicy_AppliesToGroups' ) ;
case 'd' :
return RocketChat . settings . get ( 'RetentionPolicy_AppliesToDMs' ) ;
return settings . get ( 'RetentionPolicy_AppliesToDMs' ) ;
}
return false ;
}
function roomHasPurge ( room ) {
if ( ! room || ! RocketChat . settings . get ( 'RetentionPolicy_Enabled' ) ) {
if ( ! room || ! settings . get ( 'RetentionPolicy_Enabled' ) ) {
return false ;
}
@ -172,7 +188,7 @@ function roomFilesOnly(room) {
return room . retention . filesOnly ;
}
return RocketChat . settings . get ( 'RetentionPolicy_FilesOnly' ) ;
return settings . get ( 'RetentionPolicy_FilesOnly' ) ;
}
function roomExcludePinned ( room ) {
@ -184,7 +200,7 @@ function roomExcludePinned(room) {
return room . retention . excludePinned ;
}
return RocketChat . settings . get ( 'RetentionPolicy_ExcludePinned' ) ;
return settings . get ( 'RetentionPolicy_ExcludePinned' ) ;
}
function roomMaxAge ( room ) {
@ -200,26 +216,26 @@ function roomMaxAge(room) {
}
if ( room . t === 'c' ) {
return RocketChat . settings . get ( 'RetentionPolicy_MaxAge_Channels' ) ;
return settings . get ( 'RetentionPolicy_MaxAge_Channels' ) ;
}
if ( room . t === 'p' ) {
return RocketChat . settings . get ( 'RetentionPolicy_MaxAge_Groups' ) ;
return settings . get ( 'RetentionPolicy_MaxAge_Groups' ) ;
}
if ( room . t === 'd' ) {
return RocketChat . settings . get ( 'RetentionPolicy_MaxAge_DMs' ) ;
return settings . get ( 'RetentionPolicy_MaxAge_DMs' ) ;
}
}
RocketChat . callbacks . add ( 'enter-room' , wipeFailedUploads ) ;
callbacks . add ( 'enter-room' , wipeFailedUploads ) ;
Template . room . helpers ( {
isTranslated ( ) {
const sub = ChatSubscription . findOne ( { rid : this . _id } , { fields : { autoTranslate : 1 , autoTranslateLanguage : 1 } } ) ;
RocketChat . settings . get ( 'AutoTranslate_Enabled' ) && ( ( sub != null ? sub . autoTranslate : undefined ) === true ) && ( sub . autoTranslateLanguage != null ) ;
settings . get ( 'AutoTranslate_Enabled' ) && ( ( sub != null ? sub . autoTranslate : undefined ) === true ) && ( sub . autoTranslateLanguage != null ) ;
} ,
embeddedVersion ( ) {
return RocketChat . Layout . isEmbedded ( ) ;
return Layout . isEmbedded ( ) ;
} ,
subscribed ( ) {
@ -228,7 +244,7 @@ Template.room.helpers({
messagesHistory ( ) {
const hideMessagesOfType = [ ] ;
RocketChat . settings . collection . find ( { _id : /Message_HideType_.+/ } ) . forEach ( function ( record ) {
settings . collection . find ( { _id : /Message_HideType_.+/ } ) . forEach ( function ( record ) {
let types ;
const type = record . _id . replace ( 'Message_HideType_' , '' ) ;
switch ( type ) {
@ -289,10 +305,10 @@ Template.room.helpers({
roomLeader ( ) {
const roles = RoomRoles . findOne ( { rid : this . _id , roles : 'leader' , 'u._id' : { $ne : Meteor . userId ( ) } } ) ;
if ( roles ) {
const leader = RocketChat . models . Users . findOne ( { _id : roles . u . _id } , { fields : { status : 1 } } ) || { } ;
const leader = Users . findOne ( { _id : roles . u . _id } , { fields : { status : 1 } } ) || { } ;
return {
... roles . u ,
name : RocketChat . settings . get ( 'UI_Use_Real_Name' ) ? ( roles . u . name || roles . u . username ) : roles . u . username ,
name : settings . get ( 'UI_Use_Real_Name' ) ? ( roles . u . name || roles . u . username ) : roles . u . username ,
status : leader . status || 'offline' ,
statusDisplay : ( ( status ) => status . charAt ( 0 ) . toUpperCase ( ) + status . slice ( 1 ) ) ( leader . status || 'offline' ) ,
} ;
@ -300,7 +316,7 @@ Template.room.helpers({
} ,
chatNowLink ( ) {
return RocketChat . roomTypes . getRouteLink ( 'd' , { name : this . username } ) ;
return roomTypes . getRouteLink ( 'd' , { name : this . username } ) ;
} ,
showAnnouncement ( ) {
@ -337,7 +353,7 @@ Template.room.helpers({
const roomData = Session . get ( ` roomData ${ this . _id } ` ) ;
if ( ! ( roomData != null ? roomData . t : undefined ) ) { return '' ; }
const roomIcon = RocketChat . roomTypes . getIcon ( roomData != null ? roomData . t : undefined ) ;
const roomIcon = roomTypes . getIcon ( roomData != null ? roomData . t : undefined ) ;
// Remove this 'codegueira' on header redesign
if ( ! roomIcon ) {
@ -353,11 +369,11 @@ Template.room.helpers({
userStatus ( ) {
const roomData = Session . get ( ` roomData ${ this . _id } ` ) ;
return RocketChat . roomTypes . getUserStatus ( roomData . t , this . _id ) || 'offline' ;
return roomTypes . getUserStatus ( roomData . t , this . _id ) || 'offline' ;
} ,
maxMessageLength ( ) {
return RocketChat . settings . get ( 'Message_MaxAllowedSize' ) ;
return settings . get ( 'Message_MaxAllowedSize' ) ;
} ,
unreadData ( ) {
@ -401,7 +417,7 @@ Template.room.helpers({
} ,
adminClass ( ) {
if ( RocketChat . authz . hasRole ( Meteor . userId ( ) , 'admin' ) ) { return 'admin' ; }
if ( hasRole ( Meteor . userId ( ) , 'admin' ) ) { return 'admin' ; }
} ,
showToggleFavorite ( ) {
@ -409,7 +425,7 @@ Template.room.helpers({
} ,
messageViewMode ( ) {
const viewMode = RocketChat . getUserPreference ( Meteor . userId ( ) , 'messageViewMode' ) ;
const viewMode = getUserPreference ( Meteor . userId ( ) , 'messageViewMode' ) ;
const modes = [ '' , 'cozy' , 'compact' ] ;
return modes [ viewMode ] || modes [ 0 ] ;
} ,
@ -419,11 +435,11 @@ Template.room.helpers({
} ,
hideUsername ( ) {
return RocketChat . getUserPreference ( Meteor . userId ( ) , 'hideUsernames' ) ? 'hide-usernames' : undefined ;
return getUserPreference ( Meteor . userId ( ) , 'hideUsernames' ) ? 'hide-usernames' : undefined ;
} ,
hideAvatar ( ) {
return RocketChat . getUserPreference ( Meteor . userId ( ) , 'hideAvatars' ) ? 'hide-avatars' : undefined ;
return getUserPreference ( Meteor . userId ( ) , 'hideAvatars' ) ? 'hide-avatars' : undefined ;
} ,
userCanDrop ( ) {
@ -445,15 +461,15 @@ Template.room.helpers({
return true ;
}
if ( RocketChat . settings . get ( 'Accounts_AllowAnonymousRead' ) === true ) {
if ( settings . get ( 'Accounts_AllowAnonymousRead' ) === true ) {
return true ;
}
if ( RocketChat . authz . hasAllPermission ( 'preview-c-room' ) ) {
if ( hasAllPermission ( 'preview-c-room' ) ) {
return true ;
}
return ( RocketChat . models . Subscriptions . findOne ( { rid : this . _id } ) != null ) ;
return ( Subscriptions . findOne ( { rid : this . _id } ) != null ) ;
} ,
hideLeaderHeader ( ) {
@ -494,14 +510,14 @@ let lastScrollTop;
Template . room . events ( {
'click .js-reply-broadcast' ( ) {
const message = this . _arguments [ 1 ] ;
RocketChat . roomTypes . openRouteLink ( 'd' , { name : this . _arguments [ 1 ] . u . username } , { ... FlowRouter . current ( ) . queryParams , reply : message . _id } ) ;
roomTypes . openRouteLink ( 'd' , { name : this . _arguments [ 1 ] . u . username } , { ... FlowRouter . current ( ) . queryParams , reply : message . _id } ) ;
} ,
'click, touchend' ( e , t ) {
Meteor . setTimeout ( ( ) => t . sendToBottomIfNecessaryDebounced ( ) , 100 ) ;
} ,
'click .messages-container-main' ( ) {
if ( Template . instance ( ) . tabBar . getState ( ) === 'opened' && RocketChat . getUserPreference ( Meteor . userId ( ) , 'hideFlexTab' ) ) {
if ( Template . instance ( ) . tabBar . getState ( ) === 'opened' && getUserPreference ( Meteor . userId ( ) , 'hideFlexTab' ) ) {
Template . instance ( ) . tabBar . close ( ) ;
}
} ,
@ -681,7 +697,7 @@ Template.room.events({
}
const [ , message ] = this . _arguments ;
const allItems = RocketChat . MessageAction . getButtons ( message , context , 'menu' ) . map ( ( item ) => ( {
const allItems = MessageAction . getButtons ( message , context , 'menu' ) . map ( ( item ) => ( {
icon : item . icon ,
name : t ( item . label ) ,
type : 'message-action' ,
@ -721,7 +737,7 @@ Template.room.events({
}
const channel = $ ( e . currentTarget ) . data ( 'channel' ) ;
if ( channel != null ) {
if ( RocketChat . Layout . isEmbedded ( ) ) {
if ( Layout . isEmbedded ( ) ) {
fireGlobalEvent ( 'click-mention-link' , { path : FlowRouter . path ( 'channel' , { name : channel } ) , channel } ) ;
}
@ -831,7 +847,7 @@ Template.room.events({
const roomData = Session . get ( ` roomData ${ this . _id } ` ) ;
if ( ! roomData ) { return false ; }
if ( roomData . announcementDetails != null && roomData . announcementDetails . callback != null ) {
return RocketChat . callbacks . run ( roomData . announcementDetails . callback , this . _id ) ;
return callbacks . run ( roomData . announcementDetails . callback , this . _id ) ;
} else {
modal . open ( {
title : t ( 'Announcement' ) ,
@ -853,9 +869,9 @@ Template.room.events({
if ( ! msg ) {
return ;
}
RocketChat . promises . run ( 'onClientBeforeSendMessage' , msgObject ) . then ( ( msgObject ) => {
const chatMessages = window . chatMessages [ rid ] ;
if ( chatMessages && chatMessages . processSlashCommand ( msgObject ) ) {
promises . run ( 'onClientBeforeSendMessage' , msgObject ) . then ( ( msgObject ) => {
const _ chatMessages = chatMessages [ rid ] ;
if ( _ chatMessages && _ chatMessages. processSlashCommand ( msgObject ) ) {
return ;
}
@ -941,7 +957,7 @@ Template.room.onCreated(function() {
this . hasTokenpass = new ReactiveVar ( false ) ;
if ( RocketChat . settings . get ( 'API_Tokenpass_URL' ) !== '' ) {
if ( settings . get ( 'API_Tokenpass_URL' ) !== '' ) {
Meteor . call ( 'getChannelTokenpass' , this . data . _id , ( error , result ) => {
if ( ! error ) {
this . hasTokenpass . set ( ! ! ( result && result . tokens && result . tokens . length > 0 ) ) ;
@ -990,10 +1006,10 @@ Template.room.onDestroyed(function() {
Template . room . onRendered ( function ( ) {
// $(this.find('.messages-box .wrapper')).perfectScrollbar();
const rid = Session . get ( 'openedRoom' ) ;
if ( ! window . chatMessages [ rid ] ) {
window . chatMessages [ rid ] = new ChatMessages ;
if ( ! chatMessages [ rid ] ) {
chatMessages [ rid ] = new ChatMessages ;
}
window . chatMessages [ rid ] . init ( this . firstNode ) ;
chatMessages [ rid ] . init ( this . firstNode ) ;
// ScrollListener.init()
const wrapper = this . find ( '.wrapper' ) ;
@ -1137,7 +1153,7 @@ Template.room.onRendered(function() {
}
} ) ;
}
RocketChat . callbacks . add ( 'streamMessage' , ( msg ) => {
callbacks . add ( 'streamMessage' , ( msg ) => {
if ( rid !== msg . rid || msg . editedAt ) {
return ;
}
@ -1146,7 +1162,7 @@ Template.room.onRendered(function() {
}
} ) ;
Tracker . autorun ( function ( ) {
const room = RocketChat . models . Ro oms . findOne ( { _id : template . data . _id } ) ;
const room = Rooms . findOne ( { _id : template . data . _id } ) ;
if ( ! room ) {
FlowRouter . go ( 'home' ) ;
}