@@ -6,10 +6,11 @@ use matrix_sdk::{
6
6
TimelineKey ,
7
7
} ,
8
8
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 ,
11
11
} ,
12
12
} ;
13
+ use rand:: { Rng , random} ;
13
14
14
15
use crate :: { ClientError , TimelineItem } ;
15
16
@@ -20,8 +21,10 @@ pub struct NotificationService {
20
21
21
22
pub struct NotificationItem {
22
23
pub item : Arc < TimelineItem > ,
23
- pub sender : String ,
24
+ pub title : String ,
25
+ pub subtitle : Option < String > ,
24
26
pub is_noisy : bool ,
27
+ pub avatar_url : Option < String > ,
25
28
}
26
29
27
30
impl NotificationService {
@@ -35,11 +38,26 @@ impl NotificationService {
35
38
_room_id : String ,
36
39
event_id : String ,
37
40
) -> 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
+
38
53
let sdk_event = EventTimelineItem {
39
54
key : TimelineKey :: EventId ( EventId :: parse ( event_id) . unwrap ( ) ) ,
40
55
sender : UserId :: parse ( "@username:example.com" ) . unwrap ( ) ,
41
56
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
+ } ,
43
61
in_reply_to : None ,
44
62
edited : false ,
45
63
} ) ,
@@ -50,10 +68,13 @@ impl NotificationService {
50
68
encryption_info : None ,
51
69
raw : None ,
52
70
} ;
71
+
53
72
let item = NotificationItem {
54
73
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 ( ) ) ,
56
76
is_noisy : true ,
77
+ avatar_url : Some ( "mxc://matrix.org/XzNaquIfpvjHtftUJBCRNDgX" . to_owned ( ) ) ,
57
78
} ;
58
79
Ok ( Some ( item) )
59
80
}
0 commit comments