@@ -19,6 +19,13 @@ class PushHandler extends \wcf\system\SingletonFactory {
19
19
*/
20
20
private $ deferred = array ();
21
21
22
+ /**
23
+ * Channels to join for this page view.
24
+ *
25
+ * @var string[]
26
+ */
27
+ private $ channels = [ ];
28
+
22
29
/**
23
30
* Returns whether a push service is enabled.
24
31
*
@@ -43,52 +50,42 @@ public function isRunning() {
43
50
return (boolean ) $ backend ::getInstance ()->isRunning ();
44
51
}
45
52
53
+ /**
54
+ * @see \wcf\system\push\PushHandler::getFeatureFlags()
55
+ */
56
+ public function getFeatureFlags () {
57
+ $ backend = PUSH_BACKEND ;
58
+ if (method_exists ($ backend , 'getFeatureFlags ' )) {
59
+ return $ backend ::getInstance ()->getFeatureFlags ();
60
+ }
61
+
62
+ return [ ];
63
+ }
64
+
46
65
/**
47
66
* Sends a message to the connected clients. Returns `true` on success and `false`
48
67
* otherwise.
49
68
*
50
- * If `$userIDs` is an empty array the message will be sent to every connected client.
51
- * Otherwise the message will only be sent to clients with the given userID.
52
- *
53
- * `$payload` will be made available in the JavaScript code as a parameter. Note that
54
- * a specific push backend may choose to ignore the payload, if it cannot transmit it.
55
- * Make sure that you properly handle this in your code.
56
- *
57
- * ATTENTION: Do NOT (!) send any security related information via sendMessage.
58
- * Not every push service can validate whether the userID given was forged by a malicious client!
69
+ * $message must be an array containing the following:
70
+ * message: string - The message to send.
71
+ * payload: ?array - Additional data to send.
72
+ * target: ?array - Targets to send to. The message is send to the Union of Targets.
59
73
*
60
- * @param string $message
61
- * @param array<integer> $userIDs
62
- * @param array $payload
74
+ * @param array $message
63
75
* @return boolean
64
76
*/
65
77
public function sendMessage ($ message , array $ userIDs = array (), array $ payload = array ()) {
66
78
if (!$ this ->isEnabled ()) return false ;
67
- if (!\wcf \data \package \Package::isValidPackageName ($ message )) return false ;
68
- $ userIDs = array_unique (\wcf \util \ArrayUtil::toIntegerArray ($ userIDs ));
69
79
70
80
$ backend = PUSH_BACKEND ;
71
81
return (boolean ) $ backend ::getInstance ()->sendMessage ($ message , $ userIDs , $ payload );
72
82
}
73
83
74
84
/**
75
- * Registers a deferred message. Returns `true` on any well-formed message and `false`
76
- * otherwise.
77
- * Deferred messages will be sent on shutdown. This can be useful if your handler depends
78
- * on data that may not be written to database yet or to achieve a better performance as the
79
- * page is delivered first.
80
- *
81
- * ATTENTION: Use this method only if your messages are not critical as you cannot check
82
- * whether your message was delivered successfully.
83
- * ATTENTION: Do NOT (!) send any security related information via sendDeferredMessage.
84
- * Not every push service can validate whether the userID given was forged by a malicious client!
85
- *
86
- * @see \wcf\system\push\PushHandler::sendMessage()
85
+ * @deprecated
87
86
*/
88
87
public function sendDeferredMessage ($ message , array $ userIDs = array (), array $ payload = array ()) {
89
88
if (!$ this ->isEnabled ()) return false ;
90
- if (!\wcf \data \package \Package::isValidPackageName ($ message )) return false ;
91
- $ userIDs = array_unique (\wcf \util \ArrayUtil::toIntegerArray ($ userIDs ));
92
89
93
90
$ this ->deferred [] = array (
94
91
'message ' => $ message ,
@@ -107,4 +104,22 @@ public function __destruct() {
107
104
$ this ->sendMessage ($ data ['message ' ], $ data ['userIDs ' ], $ data ['payload ' ]);
108
105
}
109
106
}
107
+
108
+ /**
109
+ * Joins the given channel for this request.
110
+ *
111
+ * @param string $name
112
+ */
113
+ public function joinChannel ($ name ) {
114
+ $ this ->channels [$ name ] = $ name ;
115
+ }
116
+
117
+ /**
118
+ * Returns the list of joined channels.
119
+ *
120
+ * @return string[]
121
+ */
122
+ public function getChannels () {
123
+ return array_values ($ this ->channels );
124
+ }
110
125
}
0 commit comments