-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add comments to updates (#1161)
* feat: add comments to updates * refactor: components * fix: use of forumUrl function * refactor: add coauthor service * feat: add update data to forum topic * refactor: create vote service * feat: update discourse with comment on update action * feat: update status text on discourse message * fix: issue with null topic data * remove console.log * refactor: DRY in comments component * feat: update text
- Loading branch information
Showing
36 changed files
with
629 additions
and
292 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import CoauthorModel from '../../entities/Coauthor/model' | ||
import { CoauthorStatus } from '../../entities/Coauthor/types' | ||
import { isSameAddress } from '../../entities/Snapshot/utils' | ||
|
||
export class CoauthorService { | ||
static async isCoauthor(proposalId: string, address: string): Promise<boolean> { | ||
const coauthors = await CoauthorModel.findCoauthors(proposalId, CoauthorStatus.APPROVED) | ||
return !!coauthors.find((coauthor) => isSameAddress(coauthor.address, address)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import logger from 'decentraland-gatsby/dist/entities/Development/logger' | ||
|
||
import { Discourse, DiscoursePost } from '../../clients/Discourse' | ||
import { ProposalAttributes } from '../../entities/Proposal/types' | ||
import UpdateModel from '../../entities/Updates/model' | ||
import { UpdateAttributes } from '../../entities/Updates/types' | ||
import { getUpdateUrl } from '../../entities/Updates/utils' | ||
import { inBackground } from '../../helpers' | ||
|
||
export class UpdateService { | ||
static async getById(id: UpdateAttributes['id']) { | ||
return await UpdateModel.findOne<UpdateAttributes>({ id }) | ||
} | ||
|
||
static async getAllByProposalId(proposal_id: ProposalAttributes['id']) { | ||
return await UpdateModel.find<UpdateAttributes>({ proposal_id }) | ||
} | ||
|
||
static async updateWithDiscoursePost(id: UpdateAttributes['id'], discoursePost: DiscoursePost) { | ||
return await UpdateModel.update( | ||
{ discourse_topic_id: discoursePost.topic_id, discourse_topic_slug: discoursePost.topic_slug }, | ||
{ id } | ||
) | ||
} | ||
|
||
static commentUpdateEditInDiscourse(update: UpdateAttributes) { | ||
inBackground(async () => { | ||
if (!update.discourse_topic_id) { | ||
logger.error('No discourse topic associated to this update', { id: update.id }) | ||
return | ||
} | ||
|
||
await Discourse.get().commentOnPost({ | ||
topic_id: update.discourse_topic_id, | ||
raw: `This project update has been edited by the author. Please check the latest version on the [Governance dApp](${getUpdateUrl( | ||
update.id, | ||
update.proposal_id | ||
)}).`, | ||
created_at: new Date().toJSON(), | ||
}) | ||
}) | ||
} | ||
|
||
static commentUpdateDeleteInDiscourse(update: UpdateAttributes) { | ||
inBackground(async () => { | ||
if (!update.discourse_topic_id) { | ||
logger.error('No discourse topic associated to this update', { id: update.id }) | ||
return | ||
} | ||
|
||
await Discourse.get().commentOnPost({ | ||
topic_id: update.discourse_topic_id, | ||
raw: `This project update has been deleted by the author.`, | ||
created_at: new Date().toJSON(), | ||
}) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import VoteModel from '../../entities/Votes/model' | ||
|
||
export class VoteService { | ||
static async getVotes(proposal_id: string) { | ||
const proposalVotes = await VoteModel.getVotes(proposal_id) | ||
return proposalVotes?.votes ? proposalVotes.votes : await VoteModel.createEmpty(proposal_id) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.