Skip to content

Commit

Permalink
finish with refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
backmeupplz committed May 16, 2023
1 parent 728f48c commit dc4c0b9
Show file tree
Hide file tree
Showing 6 changed files with 274 additions and 158 deletions.
27 changes: 6 additions & 21 deletions contracts/Feeds.sol
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "@openzeppelin/contracts/utils/Counters.sol";
import "./superclasses/Posts.sol";

contract Feeds is Posts {
Expand All @@ -72,31 +71,17 @@ contract Feeds is Posts {
// Events
event FeedAdded(uint indexed id, CID metadata);

// Modifiers
modifier onlyAllowedFeedId(uint feedId) override {
require(feedId < lastFeedId.current(), "Feed does not exist");
_;
}

function addFeed(CID memory feedMetadata) public onlyOwner returns (uint) {
uint feedId = lastFeedId.current();
feeds.push(feedMetadata);
emit FeedAdded(feedId, feedMetadata);
lastFeedId.increment();
return feedId;
}

function addFeedPost(
address sender,
uint feedId,
CID memory postMetadata
) public {
require(feedId < lastFeedId.current(), "Feed does not exist");
super.addPost(sender, feedId, postMetadata);
}

function addFeedComment(
address sender,
uint feedId,
uint postId,
CID memory commentMetadata
) public {
require(feedId < lastFeedId.current(), "Feed does not exist");
require(postId < lastPostIds[feedId].current(), "Post does not exist");
super.addComment(sender, feedId, postId, commentMetadata);
}
}
70 changes: 49 additions & 21 deletions contracts/OBSSStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -102,46 +102,74 @@ contract OBSSStorage is OwnableUpgradeable, ERC2771Recipient {
}

function addProfilePost(CID memory postMetadata) external {
profiles.addProfilePost(_msgSender(), postMetadata);
}

function getProfilePosts(
address profile,
uint skip,
uint limit
) external view returns (Post[] memory) {
uint id = uint(keccak256(abi.encodePacked(profile)));
return profiles.getPosts(id, skip, limit);
uint feedId = uint(keccak256(abi.encodePacked(_msgSender())));
profiles.addPost(_msgSender(), feedId, postMetadata);
}

function addProfileComment(
address profile,
uint feedId,
uint postId,
uint replyTo,
CID memory commentMetadata
) external {
profiles.addProfileComment(_msgSender(), profile, postId, commentMetadata);
profiles.addComment(_msgSender(), feedId, postId, replyTo, commentMetadata);
}

function addProfileReaction(
uint feedId,
uint postId,
uint commentId,
uint8 reactionType
) external payable {
profiles.addReaction(_msgSender(), feedId, postId, commentId, reactionType);
}

function removeProfileReaction(
uint feedId,
uint postId,
uint commentId,
uint reactionId
) external {
profiles.removeReaction(
_msgSender(),
feedId,
postId,
commentId,
reactionId
);
}

// Feeds

function addFeedPost(uint feedId, CID memory postMetadata) external {
feeds.addFeedPost(_msgSender(), feedId, postMetadata);
feeds.addPost(_msgSender(), feedId, postMetadata);
}

function getFeedPosts(
function addFeedComment(
uint feedId,
uint skip,
uint limit
) external view returns (Post[] memory) {
return feeds.getPosts(feedId, skip, limit);
uint postId,
uint replyTo,
CID memory commentMetadata
) external {
feeds.addComment(_msgSender(), feedId, postId, replyTo, commentMetadata);
}

function addFeedComment(
function addFeedReaction(
uint feedId,
uint postId,
CID memory commentMetadata
uint commentId,
uint8 reactionType
) external payable {
feeds.addReaction(_msgSender(), feedId, postId, commentId, reactionType);
}

function removeFeedReaction(
uint feedId,
uint postId,
uint commentId,
uint reactionId
) external {
feeds.addFeedComment(_msgSender(), feedId, postId, commentMetadata);
feeds.removeReaction(_msgSender(), feedId, postId, commentId, reactionId);
}

// OpenGSN boilerplate
Expand Down
18 changes: 0 additions & 18 deletions contracts/Profiles.sol
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,9 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "@openzeppelin/contracts/utils/Counters.sol";
import "./superclasses/Posts.sol";

contract Profiles is Posts {
using Counters for Counters.Counter;

// State
mapping(address => CID) public profiles;

Expand All @@ -78,19 +75,4 @@ contract Profiles is Posts {
profiles[sender] = profileMetadata;
emit ProfileSet(sender, profileMetadata);
}

function addProfilePost(address sender, CID memory postMetadata) public {
uint id = uint(keccak256(abi.encodePacked(sender)));
super.addPost(sender, id, postMetadata);
}

function addProfileComment(
address sender,
address profile,
uint postId,
CID memory commentMetadata
) public {
uint id = uint(keccak256(abi.encodePacked(profile)));
super.addComment(sender, id, postId, commentMetadata);
}
}
67 changes: 67 additions & 0 deletions contracts/models/PostAndParticipants.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// ,-,
// * . /.( .
// \|/ \ {
// . _ . , . -*- . `-`
// ,'-. * / \_ * / \_ /|\ * /\'__ *. *
// (____". / \ / \, __ . _/ / \ * . .
// . /\/\ /\/ :' __ \_ / \ _^/ ^/ `—./\ /\ .
// * _ / \/ \ _/ \-‘\/ ` \ /\ /.' ^_ \_ .’\\ /_/\ ,'-.
// /_\ /\ .- `. \/ \ /. / \ ;. _/ \ -. `_/ \/. \ _ (____". *
// . / \ / `-.__ ^ / .-'.--\ - \/ _ `--./ .-' `-/. \ / \ .
// / /. `. / / `. / ` .-' '-._ `._ /. \
// ~._,-'2_,-'2_,-'2_,-'2_,-'2_,-'2_,-'2_,-'2_,-'2_,-'2_,-'2_,-'2_,-'2_,-'2_,-'2_,-'2_,-'2_,-'2_,-'
// ~~~~~~~ ~~~~~~~ ~~~~~~~ ~~~~~~~ ~~~~~~~ ~~~~~~~ ~~~~~~~ ~~~~~~~ ~~~~~~~ ~~~~~~~ ~~~~~~~ ~~~~~~~~
// ~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~
// ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~
// ๐
// _
// ₒ ><_>
// _______ __ _______
// .-' | _ "\ |" \ /" _ "| ๐
// '--./ / _.---. (. |_) :) || | (: ( \___)
// '-, (__..-` \ |: \/ |: | \/ \
// \ . | (| _ \\ |. | // \ ___
// `,.__. ,__.--/ |: |_) :) |\ | (: _( _|
// '._/_.'___.-` (_______/ |__\| \_______) ๐
//
// __ __ ___ __ __ __ ___ _______
// |" |/ \| "| /" | | "\ /""\ |" | /" "|
// ๐ |' / \: |(: (__) :) / \ || | (: ______)
// |: /' | \/ \/ /' /\ \ |: | ₒ \/ |
// \// /\' | // __ \\ // __' \ \ |___ // ___)_
// / / \\ |(: ( ) :) / / \\ \ ( \_|: \ (: "|
// |___/ \___| \__| |__/ (___/ \___) \_______) \_______)
// ₒ৹
// ___ __ _______ ________
// _ |" | ₒ /""\ | _ "\ /" )
// ><_> || | / \ (. |_) :) (: \___/
// |: | /' /\ \ |: \/ \___ \
// \ |___ // __' \ (| _ \\ __/ \\ \_____)\_____
// ( \_|: \ / / \\ \ |: |_) :) /" \ :) /--v____ __`<
// \_______) (___/ \___)(_______/ (_______/ )/
// '
//
// ๐ . ' , ₒ
// ₒ _______
// ____ .`_|___|_`. ____
// \ \ / / ₒ৹
// \ ' / ๐
// ₒ \/
// ₒ / \ ) (
// ( ₒ৹ ( ( )
// ) ) _ ) ) (
// ( ) ( ( ><_> ( ( ( )
// ) ) ( ( ) ) ) ) ) ) (
// ( ( ) ) ( ( ( ( ( ( )
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "./Post.sol";

struct PostAndParticipants {
Post post;
address[] participants;
}
1 change: 1 addition & 0 deletions contracts/models/Reaction.sol
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ struct Reaction {
address sender;
uint feedId;
uint postId;
uint commentId;
uint8 reactionType;
uint value;
}
Loading

0 comments on commit dc4c0b9

Please sign in to comment.