Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions crates/sprout-relay/src/api/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ pub async fn get_event(
.await
.map_err(|_| not_found("event not found"))?;
} else {
// Channel-restricted tokens must not access global events — they are
// scoped to specific channels and global events fall outside that scope.
if ctx.channel_ids.is_some() {
return Err(not_found("event not found"));
}

// Global event — scope-aware allowlist.
let event_kind = event_kind_u32(&stored_event.event);

Expand Down
11 changes: 4 additions & 7 deletions crates/sprout-relay/src/api/workflows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,8 @@ pub async fn get_workflow(
if let Some(channel_id) = workflow.channel_id {
check_token_channel_access(&ctx, &channel_id)?;
check_channel_access(&state, channel_id, &pubkey_bytes).await?;
} else if workflow.owner_pubkey != pubkey_bytes {
return Err(forbidden("not authorized to access this workflow"));
}
require_workflow_owner(&workflow, &pubkey_bytes, "view")?;

Ok(Json(workflow_record_to_json(&workflow)))
}
Expand Down Expand Up @@ -399,7 +398,7 @@ pub async fn list_workflow_runs(
check_token_channel_access(&ctx, &channel_id)?;
check_channel_access(&state, channel_id, &pubkey_bytes).await?;
}
require_workflow_owner(&workflow, &pubkey_bytes, "trigger")?;
require_workflow_owner(&workflow, &pubkey_bytes, "view runs for")?;

let limit = params.limit.unwrap_or(20).min(100) as i64;
let runs = state
Expand Down Expand Up @@ -439,9 +438,8 @@ pub async fn list_run_approvals(
if let Some(channel_id) = workflow.channel_id {
check_token_channel_access(&ctx, &channel_id)?;
check_channel_access(&state, channel_id, &pubkey_bytes).await?;
} else if workflow.owner_pubkey != pubkey_bytes {
return Err(forbidden("not authorized to access this workflow"));
}
require_workflow_owner(&workflow, &pubkey_bytes, "view approvals for")?;

let approvals = state
.db
Expand Down Expand Up @@ -478,9 +476,8 @@ pub async fn trigger_workflow(
if let Some(channel_id) = workflow.channel_id {
check_token_channel_access(&ctx, &channel_id)?;
check_channel_access(&state, channel_id, &pubkey_bytes).await?;
} else if workflow.owner_pubkey != pubkey_bytes {
return Err(forbidden("not authorized to access this workflow"));
}
require_workflow_owner(&workflow, &pubkey_bytes, "trigger")?;

let trigger_ctx = sprout_workflow::executor::TriggerContext {
channel_id: workflow
Expand Down
10 changes: 10 additions & 0 deletions crates/sprout-relay/src/handlers/req.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,16 @@ pub async fn handle_req(
}
}

// Channel-restricted tokens must not open global subscriptions — they would
// receive events outside the token's channel allowlist.
if channel_id.is_none() && token_channel_ids.is_some() {
conn.send(RelayMessage::closed(
&sub_id,
"restricted: channel-scoped tokens cannot open global subscriptions",
));
return;
}

// Check channel access BEFORE registering the subscription.
if let Some(ch_id) = channel_id {
if !accessible_channels.contains(&ch_id) {
Expand Down
86 changes: 8 additions & 78 deletions mobile/lib/features/channels/channel_detail_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import 'package:lucide_icons_flutter/lucide_icons.dart';

import '../../shared/relay/relay.dart';
import '../../shared/theme/theme.dart';
import '../profile/presence_cache_provider.dart';
import '../profile/profile_provider.dart';
import '../profile/user_cache_provider.dart';
import '../profile/user_profile.dart';
import 'dm_presence_avatar.dart';
import 'channel.dart';
import 'channel_management_provider.dart';
import 'channel_messages_provider.dart';
Expand Down Expand Up @@ -1842,90 +1842,20 @@ class _DmAppBarTitle extends ConsumerWidget {

@override
Widget build(BuildContext context, WidgetRef ref) {
final profiles = ref.watch(userCacheProvider);
final presenceMap = ref.watch(presenceCacheProvider);
final normalizedCurrent = currentPubkey?.toLowerCase();

String? otherPubkey;
for (final pk in channel.participantPubkeys) {
if (pk.toLowerCase() != normalizedCurrent) {
otherPubkey = pk.toLowerCase();
break;
}
}

final profile = otherPubkey != null ? profiles[otherPubkey] : null;

if (otherPubkey != null) {
if (profile == null) {
ref.read(userCacheProvider.notifier).preload([otherPubkey]);
}
ref.read(presenceCacheProvider.notifier).track([otherPubkey]);
}

final avatarUrl = profile?.avatarUrl;
final initial =
profile?.initial ??
(channel.participants.isNotEmpty
? channel.participants.first[0].toUpperCase()
: '?');
final presence = otherPubkey != null
? (presenceMap[otherPubkey] ?? 'offline')
: 'offline';
final presenceLabel = switch (presence) {
final data = resolveDmPresence(ref, channel, currentPubkey);
final presenceLabel = switch (data.presence) {
'online' => 'Online',
'away' => 'Away',
_ => 'Offline',
};

return Row(
children: [
SizedBox(
width: 30,
height: 30,
child: Stack(
clipBehavior: Clip.none,
children: [
CircleAvatar(
radius: 14,
backgroundColor: context.colors.primaryContainer,
backgroundImage: avatarUrl != null
? NetworkImage(avatarUrl)
: null,
child: avatarUrl == null
? Text(
initial,
style: context.textTheme.labelSmall?.copyWith(
color: context.colors.onPrimaryContainer,
fontWeight: FontWeight.w600,
),
)
: null,
),
Positioned(
right: -1,
bottom: -1,
child: Container(
width: 10,
height: 10,
decoration: BoxDecoration(
color: switch (presence) {
'online' => context.appColors.success,
'away' => context.appColors.warning,
_ => context.colors.outline,
},
shape: BoxShape.circle,
border: Border.all(
color:
context.theme.appBarTheme.backgroundColor ??
context.theme.scaffoldBackgroundColor,
width: 1.5,
),
),
),
),
],
),
DmPresenceAvatar(
channel: channel,
currentPubkey: currentPubkey,
size: 30,
dotSize: 10,
),
const SizedBox(width: Grid.xxs),
Expanded(
Expand Down
97 changes: 2 additions & 95 deletions mobile/lib/features/channels/channels_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ import '../../shared/theme/theme.dart';
import '../profile/profile_avatar.dart';
import '../profile/profile_provider.dart';
import '../settings/settings_page.dart';
import '../profile/presence_cache_provider.dart';
import '../profile/user_cache_provider.dart';
import 'channel.dart';
import 'channel_detail_page.dart';
import 'channel_management_provider.dart';
import 'channels_provider.dart';
import 'dm_presence_avatar.dart';

enum _QuickAction { createChannel, createForum, newDm }

Expand Down Expand Up @@ -424,7 +423,7 @@ class _ChannelTile extends ConsumerWidget {
child: Row(
children: [
if (channel.isDm)
_DmAvatar(channel: channel, currentPubkey: currentPubkey)
DmPresenceAvatar(channel: channel, currentPubkey: currentPubkey)
else
Icon(
channelIcon(channel),
Expand Down Expand Up @@ -483,98 +482,6 @@ class _ChannelTile extends ConsumerWidget {
}
}

class _DmAvatar extends ConsumerWidget {
final Channel channel;
final String? currentPubkey;

const _DmAvatar({required this.channel, required this.currentPubkey});

@override
Widget build(BuildContext context, WidgetRef ref) {
final profiles = ref.watch(userCacheProvider);
final presenceMap = ref.watch(presenceCacheProvider);
final normalizedCurrent = currentPubkey?.toLowerCase();

// Find the other participant's pubkey.
String? otherPubkey;
for (final pk in channel.participantPubkeys) {
if (pk.toLowerCase() != normalizedCurrent) {
otherPubkey = pk.toLowerCase();
break;
}
}

final profile = otherPubkey != null ? profiles[otherPubkey] : null;

// Trigger fetches if not cached yet.
if (otherPubkey != null) {
if (profile == null) {
ref.read(userCacheProvider.notifier).preload([otherPubkey]);
}
ref.read(presenceCacheProvider.notifier).track([otherPubkey]);
}

final avatarUrl = profile?.avatarUrl;
final initial =
profile?.initial ??
(channel.participants.isNotEmpty
? channel.participants.first[0].toUpperCase()
: '?');
final presence = otherPubkey != null
? (presenceMap[otherPubkey] ?? 'offline')
: 'offline';

return SizedBox(
width: 22,
height: 22,
child: Stack(
clipBehavior: Clip.none,
children: [
CircleAvatar(
radius: 10,
backgroundColor: context.colors.primaryContainer,
backgroundImage: avatarUrl != null ? NetworkImage(avatarUrl) : null,
child: avatarUrl == null
? Text(
initial,
style: context.textTheme.labelSmall?.copyWith(
fontSize: 9,
color: context.colors.onPrimaryContainer,
fontWeight: FontWeight.w600,
),
)
: null,
),
Positioned(
right: -1,
bottom: -1,
child: Container(
width: 9,
height: 9,
decoration: BoxDecoration(
color: _presenceColor(context, presence),
shape: BoxShape.circle,
border: Border.all(
color: context.theme.scaffoldBackgroundColor,
width: 1.5,
),
),
),
),
],
),
);
}

Color _presenceColor(BuildContext context, String presence) {
return switch (presence) {
'online' => context.appColors.success,
'away' => context.appColors.warning,
_ => context.colors.outline,
};
}
}

class _QuickActionsSheet extends StatelessWidget {
const _QuickActionsSheet();

Expand Down
Loading