Skip to main content

ChannelManager

Struct ChannelManager 

Source
pub struct ChannelManager { /* private fields */ }
Expand description

Channel manager - handles channel-specific file operations

Provides logical isolation and tracking for files across different channels. The actual file storage is global and shared via SHA256 deduplication.

Implementations§

Source§

impl ChannelManager

Source

pub async fn new( file_manager: Arc<FileManager>, db_path: PathBuf, ) -> Result<Self>

Create a new channel manager

§Arguments
  • file_manager - Shared FileManager for file storage
  • db_path - Path to the channel metadata database
§Example
use agent_diva_files::FileManager;
use agent_diva_files::channel::ChannelManager;

let file_manager = FileManager::new(config).await?;
let channel_manager = ChannelManager::new(
    Arc::new(file_manager),
    PathBuf::from("channels.db"),
).await?;
Source

pub async fn upload_to_channel( &self, channel_id: &str, data: &[u8], metadata: FileMetadata, uploaded_by: Option<&str>, message_id: Option<&str>, ) -> Result<FileHandle>

Upload a file to a specific channel

If the file content already exists (same SHA256 hash), it will be deduplicated and associated with the new channel instead of storing duplicate data.

§Arguments
  • channel_id - The channel identifier (e.g., “telegram:chat_123”)
  • data - File content bytes
  • metadata - File metadata (name, size, mime_type, etc.)
  • uploaded_by - Optional uploader identifier
  • message_id - Optional associated message ID
§Returns

A FileHandle for the stored file

§Example
let handle = channel_manager
    .upload_to_channel(
        "telegram:chat_123",
        b"file content",
        FileMetadata { name: "document.pdf", .. },
        Some("user_456"),
        Some("msg_789"),
    )
    .await?;
Source

pub async fn add_file_to_channel( &self, channel_id: &str, file_id: &str, uploaded_by: Option<&str>, message_id: Option<&str>, ) -> Result<bool>

Add an existing file to a channel

Use this when a file has already been uploaded and you just want to associate it with a channel.

§Returns

Ok(true) if a new association was created, Ok(false) if it already existed

Source

pub async fn list_channel_files( &self, channel_id: &str, ) -> Result<Vec<ChannelFileInfo>>

List all files in a channel

Returns files with their channel-specific metadata (uploader, upload time, etc.)

§Arguments
  • channel_id - The channel to list files for
§Returns

List of files in the channel, newest first

§Example
let files = channel_manager.list_channel_files("telegram:chat_123").await?;
for info in files {
    println!("{} - uploaded by {:?} at {}",
             info.file.id, info.uploaded_by, info.uploaded_at);
}
Source

pub async fn get_channel_file( &self, channel_id: &str, file_id: &str, ) -> Result<FileHandle>

Get a specific file from a channel

§Arguments
  • channel_id - The channel ID
  • file_id - The file ID to retrieve
§Returns

FileHandle if found, error otherwise

Source

pub async fn list_file_channels(&self, file_id: &str) -> Result<Vec<String>>

List all channels a file belongs to

§Returns

List of channel IDs that contain this file

Source

pub async fn remove_from_channel( &self, channel_id: &str, file_id: &str, ) -> Result<bool>

Remove a file from a channel (but don’t delete the actual file)

This only removes the channel association, not the physical file. The file will continue to exist if other channels reference it.

§Arguments
  • channel_id - The channel to remove from
  • file_id - The file to remove
§Returns

Ok(true) if association was removed, Ok(false) if it didn’t exist

Source

pub async fn delete_channel( &self, channel_id: &str, cleanup: bool, ) -> Result<usize>

Delete an entire channel

§Arguments
  • channel_id - The channel to delete
  • cleanup - If true, also delete files that are only in this channel If false, only remove the channel associations
§Behavior

With cleanup = false:

  • Only removes channel_file associations
  • Physical files remain and can still be accessed via other channels

With cleanup = true:

  • Removes channel_file associations
  • For files unique to this channel, also soft-deletes them
  • Files shared with other channels are NOT deleted
§Example
// Delete channel but keep shared files
channel_manager.delete_channel("temp_channel", false).await?;

// Delete channel and cleanup unique files
channel_manager.delete_channel("archive_channel", true).await?;
Source

pub async fn channel_stats(&self, channel_id: &str) -> Result<ChannelStats>

Get statistics for a channel

§Returns

ChannelStats with total files, total size, and unique files count

Source

pub async fn list_channels(&self) -> Result<Vec<String>>

List all channels that have files

§Returns

List of channel IDs with at least one file

Source

pub async fn close(&self)

Close the channel database connection

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more