@@ -17,70 +17,71 @@ contract BasedShop {
1717 EVENTS
1818 //////////////////////////////////////////////////////////////*/
1919
20- event PostCreated (
21- uint256 indexed postId ,
20+ event ArticleCreated (
21+ uint256 indexed articleId ,
2222 address indexed user ,
2323 string tokenURI ,
24- uint256 timestamp
24+ uint256 date
2525 );
26- event PostDeleted (uint256 indexed postId , uint256 timestamp );
27- event PostLiked (
28- uint256 indexed postID , address indexed user , uint256 timestamp
26+ event ArticleDeleted (uint256 indexed articleId , uint256 date );
27+ event ArticleLiked (
28+ uint256 indexed articleID , address indexed user , uint256 date
2929 );
30- event PostUnliked (
31- uint256 indexed postID , address indexed user , uint256 timestamp
30+ event ArticleUnliked (
31+ uint256 indexed articleID , address indexed user , uint256 date
3232 );
33- event PostCommented (
34- uint256 indexed postID ,
33+ event ArticleCommented (
34+ uint256 indexed articleID ,
3535 address indexed user ,
3636 string text ,
3737 uint256 index ,
38- uint256 timestamp
38+ uint256 date
3939 );
40- event PostCommentDeleted (
41- uint256 indexed postID , address indexed user , uint256 timestamp
40+ event ArticleCommentDeleted (
41+ uint256 indexed articleID , address indexed user , uint256 date
4242 );
43- event PostShared (
44- uint256 indexed postID , address indexed user , uint256 timestamp
43+ event ArticleBookmarked (
44+ uint256 indexed articleID , address indexed user , uint256 date
4545 );
46- event PostUnshared (
47- uint256 indexed postID , address indexed user , uint256 timestamp
46+ event ArticleUnshared (
47+ uint256 indexed articleID , address indexed user , uint256 date
4848 );
4949 event UserFollowed (
50- address indexed user , address indexed follower , uint256 timestamp
50+ address indexed user , address indexed follower , uint256 date
5151 );
5252 event UserUnfollowed (
53- address indexed user , address indexed follower , uint256 timestamp
53+ address indexed user , address indexed follower , uint256 date
5454 );
5555 event FollowerRemoved (
56- address indexed user , address indexed follower , uint256 timestamp
56+ address indexed user , address indexed follower , uint256 date
5757 );
5858
5959 /*//////////////////////////////////////////////////////////////
6060 STATE VARIABLES
6161 //////////////////////////////////////////////////////////////*/
6262
63- uint256 public postIds ;
63+ uint256 public articleIds ;
6464 BasedProfile public punkProfile;
6565 BasedArticles public basedArticles;
6666
67- mapping (uint256 => address ) public postIdToUser ;
67+ mapping (uint256 => address ) public articleIdToUser ;
6868 mapping (address => uint256 []) public userArticles;
6969
7070 // Likes
71- mapping (uint256 post = > uint256 likes ) public postToLikes ;
72- mapping (address user = > mapping (uint256 post = > bool liked )) public
73- userToPostLikes ;
71+ mapping (uint256 article = > uint256 likes ) public articleToLikes ;
72+ mapping (address user = > mapping (uint256 article = > bool liked )) public
73+ userToArticleLikes ;
7474
7575 // Comments
76- mapping (uint256 postId = > Comment[]) public postToComments ;
77- mapping (uint256 postId = > mapping (uint256 commentId = > address user )) public
78- postCommentToUser ;
76+ mapping (uint256 articleId = > Comment[]) public articleToComments ;
77+ mapping (uint256 articleId = > mapping (uint256 commentId = > address user ))
78+ public articleCommentToUser ;
7979
80- // Shared
81- mapping (address user = > uint256 [] sharedArticles ) public userToSharedArticles;
82- mapping (address user = > mapping (uint256 post = > uint256 index )) public
83- userToSharedPostIndex;
80+ // Bookmarked
81+ mapping (address user = > uint256 [] sharedArticles ) public
82+ userToBookmarkedArticles;
83+ mapping (address user = > mapping (uint256 article = > uint256 index )) public
84+ userToBookmarkedArticleIndex;
8485
8586 // Following and Followers
8687 mapping (address user = > mapping (address follower = > bool isFollowing )) public
@@ -101,102 +102,106 @@ contract BasedShop {
101102 EXTERNAL FUNCTIONS
102103 //////////////////////////////////////////////////////////////*/
103104
104- function createPost (
105+ function createArticle (
105106 string memory _tokenURI
106107 ) public {
107- uint256 postId = postIds ++ ;
108- postIdToUser[postId ] = msg .sender ;
109- userArticles[msg .sender ].push (postId );
108+ uint256 articleId = articleIds ++ ;
109+ articleIdToUser[articleId ] = msg .sender ;
110+ userArticles[msg .sender ].push (articleId );
110111
111112 basedArticles.mint (_tokenURI);
112113
113- emit PostCreated (postId , msg .sender , _tokenURI, block .timestamp );
114+ emit ArticleCreated (articleId , msg .sender , _tokenURI, block .timestamp );
114115 }
115116
116- function deletePost (
117- uint256 _postId
117+ function deleteArticle (
118+ uint256 _articleId
118119 ) public {
119- require (postIdToUser[_postId] == msg .sender , "Not the owner of the post " );
120+ require (
121+ articleIdToUser[_articleId] == msg .sender , "Not the owner of the article "
122+ );
120123
121- basedArticles.burn (_postId );
124+ basedArticles.burn (_articleId );
122125
123- emit PostDeleted (_postId , block .timestamp );
126+ emit ArticleDeleted (_articleId , block .timestamp );
124127 }
125128
126- function likePost (
127- uint256 _postID
129+ function likeArticle (
130+ uint256 _articleID
128131 ) public {
129- _requirePostExists (_postID );
132+ _requireArticleExists (_articleID );
130133 require (
131- ! userToPostLikes[msg .sender ][_postID], "You have already liked this post "
134+ ! userToArticleLikes[msg .sender ][_articleID],
135+ "You have already liked this article "
132136 );
133- userToPostLikes [msg .sender ][_postID ] = true ;
134- postToLikes[_postID ]++ ;
135- emit PostLiked (_postID , msg .sender , block .timestamp );
137+ userToArticleLikes [msg .sender ][_articleID ] = true ;
138+ articleToLikes[_articleID ]++ ;
139+ emit ArticleLiked (_articleID , msg .sender , block .timestamp );
136140 }
137141
138- function unlikePost (
139- uint256 _postID
142+ function unlikeArticle (
143+ uint256 _articleID
140144 ) public {
141- _requirePostExists (_postID );
145+ _requireArticleExists (_articleID );
142146 require (
143- userToPostLikes[msg .sender ][_postID], "You have not liked this post yet "
147+ userToArticleLikes[msg .sender ][_articleID],
148+ "You have not liked this article yet "
144149 );
145- userToPostLikes [msg .sender ][_postID ] = false ;
146- postToLikes[_postID ]-- ;
147- emit PostUnliked (_postID , msg .sender , block .timestamp );
150+ userToArticleLikes [msg .sender ][_articleID ] = false ;
151+ articleToLikes[_articleID ]-- ;
152+ emit ArticleUnliked (_articleID , msg .sender , block .timestamp );
148153 }
149154
150- function commentOnPost (uint256 _postID , string memory _text ) public {
151- _requirePostExists (_postID );
155+ function commentOnArticle (uint256 _articleID , string memory _text ) public {
156+ _requireArticleExists (_articleID );
152157 // set max length at 250 characters
153158 require (
154159 bytes (_text).length <= 250 , "Comment must be less than 250 characters "
155160 );
156- uint256 commentIndex = postToComments[_postID ].length ;
157- postToComments[_postID ].push (Comment (msg .sender , _text, commentIndex));
158- emit PostCommented (
159- _postID , msg .sender , _text, commentIndex, block .timestamp
161+ uint256 commentIndex = articleToComments[_articleID ].length ;
162+ articleToComments[_articleID ].push (Comment (msg .sender , _text, commentIndex));
163+ emit ArticleCommented (
164+ _articleID , msg .sender , _text, commentIndex, block .timestamp
160165 );
161166 }
162167
163- function deleteComment (uint256 _postID , uint256 _commentID ) public {
164- _requirePostExists (_postID );
168+ function deleteComment (uint256 _articleID , uint256 _commentID ) public {
169+ _requireArticleExists (_articleID );
165170 require (
166- postCommentToUser[_postID ][_commentID] == msg .sender ,
167- "You can't erase what you didn't post ! "
171+ articleCommentToUser[_articleID ][_commentID] == msg .sender ,
172+ "You can't erase what you didn't article ! "
168173 );
169- delete postCommentToUser[_postID ][_commentID];
170- delete postToComments[_postID ][_commentID];
171- emit PostCommentDeleted (_postID , msg .sender , block .timestamp );
174+ delete articleCommentToUser[_articleID ][_commentID];
175+ delete articleToComments[_articleID ][_commentID];
176+ emit ArticleCommentDeleted (_articleID , msg .sender , block .timestamp );
172177 }
173178
174- function sharePost (
175- uint256 _postID
179+ function shareArticle (
180+ uint256 _articleID
176181 ) public {
177- _requirePostExists (_postID );
178- userToSharedArticles [msg .sender ].push (_postID );
179- // userToSharedPostIndex [msg.sender][_postID ] =
180- // userToSharedArticles [msg.sender].length - 1;
181- emit PostShared (_postID , msg .sender , block .timestamp );
182+ _requireArticleExists (_articleID );
183+ userToBookmarkedArticles [msg .sender ].push (_articleID );
184+ // userToBookmarkedArticleIndex [msg.sender][_articleID ] =
185+ // userToBookmarkedArticles [msg.sender].length - 1;
186+ emit ArticleBookmarked (_articleID , msg .sender , block .timestamp );
182187 }
183188
184- function deleteSharedPost (
185- uint256 _postID
189+ function deleteBookmarkedArticle (
190+ uint256 _articleID
186191 ) public {
187- _requirePostExists (_postID );
192+ _requireArticleExists (_articleID );
188193
189- // Retrieve the index of the post to be deleted
190- uint256 index = userToSharedPostIndex [msg .sender ][_postID ];
194+ // Retrieve the index of the article to be deleted
195+ uint256 index = userToBookmarkedArticleIndex [msg .sender ][_articleID ];
191196
192- // Set the post to a default value (e.g., 0)
193- userToSharedArticles [msg .sender ][index] = 0 ;
197+ // Set the article to a default value (e.g., 0)
198+ userToBookmarkedArticles [msg .sender ][index] = 0 ;
194199
195- // Delete the index entry for the deleted post
196- delete userToSharedPostIndex [msg .sender ][_postID ];
200+ // Delete the index entry for the deleted article
201+ delete userToBookmarkedArticleIndex [msg .sender ][_articleID ];
197202
198- // Emit the PostUnshared event
199- emit PostUnshared (_postID , msg .sender , block .timestamp );
203+ // Emit the ArticleUnshared event
204+ emit ArticleUnshared (_articleID , msg .sender , block .timestamp );
200205 }
201206
202207 function followUser (
@@ -238,9 +243,9 @@ contract BasedShop {
238243 VIEW FUNCTIONS
239244 //////////////////////////////////////////////////////////////*/
240245
241- function _requirePostExists (
242- uint256 _postID
246+ function _requireArticleExists (
247+ uint256 _articleID
243248 ) internal view {
244- require (basedArticles.tokenId () >= _postID , "Post does not exist " );
249+ require (basedArticles.tokenId () >= _articleID , "Article does not exist " );
245250 }
246251}
0 commit comments