PluginProbe
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin / 1.1.10
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin v1.1.10
1.1.10 1.1.9 1.1.8 1.1.7 1.1.6 1.1.5 1.1.4 1.1.3 1.1.2 1.1.1 1.1.0 1.0.1 1.0.0 0.9.8 0.9.7 0.9.6 0.9.4 0.9.5 0.9.3 0.9.2 0.9.1 0.9.0 0.8.9 0.8.8 0.8.7 All 34 releases
← All changes | includes/notes/heartbeat.php +22 -23 0.9.81.1.10 View file →
@@ -1,18 +1,17 @@
1 1 <?php
2 2 /**
3 - * Desktop Mode — Pinned notes Heartbeat sync.
3 + * OpenStation — Pinned notes Heartbeat sync.
4 4 *
5 - * Same delta model as the sticky-notes sync
6 - * (`includes/sticky-notes/heartbeat.php`): the client subscribes with
7 - * the note ids it already renders plus a high-water modified
8 - * timestamp; the server responds with notes changed since then and
9 - * with removals (trashed, deleted, or made private by their owner).
5 + * Delta model: the client subscribes with the note ids it already
6 + * renders plus a high-water modified timestamp; the server responds
7 + * with notes changed since then and with removals (trashed, deleted,
8 + * or made private by their owner).
10 9 *
11 10 * Visibility mirrors the REST list: the viewer's own notes (private +
12 11 * publish) plus every other user's public notes.
13 12 *
14 - * @package WPDesktopMode
13 + * @package OpenStation
15 14 */
16 15
17 16 defined( 'ABSPATH' ) || exit;
18 17
@@ -22,20 +21,20 @@
22 21 * @param array $response Pre-filtered response.
23 22 * @param array $data Client-sent payload.
24 23 * @return array
25 24 */
26 -function desktop_mode_notes_heartbeat_received( $response, $data ) {
25 +function openstation_notes_heartbeat_received( $response, $data ) {
27 26 if ( ! is_array( $response ) ) {
28 27 $response = array();
29 28 }
30 - if ( empty( $data['desktop_mode_notes_subscribe'] ) || ! is_array( $data['desktop_mode_notes_subscribe'] ) ) {
29 + if ( empty( $data['openstation_notes_subscribe'] ) || ! is_array( $data['openstation_notes_subscribe'] ) ) {
31 30 return $response;
32 31 }
33 - if ( ! function_exists( 'desktop_mode_is_enabled' ) || ! desktop_mode_is_enabled() ) {
32 + if ( ! function_exists( 'openstation_is_enabled' ) || ! openstation_is_enabled() ) {
34 33 return $response;
35 34 }
36 35
37 - $sub = $data['desktop_mode_notes_subscribe'];
36 + $sub = $data['openstation_notes_subscribe'];
38 37 $known_ids = isset( $sub['knownIds'] ) && is_array( $sub['knownIds'] )
39 38 ? array_values( array_unique( array_filter( array_map( 'absint', $sub['knownIds'] ) ) ) )
40 39 : array();
41 40 $known_ids = array_slice( $known_ids, 0, 500 );
@@ -40,13 +39,13 @@
40 39 : array();
41 40 $known_ids = array_slice( $known_ids, 0, 500 );
42 41 $since_ms = isset( $sub['sinceMs'] ) ? max( 0, (int) $sub['sinceMs'] ) : 0;
43 42
44 - $response['desktop_mode_notes'] = desktop_mode_notes_compute_heartbeat_delta( $known_ids, $since_ms, 100 );
43 + $response['openstation_notes'] = openstation_notes_compute_heartbeat_delta( $known_ids, $since_ms, 100 );
45 44
46 45 return $response;
47 46 }
48 -add_filter( 'heartbeat_received', 'desktop_mode_notes_heartbeat_received', 5, 2 );
47 +add_filter( 'heartbeat_received', 'openstation_notes_heartbeat_received', 5, 2 );
49 48
50 49 /**
51 50 * Compute pinned-note Heartbeat deltas for the current user.
52 51 *
@@ -54,11 +53,11 @@
54 53 * @param int $since_ms Last-seen modified timestamp in milliseconds.
55 54 * @param int $cap Maximum notes to send in one tick.
56 55 * @return array
57 56 */
58 -function desktop_mode_notes_compute_heartbeat_delta( $known_ids, $since_ms, $cap ) {
57 +function openstation_notes_compute_heartbeat_delta( $known_ids, $since_ms, $cap ) {
59 58 $cap = max( 1, (int) $cap );
60 - $query_ids = desktop_mode_notes_query_changed_ids( $since_ms, $cap + 1 );
59 + $query_ids = openstation_notes_query_changed_ids( $since_ms, $cap + 1 );
61 60 $truncated = count( $query_ids ) > $cap;
62 61 if ( $truncated ) {
63 62 $query_ids = array_slice( $query_ids, 0, $cap );
64 63 }
@@ -66,13 +65,13 @@
66 65 $notes = array();
67 66 foreach ( $query_ids as $post_id ) {
68 67 $post = get_post( $post_id );
69 68 if ( $post instanceof WP_Post ) {
70 - $notes[] = desktop_mode_notes_prepare( $post );
69 + $notes[] = openstation_notes_prepare( $post );
71 70 }
72 71 }
73 72
74 - $alive_ids = desktop_mode_notes_alive_known_ids( $known_ids );
73 + $alive_ids = openstation_notes_alive_known_ids( $known_ids );
75 74 $removed = array_values( array_diff( array_map( 'intval', $known_ids ), $alive_ids ) );
76 75
77 76 return array(
78 77 'notes' => $notes,
@@ -91,12 +90,12 @@
91 90 *
92 91 * @param array $extra Extra WP_Query args merged into both halves.
93 92 * @return int[] Matching post ids, own notes first.
94 93 */
95 -function desktop_mode_notes_query_visible_ids( $extra ) {
94 +function openstation_notes_query_visible_ids( $extra ) {
96 95 $user_id = get_current_user_id();
97 96 $base = array(
98 - 'post_type' => DESKTOP_MODE_NOTES_POST_TYPE,
97 + 'post_type' => OPENSTATION_NOTES_POST_TYPE,
99 98 'fields' => 'ids',
100 99 'no_found_rows' => true,
101 100 );
102 101
@@ -134,9 +133,9 @@
134 133 * @param int $since_ms Last-seen modified timestamp in milliseconds.
135 134 * @param int $limit Max ids to return (per visibility half).
136 135 * @return int[]
137 136 */
138 -function desktop_mode_notes_query_changed_ids( $since_ms, $limit ) {
137 +function openstation_notes_query_changed_ids( $since_ms, $limit ) {
139 138 $extra = array(
140 139 'posts_per_page' => max( 1, (int) $limit ),
141 140 'orderby' => 'modified',
142 141 'order' => 'ASC',
@@ -149,9 +148,9 @@
149 148 'inclusive' => true,
150 149 ),
151 150 );
152 151 }
153 - return desktop_mode_notes_query_visible_ids( $extra );
152 + return openstation_notes_query_visible_ids( $extra );
154 153 }
155 154
156 155 /**
157 156 * Return the subset of known ids still visible to the viewer.
@@ -158,14 +157,14 @@
158 157 *
159 158 * @param int[] $known_ids Client-known note ids.
160 159 * @return int[]
161 160 */
162 -function desktop_mode_notes_alive_known_ids( $known_ids ) {
161 +function openstation_notes_alive_known_ids( $known_ids ) {
163 162 $known_ids = array_values( array_unique( array_filter( array_map( 'absint', (array) $known_ids ) ) ) );
164 163 if ( empty( $known_ids ) ) {
165 164 return array();
166 165 }
167 - return desktop_mode_notes_query_visible_ids(
166 + return openstation_notes_query_visible_ids(
168 167 array(
169 168 'post__in' => $known_ids,
170 169 'posts_per_page' => count( $known_ids ),
171 170 )