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 -34 0.9.61.1.10 View file →
@@ -1,19 +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
15 - * @since 0.9.6
13 + * @package OpenStation
16 14 */
17 15
18 16 defined( 'ABSPATH' ) || exit;
19 17
@@ -19,26 +17,24 @@
19 17
20 18 /**
21 19 * Add pinned-note deltas to the Heartbeat response.
22 20 *
23 - * @since 0.9.6
24 - *
25 21 * @param array $response Pre-filtered response.
26 22 * @param array $data Client-sent payload.
27 23 * @return array
28 24 */
29 -function desktop_mode_notes_heartbeat_received( $response, $data ) {
25 +function openstation_notes_heartbeat_received( $response, $data ) {
30 26 if ( ! is_array( $response ) ) {
31 27 $response = array();
32 28 }
33 - 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'] ) ) {
34 30 return $response;
35 31 }
36 - if ( ! function_exists( 'desktop_mode_is_enabled' ) || ! desktop_mode_is_enabled() ) {
32 + if ( ! function_exists( 'openstation_is_enabled' ) || ! openstation_is_enabled() ) {
37 33 return $response;
38 34 }
39 35
40 - $sub = $data['desktop_mode_notes_subscribe'];
36 + $sub = $data['openstation_notes_subscribe'];
41 37 $known_ids = isset( $sub['knownIds'] ) && is_array( $sub['knownIds'] )
42 38 ? array_values( array_unique( array_filter( array_map( 'absint', $sub['knownIds'] ) ) ) )
43 39 : array();
44 40 $known_ids = array_slice( $known_ids, 0, 500 );
@@ -43,27 +39,25 @@
43 39 : array();
44 40 $known_ids = array_slice( $known_ids, 0, 500 );
45 41 $since_ms = isset( $sub['sinceMs'] ) ? max( 0, (int) $sub['sinceMs'] ) : 0;
46 42
47 - $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 );
48 44
49 45 return $response;
50 46 }
51 -add_filter( 'heartbeat_received', 'desktop_mode_notes_heartbeat_received', 5, 2 );
47 +add_filter( 'heartbeat_received', 'openstation_notes_heartbeat_received', 5, 2 );
52 48
53 49 /**
54 50 * Compute pinned-note Heartbeat deltas for the current user.
55 51 *
56 - * @since 0.9.6
57 - *
58 52 * @param int[] $known_ids Note ids currently rendered by the client.
59 53 * @param int $since_ms Last-seen modified timestamp in milliseconds.
60 54 * @param int $cap Maximum notes to send in one tick.
61 55 * @return array
62 56 */
63 -function desktop_mode_notes_compute_heartbeat_delta( $known_ids, $since_ms, $cap ) {
57 +function openstation_notes_compute_heartbeat_delta( $known_ids, $since_ms, $cap ) {
64 58 $cap = max( 1, (int) $cap );
65 - $query_ids = desktop_mode_notes_query_changed_ids( $since_ms, $cap + 1 );
59 + $query_ids = openstation_notes_query_changed_ids( $since_ms, $cap + 1 );
66 60 $truncated = count( $query_ids ) > $cap;
67 61 if ( $truncated ) {
68 62 $query_ids = array_slice( $query_ids, 0, $cap );
69 63 }
@@ -71,13 +65,13 @@
71 65 $notes = array();
72 66 foreach ( $query_ids as $post_id ) {
73 67 $post = get_post( $post_id );
74 68 if ( $post instanceof WP_Post ) {
75 - $notes[] = desktop_mode_notes_prepare( $post );
69 + $notes[] = openstation_notes_prepare( $post );
76 70 }
77 71 }
78 72
79 - $alive_ids = desktop_mode_notes_alive_known_ids( $known_ids );
73 + $alive_ids = openstation_notes_alive_known_ids( $known_ids );
80 74 $removed = array_values( array_diff( array_map( 'intval', $known_ids ), $alive_ids ) );
81 75
82 76 return array(
83 77 'notes' => $notes,
@@ -93,17 +87,15 @@
93 87 *
94 88 * Expressed as two queries merged in PHP (like the REST list) rather
95 89 * than a hand-built OR — keeps every callsite on standard WP_Query.
96 90 *
97 - * @since 0.9.6
98 - *
99 91 * @param array $extra Extra WP_Query args merged into both halves.
100 92 * @return int[] Matching post ids, own notes first.
101 93 */
102 -function desktop_mode_notes_query_visible_ids( $extra ) {
94 +function openstation_notes_query_visible_ids( $extra ) {
103 95 $user_id = get_current_user_id();
104 96 $base = array(
105 - 'post_type' => DESKTOP_MODE_NOTES_POST_TYPE,
97 + 'post_type' => OPENSTATION_NOTES_POST_TYPE,
106 98 'fields' => 'ids',
107 99 'no_found_rows' => true,
108 100 );
109 101
@@ -137,15 +129,13 @@
137 129
138 130 /**
139 131 * Query visible note ids modified since the client's high-water mark.
140 132 *
141 - * @since 0.9.6
142 - *
143 133 * @param int $since_ms Last-seen modified timestamp in milliseconds.
144 134 * @param int $limit Max ids to return (per visibility half).
145 135 * @return int[]
146 136 */
147 -function desktop_mode_notes_query_changed_ids( $since_ms, $limit ) {
137 +function openstation_notes_query_changed_ids( $since_ms, $limit ) {
148 138 $extra = array(
149 139 'posts_per_page' => max( 1, (int) $limit ),
150 140 'orderby' => 'modified',
151 141 'order' => 'ASC',
@@ -158,25 +148,23 @@
158 148 'inclusive' => true,
159 149 ),
160 150 );
161 151 }
162 - return desktop_mode_notes_query_visible_ids( $extra );
152 + return openstation_notes_query_visible_ids( $extra );
163 153 }
164 154
165 155 /**
166 156 * Return the subset of known ids still visible to the viewer.
167 157 *
168 - * @since 0.9.6
169 - *
170 158 * @param int[] $known_ids Client-known note ids.
171 159 * @return int[]
172 160 */
173 -function desktop_mode_notes_alive_known_ids( $known_ids ) {
161 +function openstation_notes_alive_known_ids( $known_ids ) {
174 162 $known_ids = array_values( array_unique( array_filter( array_map( 'absint', (array) $known_ids ) ) ) );
175 163 if ( empty( $known_ids ) ) {
176 164 return array();
177 165 }
178 - return desktop_mode_notes_query_visible_ids(
166 + return openstation_notes_query_visible_ids(
179 167 array(
180 168 'post__in' => $known_ids,
181 169 'posts_per_page' => count( $known_ids ),
182 170 )