my harness for niri
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

i should listen to more ghost data

+54 -14
+2 -1
src/discord/gateway.ts
··· 169 169 const cachedType = typeof cachedChannel?.type === "number" ? cachedChannel.type : null 170 170 const isDm = 171 171 !guildId && 172 - (channelType === ChannelType.DM || 172 + (channelType == null || 173 + channelType === ChannelType.DM || 173 174 channelType === ChannelType.GroupDM || 174 175 cachedType === ChannelType.DM || 175 176 cachedType === ChannelType.GroupDM)
+52 -13
src/discord/state.ts
··· 234 234 asBoolean(root.is_dm) || 235 235 channelType === 1 || 236 236 channelType === 3 || 237 - (guildId == null && channelType == null) 237 + guildId == null 238 238 const isFromSelf = Boolean(botId && authorId === botId) 239 239 const isFromBot = asBoolean(author?.bot ?? root.author_is_bot) || isFromSelf 240 240 ··· 283 283 284 284 const guildId = asString(channel.guild_id ?? root.guild_id ?? fallback?.guildId) 285 285 const channelType = asNumber(channel.type ?? root.channel_type ?? fallback?.channelType) 286 - const isDm = asBoolean(root.is_dm) || channelType === 1 || channelType === 3 || fallback?.isDm === true 286 + const isDm = asBoolean(root.is_dm) || channelType === 1 || channelType === 3 || fallback?.isDm === true || guildId == null 287 287 const configured = configuredChannelIdSet().has(channelId) 288 288 289 289 return { ··· 500 500 return `${text.slice(0, maxChars - 1)}...` 501 501 } 502 502 503 + function fullMessageText(value: unknown): string { 504 + const text = String(value ?? "").replace(/\r\n/g, "\n").trim() 505 + if (!text) return "(no text)" 506 + return text.replace(/\n/g, "\n ") 507 + } 508 + 503 509 function formatBatchTimestamp(value: string | null | undefined): string { 504 510 if (!value) return "unknown-time" 505 511 const parsed = new Date(value) ··· 630 636 631 637 function repairDiscordMessageChannelFlags(): number { 632 638 const db = getDb() 633 - const result = db.prepare( 639 + const dmMessageResult = db.prepare( 640 + `update discord_messages 641 + set is_dm = 1, 642 + channel_type = coalesce(channel_type, 1), 643 + last_seen_at = ? 644 + where guild_id is null 645 + and is_dm = 0`, 646 + ).run(new Date().toISOString()) 647 + 648 + const dmChannelResult = db.prepare( 649 + `update discord_channels 650 + set is_dm = 1, 651 + channel_type = case 652 + when channel_type is null or channel_type = 0 then 1 653 + else channel_type 654 + end, 655 + last_seen_at = ? 656 + where is_dm = 0 657 + and exists ( 658 + select 1 from discord_messages m 659 + where m.channel_id = discord_channels.channel_id 660 + and m.guild_id is null 661 + and m.is_dm = 1 662 + )`, 663 + ).run(new Date().toISOString()) 664 + 665 + const guildMessageResult = db.prepare( 634 666 `update discord_messages 635 667 set guild_id = ( 636 668 select c.guild_id from discord_channels c ··· 651 683 )`, 652 684 ).run(new Date().toISOString()) 653 685 654 - return Number(result.changes ?? 0) 686 + return Number(dmMessageResult.changes ?? 0) + Number(dmChannelResult.changes ?? 0) + Number(guildMessageResult.changes ?? 0) 655 687 } 656 688 657 689 function channelLabel(row: { ··· 770 802 export function listDiscordChannels(): unknown[] { 771 803 ensureConfiguredChannelsMaterialized() 772 804 const db = getDb() 805 + const configuredIds = parseChannelIds() 806 + const configuredPlaceholders = configuredIds.map(() => "?").join(", ") 807 + const configuredClause = configuredIds.length > 0 ? `channel_id in (${configuredPlaceholders})` : "0" 773 808 774 809 return db 775 810 .prepare( ··· 786 821 last_note_at, 787 822 last_seen_at 788 823 from discord_channels 789 - where configured = 1 790 - or note is not null 824 + where ${configuredClause} 791 825 or ( 792 826 is_dm = 1 793 827 and exists ( ··· 797 831 ) 798 832 order by configured desc, coalesce(guild_name, ''), coalesce(channel_name, channel_id)`, 799 833 ) 800 - .all() 834 + .all(...configuredIds) 801 835 } 802 836 803 837 export function setDiscordChannelNote(channelId: string, note: string): Record<string, unknown> { ··· 851 885 0, 852 886 Number.parseInt(process.env.DISCORD_PENDING_AUTO_SEEN_MINUTES ?? "10", 10) || 10, 853 887 ) 888 + const configuredIds = parseChannelIds() 889 + const configuredPlaceholders = configuredIds.map(() => "?").join(", ") 854 890 const channelScopeClause = batchOnlyConfigured 855 - ? "and (m.is_dm = 1 or coalesce(c.configured, 0) = 1)" 891 + ? configuredIds.length > 0 892 + ? `and (m.is_dm = 1 or m.channel_id in (${configuredPlaceholders}))` 893 + : "and m.is_dm = 1" 856 894 : "" 857 895 const botUserId = process.env.DISCORD_BOT_USER_ID?.trim() ?? "" 858 896 ··· 887 925 order by m.first_seen_at asc 888 926 limit ?`, 889 927 ) 890 - .all(botUserId, botUserId, from, maxMessages + 1) as Array<{ 928 + .all(botUserId, botUserId, from, ...configuredIds, maxMessages + 1) as Array<{ 891 929 message_id: string 892 930 channel_id: string 893 931 guild_id: string | null ··· 916 954 and (? = '' or coalesce(m.author_id, '') != ?) 917 955 ${channelScopeClause}`, 918 956 ) 919 - .get(botUserId, botUserId) as { count?: number } | undefined 957 + .get(botUserId, botUserId, ...configuredIds) as { count?: number } | undefined 920 958 const pendingCount = pendingCountRow?.count ?? 0 921 959 922 960 const pendingPreview = db ··· 943 981 order by i.last_seen_at desc 944 982 limit ?`, 945 983 ) 946 - .all(botUserId, botUserId, previewLimit) as Array<{ 984 + .all(botUserId, botUserId, ...configuredIds, previewLimit) as Array<{ 947 985 item_id: string 948 986 bucket: string 949 987 channel_id: string ··· 976 1014 const author = row.author_username ? `@${row.author_username}` : "@unknown" 977 1015 const ts = formatBatchTimestamp(row.created_at) 978 1016 const replyTo = replyContextByMessageId.get(row.message_id) 979 - lines.push(`- [${label}] [${ts}] ${author}${formatReplyContext(replyTo)}: ${compactText(row.content)}`) 1017 + lines.push(`- [${label}] [${ts}] ${author}${formatReplyContext(replyTo)}: ${fullMessageText(row.content)}`) 980 1018 } 981 1019 982 1020 if (truncated) { ··· 1293 1331 message, 1294 1332 channel: { 1295 1333 id: channelId, 1296 - type: message.type, 1334 + type: message.guild_id == null ? 1 : null, 1297 1335 guild_id: message.guild_id, 1298 1336 }, 1337 + is_dm: message.guild_id == null, 1299 1338 author_is_bot: true, 1300 1339 }, 1301 1340 { botUserId },