Skip to content

Commit

Permalink
Merge branch 'dev' into impl-missing-call-timer-setting
Browse files Browse the repository at this point in the history
  • Loading branch information
stavares843 authored Mar 26, 2024
2 parents 4061898 + f6bfabd commit 3f9e65a
Show file tree
Hide file tree
Showing 15 changed files with 341 additions and 159 deletions.
25 changes: 21 additions & 4 deletions common/src/state/chats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use warp::{

use crate::{warp_runner::ui_adapter, STATIC_ARGS};

use super::pending_message::{progress_file, FileProgression, PendingMessage};
use super::pending_message::{FileLocation, FileProgression, PendingMessage};

// let (p = window_bottom) be an index into Chat.messages
// show messages from (p - window_size) to (p + window_extra)
Expand Down Expand Up @@ -157,14 +157,31 @@ impl Chat {
true
}

pub fn update_pending_msg(&mut self, message_id: Uuid, progress: FileProgression) {
let file = progress_file(&progress);
pub fn update_pending_msg(
&mut self,
message_id: Uuid,
location: Location,
progress: FileProgression,
) {
if let Some(m) = &mut self
.pending_outgoing_messages
.iter_mut()
.find(|m| m.id().eq(&message_id))
{
m.attachments_progress.insert(location.into(), progress);
}
}

pub fn remove_pending_msg_attachment(&mut self, message_id: Uuid, location: FileLocation) {
if let Some(m) = &mut self
.pending_outgoing_messages
.iter_mut()
.find(|m| m.id().eq(&message_id))
{
m.attachments_progress.insert(file, progress);
m.attachments_progress.remove(&location);
if m.attachments_progress.is_empty() {
self.remove_pending_msg(message_id);
}
}
}

Expand Down
18 changes: 15 additions & 3 deletions common/src/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ use warp::{crypto::DID, multipass::identity::IdentityStatus, raygun};
use tracing::log;

use self::call::Call;
use self::pending_message::{FileProgression, PendingMessage};
use self::pending_message::{FileLocation, FileProgression, PendingMessage};

use self::storage::Storage;
use self::ui::{Font, Layout};
Expand Down Expand Up @@ -1248,6 +1248,7 @@ impl State {
&mut self,
conv_id: Uuid,
message_id: Uuid,
location: Location,
progress: FileProgression,
) -> bool {
let mut update = false;
Expand All @@ -1267,11 +1268,22 @@ impl State {
update = true;
}
if let Some(chat) = self.chats.all.get_mut(&conv_id) {
chat.update_pending_msg(message_id, progress);
chat.update_pending_msg(message_id, location, progress);
}
update
}

pub fn remove_outgoing_attachment(
&mut self,
conv_id: Uuid,
message_id: Uuid,
location: FileLocation,
) {
if let Some(chat) = self.chats.all.get_mut(&conv_id) {
chat.remove_pending_msg_attachment(message_id, location);
}
}

pub fn decrement_outgoing_messages(&mut self, conv_id: Uuid, message_id: Uuid) {
if let Some(chat) = self.chats.all.get_mut(&conv_id) {
chat.remove_pending_msg(message_id);
Expand Down Expand Up @@ -1823,7 +1835,7 @@ impl<'a> MessageGroup<'a> {
#[derive(Clone)]
pub struct GroupedMessage<'a> {
pub message: &'a ui_adapter::Message,
pub attachment_progress: Option<&'a HashMap<String, FileProgression>>,
pub attachment_progress: Option<&'a HashMap<FileLocation, FileProgression>>,
pub is_pending: bool,
pub is_first: bool,
pub is_last: bool,
Expand Down
33 changes: 30 additions & 3 deletions common/src/state/pending_message.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,44 @@
use std::collections::HashMap;
use std::{collections::HashMap, path::PathBuf};

use uuid::Uuid;
use warp::{constellation::Progression, crypto::DID};
use warp::{constellation::Progression, crypto::DID, raygun::Location};

use crate::warp_runner::ui_adapter::Message;
// We can improve message equality detection if warp e.g. can send us their assigned uuid.
// Else it is just a guesswork
#[derive(Clone, Debug)]
pub struct PendingMessage {
pub attachments_progress: HashMap<String, FileProgression>,
pub attachments_progress: HashMap<FileLocation, FileProgression>,
pub message: Message,
}

#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub enum FileLocation {
/// Use [`Constellation`] to send a file from constellation
Constellation { path: String },

/// Use file from disk
Disk { path: PathBuf },
}

impl From<Location> for FileLocation {
fn from(location: Location) -> Self {
match location {
Location::Constellation { path } => FileLocation::Constellation { path },
Location::Disk { path } => FileLocation::Disk { path },
}
}
}

impl From<FileLocation> for Location {
fn from(location: FileLocation) -> Self {
match location {
FileLocation::Constellation { path } => Location::Constellation { path },
FileLocation::Disk { path } => Location::Disk { path },
}
}
}

impl PendingMessage {
pub fn new(chat_id: Uuid, did: DID, message_id: Uuid, text: Vec<String>) -> Self {
// Create a dummy message
Expand Down
3 changes: 2 additions & 1 deletion common/src/warp_runner/ui_adapter/message_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use uuid::Uuid;
use warp::{
crypto::DID,
error::Error,
raygun::{self, MessageEventKind, MessageOptions},
raygun::{self, Location, MessageEventKind, MessageOptions},
};

use super::Message;
Expand Down Expand Up @@ -71,6 +71,7 @@ pub enum MessageEvent {
#[display(fmt = "AttachmentProgress")]
AttachmentProgress {
progress: FileProgression,
location: Location,
conversation_id: Uuid,
msg: Uuid,
},
Expand Down
Loading

0 comments on commit 3f9e65a

Please sign in to comment.