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

Bug fix and new functionality to the User class #15

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions PlayStationSharp.TestApp/PlayStationSharp.TestApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<StartupObject>PlayStationSharp.TestApp.Program</StartupObject>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
Expand Down
171 changes: 86 additions & 85 deletions PlayStationSharp.TestApp/TestForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 15 additions & 7 deletions PlayStationSharp.TestApp/TestForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,24 @@ public TestForm()
InitializeComponent();
}

private Account Account { get; set; }
private Account _account;
private Account Account
{
get => _account;
set
{
btnBackgroundColor.Visible = !(value is null);
_account = value;
}
}

private void btnLogin_Click(object sender, EventArgs e)
{
var account = Auth.CreateLogin();

if (account == null) return;
Account = Auth.CreateLogin();

this.Account = account;
TokenHandler.Write(account.Client.Tokens);
if (Account == null) return;
;
TokenHandler.Write(Account.Client.Tokens);

SetupLogin(false);
PopulateFields();
Expand Down Expand Up @@ -54,7 +62,7 @@ private void TestForm_Load(object sender, EventArgs e)
SetupLogin(false);
PopulateFields();
}
catch (Exception)
catch
{
SetupLogin(true);
}
Expand Down
2 changes: 2 additions & 0 deletions PlayStationSharp/API/User.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public class User : AbstractUser

public List<MessageThread> MessageThreads => _messageThreads.Value;

public bool IsOnline => Profile.Presences != null && Profile.Presences[0].OnlineStatus == "online";

[Flags]
public enum RequestType
{
Expand Down
2 changes: 1 addition & 1 deletion PlayStationSharp/Extensions/UserExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public static class UserExtensions
{
public static List<User> Online(this List<User> users)
{
return users.Where(a => a.Profile.Presences != null && a.Profile.Presences[0].OnlineStatus == "online").ToList();
return users.Where(a => a.IsOnline).ToList();
}
}
}