fix: drop the placeholder id the queues endpoint returns
Yandex answers POST /queues with 000000000000000000000000 and lists no queues afterwards, with the default or a stable device header alike; phones sync through Ynison now. Treat the placeholder as no queue so position updates aren't sent to a queue that doesn't exist.
This commit is contained in:
1 parent
24ff874d34
commit
2ef7aa9da9
1 file changed
+21
-2
@@ -38,6 +38,11 @@ fn tag_playlist_ids(raw: &serde_json::Value) -> Vec<String> {
|
|||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A queue id, unless it's the all-zero placeholder Yandex returns for a queue it didn't keep.
|
||||||
|
fn real_queue_id(id: Option<String>) -> Option<String> {
|
||||||
|
id.filter(|id| !id.is_empty() && !id.bytes().all(|b| b == b'0'))
|
||||||
|
}
|
||||||
|
|
||||||
/// The signed-in user as the UI needs them.
|
/// The signed-in user as the UI needs them.
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub struct Account {
|
pub struct Account {
|
||||||
@@ -581,7 +586,13 @@ impl YmClient {
|
|||||||
|
|
||||||
// ---- Server queue ----
|
// ---- Server queue ----
|
||||||
|
|
||||||
/// Publishes what's playing so other devices can continue it. Returns the queue id.
|
/// Publishes what's playing so other devices can continue it. Returns the queue id,
|
||||||
|
/// or `None` when Yandex didn't keep the queue.
|
||||||
|
///
|
||||||
|
/// Yandex now answers every create with the placeholder id `000000000000000000000000`
|
||||||
|
/// and lists no queues afterwards, whatever device header is sent (a stable
|
||||||
|
/// `device_id` was tried): the phone apps sync through Ynison instead. The
|
||||||
|
/// placeholder is dropped so no position updates go to a queue that doesn't exist.
|
||||||
pub async fn create_queue(&self, context: &QueueContext, tracks: &[Track], current: usize) -> Result<Option<String>> {
|
pub async fn create_queue(&self, context: &QueueContext, tracks: &[Track], current: usize) -> Result<Option<String>> {
|
||||||
let tracks: Vec<serde_json::Value> = tracks
|
let tracks: Vec<serde_json::Value> = tracks
|
||||||
.iter()
|
.iter()
|
||||||
@@ -600,7 +611,7 @@ impl YmClient {
|
|||||||
"from": "musyx-desktop",
|
"from": "musyx-desktop",
|
||||||
"isInteractive": true,
|
"isInteractive": true,
|
||||||
});
|
});
|
||||||
Ok(self.inner.create_queue(&body, None).await?)
|
Ok(real_queue_id(self.inner.create_queue(&body, None).await?))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn update_queue_position(&self, queue_id: &str, index: usize) -> Result<()> {
|
pub async fn update_queue_position(&self, queue_id: &str, index: usize) -> Result<()> {
|
||||||
@@ -664,6 +675,14 @@ mod tests {
|
|||||||
assert_eq!(tag_playlist_ids(&wrapped), vec!["9:8"]);
|
assert_eq!(tag_playlist_ids(&wrapped), vec!["9:8"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn placeholder_queue_ids_are_dropped() {
|
||||||
|
assert_eq!(real_queue_id(Some("000000000000000000000000".into())), None);
|
||||||
|
assert_eq!(real_queue_id(Some(String::new())), None);
|
||||||
|
assert_eq!(real_queue_id(None), None);
|
||||||
|
assert_eq!(real_queue_id(Some("6702a1f0c3".into())).as_deref(), Some("6702a1f0c3"));
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn anonymous_status_is_not_an_account() {
|
fn anonymous_status_is_not_an_account() {
|
||||||
assert!(Account::from_status(status(r#"{"account":{"now":"2026-10-15"}}"#)).is_none());
|
assert!(Account::from_status(status(r#"{"account":{"now":"2026-10-15"}}"#)).is_none());
|
||||||
|
|||||||
Reference in new issue
Block a user