Add displayname and avatar_url endpoints

Add PUT and GET /_matrix/client/r0/profile/{userId}/displayname Endpoint
Add PUT and GET /_matrix/client/r0/profile/{userId}/avatar_url Endpoint
Add GET /_matrix/client/r0/profile/{userId} Endpoint

Took 2 hours 16 minutes
This commit is contained in:
Marcel 2020-04-09 18:49:27 +02:00
parent 11e75e7081
commit 062c5521f0
3 changed files with 189 additions and 1 deletions

View file

@ -60,6 +60,40 @@ impl Data {
.map(|bytes| utils::string_from_bytes(&bytes))
}
/// Set a new displayname.
pub fn displayname_set(&self, user_id: &UserId, displayname: Option<String>) {
self.db
.profile_displayname
.insert(user_id.to_string(), &*displayname.unwrap_or_default())
.unwrap();
}
/// Get a the displayname of a user.
pub fn displayname_get(&self, user_id: &UserId) -> Option<String> {
self.db
.profile_displayname
.get(user_id.to_string())
.unwrap()
.map(|bytes| utils::string_from_bytes(&bytes))
}
/// Set a new avatar_url.
pub fn avatar_url_set(&self, user_id: &UserId, avatar_url: String) {
self.db
.profile_avatar_url
.insert(user_id.to_string(), &*avatar_url)
.unwrap();
}
/// Get a the avatar_url of a user.
pub fn avatar_url_get(&self, user_id: &UserId) -> Option<String> {
self.db
.profile_avatar_url
.get(user_id.to_string())
.unwrap()
.map(|bytes| utils::string_from_bytes(&bytes))
}
/// Add a new device to a user.
pub fn device_add(&self, user_id: &UserId, device_id: &str) {
if self