feat: add action to compose modal

This commit is contained in:
reya
2025-01-21 15:15:37 +07:00
parent 5f6ba4f0a6
commit 582db29209
7 changed files with 265 additions and 172 deletions
+36 -11
View File
@@ -1,10 +1,9 @@
use crate::{
constants::IMAGE_SERVICE,
utils::{room_hash, shorted_public_key},
utils::{compare, random_name, room_hash, shorted_public_key},
};
use gpui::SharedString;
use nostr_sdk::prelude::*;
use rnglib::{Language, RNG};
#[derive(Debug, Clone)]
pub struct Member {
@@ -67,6 +66,18 @@ pub struct Room {
pub new_messages: Vec<Event>, // Hold all new messages
}
impl PartialEq for Room {
fn eq(&self, other: &Self) -> bool {
let mut pubkeys: Vec<PublicKey> = self.members.iter().map(|m| m.public_key()).collect();
pubkeys.push(self.owner.public_key());
let mut pubkeys2: Vec<PublicKey> = other.members.iter().map(|m| m.public_key()).collect();
pubkeys2.push(other.owner.public_key());
compare(&pubkeys, &pubkeys2)
}
}
impl Room {
pub fn new(
id: u64,
@@ -76,6 +87,11 @@ impl Room {
last_seen: Timestamp,
) -> Self {
let is_group = members.len() > 1;
let title = if title.is_none() {
Some(random_name(2).into())
} else {
title
};
Self {
id,
@@ -103,10 +119,7 @@ impl Room {
let title = if let Some(tag) = event.tags.find(TagKind::Title) {
tag.content().map(|s| s.to_owned().into())
} else {
let rng = RNG::from(&Language::Roman);
let name = rng.generate_names(2, true).join("-").to_lowercase();
Some(name.into())
None
};
Self::new(id, owner, members, title, last_seen)
@@ -136,11 +149,23 @@ impl Room {
}
pub fn name(&self) -> String {
self.members
.iter()
.map(|profile| profile.name())
.collect::<Vec<String>>()
.join(", ")
if self.members.len() <= 2 {
self.members
.iter()
.map(|profile| profile.name())
.collect::<Vec<String>>()
.join(", ")
} else {
let name = self
.members
.iter()
.take(2)
.map(|profile| profile.name())
.collect::<Vec<String>>()
.join(", ");
format!("{}, +{}", name, self.members.len() - 2)
}
}
pub fn get_all_keys(&self) -> Vec<PublicKey> {