Fix 0 notes versions being always unread (#9030)

Co-Authored-By: Max <max@zed.dev>
Co-Authored-By: Nathan <nathan@zed.dev>

Release Notes:

- Fixed empty notes always showing as unread

Co-authored-by: Max <max@zed.dev>
Co-authored-by: Nathan <nathan@zed.dev>
This commit is contained in:
Conrad Irwin 2024-03-07 13:53:05 -07:00 committed by GitHub
parent 284a57d4d1
commit e85f190128
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -29,7 +29,7 @@ pub fn init(client: &Arc<Client>, user_store: Model<UserStore>, cx: &mut AppCont
cx.set_global(GlobalChannelStore(channel_store)); cx.set_global(GlobalChannelStore(channel_store));
} }
#[derive(Debug, Clone, Default)] #[derive(Debug, Clone, Default, PartialEq)]
struct NotesVersion { struct NotesVersion {
epoch: u64, epoch: u64,
version: clock::Global, version: clock::Global,
@ -81,12 +81,12 @@ pub struct Channel {
pub parent_path: Vec<ChannelId>, pub parent_path: Vec<ChannelId>,
} }
#[derive(Default)] #[derive(Default, Debug)]
pub struct ChannelState { pub struct ChannelState {
latest_chat_message: Option<u64>, latest_chat_message: Option<u64>,
latest_notes_versions: Option<NotesVersion>, latest_notes_version: NotesVersion,
observed_notes_version: NotesVersion,
observed_chat_message: Option<u64>, observed_chat_message: Option<u64>,
observed_notes_versions: Option<NotesVersion>,
role: Option<ChannelRole>, role: Option<ChannelRole>,
projects: HashSet<HostedProjectId>, projects: HashSet<HostedProjectId>,
} }
@ -1236,19 +1236,12 @@ impl ChannelState {
} }
fn has_channel_buffer_changed(&self) -> bool { fn has_channel_buffer_changed(&self) -> bool {
if let Some(latest_version) = &self.latest_notes_versions { self.latest_notes_version.epoch > self.observed_notes_version.epoch
if let Some(observed_version) = &self.observed_notes_versions { || (self.latest_notes_version.epoch == self.observed_notes_version.epoch
latest_version.epoch > observed_version.epoch && self
|| (latest_version.epoch == observed_version.epoch .latest_notes_version
&& latest_version
.version .version
.changed_since(&observed_version.version)) .changed_since(&self.observed_notes_version.version))
} else {
true
}
} else {
false
}
} }
fn has_new_messages(&self) -> bool { fn has_new_messages(&self) -> bool {
@ -1275,29 +1268,25 @@ impl ChannelState {
} }
fn acknowledge_notes_version(&mut self, epoch: u64, version: &clock::Global) { fn acknowledge_notes_version(&mut self, epoch: u64, version: &clock::Global) {
if let Some(existing) = &mut self.observed_notes_versions { if self.observed_notes_version.epoch == epoch {
if existing.epoch == epoch { self.observed_notes_version.version.join(version);
existing.version.join(version); } else {
return; self.observed_notes_version = NotesVersion {
}
}
self.observed_notes_versions = Some(NotesVersion {
epoch, epoch,
version: version.clone(), version: version.clone(),
}); };
}
} }
fn update_latest_notes_version(&mut self, epoch: u64, version: &clock::Global) { fn update_latest_notes_version(&mut self, epoch: u64, version: &clock::Global) {
if let Some(existing) = &mut self.latest_notes_versions { if self.latest_notes_version.epoch == epoch {
if existing.epoch == epoch { self.latest_notes_version.version.join(version);
existing.version.join(version); } else {
return; self.latest_notes_version = NotesVersion {
}
}
self.latest_notes_versions = Some(NotesVersion {
epoch, epoch,
version: version.clone(), version: version.clone(),
}); };
}
} }
fn add_hosted_project(&mut self, project_id: HostedProjectId) { fn add_hosted_project(&mut self, project_id: HostedProjectId) {