Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions mobile/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion mobile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"@bufbuild/protobuf": "^2.6.2",
"@connectrpc/connect": "^2.0.3",
"@connectrpc/connect-web": "^2.0.3",
"@gnolang/gnonative": "^4.7.0",
"@gnolang/gnonative": "^4.7.1",
"@reduxjs/toolkit": "^2.1.0",
"base-64": "^1.0.0",
"date-fns": "^3.6.0",
Expand Down
31 changes: 15 additions & 16 deletions realm/post.gno
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ package social

import (
"bytes"
"std"
"strconv"
"time"

"gno.land/p/demo/avl"
"gno.land/p/demo/ufmt"
"gno.land/p/moul/txlink"
"gno.land/p/nt/avl"
"gno.land/p/nt/ufmt"
)

//----------------------------------------
Expand All @@ -35,19 +34,19 @@ const (
type Post struct {
userPosts *UserPosts
id PostID
creator std.Address
creator address
body string
replies avl.Tree // PostID -> *Post
repliesAll avl.Tree // PostID -> *Post (all replies, for top-level posts)
reposts avl.Tree // UserPosts user std.Address -> PostID
threadID PostID // original PostID
parentID PostID // parent PostID (if reply or repost)
repostUser std.Address // UserPosts user std.Address of original post (if repost)
reactions *avl.Tree // Reaction -> *avl.Tree of std.Address -> "" (Use the avl.Tree keys as the "set" of addresses)
replies avl.Tree // PostID -> *Post
repliesAll avl.Tree // PostID -> *Post (all replies, for top-level posts)
reposts avl.Tree // UserPosts user address -> PostID
threadID PostID // original PostID
parentID PostID // parent PostID (if reply or repost)
repostUser address // UserPosts user address of original post (if repost)
reactions *avl.Tree // Reaction -> *avl.Tree of address -> "" (Use the avl.Tree keys as the "set" of addresses)
createdAt time.Time
}

func newPost(userPosts *UserPosts, id PostID, creator std.Address, body string, threadID, parentID PostID, repostUser std.Address) *Post {
func newPost(userPosts *UserPosts, id PostID, creator address, body string, threadID, parentID PostID, repostUser address) *Post {
return &Post{
userPosts: userPosts,
id: id,
Expand All @@ -72,7 +71,7 @@ func (post *Post) GetPostID() PostID {
return post.id
}

func (post *Post) AddReply(creator std.Address, body string) *Post {
func (post *Post) AddReply(creator address, body string) *Post {
userPosts := post.userPosts
pid := userPosts.incGetPostID()
pidkey := postIDKey(pid)
Expand All @@ -87,7 +86,7 @@ func (post *Post) AddReply(creator std.Address, body string) *Post {
return reply
}

func (post *Post) AddRepostTo(creator std.Address, comment string, dst *UserPosts) *Post {
func (post *Post) AddRepostTo(creator address, comment string, dst *UserPosts) *Post {
if !post.IsThread() {
panic("cannot repost non-thread post")
}
Expand Down Expand Up @@ -117,7 +116,7 @@ func (post *Post) GetReply(pid PostID) *Post {
// If userAddr is already added, do nothing.
// If the userAddr is the post's creator, do nothing. (Don't react to one's own posts.)
// Return a boolean indicating whether the userAddr was added (false if it was already added).
func (post *Post) AddReaction(userAddr std.Address, reaction Reaction) bool {
func (post *Post) AddReaction(userAddr address, reaction Reaction) bool {
validateReaction(reaction)

if userAddr == post.creator {
Expand All @@ -137,7 +136,7 @@ func (post *Post) AddReaction(userAddr std.Address, reaction Reaction) bool {
// Remove the userAddr from the posts.reactions for reaction.
// If userAddr is already removed, do nothing.
// Return a boolean indicating whether the userAddr was found and removed.
func (post *Post) RemoveReaction(userAddr std.Address, reaction Reaction) bool {
func (post *Post) RemoveReaction(userAddr address, reaction Reaction) bool {
validateReaction(reaction)

if !post.reactions.Has(reactionKey(reaction)) {
Expand Down
54 changes: 27 additions & 27 deletions realm/public.gno
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package social

import (
"std"
"chain/runtime"
"strconv"

"gno.land/p/demo/avl"
"gno.land/p/demo/avlhelpers"
"gno.land/p/demo/ufmt"
"gno.land/p/jefft0/avlhelpers"
"gno.land/p/nt/avl"
"gno.land/p/nt/ufmt"
"gno.land/r/sys/users"
)

type UserAndPostID struct {
UserPostAddr std.Address
UserPostAddr address
PostID PostID
}

Expand All @@ -20,7 +20,7 @@ type UserAndPostID struct {
// Return the "thread ID" of the new post.
// (This is similar to boards.CreateThread, but no message title)
func PostMessage(_ realm, body string) PostID {
caller := std.OriginCaller()
caller := runtime.OriginCaller()
name := usernameOf(caller)
if name == "" {
panic("please register")
Expand All @@ -37,8 +37,8 @@ func PostMessage(_ realm, body string) PostID {
// The caller must already be registered with /r/gnoland/users/v1 Register.
// Return the new post ID.
// (This is similar to boards.CreateReply.)
func PostReply(_ realm, userPostsAddr std.Address, threadid, postid PostID, body string) PostID {
caller := std.OriginCaller()
func PostReply(_ realm, userPostsAddr address, threadid, postid PostID, body string) PostID {
caller := runtime.OriginCaller()
if usernameOf(caller) == "" {
panic("please register")
}
Expand Down Expand Up @@ -67,8 +67,8 @@ func PostReply(_ realm, userPostsAddr std.Address, threadid, postid PostID, body
// the original call to PostMessage. This must be a top-level thread (not a reply).
// Return the new post ID.
// (This is similar to boards.CreateRepost.)
func RepostThread(_ realm, userPostsAddr std.Address, threadid PostID, comment string) PostID {
caller := std.OriginCaller()
func RepostThread(_ realm, userPostsAddr address, threadid PostID, comment string) PostID {
caller := runtime.OriginCaller()
if userPostsAddr == caller {
panic("Cannot repost a user's own message")
}
Expand Down Expand Up @@ -134,7 +134,7 @@ func GetJsonTopPostsByID(addrAndIDs []UserAndPostID) string {
// If threadID is X and replyID is Y, then return the posts in the thread starting with replyID. (Like render args "user/2/5".)
// The response includes reposts by this user (only if threadID is 0), but not messages of other
// users that are being followed. (See GetHomePosts.) The response is a JSON string.
func GetThreadPosts(userPostsAddr std.Address, threadID int, replyID int, startIndex int, endIndex int) string {
func GetThreadPosts(userPostsAddr address, threadID int, replyID int, startIndex int, endIndex int) string {
userPosts := getUserPosts(userPostsAddr)
if userPosts == nil {
panic("posts for userPostsAddr do not exist")
Expand Down Expand Up @@ -164,7 +164,7 @@ func GetThreadPosts(userPostsAddr std.Address, threadID int, replyID int, startI
// Update the home posts by scanning all posts from all followed users and adding the
// followed posts since the last call to RefreshHomePosts (or since started following the user).
// Return the new count of home posts. The result is something like "(12 int)".
func RefreshHomePosts(_ realm, userPostsAddr std.Address) int {
func RefreshHomePosts(_ realm, userPostsAddr address) int {
userPosts := getUserPosts(userPostsAddr)
if userPosts == nil {
panic("posts for userPostsAddr do not exist")
Expand All @@ -178,7 +178,7 @@ func RefreshHomePosts(_ realm, userPostsAddr std.Address) int {
// The result is something like "(12 int)".
// This returns the current count of the home posts (without need to pay gas). To include the
// latest followed posts, call RefreshHomePosts.
func GetHomePostsCount(userPostsAddr std.Address) int {
func GetHomePostsCount(userPostsAddr address) int {
return GetHomePosts(userPostsAddr).Size()
}

Expand All @@ -189,7 +189,7 @@ func GetHomePostsCount(userPostsAddr std.Address) int {
// If you just want the total count, use GetHomePostsCount.
// This returns the current state of the home posts (without need to pay gas). To include the
// latest followed posts, call RefreshHomePosts.
func GetHomePosts(userPostsAddr std.Address) *avl.Tree {
func GetHomePosts(userPostsAddr address) *avl.Tree {
userPosts := getUserPosts(userPostsAddr)
if userPosts == nil {
panic("posts for userPostsAddr do not exist")
Expand All @@ -204,7 +204,7 @@ func GetHomePosts(userPostsAddr std.Address) *avl.Tree {
// The response is a JSON string.
// This returns the current state of the home posts (without need to pay gas). To include the
// latest posts, call RefreshHomePosts.
func GetJsonHomePosts(userPostsAddr std.Address, startIndex int, endIndex int) string {
func GetJsonHomePosts(userPostsAddr address, startIndex int, endIndex int) string {
allPosts := GetHomePosts(userPostsAddr)
postsJson := ""
for i := startIndex; i < endIndex && i < allPosts.Size(); i++ {
Expand All @@ -224,8 +224,8 @@ func GetJsonHomePosts(userPostsAddr std.Address, startIndex int, endIndex int) s
}

// Update the caller to follow the user with followedAddr. See UserPosts.Follow.
func Follow(_ realm, followedAddr std.Address) PostID {
caller := std.OriginCaller()
func Follow(_ realm, followedAddr address) PostID {
caller := runtime.OriginCaller()
name := usernameOf(caller)
if name == "" {
panic("please register")
Expand All @@ -241,8 +241,8 @@ func Follow(_ realm, followedAddr std.Address) PostID {
}

// Update the caller to unfollow the user with followedAddr. See UserPosts.Unfollow.
func Unfollow(_ realm, followedAddr std.Address) {
caller := std.OriginCaller()
func Unfollow(_ realm, followedAddr address) {
caller := runtime.OriginCaller()
name := usernameOf(caller)
if name == "" {
panic("please register")
Expand All @@ -263,8 +263,8 @@ func Unfollow(_ realm, followedAddr std.Address) {
// (This function's arguments are similar to PostReply.)
// The caller must already be registered with /r/gnoland/users/v1 Register.
// Return a boolean indicating whether the userAddr was added. See Post.AddReaction.
func AddReaction(_ realm, userPostsAddr std.Address, threadid, postid PostID, reaction Reaction) bool {
caller := std.OriginCaller()
func AddReaction(_ realm, userPostsAddr address, threadid, postid PostID, reaction Reaction) bool {
caller := runtime.OriginCaller()
if usernameOf(caller) == "" {
panic("please register")
}
Expand Down Expand Up @@ -293,8 +293,8 @@ func AddReaction(_ realm, userPostsAddr std.Address, threadid, postid PostID, re
// (This function's arguments are similar to PostReply.)
// The caller must already be registered with /r/gnoland/users/v1 Register.
// Return a boolean indicating whether the userAddr was removed. See Post.RemoveReaction.
func RemoveReaction(_ realm, userPostsAddr std.Address, threadid, postid PostID, reaction Reaction) bool {
caller := std.OriginCaller()
func RemoveReaction(_ realm, userPostsAddr address, threadid, postid PostID, reaction Reaction) bool {
caller := runtime.OriginCaller()
if usernameOf(caller) == "" {
panic("please register")
}
Expand All @@ -319,7 +319,7 @@ func RemoveReaction(_ realm, userPostsAddr std.Address, threadid, postid PostID,

// Call users.ResolveAddress and return the result as JSON, or "" if not found.
// (This is a temporary utility until gno.land supports returning structured data directly.)
func GetJsonUserByAddress(addr std.Address) string {
func GetJsonUserByAddress(addr address) string {
user := users.ResolveAddress(addr)
if user == nil {
return ""
Expand All @@ -345,7 +345,7 @@ func GetJsonUserByName(name string) string {
// the number of items, not the items themselves. To get the items, see
// GetJsonFollowers, etc.
// The response is a JSON string.
func GetJsonUserPostsInfo(address std.Address) string {
func GetJsonUserPostsInfo(address address) string {
userPosts := getUserPosts(address)
if userPosts == nil {
return ""
Expand All @@ -363,7 +363,7 @@ func GetJsonUserPostsInfo(address std.Address) string {
// the list of followers. If the user address is not found, return "".
// Limit the response to entries from startIndex up to (not including) endIndex.
// The response is a JSON string.
func GetJsonFollowers(address std.Address, startIndex int, endIndex int) string {
func GetJsonFollowers(address address, startIndex int, endIndex int) string {
userPosts := getUserPosts(address)
if userPosts == nil {
return ""
Expand All @@ -388,7 +388,7 @@ func GetJsonFollowers(address std.Address, startIndex int, endIndex int) string
// If the user address is not found, return "".
// Limit the response to entries from startIndex up to (not including) endIndex.
// The response is a JSON string.
func GetJsonFollowing(address std.Address, startIndex int, endIndex int) string {
func GetJsonFollowing(address address, startIndex int, endIndex int) string {
userPosts := getUserPosts(address)
if userPosts == nil {
return ""
Expand Down
6 changes: 3 additions & 3 deletions realm/social.gno
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package social

import (
"gno.land/p/demo/avl"
"gno.land/p/nt/avl"
)

var (
gUserPostsByAddress avl.Tree // user's std.Address -> *UserPosts
gUserAddressByName avl.Tree // user's username -> std.Address
gUserPostsByAddress avl.Tree // user's address -> *UserPosts
gUserAddressByName avl.Tree // user's username -> address
postsCtr uint64 // increments Post.id globally
)
Loading