Skip to content

Commit 382eac5

Browse files
committed
[Core] Implement Forward Message Segment Send
1 parent 7cf9b1b commit 382eac5

File tree

4 files changed

+37
-3
lines changed

4 files changed

+37
-3
lines changed

Lagrange.Milky/Entity/Segment/ForwardSegment.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,25 @@ public class ForwardIncomingSegmentData(string forwardId)
1212
{
1313
[JsonPropertyName("forward_id")]
1414
public string ForwardId { get; } = forwardId;
15+
}
16+
17+
public class ForwardOutgoingSegment(ForwardOutgoingSegmentData data) : OutgoingSegmentBase<ForwardOutgoingSegmentData>(data) { }
18+
19+
public class ForwardOutgoingSegmentData(ForwardOutgoingSegmentDataItem[] messages)
20+
{
21+
[JsonRequired]
22+
[JsonPropertyName("messages")]
23+
public ForwardOutgoingSegmentDataItem[] Messages { get; init; } = messages;
24+
}
25+
26+
public class ForwardOutgoingSegmentDataItem(long userId, string senderName, IOutgoingSegment[] segments)
27+
{
28+
[JsonPropertyName("user_id")]
29+
public long UserId { get; init; } = userId;
30+
31+
[JsonPropertyName("sender_name")]
32+
public string SenderName { get; init; } = senderName;
33+
34+
[JsonPropertyName("segments")]
35+
public IOutgoingSegment[] Segments { get; init; } = segments;
1536
}

Lagrange.Milky/Entity/Segment/ISegment.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public interface IIncomingSegment
3030
[JsonDerivedType(typeof(ImageOutgoingSegment), typeDiscriminator: "image")]
3131
[JsonDerivedType(typeof(RecordOutgoingSegment), typeDiscriminator: "record")]
3232
[JsonDerivedType(typeof(VideoOutgoingSegment), typeDiscriminator: "video")]
33-
// [JsonDerivedType(typeof(ForwardOutgoingSegment), typeDiscriminator: "forward")]
33+
[JsonDerivedType(typeof(ForwardOutgoingSegment), typeDiscriminator: "forward")]
3434
public interface IOutgoingSegment
3535
{
3636
object? Data { get; }

Lagrange.Milky/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ Current Milky version: [77c6cbd](https://github.com/SaltifyDev/milky/tree/77c6cb
154154
- [x] image
155155
- [x] record
156156
- [ ] video
157-
- [ ] forward
157+
- [x] forward
158158

159159
#### forward
160160

Lagrange.Milky/Utility/EntityConvert.Segment.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ await _resolver.ToMemoryStreamAsync(video.Data.Uri, token),
121121
video.Data.ThumbUri != null ? await _resolver.ToMemoryStreamAsync(video.Data.ThumbUri, token) : null,
122122
disposeOnCompletion: true
123123
),
124-
// TODO: ForwardOutgoingSegment
124+
ForwardOutgoingSegment forwardOutgoingSegment => await BuildMultiMsgEntityAsync(forwardOutgoingSegment.Data.Messages, token),
125125
_ => throw new NotSupportedException(),
126126
};
127127

@@ -141,4 +141,17 @@ private async Task<IMessageEntity> ReplyFriendSegmentAsync(ReplyOutgoingSegment
141141

142142
return new ReplyEntity(message);
143143
}
144+
145+
private async Task<MultiMsgEntity> BuildMultiMsgEntityAsync(IReadOnlyList<ForwardOutgoingSegmentDataItem> data, CancellationToken token)
146+
{
147+
var multiMsgEntity = new MultiMsgEntity();
148+
foreach (var segment in data)
149+
{
150+
var msgChain = await FakeSegmentsAsync(segment.Segments, token);
151+
var msg = BotMessage.CreateCustomFriend(segment.UserId, segment.SenderName, 0, string.Empty, DateTime.Now, msgChain);
152+
multiMsgEntity.Messages.Add(msg);
153+
}
154+
155+
return multiMsgEntity;
156+
}
144157
}

0 commit comments

Comments
 (0)