Skip to content

Commit 62f5987

Browse files
committed
Updates on notification item & return text or image randomly
1 parent f2bfeb7 commit 62f5987

File tree

4 files changed

+31
-6
lines changed

4 files changed

+31
-6
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bindings/matrix-sdk-ffi/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,4 @@ tracing-subscriber = { version = "0.3", features = ["env-filter"] }
3636
# keep in sync with uniffi dependency in matrix-sdk-crypto-ffi, and uniffi_bindgen in ffi CI job
3737
uniffi = { git = "https://github.com/mozilla/uniffi-rs", rev = "091c3561656e72e1a4160412c83b36d98e556d06" }
3838
uniffi_macros = { git = "https://github.com/mozilla/uniffi-rs", rev = "091c3561656e72e1a4160412c83b36d98e556d06" }
39+
rand = "0.8.5"

bindings/matrix-sdk-ffi/src/api.udl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,8 +534,10 @@ interface AuthenticationService {
534534

535535
dictionary NotificationItem {
536536
TimelineItem item;
537-
string sender;
537+
string title;
538+
string? subtitle;
538539
boolean is_noisy;
540+
string? avatar_url;
539541
};
540542

541543
interface NotificationService {

bindings/matrix-sdk-ffi/src/notification_service.rs

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ use matrix_sdk::{
66
TimelineKey,
77
},
88
ruma::{
9-
events::room::message::{MessageType, TextMessageEventContent},
10-
EventId, MilliSecondsSinceUnixEpoch, ServerName, UserId,
9+
events::room::{message::{MessageType, TextMessageEventContent, ImageMessageEventContent}, ImageInfo},
10+
EventId, MilliSecondsSinceUnixEpoch, ServerName, UserId, api::client::message, MxcUri, UInt,
1111
},
1212
};
13+
use rand::{Rng, random};
1314

1415
use crate::{ClientError, TimelineItem};
1516

@@ -20,8 +21,10 @@ pub struct NotificationService {
2021

2122
pub struct NotificationItem {
2223
pub item: Arc<TimelineItem>,
23-
pub sender: String,
24+
pub title: String,
25+
pub subtitle: Option<String>,
2426
pub is_noisy: bool,
27+
pub avatar_url: Option<String>,
2528
}
2629

2730
impl NotificationService {
@@ -35,11 +38,26 @@ impl NotificationService {
3538
_room_id: String,
3639
event_id: String,
3740
) -> anyhow::Result<Option<NotificationItem>> {
41+
42+
let text_message_type = MessageType::Text(TextMessageEventContent::plain("Notified text"));
43+
let mut image_info = ImageInfo::new();
44+
image_info.height = UInt::new(640);
45+
image_info.width = UInt::new(638);
46+
image_info.mimetype = Some("image/jpeg".to_owned());
47+
image_info.size = UInt::new(118141);
48+
image_info.blurhash = Some("TFF~Ba5at616yD^%~T-oXU9bt6kr".to_owned());
49+
let image_message_type = MessageType::Image(ImageMessageEventContent::plain("body".to_owned(), (*Box::<MxcUri>::from("mxc://matrix.org/vNOdmUTIPIwWvMneNzyCzNhb")).to_owned(), Some(Box::new(image_info))));
50+
51+
let random = rand::thread_rng().gen_range(0..2);
52+
3853
let sdk_event = EventTimelineItem {
3954
key: TimelineKey::EventId(EventId::parse(event_id).unwrap()),
4055
sender: UserId::parse("@username:example.com").unwrap(),
4156
content: TimelineItemContent::Message(Message {
42-
msgtype: MessageType::Text(TextMessageEventContent::plain("Notified text")),
57+
msgtype: match random {
58+
1 => image_message_type,
59+
_ => text_message_type,
60+
},
4361
in_reply_to: None,
4462
edited: false,
4563
}),
@@ -50,10 +68,13 @@ impl NotificationService {
5068
encryption_info: None,
5169
raw: None,
5270
};
71+
5372
let item = NotificationItem {
5473
item: Arc::new(TimelineItem(matrix_sdk::room::timeline::TimelineItem::Event(sdk_event))),
55-
sender: "sender".to_owned(),
74+
title: "ismailgulek".to_owned(),
75+
subtitle: Some("Element iOS - Internal".to_owned()),
5676
is_noisy: true,
77+
avatar_url: Some("mxc://matrix.org/XzNaquIfpvjHtftUJBCRNDgX".to_owned()),
5778
};
5879
Ok(Some(item))
5980
}

0 commit comments

Comments
 (0)