client-api: Update tag endpoints to the new API standards
This commit is contained in:
parent
532e7a7233
commit
5407a95a99
@ -14,25 +14,42 @@ ruma_api! {
|
||||
requires_authentication: true,
|
||||
}
|
||||
|
||||
#[non_exhaustive]
|
||||
request: {
|
||||
/// The ID of the user creating the tag.
|
||||
#[ruma_api(path)]
|
||||
pub user_id: UserId,
|
||||
pub user_id: &'a UserId,
|
||||
|
||||
/// The room to tag.
|
||||
#[ruma_api(path)]
|
||||
pub room_id: RoomId,
|
||||
pub room_id: &'a RoomId,
|
||||
|
||||
/// The name of the tag to create.
|
||||
#[ruma_api(path)]
|
||||
pub tag: String,
|
||||
pub tag: &'a str,
|
||||
|
||||
/// Info about the tag.
|
||||
#[ruma_api(body)]
|
||||
pub tag_info: TagInfo,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
#[non_exhaustive]
|
||||
response: {}
|
||||
|
||||
error: crate::Error
|
||||
}
|
||||
|
||||
impl<'a> Request<'a> {
|
||||
/// Creates a new `Request` with the given user ID, room ID, tag and tag info.
|
||||
pub fn new(user_id: &'a UserId, room_id: &'a RoomId, tag: &'a str, tag_info: TagInfo) -> Self {
|
||||
Self { user_id, room_id, tag, tag_info }
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates an empty `Response`.
|
||||
pub fn new() -> Self {
|
||||
Self
|
||||
}
|
||||
}
|
||||
|
@ -13,21 +13,38 @@ ruma_api! {
|
||||
requires_authentication: true,
|
||||
}
|
||||
|
||||
#[non_exhaustive]
|
||||
request: {
|
||||
/// The user whose tag will be deleted.
|
||||
#[ruma_api(path)]
|
||||
pub user_id: UserId,
|
||||
pub user_id: &'a UserId,
|
||||
|
||||
/// The tagged room.
|
||||
#[ruma_api(path)]
|
||||
pub room_id: RoomId,
|
||||
pub room_id: &'a RoomId,
|
||||
|
||||
/// The name of the tag to delete.
|
||||
#[ruma_api(path)]
|
||||
pub tag: String,
|
||||
pub tag: &'a str,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
#[non_exhaustive]
|
||||
response: {}
|
||||
|
||||
error: crate::Error
|
||||
}
|
||||
|
||||
impl<'a> Request<'a> {
|
||||
/// Creates a new `Request` with the given user ID, room ID and tag
|
||||
pub fn new(user_id: &'a UserId, room_id: &'a RoomId, tag: &'a str) -> Self {
|
||||
Self { user_id, room_id, tag }
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates an empty `Response`.
|
||||
pub fn new() -> Self {
|
||||
Self
|
||||
}
|
||||
}
|
||||
|
@ -14,16 +14,18 @@ ruma_api! {
|
||||
requires_authentication: true,
|
||||
}
|
||||
|
||||
#[non_exhaustive]
|
||||
request: {
|
||||
/// The user whose tags will be retrieved.
|
||||
#[ruma_api(path)]
|
||||
pub user_id: UserId,
|
||||
pub user_id: &'a UserId,
|
||||
|
||||
/// The room from which tags will be retrieved.
|
||||
#[ruma_api(path)]
|
||||
pub room_id: RoomId,
|
||||
pub room_id: &'a RoomId,
|
||||
}
|
||||
|
||||
#[non_exhaustive]
|
||||
response: {
|
||||
/// The user's tags for the room.
|
||||
pub tags: Tags,
|
||||
@ -32,19 +34,35 @@ ruma_api! {
|
||||
error: crate::Error
|
||||
}
|
||||
|
||||
impl<'a> Request<'a> {
|
||||
/// Creates a new `Request` with the given user ID and room ID.
|
||||
pub fn new(user_id: &'a UserId, room_id: &'a RoomId) -> Self {
|
||||
Self { user_id, room_id }
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates a new `Response` with the given tags.
|
||||
pub fn new(tags: Tags) -> Self {
|
||||
Self { tags }
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::convert::TryFrom;
|
||||
|
||||
use assign::assign;
|
||||
use ruma_events::tag::{TagInfo, Tags};
|
||||
use serde_json::json;
|
||||
|
||||
use super::Response;
|
||||
use ruma_events::tag::{TagInfo, Tags};
|
||||
use std::convert::TryFrom;
|
||||
|
||||
#[test]
|
||||
fn test_serializing_get_tags_response() {
|
||||
let mut tags = Tags::new();
|
||||
tags.insert("m.favourite".into(), TagInfo { order: Some(0.25) });
|
||||
tags.insert("u.user_tag".into(), TagInfo { order: Some(0.11) });
|
||||
tags.insert("m.favourite".into(), assign!(TagInfo::new(), { order: Some(0.25) }));
|
||||
tags.insert("u.user_tag".into(), assign!(TagInfo::new(), { order: Some(0.11) }));
|
||||
let response = Response { tags };
|
||||
|
||||
let http_response = http::Response::<Vec<u8>>::try_from(response).unwrap();
|
||||
|
@ -15,16 +15,38 @@ pub type Tags = BTreeMap<String, TagInfo>;
|
||||
|
||||
/// The payload for `TagEvent`.
|
||||
#[derive(Clone, Debug, Deserialize, Serialize, BasicEventContent)]
|
||||
#[non_exhaustive]
|
||||
#[ruma_event(type = "m.tag")]
|
||||
pub struct TagEventContent {
|
||||
/// A map of tag names to tag info.
|
||||
pub tags: Tags,
|
||||
}
|
||||
|
||||
impl TagEventContent {
|
||||
/// Creates a new `TagEventContent` with the given `Tags`.
|
||||
pub fn new(tags: Tags) -> Self {
|
||||
Self { tags }
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Tags> for TagEventContent {
|
||||
fn from(tags: Tags) -> Self {
|
||||
Self::new(tags)
|
||||
}
|
||||
}
|
||||
|
||||
/// Information about a tag.
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
||||
#[non_exhaustive]
|
||||
pub struct TagInfo {
|
||||
/// Value to use for lexicographically ordering rooms with this tag.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub order: Option<f64>,
|
||||
}
|
||||
|
||||
impl TagInfo {
|
||||
/// Creates an empty `TagInfo`.
|
||||
pub fn new() -> Self {
|
||||
Default::default()
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user