Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions src-tauri/src/seventv/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,15 @@ impl SeventTvClient {

#[tracing::instrument(name = "7tv_subscribe", skip(self, condition), fields(%condition))]
pub async fn subscribe(&self, event: &str, condition: &serde_json::Value) {
let Some(id) = condition
.get("id")
.or(condition.get("object_id"))
.and_then(|v| v.as_str())
else {
tracing::warn!("Condition is missing an identifiable field");
return;
};

let payload = json!({
"op": 35,
"d": {
Expand All @@ -126,7 +135,7 @@ impl SeventTvClient {
{
Ok(_) => {
let mut subscriptions = self.subscriptions.lock().await;
subscriptions.insert(event.to_string(), condition.clone());
subscriptions.insert(format!("{id}:{event}"), condition.clone());

tracing::trace!("Subscription created");
}
Expand All @@ -136,10 +145,10 @@ impl SeventTvClient {
}
}

pub async fn unsubscribe(&self, event: &str) {
pub async fn unsubscribe(&self, event: &str, id: &str) {
let mut subscriptions = self.subscriptions.lock().await;

if let Some(condition) = subscriptions.remove(event) {
if let Some(condition) = subscriptions.remove(&format!("{id}:{event}")) {
let payload = json!({
"op": 36,
"d": {
Expand All @@ -157,7 +166,9 @@ impl SeventTvClient {
pub async fn unsubscribe_all(&self) {
let mut subscriptions = self.subscriptions.lock().await;

for (event, condition) in subscriptions.drain() {
for (key, condition) in subscriptions.drain() {
let (_, event) = key.split_once(':').unwrap();
Copy link

Copilot AI Dec 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The unwrap() call on split_once(':') could panic if the subscription key format is unexpected or malformed. Consider using proper error handling or a split_once(':').expect() with a descriptive message, or use pattern matching with if let Some((_, event)) = key.split_once(':') to skip malformed keys.

Copilot uses AI. Check for mistakes.

let payload = json!({
"op": 36,
"d": {
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/src/seventv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub async fn resub_emote_set(
return Ok(());
};

seventv.unsubscribe("emote_set.*").await;
seventv.unsubscribe("emote_set.*", &set_id).await;
seventv
.subscribe("emote_set.*", &json!({ "object_id": set_id }))
.await;
Expand Down