Skip to content

add group images #4905

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added assets/icon-group.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
68 changes: 68 additions & 0 deletions assets/icon-group.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 0 additions & 6 deletions node/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -440,12 +440,6 @@ describe('Offline Tests with unconfigured account', function () {
expect(blobPath.startsWith(blobs)).to.be.true
expect(blobPath.includes('image')).to.be.true
expect(blobPath.endsWith('.jpeg')).to.be.true

context.setChatProfileImage(chatId, null)
expect(context.getChat(chatId).getProfileImage()).to.be.equal(
null,
'image is null'
)
})

it('test setting ephemeral timer', function () {
Expand Down
33 changes: 31 additions & 2 deletions src/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1451,6 +1451,12 @@ impl Chat {
if let Ok(image_rel) = get_archive_icon(context).await {
return Ok(Some(get_abs_path(context, Path::new(&image_rel))));
}
}

if self.typ == Chattype::Group {
if let Ok(image_rel) = get_group_icon(context).await {
return Ok(Some(get_abs_path(context, Path::new(&image_rel))));
}
} else if self.typ == Chattype::Single {
let contacts = get_chat_contacts(context, self.id).await?;
if let Some(contact_id) = contacts.first() {
Expand Down Expand Up @@ -1983,6 +1989,21 @@ pub(crate) async fn get_broadcast_icon(context: &Context) -> Result<String> {
Ok(icon)
}

pub(crate) async fn get_group_icon(context: &Context) -> Result<String> {
if let Some(icon) = context.sql.get_raw_config("icon-group").await? {
return Ok(icon);
}

let icon = include_bytes!("../assets/icon-group.png");
let blob = BlobObject::create(context, "icon-group.png", icon).await?;
let icon = blob.as_name().to_string();
context
.sql
.set_raw_config("icon-group", Some(&icon))
.await?;
Ok(icon)
}

pub(crate) async fn get_archive_icon(context: &Context) -> Result<String> {
if let Some(icon) = context.sql.get_raw_config("icon-archive").await? {
return Ok(icon);
Expand Down Expand Up @@ -4347,8 +4368,16 @@ mod tests {
assert_eq!(a1_chat.grpid, a2_chat.grpid);
assert_eq!(a1_chat.name, "foo");
assert_eq!(a2_chat.name, "foo");
assert_eq!(a1_chat.get_profile_image(&a1).await?, None);
assert_eq!(a2_chat.get_profile_image(&a2).await?, None);
assert!(a1_chat
.get_profile_image(&a1)
.await?
.unwrap()
.ends_with("icon-group.png"));
assert!(a2_chat
.get_profile_image(&a2)
.await?
.unwrap()
.ends_with("icon-group.png"));
assert_eq!(get_chat_contacts(&a1, a1_chat_id).await?.len(), 1);
assert_eq!(get_chat_contacts(&a2, a2_chat_id).await?.len(), 1);

Expand Down