api!: make Message.text non-optional

Message.set_text() and Message.get_text() are modified accordingly
to accept String and return String.

Messages which previously contained None text
are now represented as messages with empty text.
Use Message.set_text("".to_string())
instead of Message.set_text(None).
This commit is contained in:
link2xt
2023-07-03 13:34:13 +00:00
parent 8e17e400b3
commit 9c68fac4b6
33 changed files with 248 additions and 325 deletions

View File

@@ -185,16 +185,14 @@ pub(crate) async fn maybe_add_time_based_warnings(context: &Context) {
async fn maybe_warn_on_bad_time(context: &Context, now: i64, known_past_timestamp: i64) -> bool {
if now < known_past_timestamp {
let mut msg = Message::new(Viewtype::Text);
msg.text = Some(
stock_str::bad_time_msg_body(
context,
&Local.timestamp_opt(now, 0).single().map_or_else(
|| "YY-MM-DD hh:mm:ss".to_string(),
|ts| ts.format("%Y-%m-%d %H:%M:%S").to_string(),
),
)
.await,
);
msg.text = stock_str::bad_time_msg_body(
context,
&Local.timestamp_opt(now, 0).single().map_or_else(
|| "YY-MM-DD hh:mm:ss".to_string(),
|ts| ts.format("%Y-%m-%d %H:%M:%S").to_string(),
),
)
.await;
if let Some(timestamp) = chrono::NaiveDateTime::from_timestamp_opt(now, 0) {
add_device_msg_with_importance(
context,
@@ -221,7 +219,7 @@ async fn maybe_warn_on_bad_time(context: &Context, now: i64, known_past_timestam
async fn maybe_warn_on_outdated(context: &Context, now: i64, approx_compile_time: i64) {
if now > approx_compile_time + DC_OUTDATED_WARNING_DAYS * 24 * 60 * 60 {
let mut msg = Message::new(Viewtype::Text);
msg.text = Some(stock_str::update_reminder_msg_body(context).await);
msg.text = stock_str::update_reminder_msg_body(context).await;
if let Some(timestamp) = chrono::NaiveDateTime::from_timestamp_opt(now, 0) {
add_device_msg(
context,