Skip to content

Commit

Permalink
wip: standarize userId for social_feeds
Browse files Browse the repository at this point in the history
  • Loading branch information
hthieu1110 committed Aug 10, 2023
1 parent a35e513 commit ae88cfc
Show file tree
Hide file tree
Showing 14 changed files with 98 additions and 102 deletions.
2 changes: 1 addition & 1 deletion api/feed/v1/feed.proto
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ message Post {
string metadata = 4;
string parent_post_identifier = 5;
uint32 sub_post_length = 6;
string created_by = 7;
string author_id = 7;
int64 created_at = 8;
int64 tip_amount = 10;
repeated Reaction reactions = 9;
Expand Down
2 changes: 1 addition & 1 deletion go/internal/indexerdb/feed.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type Post struct {
IsBot bool `gorm:"default:false"`
Metadata ObjectJSONB `gorm:"type:jsonb;default:'{}'"`
UserReactions ObjectJSONB `gorm:"type:jsonb;default:'{}'"`
CreatedBy networks.UserID `gorm:"index"`
AuthorId networks.UserID `gorm:"index"`
CreatedAt int64
IsDeleted bool
IsFree bool
Expand Down
2 changes: 1 addition & 1 deletion go/internal/indexerhandler/feed.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func (h *Handler) createPost(
Category: createPostMsg.Category,
Metadata: metadataJSON,
UserReactions: map[string]interface{}{},
CreatedBy: h.config.Network.UserID(execMsg.Sender),
AuthorId: h.config.Network.UserID(execMsg.Sender),
CreatedAt: createdAt.Unix(),
IsBot: isBot,
}
Expand Down
2 changes: 1 addition & 1 deletion go/pkg/feed/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func (s *FeedService) Posts(ctx context.Context, req *feedpb.PostsRequest) (*fee
Metadata: string(metadata),
ParentPostIdentifier: dbPost.ParentPostIdentifier,
SubPostLength: dbPost.SubPostLength,
CreatedBy: string(dbPost.CreatedBy),
AuthorId: string(dbPost.AuthorId),
CreatedAt: dbPost.CreatedAt,
Reactions: reactions,
TipAmount: dbPost.TipAmount,
Expand Down
82 changes: 41 additions & 41 deletions go/pkg/feedpb/feed.pb.go

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

16 changes: 8 additions & 8 deletions packages/api/feed/v1/feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export interface Post {
metadata: string;
parentPostIdentifier: string;
subPostLength: number;
createdBy: string;
authorId: string;
createdAt: number;
tipAmount: number;
reactions: Reaction[];
Expand Down Expand Up @@ -209,7 +209,7 @@ function createBasePost(): Post {
metadata: "",
parentPostIdentifier: "",
subPostLength: 0,
createdBy: "",
authorId: "",
createdAt: 0,
tipAmount: 0,
reactions: [],
Expand All @@ -236,8 +236,8 @@ export const Post = {
if (message.subPostLength !== 0) {
writer.uint32(48).uint32(message.subPostLength);
}
if (message.createdBy !== "") {
writer.uint32(58).string(message.createdBy);
if (message.authorId !== "") {
writer.uint32(58).string(message.authorId);
}
if (message.createdAt !== 0) {
writer.uint32(64).int64(message.createdAt);
Expand Down Expand Up @@ -277,7 +277,7 @@ export const Post = {
message.subPostLength = reader.uint32();
break;
case 7:
message.createdBy = reader.string();
message.authorId = reader.string();
break;
case 8:
message.createdAt = longToNumber(reader.int64() as Long);
Expand All @@ -304,7 +304,7 @@ export const Post = {
metadata: isSet(object.metadata) ? String(object.metadata) : "",
parentPostIdentifier: isSet(object.parentPostIdentifier) ? String(object.parentPostIdentifier) : "",
subPostLength: isSet(object.subPostLength) ? Number(object.subPostLength) : 0,
createdBy: isSet(object.createdBy) ? String(object.createdBy) : "",
authorId: isSet(object.authorId) ? String(object.authorId) : "",
createdAt: isSet(object.createdAt) ? Number(object.createdAt) : 0,
tipAmount: isSet(object.tipAmount) ? Number(object.tipAmount) : 0,
reactions: Array.isArray(object?.reactions) ? object.reactions.map((e: any) => Reaction.fromJSON(e)) : [],
Expand All @@ -319,7 +319,7 @@ export const Post = {
message.metadata !== undefined && (obj.metadata = message.metadata);
message.parentPostIdentifier !== undefined && (obj.parentPostIdentifier = message.parentPostIdentifier);
message.subPostLength !== undefined && (obj.subPostLength = Math.round(message.subPostLength));
message.createdBy !== undefined && (obj.createdBy = message.createdBy);
message.authorId !== undefined && (obj.authorId = message.authorId);
message.createdAt !== undefined && (obj.createdAt = Math.round(message.createdAt));
message.tipAmount !== undefined && (obj.tipAmount = Math.round(message.tipAmount));
if (message.reactions) {
Expand All @@ -338,7 +338,7 @@ export const Post = {
message.metadata = object.metadata ?? "";
message.parentPostIdentifier = object.parentPostIdentifier ?? "";
message.subPostLength = object.subPostLength ?? 0;
message.createdBy = object.createdBy ?? "";
message.authorId = object.authorId ?? "";
message.createdAt = object.createdAt ?? 0;
message.tipAmount = object.tipAmount ?? 0;
message.reactions = object.reactions?.map((e) => Reaction.fromPartial(e)) || [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export const SocialCommentCard: React.FC<SocialCommentCardProps> = ({
const wallet = useSelectedWallet();
const selectedNetwork = useSelectedNetworkInfo();
const selectedNetworkId = selectedNetwork?.id || "";
const [, userAddress] = parseUserId(localComment.createdBy);
const [, authorAddress] = parseUserId(localComment.authorId);
const { data, refetch, fetchNextPage, hasNextPage, isFetching } =
useFetchComments({
parentId: localComment.identifier,
Expand Down Expand Up @@ -124,7 +124,7 @@ export const SocialCommentCard: React.FC<SocialCommentCardProps> = ({
);
const moreCommentsCount = localComment.subPostLength - comments.length;
const metadata = JSON.parse(localComment.metadata);
const authorNSInfo = useNSUserInfo(localComment.createdBy);
const authorNSInfo = useNSUserInfo(localComment.authorId);
const userInfo = useNSUserInfo(wallet?.userId);
const username = authorNSInfo?.metadata?.tokenId
? tinyAddress(authorNSInfo?.metadata?.tokenId || "", 19)
Expand Down Expand Up @@ -269,8 +269,8 @@ export const SocialCommentCard: React.FC<SocialCommentCardProps> = ({
<View style={styles.commentContainerInside}>
{/*====== Card Header */}
<SocialCardHeader
authorAddress={userAddress}
authorId={localComment.createdBy}
authorAddress={authorAddress}
authorId={localComment.authorId}
postMetadata={metadata}
authorMetadata={authorNSInfo?.metadata}
/>
Expand Down
10 changes: 5 additions & 5 deletions packages/components/socialFeed/SocialThread/SocialThreadCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ export const SocialThreadCard: React.FC<{
const wallet = useSelectedWallet();
const selectedNetworkInfo = useSelectedNetworkInfo();
const selectedNetworkId = selectedNetworkInfo?.id;
const authorNSInfo = useNSUserInfo(localPost.createdBy);
const [, userAddress] = parseUserId(localPost.createdBy);
const authorNSInfo = useNSUserInfo(localPost.authorId);
const [, authorAddress] = parseUserId(localPost.authorId);
const userInfo = useNSUserInfo(wallet?.userId);
const navigation = useAppNavigation();
const metadata: SocialFeedMetadata = JSON.parse(localPost.metadata);
const username = authorNSInfo?.metadata?.tokenId || userAddress;
const username = authorNSInfo?.metadata?.tokenId || authorAddress;

//TODO: Handle this later
// const communityHashtag = useMemo(() => {
Expand Down Expand Up @@ -183,8 +183,8 @@ export const SocialThreadCard: React.FC<{
>
{/*====== Card Header */}
<SocialCardHeader
authorAddress={userAddress}
authorId={localPost.createdBy}
authorAddress={authorAddress}
authorId={localPost.authorId}
postMetadata={metadata}
authorMetadata={authorNSInfo?.metadata}
/>
Expand Down
8 changes: 4 additions & 4 deletions packages/components/socialFeed/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const decodeGnoPost = (postData: string): Post => {

const addrLen = buf.readUInt16BE(offset);
offset += 2;
const createdBy = buf.slice(offset, offset + addrLen).toString();
const authorId = buf.slice(offset, offset + addrLen).toString();
offset += addrLen;

const createdAt = buf.readUInt32BE(offset);
Expand Down Expand Up @@ -66,11 +66,11 @@ export const decodeGnoPost = (postData: string): Post => {
const post: Post = {
category,
isDeleted: false,
identifier: "" + identifier,
identifier: identifier ? "" + identifier : "",
metadata,
parentPostIdentifier: "" + parentPostIdentifier,
parentPostIdentifier: parentPostIdentifier ? "" + parentPostIdentifier : "",
subPostLength: subpostIDs.length,
createdBy,
authorId,
createdAt: +createdAt * 1000,
tipAmount: 0,
reactions,
Expand Down
2 changes: 1 addition & 1 deletion packages/hooks/feed/useFetchComments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const fetchGnoComments = async (
metadata: post.metadata,
reactions: post.reactions,
user_reactions: [],
post_by: post.createdBy,
post_by: post.authorId,
deleted: post.isDeleted,
sub_post_length: post.subPostLength,
tip_amount: post.subPostLength,
Expand Down
8 changes: 1 addition & 7 deletions packages/hooks/feed/useFetchFeed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@ import {
TERITORI_FEED_ID,
} from "../../components/socialFeed/const";
import { decodeGnoPost } from "../../components/socialFeed/utils";
import {
getUserId,
GnoNetworkInfo,
NetworkInfo,
NetworkKind,
} from "../../networks";
import { GnoNetworkInfo, NetworkInfo, NetworkKind } from "../../networks";
import { mustGetFeedClient } from "../../utils/backend";
import { extractGnoString } from "../../utils/gno";
import { useSelectedNetworkInfo } from "../useSelectedNetwork";
Expand Down Expand Up @@ -72,7 +67,6 @@ const fetchGnoFeed = async (
const outputStr = extractGnoString(output);
for (const postData of outputStr.split(",")) {
const post = decodeGnoPost(postData);
post.createdBy = getUserId(selectedNetwork.id, post.createdBy);
posts.push(post);
}

Expand Down
Loading

0 comments on commit ae88cfc

Please sign in to comment.