mirror of
https://github.com/chatmail/core.git
synced 2026-04-19 14:36:29 +03:00
jsonrpc: add miscGetStickerFolder and miscGetStickers (#3672)
* jsonrpc: add `miscGetStickerFolder` and `miscGetStickers` * add pr number to changelog * refactor * fix clippy
This commit is contained in:
@@ -24,7 +24,7 @@ use deltachat::{
|
||||
use std::collections::BTreeMap;
|
||||
use std::sync::Arc;
|
||||
use std::{collections::HashMap, str::FromStr};
|
||||
use tokio::sync::RwLock;
|
||||
use tokio::{fs, sync::RwLock};
|
||||
use walkdir::WalkDir;
|
||||
use yerpc::rpc;
|
||||
|
||||
@@ -1500,6 +1500,63 @@ impl CommandApi {
|
||||
// that might get removed later again
|
||||
// ---------------------------------------------
|
||||
|
||||
async fn misc_get_sticker_folder(&self, account_id: u32) -> Result<String> {
|
||||
let ctx = self.get_context(account_id).await?;
|
||||
let account_folder = ctx
|
||||
.get_dbfile()
|
||||
.parent()
|
||||
.context("account folder not found")?;
|
||||
let sticker_folder_path = account_folder.join("./stickers");
|
||||
fs::create_dir_all(&sticker_folder_path).await?;
|
||||
sticker_folder_path
|
||||
.to_str()
|
||||
.map(|s| s.to_owned())
|
||||
.context("path conversion to string failed")
|
||||
}
|
||||
|
||||
/// for desktop, get stickers from stickers folder,
|
||||
/// grouped by the folder they are in.
|
||||
async fn misc_get_stickers(&self, account_id: u32) -> Result<HashMap<String, Vec<String>>> {
|
||||
let ctx = self.get_context(account_id).await?;
|
||||
let account_folder = ctx
|
||||
.get_dbfile()
|
||||
.parent()
|
||||
.context("account folder not found")?;
|
||||
let sticker_folder_path = account_folder.join("./stickers");
|
||||
fs::create_dir_all(&sticker_folder_path).await?;
|
||||
let mut result = HashMap::new();
|
||||
|
||||
let mut packs = tokio::fs::read_dir(sticker_folder_path).await?;
|
||||
while let Some(entry) = packs.next_entry().await? {
|
||||
if !entry.file_type().await?.is_dir() {
|
||||
continue;
|
||||
}
|
||||
let pack_name = entry.file_name().into_string().unwrap_or_default();
|
||||
let mut stickers = tokio::fs::read_dir(entry.path()).await?;
|
||||
let mut sticker_paths = Vec::new();
|
||||
while let Some(sticker_entry) = stickers.next_entry().await? {
|
||||
if !sticker_entry.file_type().await?.is_file() {
|
||||
continue;
|
||||
}
|
||||
let sticker_name = sticker_entry.file_name().into_string().unwrap_or_default();
|
||||
if sticker_name.ends_with(".png") || sticker_name.ends_with(".webp") {
|
||||
sticker_paths.push(
|
||||
sticker_entry
|
||||
.path()
|
||||
.to_str()
|
||||
.map(|s| s.to_owned())
|
||||
.context("path conversion to string failed")?,
|
||||
);
|
||||
}
|
||||
}
|
||||
if !sticker_paths.is_empty() {
|
||||
result.insert(pack_name, sticker_paths);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
/// Returns the messageid of the sent message
|
||||
async fn misc_send_text_message(
|
||||
&self,
|
||||
|
||||
Reference in New Issue
Block a user