• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

hicommonwealth / commonwealth / 22331928937

24 Feb 2026 01:00AM UTC coverage: 38.204% (+0.03%) from 38.173%
22331928937

Pull #13194

github

web-flow
Merge 37238f8f5 into 6658c85df
Pull Request #13194: AI Completion Fixes

2110 of 6026 branches covered (35.01%)

Branch coverage included in aggregate %.

9 of 81 new or added lines in 4 files covered. (11.11%)

30 existing lines in 14 files now uncovered.

3752 of 9318 relevant lines covered (40.27%)

52.52 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/libs/model/src/utils/getBaseActivityFeed.ts
1
import { Actor } from '@hicommonwealth/core';
2
import { CommunityTierMap } from '@hicommonwealth/shared';
3
import { buildGatedOutput, buildOpenGates } from './gating';
4

5
/**
6
 * Base query for global and user activity feeds
7
 * - Based on `gated_output` CTE from the builder functions
8
 */
UNCOV
9
const baseActivityQuery = `
×
10
  SELECT
11
    T.community_id,
12
    T.icon_url as community_icon,
13
    T.id,
14
    T.address_id,
15
    json_build_object(
16
        'id', A.id,
17
        'address', A.address,
18
        'community_id', A.community_id
19
    ) as "Address",
20
    U.id as user_id,
21
    U.tier as user_tier,
22
    A.last_active as address_last_active,
23
    U.profile->>'avatar_url' as avatar_url,
24
    U.profile->>'name' as profile_name,
25
    T.body,
26
    T.content_url,
27
    T.title,
28
    T.kind,
29
    T.stage,
30
    T.comment_count,
31
    T.created_at::text,
32
    T.updated_at::text,
33
    T.deleted_at::text,
34
    T.locked_at::text,
35
    T.archived_at::text,
36
    T.marked_as_spam_at::text,
37
    T.read_only,
38
    T.has_poll,
39
    T.discord_meta,
40
    T.is_linking_token,
41
    T.topic_id,
42
    jsonb_build_object(
43
      'community_id', T.community_id,
44
      'id', T.topic_id,
45
      'name', Tp.name,
46
      'description', Tp.description
47
    ) as topic,
48
    COALESCE(
49
      (SELECT jsonb_agg(jsonb_strip_nulls(jsonb_build_object(
50
        'id', C.id,
51
        'address', C.address,
52
        'user_id', C.user_id,
53
        'user_tier', C.user_tier,
54
        'profile_name', C.profile_name,
55
        'profile_avatar', C.profile_avatar,
56
        'body', C.body,
57
        'content_url', C.content_url,
58
        'created_at', C.created_at::text,
59
        'updated_at', C.updated_at::text,
60
        'deleted_at', C.deleted_at::text,
61
        'marked_as_spam_at', C.marked_as_spam_at::text,
62
        'discord_meta', C.discord_meta
63
      )) ORDER BY C.created_at DESC)
64
        FROM (
65
          SELECT
66
            C.*,
67
            A.address,
68
            U.id as user_id,
69
            U.tier as user_tier,
70
            U.profile->>'name' as profile_name,
71
            U.profile->>'avatar_url' as profile_avatar,
72
            ROW_NUMBER() OVER (PARTITION BY C.thread_id ORDER BY C.created_at DESC) AS rn
73
          FROM "Comments" C
74
                  JOIN "Addresses" A on C.address_id = A.id
75
                  JOIN "Users" U on A.user_id = U.id
76
          WHERE
77
            C.thread_id = T.id
78
            AND C.deleted_at IS NULL
79
            AND C.marked_as_spam_at IS NULL
80
        ) C WHERE C.rn <= :comment_limit), '[]') as comments
81
  FROM
82
    gated_output T
83
      JOIN "Addresses" A ON A.id = T.address_id AND A.community_id = T.community_id
84
      JOIN "Users" U ON U.id = A.user_id
85
      JOIN "Topics" Tp ON Tp.id = T.topic_id
86
`;
87

88
/**
89
 * Global activity feed query builder
90
 * - Can be scoped to a specific community or search term
91
 */
92
export function buildGlobalActivityQuery(
93
  actor: Actor,
94
  community_id?: string,
95
  search?: string,
96
) {
97
  const query = `
×
98
WITH output_with_topics AS (
99
  SELECT
100
    T.*,
101
    C.icon_url,
102
    count(*) OVER () AS total
103
  FROM
104
    "Threads" T
105
    JOIN "Communities" C ON C.id = T.community_id 
106
  WHERE
107
    T.id IN (:threadIds)
108
    AND T.deleted_at IS NULL
109
    AND T.archived_at IS NULL
110
    AND T.marked_as_spam_at IS NULL
111
    AND C.active IS TRUE
112
    AND C.tier != ${CommunityTierMap.SpamCommunity}
113
    ${community_id ? 'AND T.community_id = :community_id' : ''}
×
114
    ${search ? 'AND T.title ILIKE :search' : ''}
×
115
),
116
${buildGatedOutput(actor)}
117
${baseActivityQuery}
118
ORDER BY ARRAY_POSITION(ARRAY[:threadIds], T.id);
119
`;
120

121
  return query;
×
122
}
123

124
/**
125
 * User activity feed query builder
126
 */
127
export function buildUserActivityQuery(actor: Actor) {
128
  const query = `
×
129
WITH user_communities AS (
130
  SELECT DISTINCT community_id FROM "Addresses" WHERE user_id = ${actor.user?.id}
131
),
132
${buildOpenGates(actor)},
133
gated_output AS (
134
  SELECT
135
    T.*,
136
    count(*) OVER() AS total,
137
    C.icon_url
138
  FROM
139
    "Threads" T
140
    JOIN open_gates og ON T.topic_id = og.topic_id
141
    JOIN user_communities UC ON UC.community_id = T.community_id
142
    JOIN "Communities" C ON C.id = T.community_id
143
  WHERE
144
    T.deleted_at IS NULL 
145
    AND T.marked_as_spam_at IS NULL 
146
    AND C.active IS TRUE 
147
    AND C.tier != ${CommunityTierMap.SpamCommunity}
148
    AND C.id NOT IN ('ethereum', 'cosmos', 'polkadot')
149
  ORDER BY
150
    T.activity_rank_date DESC NULLS LAST
151
  LIMIT :limit OFFSET :offset 
152
)
153
${baseActivityQuery}
154
ORDER BY T.activity_rank_date DESC NULLS LAST
155
`;
156

157
  return query;
×
158
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc