Merge branch 'remove_strn' into 'master'
Remove the custom strn! macro. See merge request World/fractal!164
This commit is contained in:
commit
ce59272e76
7 changed files with 32 additions and 39 deletions
|
@ -160,8 +160,8 @@ impl AppOp {
|
|||
}
|
||||
Some("join") => {
|
||||
let m = Member {
|
||||
avatar: Some(strn!(ev.content["avatar_url"].as_str().unwrap_or(""))),
|
||||
alias: Some(strn!(ev.content["displayname"].as_str().unwrap_or(""))),
|
||||
avatar: Some(String::from(ev.content["avatar_url"].as_str().unwrap_or(""))),
|
||||
alias: Some(String::from(ev.content["displayname"].as_str().unwrap_or(""))),
|
||||
uid: sender.clone(),
|
||||
};
|
||||
if let Some(r) = self.rooms.get_mut(&ev.room.clone()) {
|
||||
|
|
|
@ -358,7 +358,7 @@ impl AppOp {
|
|||
let room = self.active_room.clone();
|
||||
let now = Local::now();
|
||||
|
||||
let mtype = strn!("m.text");
|
||||
let mtype = String::from("m.text");
|
||||
|
||||
let mut m = Message {
|
||||
sender: self.uid.clone().unwrap_or_default(),
|
||||
|
@ -376,7 +376,7 @@ impl AppOp {
|
|||
|
||||
if msg.starts_with("/me ") {
|
||||
m.body = msg.trim_left_matches("/me ").to_owned();
|
||||
m.mtype = strn!("m.emote");
|
||||
m.mtype = String::from("m.emote");
|
||||
}
|
||||
|
||||
/* reenable autoscroll to jump to new message in history */
|
||||
|
@ -424,7 +424,7 @@ impl AppOp {
|
|||
"image/jpg" => "m.image",
|
||||
_ => "m.file"
|
||||
};
|
||||
let body = strn!(file.split("/").last().unwrap_or(&file));
|
||||
let body = String::from(file.split("/").last().unwrap_or(&file));
|
||||
|
||||
let mut m = Message {
|
||||
sender: self.uid.clone().unwrap_or_default(),
|
||||
|
@ -474,7 +474,7 @@ impl AppOp {
|
|||
dialog.connect_response(move |dialog, resp| {
|
||||
if resp == 1 {
|
||||
if let Some(fname) = dialog.get_filename() {
|
||||
let f = strn!(fname.to_str().unwrap_or(""));
|
||||
let f = String::from(fname.to_str().unwrap_or(""));
|
||||
internal.send(InternalCommand::AttachMessage(f)).unwrap();
|
||||
}
|
||||
}
|
||||
|
@ -484,7 +484,7 @@ impl AppOp {
|
|||
let internal = self.internal.clone();
|
||||
dialog.connect_file_activated(move |dialog| {
|
||||
if let Some(fname) = dialog.get_filename() {
|
||||
let f = strn!(fname.to_str().unwrap_or(""));
|
||||
let f = String::from(fname.to_str().unwrap_or(""));
|
||||
internal.send(InternalCommand::AttachMessage(f)).unwrap();
|
||||
}
|
||||
dialog.destroy();
|
||||
|
|
|
@ -183,7 +183,7 @@ mod ss_storage {
|
|||
// old name password
|
||||
let passwd = allpass
|
||||
.iter()
|
||||
.find(|x| x.get_label().unwrap_or(strn!("")) == "guillotine");
|
||||
.find(|x| x.get_label().unwrap_or_default() == "guillotine");
|
||||
|
||||
if passwd.is_none() {
|
||||
return Ok(());
|
||||
|
|
|
@ -130,7 +130,7 @@ pub fn logout(bk: &Backend) -> Result<(), Error> {
|
|||
pub fn register(bk: &Backend, user: String, password: String, server: String) -> Result<(), Error> {
|
||||
let s = server.clone();
|
||||
bk.data.lock().unwrap().server_url = s;
|
||||
let url = bk.url("register", vec![("kind", strn!("user"))])?;
|
||||
let url = bk.url("register", vec![("kind", String::from("user"))])?;
|
||||
|
||||
let attrs = json!({
|
||||
"auth": {"type": "m.login.password"},
|
||||
|
|
|
@ -117,8 +117,8 @@ pub fn get_room_members(bk: &Backend, roomid: String) -> Result<(), Error> {
|
|||
let avatar = &joined[memberid]["avatar_url"];
|
||||
|
||||
let m = Member {
|
||||
alias: match alias.as_str() { None => None, Some(a) => Some(strn!(a)) },
|
||||
avatar: match avatar.as_str() { None => None, Some(a) => Some(strn!(a)) },
|
||||
alias: match alias.as_str() { None => None, Some(a) => Some(String::from(a)) },
|
||||
avatar: match avatar.as_str() { None => None, Some(a) => Some(String::from(a)) },
|
||||
uid: memberid.to_string(),
|
||||
};
|
||||
ms.push(m);
|
||||
|
@ -408,7 +408,7 @@ pub fn new_room(bk: &Backend, name: String, privacy: RoomType, internal_id: Stri
|
|||
let tx = bk.tx.clone();
|
||||
post!(&url, &attrs,
|
||||
move |r: JsonValue| {
|
||||
let id = strn!(r["room_id"].as_str().unwrap_or(""));
|
||||
let id = String::from(r["room_id"].as_str().unwrap_or(""));
|
||||
let name = n;
|
||||
let r = Room::new(id, Some(name));
|
||||
tx.send(BKResponse::NewRoom(r, internal_id)).unwrap();
|
||||
|
@ -435,7 +435,7 @@ pub fn direct_chat(bk: &Backend, user: Member, internal_id: String) -> Result<()
|
|||
let tx = bk.tx.clone();
|
||||
post!(&url, &attrs,
|
||||
move |r: JsonValue| {
|
||||
let id = strn!(r["room_id"].as_str().unwrap_or(""));
|
||||
let id = String::from(r["room_id"].as_str().unwrap_or(""));
|
||||
let mut r = Room::new(id.clone(), m.alias);
|
||||
r.direct = true;
|
||||
tx.send(BKResponse::NewRoom(r, internal_id)).unwrap();
|
||||
|
|
|
@ -20,7 +20,7 @@ pub fn sync(bk: &Backend) -> Result<(), Error> {
|
|||
let userid = bk.data.lock().unwrap().user_id.clone();
|
||||
|
||||
let mut params: Vec<(&str, String)> = vec![];
|
||||
params.push(("full_state", strn!("false")));
|
||||
params.push(("full_state", String::from("false")));
|
||||
|
||||
let timeout;
|
||||
|
||||
|
@ -42,12 +42,12 @@ pub fn sync(bk: &Backend) -> Result<(), Error> {
|
|||
\"event_fields\": [\"type\", \"content\", \"sender\", \"event_id\", \"age\", \"unsigned\"]
|
||||
}}", globals::PAGE_LIMIT);
|
||||
|
||||
params.push(("filter", strn!(filter)));
|
||||
params.push(("timeout", strn!("0")));
|
||||
params.push(("filter", String::from(filter)));
|
||||
params.push(("timeout", String::from("0")));
|
||||
timeout = 0;
|
||||
} else {
|
||||
params.push(("since", since.clone()));
|
||||
params.push(("timeout", strn!("30000")));
|
||||
params.push(("timeout", String::from("30000")));
|
||||
timeout = 30;
|
||||
}
|
||||
|
||||
|
@ -108,11 +108,11 @@ pub fn sync(bk: &Backend) -> Result<(), Error> {
|
|||
for ev in events {
|
||||
match ev.stype.as_ref() {
|
||||
"m.room.name" => {
|
||||
let name = strn!(ev.content["name"].as_str().unwrap_or(""));
|
||||
let name = String::from(ev.content["name"].as_str().unwrap_or(""));
|
||||
tx.send(BKResponse::RoomName(ev.room.clone(), name)).unwrap();
|
||||
}
|
||||
"m.room.topic" => {
|
||||
let t = strn!(ev.content["topic"].as_str().unwrap_or(""));
|
||||
let t = String::from(ev.content["topic"].as_str().unwrap_or(""));
|
||||
tx.send(BKResponse::RoomTopic(ev.room.clone(), t)).unwrap();
|
||||
}
|
||||
"m.room.avatar" => {
|
||||
|
|
|
@ -83,13 +83,6 @@ macro_rules! clone {
|
|||
);
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! strn {
|
||||
($p: expr) => (
|
||||
String::from($p)
|
||||
);
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! client_url {
|
||||
($b: expr, $path: expr, $params: expr) => (
|
||||
|
@ -325,7 +318,7 @@ pub fn get_rooms_from_json(r: &JsonValue, userid: &str, baseu: &Url) -> Result<V
|
|||
Member {
|
||||
alias: Some(alias),
|
||||
avatar: Some(avatar),
|
||||
uid: strn!(userid),
|
||||
uid: String::from(userid),
|
||||
}
|
||||
);
|
||||
}
|
||||
|
@ -435,10 +428,10 @@ pub fn parse_sync_events(r: &JsonValue) -> Result<Vec<Event>, Error> {
|
|||
//println!("ev: {:#?}", ev);
|
||||
evs.push(Event {
|
||||
room: k.clone(),
|
||||
sender: strn!(ev["sender"].as_str().unwrap_or("")),
|
||||
sender: String::from(ev["sender"].as_str().unwrap_or("")),
|
||||
content: ev["content"].clone(),
|
||||
stype: strn!(ev["type"].as_str().unwrap_or("")),
|
||||
id: strn!(ev["id"].as_str().unwrap_or("")),
|
||||
stype: String::from(ev["type"].as_str().unwrap_or("")),
|
||||
id: String::from(ev["id"].as_str().unwrap_or("")),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -469,7 +462,7 @@ pub fn get_room_media_list(baseu: &Url,
|
|||
prev_batch: Option<String>)
|
||||
-> Result<(Vec<Message>, String), Error> {
|
||||
let mut params = vec![
|
||||
("dir", strn!("b")),
|
||||
("dir", String::from("b")),
|
||||
("limit", format!("{}", limit)),
|
||||
("access_token", tk.clone()),
|
||||
("filter", "{\"filter_json\": { \"contains_url\": true, \"not_types\": [\"m.sticker\"] } }".to_string()),
|
||||
|
@ -546,7 +539,7 @@ pub fn resolve_media_url(
|
|||
if thumb {
|
||||
params.push(("width", format!("{}", w)));
|
||||
params.push(("height", format!("{}", h)));
|
||||
params.push(("method", strn!("scale")));
|
||||
params.push(("method", String::from("scale")));
|
||||
path = format!("thumbnail/{}/{}", server, media);
|
||||
} else {
|
||||
path = format!("download/{}/{}", server, media);
|
||||
|
@ -573,7 +566,7 @@ pub fn dw_media(base: &Url,
|
|||
if thumb {
|
||||
params.push(("width", format!("{}", w)));
|
||||
params.push(("height", format!("{}", h)));
|
||||
params.push(("method", strn!("scale")));
|
||||
params.push(("method", String::from("scale")));
|
||||
path = format!("thumbnail/{}/{}", server, media);
|
||||
} else {
|
||||
path = format!("download/{}/{}", server, media);
|
||||
|
@ -685,7 +678,7 @@ pub fn get_user_avatar(baseu: &Url, userid: &str) -> Result<(String, String), Er
|
|||
}
|
||||
|
||||
pub fn get_room_st(base: &Url, tk: &str, roomid: &str) -> Result<JsonValue, Error> {
|
||||
let url = client_url!(base, &format!("rooms/{}/state", roomid), vec![("access_token", strn!(tk))])?;
|
||||
let url = client_url!(base, &format!("rooms/{}/state", roomid), vec![("access_token", String::from(tk))])?;
|
||||
|
||||
let attrs = json!(null);
|
||||
let st = json_q("get", &url, &attrs, globals::TIMEOUT)?;
|
||||
|
@ -807,7 +800,7 @@ pub fn get_initial_room_messages(baseu: &Url,
|
|||
let mut nend;
|
||||
|
||||
let mut params = vec![
|
||||
("dir", strn!("b")),
|
||||
("dir", String::from("b")),
|
||||
("limit", format!("{}", limit)),
|
||||
("access_token", tk.clone()),
|
||||
];
|
||||
|
@ -859,7 +852,7 @@ pub fn fill_room_gap(baseu: &Url,
|
|||
let nend;
|
||||
|
||||
let mut params = vec![
|
||||
("dir", strn!("f")),
|
||||
("dir", String::from("f")),
|
||||
("limit", format!("{}", globals::PAGE_LIMIT)),
|
||||
("access_token", tk.clone()),
|
||||
];
|
||||
|
@ -965,15 +958,15 @@ pub fn parse_room_member(msg: &JsonValue) -> Option<Member> {
|
|||
|
||||
let displayname = match c["displayname"].as_str() {
|
||||
None => None,
|
||||
Some(s) => Some(strn!(s))
|
||||
Some(s) => Some(String::from(s))
|
||||
};
|
||||
let avatar_url = match c["avatar_url"].as_str() {
|
||||
None => None,
|
||||
Some(s) => Some(strn!(s))
|
||||
Some(s) => Some(String::from(s))
|
||||
};
|
||||
|
||||
Some(Member {
|
||||
uid: strn!(sender),
|
||||
uid: String::from(sender),
|
||||
alias: displayname,
|
||||
avatar: avatar_url,
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue