Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Core] Add get messages by resId api #616

Merged
merged 1 commit into from
Sep 29, 2024
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
9 changes: 7 additions & 2 deletions Lagrange.Core/Common/Interface/Api/OperationExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public static Task<bool> RecallGroupMessage(this BotContext bot, uint groupUin,
/// <returns>Successfully recalled or not</returns>
public static Task<bool> RecallFriendMessage(this BotContext bot, uint friendUin, MessageResult result)
=> bot.ContextCollection.Business.OperationLogic.RecallFriendMessage(friendUin, result);

/// <summary>
/// Recall the group message by <see cref="MessageChain"/>
/// </summary>
Expand All @@ -98,7 +98,7 @@ public static Task<bool> RecallFriendMessage(this BotContext bot, uint friendUin
/// <returns>Successfully recalled or not</returns>
public static Task<bool> RecallFriendMessage(this BotContext bot, MessageChain chain)
=> bot.ContextCollection.Business.OperationLogic.RecallFriendMessage(chain);

/// <summary>
/// Fetch Notifications and requests such as friend requests and Group Join Requests
/// </summary>
Expand Down Expand Up @@ -186,6 +186,11 @@ public static Task<bool> Like(this BotContext bot, uint targetUin, uint count =
return bot.ContextCollection.Business.OperationLogic.GetC2cMessage(friendUin, startSequence, endSequence);
}

public static Task<(int code, List<MessageChain>? chains)> GetMessagesByResId(this BotContext bot, string resId)
{
return bot.ContextCollection.Business.OperationLogic.GetMessagesByResId(resId);
}

/// <summary>
/// Do group clock in (群打卡)
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,17 @@ public async Task<bool> SetFriendRequest(string targetUid, bool accept)
return results.Count != 0 ? ((GetC2cMessageEvent)results[0]).Chains : null;
}

public async Task<(int code, List<MessageChain>? chains)> GetMessagesByResId(string resId)
{
var @event = MultiMsgDownloadEvent.Create(Collection.Keystore.Uid ?? "", resId);
var results = await Collection.Business.SendEvent(@event);

if (results.Count == 0) return (-9999, null);
var result = (MultiMsgDownloadEvent)results[0];

return (result.ResultCode, result.Chains);
}

public async Task<List<string>?> FetchCustomFace()
{
var fetchCustomFaceEvent = FetchCustomFaceEvent.Create();
Expand Down
10 changes: 7 additions & 3 deletions Lagrange.OneBot/Core/Operation/Message/GetForwardMsgOperation.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Text.Json;
using System.Text.Json.Nodes;
using Lagrange.Core;
using Lagrange.Core.Common.Interface.Api;
using Lagrange.Core.Internal.Event.Message;
using Lagrange.OneBot.Core.Entity.Action;
using Lagrange.OneBot.Core.Entity.Action.Response;
Expand All @@ -17,11 +18,14 @@ public async Task<OneBotResult> HandleOperation(BotContext context, JsonNode? pa
{
if (payload.Deserialize<OneBotGetForwardMsg>(SerializerOptions.DefaultOptions) is { } forwardMsg)
{
var (code, chains) = await context.GetMessagesByResId(forwardMsg.Id);

if (code != 0) return new OneBotResult(null, code, "failed");

var nodes = new List<OneBotSegment>();
if (chains == null) return new OneBotResult(new OneBotGetForwardMsgResponse(nodes), 0, "ok");

var @event = MultiMsgDownloadEvent.Create(context.ContextCollection.Keystore.Uid ?? "", forwardMsg.Id);
var results = await context.ContextCollection.Business.SendEvent(@event);
foreach (var chain in ((MultiMsgDownloadEvent)results[0]).Chains ?? throw new Exception())
foreach (var chain in chains)
{
var parsed = service.Convert(chain);
var nickname = string.IsNullOrEmpty(chain.FriendInfo?.Nickname)
Expand Down