[fractal] Change statics for consts
- From: Alejandro Domínguez <aledomu src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [fractal] Change statics for consts
- Date: Mon, 30 Nov 2020 09:24:58 +0000 (UTC)
commit 2864e630074a72ec4267a3dae954c6f7de8ccf79
Author: Alejandro Domínguez <adomu net-c com>
Date: Sun Nov 29 16:16:46 2020 +0100
Change statics for consts
fractal-gtk/src/backend/sync.rs | 6 ++----
fractal-gtk/src/client.rs | 3 +--
fractal-gtk/src/config.rs.in | 10 +++++-----
fractal-gtk/src/globals.rs | 28 ++++++++++++++--------------
fractal-gtk/src/model/message.rs | 20 ++++++--------------
fractal-gtk/src/widgets/clip_container.rs | 2 +-
6 files changed, 29 insertions(+), 40 deletions(-)
---
diff --git a/fractal-gtk/src/backend/sync.rs b/fractal-gtk/src/backend/sync.rs
index 460b3795..622aae4a 100644
--- a/fractal-gtk/src/backend/sync.rs
+++ b/fractal-gtk/src/backend/sync.rs
@@ -27,8 +27,7 @@ use serde_json::value::from_value;
use std::{
collections::HashMap,
convert::{TryFrom, TryInto},
- thread,
- time::{self, Duration},
+ thread, time,
};
use super::{remove_matrix_access_token_if_present, HandleError};
@@ -176,8 +175,7 @@ pub fn sync(
set_presence: Default::default(),
};
- let client_builder_timeout =
- Client::builder().timeout(Some(Duration::from_secs(globals::TIMEOUT) + timeout));
+ let client_builder_timeout = Client::builder().timeout(Some(globals::TIMEOUT + timeout));
let query = ProxySettings::current().and_then(|proxy_settings| {
let client = proxy_settings
diff --git a/fractal-gtk/src/client.rs b/fractal-gtk/src/client.rs
index 0d85be8e..67462068 100644
--- a/fractal-gtk/src/client.rs
+++ b/fractal-gtk/src/client.rs
@@ -5,7 +5,6 @@ use fractal_api::reqwest;
use gio::prelude::*;
use std::sync::Mutex;
-use std::time::Duration;
// Special URI used by gio to indicate no proxy
const PROXY_DIRECT_URI: &str = "direct://";
@@ -119,7 +118,7 @@ impl Client {
) -> fractal_api::reqwest::blocking::Client {
builder
.gzip(true)
- .timeout(Duration::from_secs(globals::TIMEOUT))
+ .timeout(globals::TIMEOUT)
.build()
.expect("Couldn't create a http client")
}
diff --git a/fractal-gtk/src/config.rs.in b/fractal-gtk/src/config.rs.in
index 9af5e2ab..fed43b2d 100644
--- a/fractal-gtk/src/config.rs.in
+++ b/fractal-gtk/src/config.rs.in
@@ -17,8 +17,8 @@
//
// SPDX-License-Identifier: GPL-3.0-or-later
-pub static LOCALEDIR: &str = @LOCALEDIR@;
-pub static APP_ID: &str = @APP_ID@;
-pub static NAME_SUFFIX: &str = @NAME_SUFFIX@;
-pub static VERSION: &str = @VERSION@;
-pub static PKGDATADIR: &str = @PKGDATADIR@;
+pub const LOCALEDIR: &str = @LOCALEDIR@;
+pub const APP_ID: &str = @APP_ID@;
+pub const NAME_SUFFIX: &str = @NAME_SUFFIX@;
+pub const VERSION: &str = @VERSION@;
+pub const PKGDATADIR: &str = @PKGDATADIR@;
diff --git a/fractal-gtk/src/globals.rs b/fractal-gtk/src/globals.rs
index 35b8e5e8..6efcc99e 100644
--- a/fractal-gtk/src/globals.rs
+++ b/fractal-gtk/src/globals.rs
@@ -2,23 +2,23 @@ use directories::ProjectDirs;
use fractal_api::url::Url;
use lazy_static::lazy_static;
use regex::Regex;
-use std::path::PathBuf;
+use std::{path::PathBuf, time::Duration};
-pub static TIMEOUT: u64 = 80;
-pub static PAGE_LIMIT: i32 = 40;
-pub static ROOM_DIRECTORY_LIMIT: i32 = 20;
-pub static DEVICE_NAME: &str = "Fractal";
+pub const TIMEOUT: Duration = Duration::from_secs(80);
+pub const PAGE_LIMIT: i32 = 40;
+pub const ROOM_DIRECTORY_LIMIT: i32 = 20;
+pub const DEVICE_NAME: &str = "Fractal";
-pub static CACHE_SIZE: usize = 40;
-pub static MSG_ICON_SIZE: i32 = 40;
-pub static USERLIST_ICON_SIZE: i32 = 30;
-pub static PILL_ICON_SIZE: i32 = 18;
-pub static MINUTES_TO_SPLIT_MSGS: i64 = 30;
-pub static PLACEHOLDER_TEXT: &str = "Matrix username, email or phone number";
-pub static RIOT_REGISTER_URL: &str = "https://riot.im/app/#/register";
+pub const CACHE_SIZE: usize = 40;
+pub const MSG_ICON_SIZE: i32 = 40;
+pub const USERLIST_ICON_SIZE: i32 = 30;
+pub const PILL_ICON_SIZE: i32 = 18;
+pub const MINUTES_TO_SPLIT_MSGS: i64 = 30;
+pub const PLACEHOLDER_TEXT: &str = "Matrix username, email or phone number";
+pub const RIOT_REGISTER_URL: &str = "https://riot.im/app/#/register";
-pub static MAX_IMAGE_SIZE: (i32, i32) = (600, 400);
-pub static MAX_STICKER_SIZE: (i32, i32) = (200, 130);
+pub const MAX_IMAGE_SIZE: (i32, i32) = (600, 400);
+pub const MAX_STICKER_SIZE: (i32, i32) = (200, 130);
lazy_static! {
pub static ref DEFAULT_HOMESERVER: Url =
diff --git a/fractal-gtk/src/model/message.rs b/fractal-gtk/src/model/message.rs
index 66d1d72a..56158e8e 100644
--- a/fractal-gtk/src/model/message.rs
+++ b/fractal-gtk/src/model/message.rs
@@ -62,6 +62,11 @@ impl PartialOrd for Message {
}
impl Message {
+ /// List all supported types. By default a message map a m.room.message event, but there's
+ /// other events that we want to show in the message history so we map other event types to our
+ /// Message struct, like stickers
+ pub const TYPES: [&'static str; 2] = ["m.room.message", "m.sticker"];
+
pub fn new(
room: RoomId,
sender: UserId,
@@ -103,25 +108,12 @@ impl Message {
format!("{:x}", digest)
}
- /// List all supported types. By default a message map a m.room.message event, but there's
- /// other events that we want to show in the message history so we map other event types to our
- /// Message struct, like stickers
- pub fn types() -> [&'static str; 2] {
- ["m.room.message", "m.sticker"]
- }
-
/// Helper function to use in iterator filter of a matrix.org json response to filter supported
/// events
pub fn supported_event(ev: &&JsonValue) -> bool {
let type_ = ev["type"].as_str().unwrap_or_default();
- for t in Message::types().iter() {
- if t == &type_ {
- return true;
- }
- }
-
- false
+ Self::TYPES.contains(&type_)
}
/// Parses a matrix.org event and return a Message object
diff --git a/fractal-gtk/src/widgets/clip_container.rs b/fractal-gtk/src/widgets/clip_container.rs
index ca4dc250..36148518 100644
--- a/fractal-gtk/src/widgets/clip_container.rs
+++ b/fractal-gtk/src/widgets/clip_container.rs
@@ -22,7 +22,7 @@ pub enum Corner {
BottomRight,
}
-static CORNERS: [Corner; 4] = [
+const CORNERS: [Corner; 4] = [
Corner::TopLeft,
Corner::TopRight,
Corner::BottomLeft,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]