Skip to content

Commit

Permalink
feat(gh): Added ability for the receiver to fetch public streams with…
Browse files Browse the repository at this point in the history
… an old account (#1557)

feat(gh): Added ability for the receiver to fetch public streams without an account.
  • Loading branch information
AlanRynne authored Aug 30, 2022
2 parents 7666a03 + 1fbe6f2 commit 078813c
Showing 1 changed file with 20 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
using Speckle.Core.Credentials;
using Speckle.Core.Logging;
using Speckle.Core.Models;
using Speckle.Core.Models.Extensions;
using Speckle.Core.Transports;
using Utilities = ConnectorGrasshopper.Extras.Utilities;

Expand Down Expand Up @@ -424,8 +425,20 @@ private async Task ResetApiClient(StreamWrapper wrapper)
try
{
ApiClient?.Dispose();
var acc = await wrapper.GetAccount();
ApiClient = new Client(acc);
Account account = null;
try
{
account = wrapper?.GetAccount().Result;
}
catch (Exception e)
{
AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, e.ToFormattedString());
account = new Account
{
id = wrapper?.StreamId, serverInfo = new ServerInfo() { url = wrapper?.ServerUrl }, token = "", refreshToken = ""
};
}
ApiClient = new Client(account);
ApiClient.SubscribeCommitCreated(StreamWrapper.StreamId);
ApiClient.OnCommitCreated += ApiClient_OnCommitCreated;
}
Expand Down Expand Up @@ -543,22 +556,10 @@ public override void DoWork(Action<string, double> ReportProgress, Action Done)
}
});
};

Speckle.Core.Logging.Analytics.TrackEvent(receiveComponent.ApiClient.Account, Speckle.Core.Logging.Analytics.Events.Receive, new Dictionary<string, object>() { { "auto", receiveComponent.AutoReceive } });

Client client;
try
{
client = new Client(InputWrapper?.GetAccount().Result);
}
catch (Exception e)
{
RuntimeMessages.Add((GH_RuntimeMessageLevel.Warning, e.InnerException?.Message ?? e.Message));
Done();
return;
}

Speckle.Core.Logging.Analytics.TrackEvent(client.Account, Speckle.Core.Logging.Analytics.Events.Receive, new Dictionary<string, object>() { { "auto", receiveComponent.AutoReceive } });

var remoteTransport = new ServerTransport(InputWrapper?.GetAccount().Result, InputWrapper?.StreamId);
var remoteTransport = new ServerTransport(receiveComponent.ApiClient.Account, InputWrapper?.StreamId);
remoteTransport.TransportName = "R";

// Means it's a copy paste of an empty non-init component; set the record and exit fast unless ReceiveOnOpen is true.
Expand All @@ -575,7 +576,7 @@ public override void DoWork(Action<string, double> ReportProgress, Action Done)
var t = Task.Run(async () =>
{
((VariableInputReceiveComponent)Parent).PrevReceivedData = null;
var myCommit = await GetCommit(InputWrapper, client, (level, message) =>
var myCommit = await GetCommit(InputWrapper, receiveComponent.ApiClient, (level, message) =>
{
RuntimeMessages.Add((level, message));

Expand Down Expand Up @@ -607,7 +608,7 @@ public override void DoWork(Action<string, double> ReportProgress, Action Done)

try
{
await client.CommitReceived(new CommitReceivedInput
await receiveComponent.ApiClient.CommitReceived(new CommitReceivedInput
{
streamId = InputWrapper.StreamId,
commitId = myCommit.id,
Expand Down

0 comments on commit 078813c

Please sign in to comment.