Feature #3032
openStreams::invite to process invites with PHP instead of Node
0%
Description
Right now, Streams::invite
calls Node in order to finish processing invites:
// let node handle the rest, and get the result $params = array( "Q/method" => "Streams/Stream/invite", "invitingUserId" => $asUserId, "username" => $asUser->username, "preferredLanguage" => $asUser->preferredLanguage, "userIds" => Q::json_encode($userIds), "stream" => Q::json_encode($stream->toArray()), "appUrl" => $appUrl, "label" => $label, "addLabel" => $addLabel, "addMyLabel" => $addMyLabel, "alwaysSend" => $alwaysSend, "readLevel" => $readLevel, "writeLevel" => $writeLevel, "adminLevel" => $adminLevel, "permissions" => $permissions, "displayName" => $displayName, "expireTime" => $expireTime ); if (!empty($template)) { $params['template'] = $template; $params['batchName'] = $batchName; } if (!empty($templateDir)) { $params['templateDir'] = $templateDir; } try { $result = Q_Utils::queryInternal('Q/node', $params); } catch (Exception $e) { // just suppress it $result = null; }
Refactor¶
First, please refactor this to be like the other standard calls:
// Send a message to Node Q_Utils::sendToNode(array( "Q/method" => "Streams/Stream/$type", "participant" => Q::json_encode($participant->toArray()), "stream" => Q::json_encode($stream->toArray()), "prevState" => $prevState ));
Implement PHP version¶
Streams::invite
should have a new option called documented in the YUIDoc:
* @param {array} $usingPHP Instructions on processing invites with PHP * @param {integer} [$usingPHP.max] the maximum number of users to handle with PHP
After this line:
// remove already participating users if alwaysSend=false if (!$alwaysSend) { $userIds = array_diff($raw_userIds, $alreadyParticipating); }
if the count($userIds) < Q::ifset($options, 'usingPHP', 'max', 0)
then do what Node does, but in PHP.
What Node does:¶
Look at classes/Streams/Streams.js
line 697:
case 'Streams/Stream/invite': try { userIds = JSON.parse(parsed.userIds); invitingUserId = parsed.invitingUserId; username = parsed.username; appUrl = parsed.appUrl; readLevel = parsed.readLevel || null; writeLevel = parsed.writeLevel || null; adminLevel = parsed.adminLevel || null; permissions = parsed.permissions || null; displayName = parsed.displayName || ''; label = parsed.label || ''; addLabel = parsed.addLabel || []; addMyLabel = parsed.addMylabel || []; alwaysSend = parsed.alwaysSend || false; expireTime = parsed.expireTime ? new Date(parsed.expireTime*1000) : null; } catch (e) { return res.send({data: false}); } res.send({data: true}); if (logKey = Q.Config.get(['Streams', 'logging'], false)) { Q.log( 'Streams.listen: Streams/Stream/invite {' + '"publisherId": "' + stream.fields.publisherId + '", "name": "' + stream.fields.name + '", "userIds": ' + parsed.userIds + '}', logKey ); } if (expireTime && expireTime <= new Date()) { break; } persist(); return;
Implement this same thing in PHP, including the persist()
method.
Subscriptions and Notifications¶
In order for this to work, you'd have to also port delivering subscriptions and notifications via PHP, with the same "max" mechanism.
Note that, in Node.js, posting to Streams/invited
stream that the publisher subscribed to, can trigger a notification that will be delivered
to email, mobile, devices, to all subscribers (usually only its publisher). This is a lot of code to port to PHP.
Conclusion¶
But if there are too many users invited, then send to node instead.
This will allow us to handle invites with PHP without relying on Node.js to be running.
No data to display