[Fix] Omikron Veryfies users/Omikrons
This commit is contained in:
parent
5cf838ae5d
commit
d138484c99
1 changed files with 39 additions and 52 deletions
|
|
@ -797,8 +797,8 @@ impl OmikronConnection {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if cv.is_type(CommunicationType::change_iota_data) {
|
if cv.is_type(CommunicationType::change_iota_data) {
|
||||||
if let (Some(user_id), Some(iota_id), Some(reset_token), Some(new_token)) = (
|
if let (user_id, Some(iota_id), Some(reset_token), Some(new_token)) = (
|
||||||
cv.get_data(DataTypes::user_id).and_then(|v| v.as_i64()),
|
cv.get_sender(),
|
||||||
cv.get_data(DataTypes::iota_id).and_then(|v| v.as_i64()),
|
cv.get_data(DataTypes::iota_id).and_then(|v| v.as_i64()),
|
||||||
cv.get_data(DataTypes::reset_token).and_then(|v| v.as_str()),
|
cv.get_data(DataTypes::reset_token).and_then(|v| v.as_str()),
|
||||||
cv.get_data(DataTypes::new_token).and_then(|v| v.as_str()),
|
cv.get_data(DataTypes::new_token).and_then(|v| v.as_str()),
|
||||||
|
|
@ -854,25 +854,21 @@ impl OmikronConnection {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if cv.is_type(CommunicationType::delete_user) {
|
if cv.is_type(CommunicationType::delete_user) {
|
||||||
if let Some(user_id) = cv.get_data(DataTypes::user_id).and_then(|v| v.as_i64()) {
|
let user_id = cv.get_sender();
|
||||||
match sql::delete_user(user_id).await {
|
match sql::delete_user(user_id).await {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
let response = CommunicationValue::new(CommunicationType::success)
|
let response =
|
||||||
.with_id(cv.get_id());
|
CommunicationValue::new(CommunicationType::success).with_id(cv.get_id());
|
||||||
self.send_message(&response).await;
|
self.send_message(&response).await;
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
self.send_message(
|
|
||||||
&CommunicationValue::new(CommunicationType::error)
|
|
||||||
.with_id(cv.get_id())
|
|
||||||
.add_data_str(DataTypes::error_type, e.to_string()),
|
|
||||||
)
|
|
||||||
.await;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
Err(e) => {
|
||||||
self.send_error_response(&cv.get_id(), CommunicationType::error_invalid_data)
|
self.send_message(
|
||||||
|
&CommunicationValue::new(CommunicationType::error)
|
||||||
|
.with_id(cv.get_id())
|
||||||
|
.add_data_str(DataTypes::error_type, e.to_string()),
|
||||||
|
)
|
||||||
.await;
|
.await;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -902,35 +898,29 @@ impl OmikronConnection {
|
||||||
|
|
||||||
// NOTIFICATIONS
|
// NOTIFICATIONS
|
||||||
if cv.is_type(CommunicationType::get_notifications) {
|
if cv.is_type(CommunicationType::get_notifications) {
|
||||||
if let Some(JsonValue::Number(user_id)) = cv.get_data(DataTypes::user_id) {
|
let user_id = cv.get_sender();
|
||||||
if let Ok(notifications) =
|
if let Ok(notifications) = sql::get_notifications(user_id).await {
|
||||||
sql::get_notifications(user_id.as_fixed_point_i64(0).unwrap()).await
|
let mut json_array = Vec::new();
|
||||||
{
|
for (sender, amount) in notifications {
|
||||||
let mut json_array = Vec::new();
|
let mut obj = JsonValue::new_object();
|
||||||
for (sender, amount) in notifications {
|
let _ = obj.insert("sender", JsonValue::from(sender));
|
||||||
let mut obj = JsonValue::new_object();
|
let _ = obj.insert("amount", JsonValue::from(amount));
|
||||||
let _ = obj.insert("sender", JsonValue::from(sender));
|
json_array.push(obj);
|
||||||
let _ = obj.insert("amount", JsonValue::from(amount));
|
|
||||||
json_array.push(obj);
|
|
||||||
}
|
|
||||||
let response = CommunicationValue::new(CommunicationType::get_notifications)
|
|
||||||
.with_id(cv.get_id())
|
|
||||||
.add_array(DataTypes::notifications, json_array);
|
|
||||||
self.send_message(&response).await;
|
|
||||||
}
|
}
|
||||||
|
let response = CommunicationValue::new(CommunicationType::get_notifications)
|
||||||
|
.with_id(cv.get_id())
|
||||||
|
.add_array(DataTypes::notifications, json_array);
|
||||||
|
self.send_message(&response).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if cv.is_type(CommunicationType::read_notification) {
|
if cv.is_type(CommunicationType::read_notification) {
|
||||||
if let (Some(JsonValue::Number(user_id)), Some(JsonValue::Number(other_id))) = (
|
if let (user_id, Some(other_id)) = (
|
||||||
cv.get_data(DataTypes::receiver_id),
|
cv.get_sender(),
|
||||||
cv.get_data(DataTypes::sender_id),
|
cv.get_data(DataTypes::sender_id)
|
||||||
|
.unwrap_or(&JsonValue::Null)
|
||||||
|
.as_i64(),
|
||||||
) {
|
) {
|
||||||
if let Ok(_) = sql::read_notification(
|
if let Ok(_) = sql::read_notification(user_id, other_id).await {
|
||||||
user_id.as_fixed_point_i64(0).unwrap(),
|
|
||||||
other_id.as_fixed_point_i64(0).unwrap(),
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
{
|
|
||||||
let response = CommunicationValue::new(CommunicationType::read_notification)
|
let response = CommunicationValue::new(CommunicationType::read_notification)
|
||||||
.with_id(cv.get_id());
|
.with_id(cv.get_id());
|
||||||
self.send_message(&response).await;
|
self.send_message(&response).await;
|
||||||
|
|
@ -938,16 +928,13 @@ impl OmikronConnection {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if cv.is_type(CommunicationType::push_notification) {
|
if cv.is_type(CommunicationType::push_notification) {
|
||||||
if let (Some(JsonValue::Number(user_id)), Some(JsonValue::Number(other_id))) = (
|
if let (user_id, Some(other_id)) = (
|
||||||
cv.get_data(DataTypes::receiver_id),
|
cv.get_sender(),
|
||||||
cv.get_data(DataTypes::sender_id),
|
cv.get_data(DataTypes::sender_id)
|
||||||
|
.unwrap_or(&JsonValue::Null)
|
||||||
|
.as_i64(),
|
||||||
) {
|
) {
|
||||||
if let Ok(_) = sql::add_notification(
|
if let Ok(_) = sql::add_notification(user_id, other_id).await {
|
||||||
user_id.as_fixed_point_i64(0).unwrap(),
|
|
||||||
other_id.as_fixed_point_i64(0).unwrap(),
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
{
|
|
||||||
let response = CommunicationValue::new(CommunicationType::push_notification)
|
let response = CommunicationValue::new(CommunicationType::push_notification)
|
||||||
.with_id(cv.get_id());
|
.with_id(cv.get_id());
|
||||||
self.send_message(&response).await;
|
self.send_message(&response).await;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue