 
 		RocketChatAssetsInstance.deleteFile asset
 
-		RocketChat.settings.updateById "Assets_#{asset}", {defaultUrl: assets[asset].defaultUrl}
+		key = "Assets_#{asset}"
+		value = {
+			defaultUrl: assets[asset].defaultUrl
+		}
+		RocketChat.settings.updateById key, value
+		RocketChat.Assets.processAsset key, value
 		return
 
 	refreshClients: ->
 		process.emit('message', {refresh: 'client'})
+
+	processAsset: (settingKey, settingValue) ->
+		if settingKey.indexOf('Assets_') isnt 0
+			return
+
+		assetKey = settingKey.replace /^Assets_/, ''
+		assetValue = assets[assetKey]
+
+		if not assetValue?
+			return
+
+		if not settingValue?.url?
+			assetValue.cache = undefined
+			return
+
+		file = RocketChatAssetsInstance.getFileSync assetKey
+		if not file
+			assetValue.cache = undefined
+			return
+
+		hash = crypto.createHash('sha1').update(file.buffer).digest('hex')
+		extension = settingValue.url.split('.').pop()
+		assetValue.cache =
+			path: "assets/#{assetKey}.#{extension}"
+			cacheable: false
+			sourceMapUrl: undefined
+			where: 'client'
+			type: 'asset'
+			content: file.buffer
+			extension: extension
+			url: "/assets/#{assetKey}.#{extension}?#{hash}"
+			size: file.length
+			uploadDate: file.uploadDate
+			contentType: file.contentType
+			hash: hash
 
 
 RocketChat.settings.addGroup 'Assets'

		RocketChat.settings.add "Assets_#{key}", {defaultUrl: value.defaultUrl}, { type: 'asset', group: 'Assets', fileConstraints: value.constraints, i18nLabel: value.label, asset: key, public: true }


forEachAsset = (key, value) ->
	RocketChat.settings.get "Assets_#{key}", (settingKey, settingValue) ->
		if not settingValue?.url?
			value.cache = undefined
			return

		file = RocketChatAssetsInstance.getFileWithReadStream key
		if not file
			value.cache = undefined
			return

		data = []
		file.readStream.on 'data', Meteor.bindEnvironment (chunk) ->
			data.push chunk

		file.readStream.on 'end', Meteor.bindEnvironment ->
			data = Buffer.concat(data)
			hash = crypto.createHash('sha1').update(data).digest('hex')
			extension = settingValue.url.split('.').pop()
			value.cache =
				path: "assets/#{key}.#{extension}"
				cacheable: false
				sourceMapUrl: undefined
				where: 'client'
				type: 'asset'
				content: data
				extension: extension
				url: "/assets/#{key}.#{extension}?#{hash}"
				size: file.length
				uploadDate: file.uploadDate
				contentType: file.contentType
				hash: hash


forEachAsset(key, value) for key, value of assets

calculateClientHash = WebAppHashing.calculateClientHash
WebAppHashing.calculateClientHash = (manifest, includeFilter, runtimeConfigOverride) ->
	for key, value of assets
		if not value.cache? && not value.defaultUrl?
			continue

		manifestItem = _.find manifest, (item) ->
			return item.path is key

		cache = {}
		if value.cache

		unless hasPermission
			throw new Meteor.Error 'error-action-now-allowed', 'Managing assets not allowed', { method: 'refreshClients', action: 'Managing_assets' }

		RocketChat.Assets.refreshClients()


	unsetAsset: (asset) ->
