Skip to content

Commit ad6e032

Browse files
committed
[Core] Return seq for SendFriendFile
1 parent 4e83662 commit ad6e032

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

Lagrange.Core/Common/Interface/MessageExt.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public static Task<List<BotMessage>> GetRoamMessage(this BotContext context, Bot
2626
public static Task<List<BotMessage>> GetC2CMessage(this BotContext context, long peerUin, uint startSequence, uint endSequence)
2727
=> context.EventContext.GetLogic<MessagingLogic>().GetC2CMessage(peerUin, startSequence, endSequence);
2828

29-
public static Task<bool> SendFriendFile(this BotContext context, long targetUin, Stream fileStream, string? fileName = null)
29+
public static Task<(int Sequence, DateTime Time)> SendFriendFile(this BotContext context, long targetUin, Stream fileStream, string? fileName = null)
3030
=> context.EventContext.GetLogic<OperationLogic>().SendFriendFile(targetUin, fileStream, fileName);
3131

3232
public static Task<string> SendGroupFile(this BotContext context, long groupUin, Stream fileStream, string? fileName = null, string parentDirectory = "/")

Lagrange.Core/Internal/Logic/OperationLogic.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public async Task<string> GroupFSDownload(long groupUin, string fileId)
3939

4040
public async Task GroupFSDelete(long groupUin, string fileId) => await context.EventContext.SendEvent<GroupFSDeleteEventResp>(new GroupFSDeleteEventReq(groupUin, fileId));
4141

42-
public async Task<bool> SendFriendFile(long targetUin, Stream fileStream, string? fileName)
42+
public async Task<(int, DateTime)> SendFriendFile(long targetUin, Stream fileStream, string? fileName)
4343
{
4444
fileName = ResolveFileName(fileStream, fileName);
4545

@@ -94,15 +94,15 @@ public async Task<bool> SendFriendFile(long targetUin, Stream fileStream, string
9494
};
9595

9696
bool success = await context.HighwayContext.UploadFile(fileStream, 95, ProtoHelper.Serialize(ext));
97-
if (!success) return false;
97+
if (!success) throw new OperationException(-1, "File upload failed");
9898
}
9999

100100
int sequence = Random.Shared.Next(10000, 99999);
101101
uint random = (uint)Random.Shared.Next();
102102
var sendResult = await context.EventContext.SendEvent<SendMessageEventResp>(new SendFriendFileEventReq(friend, request, result, sequence, random));
103103
if (sendResult.Result != 0) throw new OperationException(sendResult.Result);
104104

105-
return true;
105+
return (sequence, DateTimeOffset.FromUnixTimeSeconds(sendResult.SendTime).UtcDateTime);
106106
}
107107

108108
private static string ResolveFileName(Stream fileStream, string? fileName)

0 commit comments

Comments
 (0)