Skip to content

Commit

Permalink
Merge pull request #155 from RocketChat/rocket-packages
Browse files Browse the repository at this point in the history
  • Loading branch information
engelgabriel committed Jun 5, 2015
2 parents f905a6c + ef52903 commit 566abe7
Show file tree
Hide file tree
Showing 21 changed files with 202 additions and 29 deletions.
2 changes: 2 additions & 0 deletions .meteor/packages
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,5 @@ rocket:file
pauli:accounts-linkedin
iframely:oembed
pierreeric:rxfavico
rocket:lib
rocket:me
2 changes: 2 additions & 0 deletions .meteor/versions
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ reactive-var@1.0.5
reload@1.1.3
retry@1.0.3
rocket:file@0.0.1
rocket:lib@0.0.1
rocket:me@0.0.1
routepolicy@1.0.5
service-configuration@1.0.4
session@1.1.0
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2015 ChatRocket
Copyright (c) 2015 RocketChat

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion client/lib/rocket.coffee
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@Rocket = (->
@RocketChat = (->


@Login = (->
Expand Down
12 changes: 12 additions & 0 deletions ecosystem.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"deploy": {
"production": {
"user": "root",
"host": ["rocket.chat"],
"ref": "origin/master",
"repo": "https://github.com/RocketChat/Rocket.Chat.git",
"path": "/var/www/rocket.chat",
"post-deploy": "source build.sh production"
}
}
}
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,28 @@ path = Npm.require('path')
mkdirp = Npm.require('mkdirp')
gm = Npm.require('gm')

RocketFile =
RocketChatFile =
gm: gm

RocketFile.bufferToStream = (buffer) ->
RocketChatFile.bufferToStream = (buffer) ->
bufferStream = new stream.PassThrough()
bufferStream.end buffer
bufferStream.end buffer
return bufferStream

RocketFile.dataURIParse = (dataURI) ->
RocketChatFile.dataURIParse = (dataURI) ->
imageData = dataURI.split ';base64,'
return {
image: imageData[1]
contentType: imageData[0].replace('data:', '')
}

RocketFile.addPassThrough = (st, fn) ->
RocketChatFile.addPassThrough = (st, fn) ->
pass = new stream.PassThrough()
fn pass, st
return pass


RocketFile.GridFS = class
RocketChatFile.GridFS = class
constructor: (config={}) ->
{name, transformWrite} = config

Expand Down Expand Up @@ -61,7 +61,7 @@ RocketFile.GridFS = class
content_type: contentType

if self.transformWrite?
ws = RocketFile.addPassThrough ws, (rs, ws) ->
ws = RocketChatFile.addPassThrough ws, (rs, ws) ->
file =
name: self.name
fileName: fileName
Expand Down Expand Up @@ -101,7 +101,7 @@ RocketFile.GridFS = class
return this.remove fileName


RocketFile.FileSystem = class
RocketChatFile.FileSystem = class
constructor: (config={}) ->
{absolutePath, transformWrite} = config

Expand All @@ -127,7 +127,7 @@ RocketFile.FileSystem = class
ws = fs.createWriteStream path.join this.absolutePath, fileName

if self.transformWrite?
ws = RocketFile.addPassThrough ws, (rs, ws) ->
ws = RocketChatFile.addPassThrough ws, (rs, ws) ->
file =
fileName: fileName
contentType: contentType
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package.describe({
name: 'rocket:file',
name: 'rocketchat:file',
version: '0.0.1',
summary: '',
git: ''
Expand All @@ -18,9 +18,9 @@ Package.onUse(function(api) {

api.addFiles('file.server.coffee', 'server');

api.export(['RocketFile'], ['server']);
api.export(['RocketChatFile'], ['server']);
});

Package.onTest(function(api) {

});
});
84 changes: 84 additions & 0 deletions packages/rocketchat-lib/lib/callbacks.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# https://github.com/TelescopeJS/Telescope/blob/master/packages/telescope-lib/lib/callbacks.js

###
# Callback hooks provide an easy way to add extra steps to common operations.
# @namespace RocketChat.callbacks
###
RocketChat.callbacks = {}

###
# Callback priorities
###
RocketChat.callbacks.priority =
HIGH: -1
MEDIUM: 0
LOW: 1

###
# Add a callback function to a hook
# @param {String} hook - The name of the hook
# @param {Function} callback - The callback function
###

RocketChat.callbacks.add = (hook, callback, priority) ->
# if callback array doesn't exist yet, initialize it
priority ?= RocketChat.callbacks.priority.MEDIUM
unless _.isNumber priority
priority = RocketChat.callbacks.priority.MEDIUM
callback.priority = priority
RocketChat.callbacks[hook] ?= []
RocketChat.callbacks[hook].push callback
return

###
# Remove a callback from a hook
# @param {string} hook - The name of the hook
# @param {string} functionName - The name of the function to remove
###

RocketChat.callbacks.remove = (hookName, callbackName) ->
RocketChat.callbacks[hookName] = _.reject RocketChat.callbacks[hookName], (callback) ->
callback.name is callbackName
return

###
# Successively run all of a hook's callbacks on an item
# @param {String} hook - The name of the hook
# @param {Object} item - The post, comment, modifier, etc. on which to run the callbacks
# @param {Object} [constant] - An optional constant that will be passed along to each callback
# @returns {Object} Returns the item after it's been through all the callbacks for this hook
###

RocketChat.callbacks.run = (hook, item, constant) ->
callbacks = RocketChat.callbacks[hook]
if !!callbacks?.length
# if the hook exists, and contains callbacks to run
_.sortBy(callbacks, (callback) -> return callback.priority or RocketChat.callbacks.priority.MEDIUM).reduce (result, callback) ->
# console.log(callback.name);
callback result, constant
, item
else
# else, just return the item unchanged
item

###
# Successively run all of a hook's callbacks on an item, in async mode (only works on server)
# @param {String} hook - The name of the hook
# @param {Object} item - The post, comment, modifier, etc. on which to run the callbacks
# @param {Object} [constant] - An optional constant that will be passed along to each callback
###

RocketChat.callbacks.runAsync = (hook, item, constant) ->
callbacks = RocketChat.callbacks[hook]
if Meteor.isServer and !!callbacks?.length
# use defer to avoid holding up client
Meteor.defer ->
# run all post submit server callbacks on post object successively
_.sortBy(callbacks, (callback) -> return callback.priority or RocketChat.callbacks.priority.MEDIUM).forEach (callback) ->
# console.log(callback.name);
callback item, constant
return
return
else
return item
return
6 changes: 6 additions & 0 deletions packages/rocketchat-lib/lib/core.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
###
# Kick off the global namespace for RocketChat.
# @namespace RocketChat
###

RocketChat = {}
5 changes: 5 additions & 0 deletions packages/rocketchat-lib/lib/underscore.string.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# This will add underscore.string methods to Underscore.js
# except for include, contains, reverse and join that are
# dropped because they collide with the functions already
# defined by Underscore.js.
_.mixin(s.exports())
26 changes: 26 additions & 0 deletions packages/rocketchat-lib/package.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Package.describe({
name: 'rocketchat:lib',
version: '0.0.1',
summary: 'RocketChat libraries',
git: ''
});

Package.onUse(function(api) {
api.versionsFrom('1.0');

api.use([
'coffeescript',
'underscore',
'underscorestring:underscore.string'
]);

api.addFiles('lib/underscore.string.coffee', 'server');
api.addFiles('lib/core.coffee', 'server');
api.addFiles('lib/callbacks.coffee', 'server');

api.export(['RocketChat'], ['server']);
});

Package.onTest(function(api) {

});
13 changes: 13 additions & 0 deletions packages/rocketchat-me/me.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
###
# Me is a named function that will replace /me commands
# @param {Object} doc - The message object
###

class Me
constructor: (doc) ->
# If message starts with /me, replace it for text formatting
if doc.message.indexOf('/me') is 0
doc.message = '######' + Meteor.user().name + doc.message.replace('/me', '')
return doc

RocketChat.callbacks.add 'sendMessage', Me
21 changes: 21 additions & 0 deletions packages/rocketchat-me/package.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Package.describe({
name: 'rocketchat:me',
version: '0.0.1',
summary: 'Message pre-processor that will translate /me commands',
git: ''
});

Package.onUse(function(api) {
api.versionsFrom('1.0');

api.use([
'coffeescript',
'rocketchat:lib@0.0.1'
]);

api.addFiles('me.coffee', 'server');
});

Package.onTest(function(api) {

});
2 changes: 1 addition & 1 deletion public/landing/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
<button class="button red"><span>Access the Online Demo</span></button>
</a>
<div class='text'>
<h1>RocketChat</h1>
<h1>Rocket.Chat</h1>
<h2>Your own Open Source chat solution</h2>
<p>Have your own web chat. Developed with Meteor.com, the Rocket.Chat is a great solution for developers looking forward to build and evolve their own chat platform.</p>
<a class="button" href="/login"><span>Access the Online Demo</span></a>
Expand Down
2 changes: 2 additions & 0 deletions server/methods/sendMessage.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ Meteor.methods
if mentions.length is 0
mentions = undefined

msg = RocketChat.callbacks.run 'sendMessage', msg

ChatMessage.upsert messageFilter,
$set:
'u._id': Meteor.userId()
Expand Down
8 changes: 4 additions & 4 deletions server/methods/setAvatarFromService.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ Meteor.methods
Meteor.users.update {_id: user._id}, {$set: {avatarOrigin: service}}
return

{image, contentType} = RocketFile.dataURIParse dataURI
{image, contentType} = RocketChatFile.dataURIParse dataURI

rs = RocketFile.bufferToStream new Buffer(image, 'base64')
ws = RocketFileAvatarInstance.createWriteStream "#{user.username}.jpg", contentType
rs = RocketChatFile.bufferToStream new Buffer(image, 'base64')
ws = RocketChatFileAvatarInstance.createWriteStream "#{user.username}.jpg", contentType
ws.on 'end', Meteor.bindEnvironment ->
Meteor.users.update {_id: user._id}, {$set: {avatarOrigin: service}}

Expand All @@ -26,7 +26,7 @@ Meteor.methods

user = Meteor.user()

RocketFileAvatarInstance.deleteFile "#{user.username}.jpg"
RocketChatFileAvatarInstance.deleteFile "#{user.username}.jpg"

Meteor.users.update user._id, {$unset: {avatarOrigin: 1}}
return
12 changes: 6 additions & 6 deletions server/startup/avatar.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ Meteor.startup ->
if Meteor.settings?.public?.avatarStore?.type?
storeType = Meteor.settings.public.avatarStore.type

RocketStore = RocketFile[storeType]
RocketChatStore = RocketChatFile[storeType]

if not RocketStore?
throw new Error "Invalid RocketStore type [#{storeType}]"
if not RocketChatStore?
throw new Error "Invalid RocketChatStore type [#{storeType}]"

console.log "Using #{storeType} for Avatar storage".green

Expand All @@ -16,14 +16,14 @@ Meteor.startup ->
height = Meteor.settings.public.avatarStore.size.height
width = Meteor.settings.public.avatarStore.size.width
transformWrite = (file, readStream, writeStream) ->
RocketFile.gm(readStream, file.fileName).background('#ffffff').resize(width, height+'^>').gravity('Center').extent(width, height).stream('jpeg').pipe(writeStream)
RocketChatFile.gm(readStream, file.fileName).background('#ffffff').resize(width, height+'^>').gravity('Center').extent(width, height).stream('jpeg').pipe(writeStream)

path = "~/uploads"

if Meteor.settings?.public?.avatarStore?.path?
path = Meteor.settings.public.avatarStore.path

@RocketFileAvatarInstance = new RocketStore
@RocketChatFileAvatarInstance = new RocketChatStore
name: 'avatars'
absolutePath: path
transformWrite: transformWrite
Expand All @@ -33,7 +33,7 @@ Meteor.startup ->
'stream': true
'get': (data) ->
this.params.username
file = RocketFileAvatarInstance.getFileWithReadStream this.params.username
file = RocketChatFileAvatarInstance.getFileWithReadStream this.params.username

this.addHeader 'Content-Disposition', 'inline'

Expand Down
8 changes: 4 additions & 4 deletions server/startup/migrations/v0.1.2.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ Meteor.startup ->

dataURI = avatars[service].blob

{image, contentType} = RocketFile.dataURIParse dataURI
{image, contentType} = RocketChatFile.dataURIParse dataURI

rs = RocketFile.bufferToStream new Buffer(image, 'base64')
ws = RocketFileAvatarInstance.createWriteStream "#{user.username}.jpg", contentType
rs = RocketChatFile.bufferToStream new Buffer(image, 'base64')
ws = RocketChatFileAvatarInstance.createWriteStream "#{user.username}.jpg", contentType
ws.on 'end', Meteor.bindEnvironment ->
Meteor.users.update {_id: user._id}, {$set: {avatarOrigin: service}}

rs.pipe(ws)
rs.pipe(ws)

0 comments on commit 566abe7

Please sign in to comment.