fix(channels): follow annotation is no reaction, annotation failure keeps the follow
- chatsvc emotions: skip the annotation keys follow, star and acks (Teams' non-reaction set) when building reactions, so a followed post shows no reaction pill - set_post_followed: once rcmetadata is written the follow counts as done; an annotation error is logged, the UI is not reverted - tests for both Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@@ -129,7 +129,13 @@ impl AppState {
129
129
let (channel, root) = (channel_id.to_owned(), root_id.to_owned());
130
130
self.run_channel_action(
131
131
follow_failure(followed),
132
async move { engine.set_post_followed(&channel, &root, followed).await },
132
async move {
133
let annotation_failure = engine.set_post_followed(&channel, &root, followed).await?;
134
if let Some(error) = annotation_failure {
135
log::warn!("post follow annotation not written: {error}");
136
}
137
Ok(())
138
},
133
139
move |state, cx| {
134
140
match previous {
135
141
Some(previous) => state.post_follows.states.insert(key, previous),
@@ -129,7 +129,13 @@ impl AppState {129
let (channel, root) = (channel_id.to_owned(), root_id.to_owned());129
let (channel, root) = (channel_id.to_owned(), root_id.to_owned());130
self.run_channel_action(130
self.run_channel_action(131
follow_failure(followed),131
follow_failure(followed),132
async move { engine.set_post_followed(&channel, &root, followed).await },132
async move {133
let annotation_failure = engine.set_post_followed(&channel, &root, followed).await?;134
if let Some(error) = annotation_failure {135
log::warn!("post follow annotation not written: {error}");136
}137
Ok(())138
},133
move |state, cx| {139
move |state, cx| {134
match previous {140
match previous {135
Some(previous) => state.post_follows.states.insert(key, previous),141
Some(previous) => state.post_follows.states.insert(key, previous),@@ -6,6 +6,7 @@ use crate::messages::{MessageTransport, Messages, ensure_success};
6
6
use crate::window::WindowDirection;
7
7
8
8
const ORGID_PREFIX: &str = "8:orgid:";
9
const ANNOTATION_KEYS: [&str; 3] = ["follow", "star", "acks"];
9
10
10
11
#[derive(Debug, Clone, PartialEq, Eq)]
11
12
pub struct EmotionReaction {
@@ -30,7 +31,11 @@ fn reactions(emotions: Option<&Value>) -> Vec<EmotionReaction> {
30
31
.into_iter()
31
32
.flatten()
32
33
.flat_map(|entry| {
33
let key = entry.get("key").and_then(Value::as_str).unwrap_or_default();
34
let key = entry
35
.get("key")
36
.and_then(Value::as_str)
37
.filter(|key| !ANNOTATION_KEYS.contains(key))
38
.unwrap_or_default();
34
39
entry
35
40
.get("users")
36
41
.and_then(Value::as_array)
@@ -111,4 +116,19 @@ mod tests {
111
116
assert_eq!(parsed[0].reactions[1].time_ms, Some(1792135855900));
112
117
assert!(parsed[1].reactions.is_empty());
113
118
}
119
120
#[test]
121
fn follow_star_and_acks_annotations_are_not_reactions() {
122
let body = json!({"messages": [
123
{"id": "1", "properties": {"emotions": [
124
{"key": "follow", "users": [{"mri": "8:orgid:aaa", "time": 1_i64, "value": "1"}]},
125
{"key": "star", "users": [{"mri": "8:orgid:aaa", "time": 2_i64, "value": "1"}]},
126
{"key": "acks", "users": [{"mri": "8:orgid:bbb", "time": 3_i64, "value": "1"}]},
127
{"key": "like", "users": [{"mri": "8:orgid:bbb", "time": 4_i64, "value": "1"}]}
128
]}}
129
]});
130
let parsed = parse_message_emotions(&body);
131
let keys: Vec<&str> = parsed[0].reactions.iter().map(|reaction| reaction.key.as_str()).collect();
132
assert_eq!(keys, ["like"]);
133
}
114
134
}
@@ -6,6 +6,7 @@ use crate::messages::{MessageTransport, Messages, ensure_success};6
use crate::window::WindowDirection;6
use crate::window::WindowDirection;7
7
8
const ORGID_PREFIX: &str = "8:orgid:";8
const ORGID_PREFIX: &str = "8:orgid:";9
const ANNOTATION_KEYS: [&str; 3] = ["follow", "star", "acks"];9
10
10
#[derive(Debug, Clone, PartialEq, Eq)]11
#[derive(Debug, Clone, PartialEq, Eq)]11
pub struct EmotionReaction {12
pub struct EmotionReaction {@@ -30,7 +31,11 @@ fn reactions(emotions: Option<&Value>) -> Vec<EmotionReaction> {30
.into_iter()31
.into_iter()31
.flatten()32
.flatten()32
.flat_map(|entry| {33
.flat_map(|entry| {33
let key = entry.get("key").and_then(Value::as_str).unwrap_or_default();34
let key = entry35
.get("key")36
.and_then(Value::as_str)37
.filter(|key| !ANNOTATION_KEYS.contains(key))38
.unwrap_or_default();34
entry39
entry35
.get("users")40
.get("users")36
.and_then(Value::as_array)41
.and_then(Value::as_array)@@ -111,4 +116,19 @@ mod tests {111
assert_eq!(parsed[0].reactions[1].time_ms, Some(1792135855900));116
assert_eq!(parsed[0].reactions[1].time_ms, Some(1792135855900));112
assert!(parsed[1].reactions.is_empty());117
assert!(parsed[1].reactions.is_empty());113
}118
}119
120
#[test]121
fn follow_star_and_acks_annotations_are_not_reactions() {122
let body = json!({"messages": [123
{"id": "1", "properties": {"emotions": [124
{"key": "follow", "users": [{"mri": "8:orgid:aaa", "time": 1_i64, "value": "1"}]},125
{"key": "star", "users": [{"mri": "8:orgid:aaa", "time": 2_i64, "value": "1"}]},126
{"key": "acks", "users": [{"mri": "8:orgid:bbb", "time": 3_i64, "value": "1"}]},127
{"key": "like", "users": [{"mri": "8:orgid:bbb", "time": 4_i64, "value": "1"}]}128
]}}129
]});130
let parsed = parse_message_emotions(&body);131
let keys: Vec<&str> = parsed[0].reactions.iter().map(|reaction| reaction.key.as_str()).collect();132
assert_eq!(keys, ["like"]);133
}114
}134
}@@ -111,17 +111,18 @@ impl<T: MessageTransport> Messages<T> {
111
111
channel_id: &str,
112
112
root_id: &str,
113
113
followed: bool,
114
) -> Result<()> {
114
) -> Result<Option<String>> {
115
115
let answer = self
116
116
.transport
117
117
.send(self.post_follow_request(user_id, channel_id, root_id, followed))
118
118
.await?;
119
119
ensure_success(&answer)?;
120
let answer = self
120
let annotation = self
121
121
.transport
122
122
.send(self.post_follow_annotation_request(channel_id, root_id, followed))
123
.await?;
124
ensure_success(&answer)
123
.await
124
.and_then(|answer| ensure_success(&answer));
125
Ok(annotation.err().map(|error| error.to_string()))
125
126
}
126
127
127
128
pub async fn post_follow_states(
@@ -151,16 +152,18 @@ mod tests {
151
152
use super::*;
152
153
153
154
struct Canned {
154
status: u16,
155
statuses: Vec<u16>,
155
156
body: Value,
156
157
requests: Mutex<Vec<Request>>,
157
158
}
158
159
159
160
impl MessageTransport for Canned {
160
161
async fn send(&self, request: Request) -> Result<ApiResponse> {
161
self.requests.lock().unwrap().push(request);
162
let mut requests = self.requests.lock().unwrap();
163
let status = self.statuses[requests.len().min(self.statuses.len() - 1)];
164
requests.push(request);
162
165
Ok(ApiResponse {
163
status: self.status,
166
status,
164
167
body: self.body.clone(),
165
168
retry_after: None,
166
169
})
@@ -168,9 +171,13 @@ mod tests {
168
171
}
169
172
170
173
fn canned(status: u16, body: Value) -> Messages<Canned> {
174
canned_sequence(vec![status], body)
175
}
176
177
fn canned_sequence(statuses: Vec<u16>, body: Value) -> Messages<Canned> {
171
178
Messages::with_transport(
172
179
Canned {
173
status,
180
statuses,
174
181
body,
175
182
requests: Mutex::new(Vec::new()),
176
183
},
@@ -229,6 +236,17 @@ mod tests {
229
236
assert_eq!(messages.transport.requests.lock().unwrap().len(), 1);
230
237
}
231
238
239
#[tokio::test]
240
async fn failed_annotation_still_counts_as_followed() {
241
let messages = canned_sequence(vec![200, 500], json!({}));
242
let annotation_failure = messages
243
.set_post_followed("a1", "19:c", "1", true)
244
.await
245
.unwrap();
246
assert!(annotation_failure.is_some());
247
assert_eq!(messages.transport.requests.lock().unwrap().len(), 2);
248
}
249
232
250
#[tokio::test]
233
251
async fn reads_follow_states_of_root_posts() {
234
252
let body = json!({"conversationId": "19:c", "rcMetadataList": [
@@ -111,17 +111,18 @@ impl<T: MessageTransport> Messages<T> {111
channel_id: &str,111
channel_id: &str,112
root_id: &str,112
root_id: &str,113
followed: bool,113
followed: bool,114
) -> Result<()> {114
) -> Result<Option<String>> {115
let answer = self115
let answer = self116
.transport116
.transport117
.send(self.post_follow_request(user_id, channel_id, root_id, followed))117
.send(self.post_follow_request(user_id, channel_id, root_id, followed))118
.await?;118
.await?;119
ensure_success(&answer)?;119
ensure_success(&answer)?;120
let answer = self120
let annotation = self121
.transport121
.transport122
.send(self.post_follow_annotation_request(channel_id, root_id, followed))122
.send(self.post_follow_annotation_request(channel_id, root_id, followed))123
.await?;123
.await124
ensure_success(&answer)124
.and_then(|answer| ensure_success(&answer));125
Ok(annotation.err().map(|error| error.to_string()))125
}126
}126
127
127
pub async fn post_follow_states(128
pub async fn post_follow_states(@@ -151,16 +152,18 @@ mod tests {151
use super::*;152
use super::*;152
153
153
struct Canned {154
struct Canned {154
status: u16,155
statuses: Vec<u16>,155
body: Value,156
body: Value,156
requests: Mutex<Vec<Request>>,157
requests: Mutex<Vec<Request>>,157
}158
}158
159
159
impl MessageTransport for Canned {160
impl MessageTransport for Canned {160
async fn send(&self, request: Request) -> Result<ApiResponse> {161
async fn send(&self, request: Request) -> Result<ApiResponse> {161
self.requests.lock().unwrap().push(request);162
let mut requests = self.requests.lock().unwrap();163
let status = self.statuses[requests.len().min(self.statuses.len() - 1)];164
requests.push(request);162
Ok(ApiResponse {165
Ok(ApiResponse {163
status: self.status,166
status,164
body: self.body.clone(),167
body: self.body.clone(),165
retry_after: None,168
retry_after: None,166
})169
})@@ -168,9 +171,13 @@ mod tests {168
}171
}169
172
170
fn canned(status: u16, body: Value) -> Messages<Canned> {173
fn canned(status: u16, body: Value) -> Messages<Canned> {174
canned_sequence(vec![status], body)175
}176
177
fn canned_sequence(statuses: Vec<u16>, body: Value) -> Messages<Canned> {171
Messages::with_transport(178
Messages::with_transport(172
Canned {179
Canned {173
status,180
statuses,174
body,181
body,175
requests: Mutex::new(Vec::new()),182
requests: Mutex::new(Vec::new()),176
},183
},@@ -229,6 +236,17 @@ mod tests {229
assert_eq!(messages.transport.requests.lock().unwrap().len(), 1);236
assert_eq!(messages.transport.requests.lock().unwrap().len(), 1);230
}237
}231
238
239
#[tokio::test]240
async fn failed_annotation_still_counts_as_followed() {241
let messages = canned_sequence(vec![200, 500], json!({}));242
let annotation_failure = messages243
.set_post_followed("a1", "19:c", "1", true)244
.await245
.unwrap();246
assert!(annotation_failure.is_some());247
assert_eq!(messages.transport.requests.lock().unwrap().len(), 2);248
}249
232
#[tokio::test]250
#[tokio::test]233
async fn reads_follow_states_of_root_posts() {251
async fn reads_follow_states_of_root_posts() {234
let body = json!({"conversationId": "19:c", "rcMetadataList": [252
let body = json!({"conversationId": "19:c", "rcMetadataList": [@@ -70,7 +70,7 @@ impl<R: Remote> SyncEngine<R> {
70
70
channel_id: &str,
71
71
root_id: &str,
72
72
followed: bool,
73
) -> Result<()> {
73
) -> Result<Option<String>> {
74
74
let my_user_id = self.my_user_id().await?;
75
75
self.remote
76
76
.set_post_followed(&my_user_id, channel_id, root_id, followed)
@@ -70,7 +70,7 @@ impl<R: Remote> SyncEngine<R> {70
channel_id: &str,70
channel_id: &str,71
root_id: &str,71
root_id: &str,72
followed: bool,72
followed: bool,73
) -> Result<()> {73
) -> Result<Option<String>> {74
let my_user_id = self.my_user_id().await?;74
let my_user_id = self.my_user_id().await?;75
self.remote75
self.remote76
.set_post_followed(&my_user_id, channel_id, root_id, followed)76
.set_post_followed(&my_user_id, channel_id, root_id, followed)@@ -351,7 +351,7 @@ pub trait Remote {
351
351
_channel_id: &str,
352
352
_root_id: &str,
353
353
_followed: bool,
354
) -> Result<()> {
354
) -> Result<Option<String>> {
355
355
Err(Error::Unsupported("following posts"))
356
356
}
357
357
@@ -1170,7 +1170,7 @@ impl Remote for Graph {
1170
1170
channel_id: &str,
1171
1171
root_id: &str,
1172
1172
followed: bool,
1173
) -> Result<()> {
1173
) -> Result<Option<String>> {
1174
1174
Ok(Messages::new(self.session())
1175
1175
.set_post_followed(user_id, channel_id, root_id, followed)
1176
1176
.await?)
@@ -351,7 +351,7 @@ pub trait Remote {351
_channel_id: &str,351
_channel_id: &str,352
_root_id: &str,352
_root_id: &str,353
_followed: bool,353
_followed: bool,354
) -> Result<()> {354
) -> Result<Option<String>> {355
Err(Error::Unsupported("following posts"))355
Err(Error::Unsupported("following posts"))356
}356
}357
357
@@ -1170,7 +1170,7 @@ impl Remote for Graph {1170
channel_id: &str,1170
channel_id: &str,1171
root_id: &str,1171
root_id: &str,1172
followed: bool,1172
followed: bool,1173
) -> Result<()> {1173
) -> Result<Option<String>> {1174
Ok(Messages::new(self.session())1174
Ok(Messages::new(self.session())1175
.set_post_followed(user_id, channel_id, root_id, followed)1175
.set_post_followed(user_id, channel_id, root_id, followed)1176
.await?)1176
.await?)@@ -910,9 +910,9 @@ impl Remote for Handle {
910
910
channel_id: &str,
911
911
root_id: &str,
912
912
followed: bool,
913
) -> Result<()> {
913
) -> Result<Option<String>> {
914
914
self.record(format!("follow {user_id} {channel_id} {root_id} {followed}"));
915
Ok(())
915
Ok(None)
916
916
}
917
917
918
918
async fn pin_message(&self, chat_id: &str, message_id: &str) -> Result<()> {
@@ -910,9 +910,9 @@ impl Remote for Handle {910
channel_id: &str,910
channel_id: &str,911
root_id: &str,911
root_id: &str,912
followed: bool,912
followed: bool,913
) -> Result<()> {913
) -> Result<Option<String>> {914
self.record(format!("follow {user_id} {channel_id} {root_id} {followed}"));914
self.record(format!("follow {user_id} {channel_id} {root_id} {followed}"));915
Ok(())915
Ok(None)916
}916
}917
917
918
async fn pin_message(&self, chat_id: &str, message_id: &str) -> Result<()> {918
async fn pin_message(&self, chat_id: &str, message_id: &str) -> Result<()> {