@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Allow Aphlict to load Javelin and use Javelin class definitions

Summary:
Ref T4324. The server code is probably going to get a fair amount more complicated, so allow it to load Javelin classes in a mostly-reasonable way.

This integration has a few warts, but should be good enough to let us manage complexity through the next iteration of the server.

(Mostly I just want the concicse Javelin mechanism for defining new classes.)

Version bump is just so I can figure stuff out if this creates any issues for users based on which version of things they're running.

Test Plan: Started server, posted some messages through it.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T4324

Differential Revision: https://secure.phabricator.com/D8253

+85 -20
+1 -1
src/applications/notification/client/PhabricatorNotificationClient.php
··· 2 2 3 3 final class PhabricatorNotificationClient { 4 4 5 - const EXPECT_VERSION = 2; 5 + const EXPECT_VERSION = 3; 6 6 7 7 public static function getServerStatus() { 8 8 $uri = PhabricatorEnv::getEnvConfig('notification.server-uri');
+8 -19
support/aphlict/server/aphlict_server.js
··· 6 6 * You can also specify `port`, `admin`, `host` and `log`. 7 7 */ 8 8 9 + var JX = require('./lib/javelin').JX; 10 + JX.require('lib/AphlictIDGenerator', __dirname); 11 + 12 + var id_generator = new JX.AphlictIDGenerator(); 13 + 9 14 var config = parse_command_line_arguments(process.argv); 10 15 11 16 function parse_command_line_arguments(argv) { ··· 108 113 109 114 var clients = {}; 110 115 var current_connections = 0; 111 - // According to the internet up to 2^53 can 112 - // be stored in javascript, this is less than that 113 - var MAX_ID = 9007199254740991;//2^53 -1 114 - 115 - // If we get one connections per millisecond this will 116 - // be fine as long as someone doesn't maintain a 117 - // connection for longer than 6854793 years. If 118 - // you want to write something pretty be my guest 119 - 120 - function generate_id() { 121 - if (typeof generate_id.current_id == 'undefined' || 122 - generate_id.current_id > MAX_ID) { 123 - generate_id.current_id = 0; 124 - } 125 - return generate_id.current_id++; 126 - } 127 116 128 117 var send_server = net.createServer(function(socket) { 129 - var client_id = generate_id(); 118 + var client_id = id_generator.generateNext(); 130 119 var client_name = '[' + socket.remoteAddress + '] [#' + client_id + '] '; 131 120 132 121 clients[client_id] = socket; ··· 189 178 var status = { 190 179 'uptime': (new Date().getTime() - start_time), 191 180 'clients.active': current_connections, 192 - 'clients.total': generate_id.current_id || 0, 181 + 'clients.total': id_generator.getTotalCount(), 193 182 'messages.in': messages_in, 194 183 'messages.out': messages_out, 195 184 'log': config.log, 196 - 'version': 2 185 + 'version': 3 197 186 }; 198 187 199 188 response.write(JSON.stringify(status));
+18
support/aphlict/server/lib/AphlictIDGenerator.js
··· 1 + var JX = require('javelin').JX; 2 + 3 + JX.install('AphlictIDGenerator', { 4 + 5 + members : { 6 + _next : 0, 7 + 8 + generateNext : function() { 9 + this._next = ((this._next + 1) % 1000000000000); 10 + return this._next; 11 + }, 12 + 13 + getTotalCount : function() { 14 + return this._next; 15 + } 16 + } 17 + 18 + });
+13
support/aphlict/server/lib/javelin.js
··· 1 + var javelin_root = '../../../../webroot/rsrc/externals/javelin/'; 2 + var JX = require(javelin_root + 'core/init_node.js').JX; 3 + 4 + JX.require('core/util'); 5 + JX.require('core/install'); 6 + 7 + // NOTE: This is faking out a piece of code in JX.install which waits for 8 + // Stratcom before running static initializers. 9 + JX.Stratcom = {ready : true}; 10 + JX.require('core/Event'); 11 + JX.require('core/Stratcom'); 12 + 13 + exports.JX = JX;
+45
webroot/rsrc/externals/javelin/core/init_node.js
··· 1 + /** 2 + * Alternative Javelin init file for Node.js. 3 + * 4 + * @javelin-installs JX.enableDispatch 5 + * @javelin-installs JX.onload 6 + * @javelin-installs JX.flushHoldingQueue 7 + * @javelin-installs JX.require 8 + * 9 + * @javelin 10 + */ 11 + 12 + var JX = {}; 13 + var fs = require('fs'); 14 + var vm = require('vm'); 15 + var pathModule = require('path'); 16 + 17 + var noop = function() {}; 18 + 19 + JX.enableDispatch = noop; 20 + JX.flushHoldingQueue = noop; 21 + 22 + JX.onload = function(func) { 23 + func(); 24 + }; 25 + 26 + JX.require = function(thing, relative) { 27 + relative = relative || __dirname + '/..'; 28 + var path = relative + '/' + thing + '.js'; 29 + var content = fs.readFileSync(path); 30 + 31 + var sandbox = { 32 + JX : this, 33 + __DEV__ : 0, 34 + console : console, 35 + window : {}, 36 + require : function (thing) { 37 + return require(pathModule.dirname(path) + '/' + thing); 38 + } 39 + }; 40 + 41 + vm.createScript(content, path) 42 + .runInNewContext(sandbox, path); 43 + }; 44 + 45 + exports.JX = JX;