fix: hide outbound media from gallery
This commit is contained in:
1 parent
c0cc661a2f
commit
488145340d
5 files changed
+65
-4
No files matched your search
@@ -84,7 +84,7 @@ export const API_OPERATIONS: readonly ApiOperation[] = [
|
||||
operation('suggestMediaAsk', 'POST', '/api/conversations/{id}/suggest-media-ask', 'Generate a media request suggestion', ['Conversations']),
|
||||
operation('sendReply', 'POST', '/api/conversations/{id}/send-reply', 'Send a conversation reply', ['Conversations']),
|
||||
operation('startConversation', 'POST', '/api/conversations/start', 'Start a new conversation', ['Conversations']),
|
||||
operation('getMedia', 'GET', '/api/media', 'List indexed private media', ['Media']),
|
||||
operation('getMedia', 'GET', '/api/media', 'List received private media', ['Media']),
|
||||
operation('getMediaSync', 'GET', '/api/media/sync', 'Get media sync state', ['Media']),
|
||||
operation('triggerMediaSync', 'POST', '/api/media/sync', 'Trigger media sync', ['Media']),
|
||||
operation('triggerFullMediaSync', 'POST', '/api/media/sync/full', 'Trigger full media sync', ['Media']),
|
||||
|
||||
+29
-1
@@ -30,7 +30,14 @@ export function createMediaRouter(ctx: WebContext): Router {
|
||||
: (ctx.services.chat ? await ctx.services.chat.getCachedConversations() : []).map((chat) => ({ ...chat, accountId: '' }));
|
||||
const byRoom = new Map(liveChats.map((c) => [`${c.accountId}:${c.roomId ?? ''}`, c] as const));
|
||||
|
||||
res.json(items.map((item) => {
|
||||
const receivedItems = items.filter((item) => {
|
||||
const account = item.accountId
|
||||
? ctx.services.redditAccounts?.get(item.accountId)
|
||||
: null;
|
||||
return !isOwnedSender(item.sender, item.accountId, account?.redditUsername);
|
||||
});
|
||||
|
||||
res.json(receivedItems.map((item) => {
|
||||
const { accountId, ...publicItem } = item;
|
||||
const live = item.chatRoomId ? byRoom.get(`${accountId ?? ''}:${item.chatRoomId}`) : undefined;
|
||||
const username = resolveRedditUsername(
|
||||
@@ -143,3 +150,24 @@ function newest(values: Array<number | null>): number | null {
|
||||
const present = values.filter((value): value is number => value !== null);
|
||||
return present.length > 0 ? Math.max(...present) : null;
|
||||
}
|
||||
|
||||
function isOwnedSender(sender: string, accountId?: string, redditUsername?: string): boolean {
|
||||
const normalizedSender = sender.trim().toLowerCase();
|
||||
if (/^(me|you)$/i.test(normalizedSender)) return true;
|
||||
|
||||
const ownedIdentities = new Set<string>();
|
||||
if (accountId) {
|
||||
const normalizedAccountId = accountId.trim().toLowerCase();
|
||||
ownedIdentities.add(normalizedAccountId);
|
||||
if (!normalizedAccountId.startsWith('@')) {
|
||||
ownedIdentities.add(`@${normalizedAccountId}:reddit.com`);
|
||||
}
|
||||
}
|
||||
if (redditUsername) {
|
||||
const normalizedUsername = redditUsername.trim().toLowerCase();
|
||||
ownedIdentities.add(normalizedUsername);
|
||||
ownedIdentities.add(`u/${normalizedUsername}`);
|
||||
}
|
||||
|
||||
return ownedIdentities.has(normalizedSender);
|
||||
}
|
||||
Reference in new issue
Block a user