feat: add support for subject of conversation

This commit is contained in:
2025-04-22 15:10:36 +07:00
parent 52a79dca08
commit 86eca5803f
11 changed files with 256 additions and 70 deletions

View File

@@ -288,19 +288,20 @@ impl ChatRegistry {
if let Some(room) = self.rooms.iter().find(|room| room.read(cx).id == id) {
room.update(cx, |this, cx| {
this.created_at(event.created_at, cx);
this.emit_message(event, window, cx);
cx.defer_in(window, |this, window, cx| {
this.emit_message(event, window, cx);
});
});
// Re-sort rooms by last seen
self.rooms
.sort_by_key(|room| Reverse(room.read(cx).created_at));
cx.defer_in(window, |this, _, cx| {
this.rooms
.sort_by_key(|room| Reverse(room.read(cx).created_at));
});
} else {
let new_room = cx.new(|_| Room::new(&event));
// Push the new room to the front of the list
self.rooms.insert(0, new_room);
self.rooms.insert(0, cx.new(|_| Room::new(&event)));
cx.notify();
}
cx.notify();
}
}

View File

@@ -1,7 +1,7 @@
use std::sync::Arc;
use account::Account;
use anyhow::Error;
use anyhow::{anyhow, Error};
use chrono::{Local, TimeZone};
use common::{compare, profile::SharedProfile, room_hash};
use global::get_client;
@@ -285,6 +285,17 @@ impl Room {
cx.notify();
}
/// Updates the subject of the room
///
/// # Arguments
///
/// * `subject` - The new subject to set
/// * `cx` - The context to notify about the update
pub fn subject(&mut self, subject: String, cx: &mut Context<Self>) {
self.subject = Some(subject.into());
cx.notify();
}
/// Fetches metadata for all members in the room
///
/// # Arguments
@@ -358,15 +369,21 @@ impl Room {
/// A Task that resolves to Result<Vec<String>, Error> where the
/// strings contain error messages for any failed sends
pub fn send_message(&self, content: String, cx: &App) -> Task<Result<Vec<String>, Error>> {
let client = get_client();
let account = Account::global(cx).read(cx);
let Some(profile) = account.profile.clone() else {
return Task::ready(Err(anyhow!("User is not logged in")));
};
let public_key = profile.public_key();
let subject = self.subject.clone();
let pubkeys = self.members.clone();
cx.background_spawn(async move {
let signer = client.signer().await?;
let public_key = signer.get_public_key().await?;
let client = get_client();
let mut report = vec![];
let tags: Vec<Tag> = pubkeys
let mut tags: Vec<Tag> = pubkeys
.iter()
.filter_map(|pubkey| {
if pubkey != &public_key {
@@ -377,6 +394,12 @@ impl Room {
})
.collect();
if let Some(subject) = subject {
tags.push(Tag::from_standardized(TagStandard::Subject(
subject.to_string(),
)));
}
for pubkey in pubkeys.iter() {
if let Err(e) = client
.send_private_msg(*pubkey, &content, tags.clone())