Skip to content

Commit

Permalink
fix: Fix proposal notifications to be posted on behalf of devhub's co…
Browse files Browse the repository at this point in the history
…ntract (#100)
  • Loading branch information
PolyProgrammist authored Mar 3, 2024
1 parent 29031c9 commit ff47a8e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
28 changes: 18 additions & 10 deletions src/notify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ pub fn get_text_mentions(text: &str) -> Vec<String> {
mentions
}

pub fn notify_accounts(accounts: Vec<String>, notify_value: serde_json::Value) {
pub fn notify_accounts(
notifier: AccountId,
accounts: Vec<String>,
notify_value: serde_json::Value,
) {
if !accounts.is_empty() {
let mut notify_values = Vec::new();

Expand All @@ -49,10 +53,11 @@ pub fn notify_accounts(accounts: Vec<String>, notify_value: serde_json::Value) {
.with_static_gas(env::prepaid_gas().saturating_div(4))
.with_attached_deposit(env::attached_deposit())
.set(json!({
env::predecessor_account_id() : {
"index": {
"notify": json!(notify_values).to_string()
} }
notifier : {
"index": {
"notify": json!(notify_values).to_string()
}
}
}));
}
}
Expand All @@ -61,6 +66,7 @@ pub fn notify_proposal_subscribers(proposal: &Proposal) {
let accounts = get_subscribers(&proposal.snapshot.body.clone().latest_version());

notify_accounts(
env::current_account_id(),
accounts,
json!({
"type": "devgovgigs/mention",
Expand All @@ -73,6 +79,7 @@ pub fn notify_mentions(text: &str, post_id: PostId) {
let mentions = get_text_mentions(text);

notify_accounts(
env::predecessor_account_id(),
mentions,
json!({
"type": "devgovgigs/mention",
Expand All @@ -82,19 +89,20 @@ pub fn notify_mentions(text: &str, post_id: PostId) {
}

pub fn notify_like(post_id: PostId, post_author: AccountId) -> Promise {
notify(post_author, notify_value(post_id, "like"))
notify(env::predecessor_account_id(), post_author, notify_value(post_id, "like"))
}

pub fn notify_reply(post_id: PostId, post_author: AccountId) -> Promise {
notify(post_author, notify_value(post_id, "reply"))
notify(env::predecessor_account_id(), post_author, notify_value(post_id, "reply"))
}

pub fn notify_edit(post_id: PostId, post_author: AccountId) -> Promise {
notify(post_author, notify_value(post_id, "edit"))
notify(env::predecessor_account_id(), post_author, notify_value(post_id, "edit"))
}

pub fn notify_edit_proposal(proposal_id: ProposalId, post_author: AccountId) -> Promise {
notify(
env::current_account_id(),
post_author,
json!({
"type": format!("devgovgigs/{}", "edit"),
Expand All @@ -110,12 +118,12 @@ fn notify_value(post_id: PostId, action: &str) -> serde_json::Value {
})
}

fn notify(post_author: AccountId, notify_value: serde_json::Value) -> Promise {
fn notify(notifier: AccountId, post_author: AccountId, notify_value: serde_json::Value) -> Promise {
social_db_contract()
.with_static_gas(env::prepaid_gas().saturating_div(4))
.with_attached_deposit(env::attached_deposit())
.set(json!({
env::predecessor_account_id() : {
notifier : {
"index": {
"notify": json!({
"key": post_author,
Expand Down
4 changes: 2 additions & 2 deletions src/repost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ mod tests {
snapshot_history: vec![],
};

let call_args = repost_internal(post, "devgovgigs.near".parse().unwrap());
let call_args = repost_internal(post, "devhub.near".parse().unwrap());
let expected = json!({
"devgovgigs.near": {
"devhub.near": {
"post": {
"main": "{\"type\":\"md\",\"text\":\"@neardevgov.near [Posted on DevHub](/devhub.near/widget/app?page=post&id=0)\\n## Idea: A call for Zero Knowledge Work Group members!\\nWe are excited to create a more formal Zero Knowledge Work Group (WG) to oversee official decisions on Zero Knowledge proposals. We’re looking for 3-7 experts to participate. Reply to the post if you’re interested in becoming a work group member.\"}"
},
Expand Down

0 comments on commit ff47a8e

Please sign in to comment.