Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void ExistingThread_ContinuesWithoutMention()
}

[Fact]
public void ThreadReply_RequiresMention_WhenNoExistingActor()
public void ThreadReply_RehydratesSession_WhenNoExistingActor()
{
var message = CreateMessage(text: "follow up", rootMessageId: null, isThread: true);

Expand All @@ -69,8 +69,8 @@ public void ThreadReply_RequiresMention_WhenNoExistingActor()
threadExists: false,
containsBotMention: false);

Assert.Equal(DiscordRoutingDecisionKind.Ignore, decision.Kind);
Assert.Equal(DiscordRoutingIgnoreReason.ChannelMentionRequired, decision.IgnoreReason);
Assert.Equal(DiscordRoutingDecisionKind.StartOrContinue, decision.Kind);
Assert.Null(decision.IgnoreReason);
}

[Fact]
Expand Down Expand Up @@ -227,6 +227,7 @@ private static DiscordGatewayMessage CreateMessage(
IsDirectMessage: isDirectMessage,
ContainsBotMention: false,
Text: text,
ReceivedAt: DateTimeOffset.UtcNow);
ReceivedAt: DateTimeOffset.UtcNow,
IsInThread: isThread);
}
}
6 changes: 6 additions & 0 deletions src/Netclaw.Channels.Discord/DiscordRoutingPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ public static DiscordRoutingDecision Evaluate(
if (threadExists)
return DiscordRoutingDecision.ContinueOnly;

// Thread reply where the actor was lost (e.g. daemon restart):
// the message is in a Discord thread, so re-create the session
// binding and continue the persisted session.
if (message.IsInThread)
return DiscordRoutingDecision.StartOrContinue;

if (!mentionOnly)
return DiscordRoutingDecision.StartOrContinue;

Expand Down
3 changes: 2 additions & 1 deletion src/Netclaw.Channels.Discord/DiscordTransportContracts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ public sealed record DiscordGatewayMessage(
bool ContainsBotMention,
string Text,
DateTimeOffset ReceivedAt,
IReadOnlyList<DiscordFileReference>? Attachments = null);
IReadOnlyList<DiscordFileReference>? Attachments = null,
bool IsInThread = false);

/// <summary>
/// Normalized Discord interaction response payload emitted by the transport client.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ private async Task OnMessageReceivedAsync(SocketMessage message)
ContainsBotMention: containsMention,
Text: message.Content,
ReceivedAt: _timeProvider.GetUtcNow(),
Attachments: attachments);
Attachments: attachments,
IsInThread: isThread);

try
{
Expand Down