Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Threads semantics #5648

Merged
merged 29 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
5896958
migration init
timolegros Nov 8, 2023
205bcf7
Sequelize model update
timolegros Nov 8, 2023
744c5e7
Threads.chain -> Threads.community_id server side direct references
timolegros Nov 8, 2023
d4bcc16
raw queries
timolegros Nov 8, 2023
25eb507
prettier commit - I SWTG I'M ABOUT TO NUKE PRETTIER
timolegros Nov 8, 2023
386b86f
import server-side fix + client semantic updates
timolegros Nov 9, 2023
a6c696b
import server-side fix + client semantic updates
timolegros Nov 9, 2023
22d97f2
client type fixes
timolegros Nov 9, 2023
eaed9b4
prettier -_-
timolegros Nov 9, 2023
256c79c
Thread model mock updates
timolegros Nov 9, 2023
a4017ec
Merge branch 'master' into tim/threads-semantics
timolegros Nov 9, 2023
41f3e8a
migration update
timolegros Nov 9, 2023
b6cc79f
attributesOf helper
timolegros Nov 9, 2023
6253168
test fixes
timolegros Nov 9, 2023
a3aac40
alias fix for profile fetching
timolegros Nov 9, 2023
3f6ac3f
view profile fix
timolegros Nov 9, 2023
57abb15
end to end search result types
timolegros Nov 10, 2023
157855f
remove log
timolegros Nov 10, 2023
f29ac3a
Merge branch 'master' into tim/threads-semantics
timolegros Dec 21, 2023
783883e
post merge fixes
timolegros Dec 21, 2023
c7d28c7
reorder migration
timolegros Dec 21, 2023
030fccf
Merge branch 'master' into tim/threads-semantics
timolegros Dec 27, 2023
e91cf20
Merge branch 'master' into tim/threads-semantics
timolegros Dec 28, 2023
7b39ae3
community_id to communityId on client Thread model
timolegros Dec 28, 2023
8b2b058
hugely simplify thread count query in `bulkOffchain`
timolegros Jan 2, 2024
cb66a52
Merge branch 'master' into tim/threads-semantics
timolegros Jan 4, 2024
33f2d6f
get_stats fix for threads
timolegros Jan 4, 2024
5d7972e
Merge branch 'master' into tim/threads-semantics
timolegros Jan 5, 2024
a85e555
Merge branch 'master' into tim/threads-semantics
timolegros Jan 5, 2024
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
2 changes: 1 addition & 1 deletion packages/commonwealth/client/scripts/identifiers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import app from './state';
// custom domain prefixes as well.
export const getProposalUrlPath = (
type: ProposalType,
id: string,
id: number | string,
omitActiveId = true,
chainId?: string,
): string => {
Expand Down
8 changes: 4 additions & 4 deletions packages/commonwealth/client/scripts/models/Thread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export class Thread implements IUniqueId {
public readonly slug = ProposalType.Thread;
public readonly url: string;
public readonly versionHistory: VersionHistory[];
public readonly chain: string;
public readonly communityId: string;
public readonly lastEdited: Moment;

public markedAsSpamAt: Moment;
Expand All @@ -164,7 +164,7 @@ export class Thread implements IUniqueId {
kind,
stage,
version_history,
chain,
community_id,
read_only,
body,
plaintext,
Expand Down Expand Up @@ -194,7 +194,7 @@ export class Thread implements IUniqueId {
id: number;
kind: ThreadKind;
stage: ThreadStage;
chain: string;
community_id: string;
url?: string;
pinned?: boolean;
links?: Link[];
Expand Down Expand Up @@ -235,7 +235,7 @@ export class Thread implements IUniqueId {
this.authorChain = Address.community_id;
this.pinned = pinned;
this.url = url;
this.chain = chain;
this.communityId = community_id;
this.readOnly = read_only;
this.collaborators = collaborators || [];
this.lastCommentedOn = last_commented_on ? moment(last_commented_on) : null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,16 @@ interface AddThreadLinksProps {
}

const addThreadLinks = async ({
chainId,
threadId,
links,
}: AddThreadLinksProps) => {
}: AddThreadLinksProps): Promise<Thread> => {
const response = await axios.post(
`${app.serverUrl()}/linking/addThreadLinks`,
{
thread_id: threadId,
links,
jwt: app.user.jwt,
}
},
);

return new Thread(response.data.result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const createThread = async ({
url,
readOnly,
authorProfile,
}: CreateThreadProps) => {
}: CreateThreadProps): Promise<Thread> => {
const {
action = null,
session = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ interface DeleteThreadLinksProps {
}

const deleteThreadLinks = async ({
chainId,
threadId,
links,
}: DeleteThreadLinksProps) => {
}: DeleteThreadLinksProps): Promise<Thread> => {
const response = await axios.delete(
`${app.serverUrl()}/linking/deleteLinks`,
{
Expand All @@ -23,7 +22,7 @@ const deleteThreadLinks = async ({
links,
jwt: app.user.jwt,
},
}
},
);

return new Thread(response.data.result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const editThread = async ({
topicId,
// for editing thread collaborators
collaborators,
}: EditThreadProps) => {
}: EditThreadProps): Promise<Thread> => {
const {
action = null,
session = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,17 @@ const getFetchThreadsQueryKey = (props) => {
};

const fetchBulkThreads = (props) => {
return async ({ pageParam = 1 }) => {
return async ({
pageParam = 1,
}): Promise<{
data: {
numVotingThreads: number;
limit: number;
page: number;
threads: Thread[];
};
pageParam: number | undefined;
}> => {
const res = await axios.get(
`${app.serverUrl()}${ApiEndpoints.FETCH_THREADS}`,
{
Expand Down Expand Up @@ -156,7 +166,7 @@ const fetchBulkThreads = (props) => {
};

const fetchActiveThreads = (props) => {
return async () => {
return async (): Promise<Thread[]> => {
const response = await axios.get(
`${app.serverUrl()}${ApiEndpoints.FETCH_THREADS}`,
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ interface GetThreadsByIdProps {
apiCallEnabled?: boolean;
}

const getThreadsById = async ({ chainId, ids }: GetThreadsByIdProps) => {
const getThreadsById = async ({
chainId,
ids,
}: GetThreadsByIdProps): Promise<Thread[]> => {
const response = await axios.get(
`${app.serverUrl()}${ApiEndpoints.FETCH_THREADS}`,
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ interface GetThreadsByLinkProps {
enabled: boolean;
}

const getThreadsByLink = async ({ link }: GetThreadsByLinkProps) => {
const getThreadsByLink = async ({
link,
}: GetThreadsByLinkProps): Promise<{ id: number; title: string }[]> => {
const response = await axios.post(`${app.serverUrl()}/linking/getLinks`, {
link,
jwt: app.user.jwt,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ const searchThreads = async ({
orderBy,
orderDirection,
threadTitleOnly,
}: SearchThreadsProps & { pageParam: number }) => {
}: SearchThreadsProps & {
pageParam: number;
}): Promise<SearchThreadsResponse> => {
const {
data: { result },
} = await axios.get<{ result: SearchThreadsResponse }>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from 'react';
import 'components/Profile/ProfileActivityRow.scss';
import moment from 'moment';

import type Thread from 'models/Thread';
import Thread from 'models/Thread';
import withRouter, {
navigateToCommunity,
useCommonNavigate,
Expand All @@ -22,12 +22,18 @@ type ProfileActivityRowProps = {

const ProfileActivityRow = ({ activity }: ProfileActivityRowProps) => {
const navigate = useCommonNavigate();
const { chain: communityId, createdAt, author, title, id, body } = activity;
const { createdAt, author, title, id, body } = activity;
let communityId: string;
if (activity instanceof Thread) {
communityId = activity.communityId;
} else {
communityId = activity.chain;
}
const isThread = !!(activity as Thread).kind;
const comment = activity as CommentWithAssociatedThread;
const { iconUrl } = app.config.chains.getById(communityId);
const domain = document.location.origin;
let decodedTitle;
let decodedTitle: string;

try {
if (isThread) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@
align-items: center;
color: $neutral-400;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@
new Thread({
id: t.id,
title: t.title,
chain: t.community_id,
community_id: t.community_id,
Address: new AddressInfo({
id: t.address_id,
address: t.address,
chainId: t.address_chain,
}),
} as any),
} as ConstructorParameters<typeof Thread>[0]),
);
}, [threadsData]);

Expand Down Expand Up @@ -94,7 +94,7 @@
[linkedThreadsToSet, onSelect],
);

const EmptyComponent = () => (

Check warning on line 97 in packages/commonwealth/client/scripts/views/components/thread_selector/thread_selector.tsx

View workflow job for this annotation

GitHub Actions / Code Quality checks (18)

Declare only one React component per file

Check warning on line 97 in packages/commonwealth/client/scripts/views/components/thread_selector/thread_selector.tsx

View workflow job for this annotation

GitHub Actions / Code Quality Recommendations (18)

Declare only one React component per file
<div className="empty-component">{getEmptyContentMessage()}</div>
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
align-items: baseline;
gap: 8px;

@include extraSmall{
@include extraSmall {
justify-content: flex-end;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -466,11 +466,11 @@ const NotificationSettingsPage = () => {
</div>
{subs.map((sub) => {
const getUser = () => {
if (sub.Thread?.chain) {
if (sub.Thread?.communityId) {
return (
<User
userAddress={sub.Thread.author}
userCommunityId={sub.Thread.chain}
userCommunityId={sub.Thread.communityId}
/>
);
} else if (sub.Comment?.chain) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ const SearchPage = () => {
)}
<div className="search-results-list">
{renderSearchResults(
results as any,
results,
queryParams.q,
activeTab,
commonNavigate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
proposal: CompoundProposal;
} & BaseCancelButtonProps;

export const CompoundCancelButton = (props: CompoundCancelButtonProps) => {

Check warning on line 50 in packages/commonwealth/client/scripts/views/pages/view_proposal/proposal_components.tsx

View workflow job for this annotation

GitHub Actions / Code Quality checks (18)

Declare only one React component per file

Check warning on line 50 in packages/commonwealth/client/scripts/views/pages/view_proposal/proposal_components.tsx

View workflow job for this annotation

GitHub Actions / Code Quality Recommendations (18)

Declare only one React component per file
const { proposal, votingModalOpen, onModalClose, toggleVotingModal } = props;

return (
Expand All @@ -68,10 +68,11 @@
proposal: SubheaderProposalType;
} & BaseCancelButtonProps;

export const ProposalSubheader = (props: ProposalSubheaderProps) => {

Check warning on line 71 in packages/commonwealth/client/scripts/views/pages/view_proposal/proposal_components.tsx

View workflow job for this annotation

GitHub Actions / Code Quality checks (18)

Declare only one React component per file

Check warning on line 71 in packages/commonwealth/client/scripts/views/pages/view_proposal/proposal_components.tsx

View workflow job for this annotation

GitHub Actions / Code Quality Recommendations (18)

Declare only one React component per file
const { onModalClose, proposal, toggleVotingModal, votingModalOpen } = props;
const forceRerender = useForceRerender();
const [linkedThreads, setLinkedThreads] = useState(null);
const [linkedThreads, setLinkedThreads] =
useState<{ id: number; title: string }[]>(null);

useEffect(() => {
app.proposalEmitter.on('redraw', forceRerender);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ import { getProposalUrlPath } from 'identifiers';
import { CWIcon } from '../../components/component_kit/cw_icons/cw_icon';

type ProposalHeaderLinkProps = {
threads: any[];
threads: { id: number; title: string }[];
community: string;
};

// "Go to discussion"
const threadLinkButton = (
threadId: string,
threadId: number,
title: string,
community: string,
) => {
const path = getProposalUrlPath(
ProposalType.Thread,
`${threadId}`,
threadId,
false,
community,
);
Expand All @@ -44,7 +44,7 @@ export const ThreadLink = ({ threads, community }: ProposalHeaderLinkProps) => {
};

type SnapshotThreadLinkProps = {
thread: { id: string; title: string };
thread: { id: number; title: string };
};

export const SnapshotThreadLink = ({ thread }: SnapshotThreadLinkProps) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

type SnapshotInfoLinkRowProps = SnapshotInfoRowProps & { url: string };

const SnapshotInfoLinkRow = (props: SnapshotInfoLinkRowProps) => {

Check warning on line 36 in packages/commonwealth/client/scripts/views/pages/view_snapshot_proposal/snapshot_information_card.tsx

View workflow job for this annotation

GitHub Actions / Code Quality checks (18)

Declare only one React component per file

Check warning on line 36 in packages/commonwealth/client/scripts/views/pages/view_snapshot_proposal/snapshot_information_card.tsx

View workflow job for this annotation

GitHub Actions / Code Quality Recommendations (18)

Declare only one React component per file
const { label, url, value } = props;

return (
Expand All @@ -53,10 +53,10 @@

type SnapshotInformationCardProps = {
proposal: SnapshotProposal;
threads: Array<{ id: string; title: string }> | null;
threads: Array<{ id: number; title: string }> | null;
};

export const SnapshotInformationCard = ({

Check warning on line 59 in packages/commonwealth/client/scripts/views/pages/view_snapshot_proposal/snapshot_information_card.tsx

View workflow job for this annotation

GitHub Actions / Code Quality checks (18)

Declare only one React component per file

Check warning on line 59 in packages/commonwealth/client/scripts/views/pages/view_snapshot_proposal/snapshot_information_card.tsx

View workflow job for this annotation

GitHub Actions / Code Quality Recommendations (18)

Declare only one React component per file
proposal,
threads,
}: SnapshotInformationCardProps) => {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ const ViewThreadPage = ({ identifier }: ViewThreadPageProps) => {
if (
(!isLoading && !thread) ||
fetchThreadError ||
thread.chain !== app.activeChainId()
thread.communityId !== app.activeChainId()
) {
return <PageNotFound />;
}
Expand Down Expand Up @@ -400,7 +400,7 @@ const ViewThreadPage = ({ identifier }: ViewThreadPageProps) => {
showLinkedThreadOptions ||
polls?.length > 0 ||
isAuthor ||
hasWebLinks
!!hasWebLinks
}
isSpamThread={!!thread.markedAsSpamAt}
title={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export const LinkedProposalsCard = ({
const proposal = initialSnapshotLinks[0];
if (proposal.identifier.includes('/')) {
setSnapshotUrl(
`${app.isCustomDomain() ? '' : `/${thread.chain}`}/snapshot/${
`${app.isCustomDomain() ? '' : `/${thread.communityId}`}/snapshot/${
proposal.identifier
}`,
);
Expand All @@ -76,9 +76,9 @@ export const LinkedProposalsCard = ({
if (matchingSnapshot) {
setSnapshotTitle(matchingSnapshot.title);
setSnapshotUrl(
`${app.isCustomDomain() ? '' : `/${thread.chain}`}/snapshot/${
_space.id
}/${matchingSnapshot.id}`,
`${
app.isCustomDomain() ? '' : `/${thread.communityId}`
}/snapshot/${_space.id}/${matchingSnapshot.id}`,
);
break;
}
Expand All @@ -87,7 +87,7 @@ export const LinkedProposalsCard = ({
}
setSnapshotProposalsLoaded(true);
}
}, [initialSnapshotLinks, thread.chain]);
}, [initialSnapshotLinks, thread.communityId]);

const showSnapshot =
initialSnapshotLinks.length > 0 && snapshotProposalsLoaded;
Expand All @@ -112,7 +112,7 @@ export const LinkedProposalsCard = ({
<ReactRouterLink
key={l.identifier}
to={getThreadLink({
threadChain: thread.chain,
threadChain: thread.communityId,
identifier: l.identifier,
})}
>
Expand Down
Loading
Loading