Skip to content

Commit

Permalink
- Adding in check for YouTube membership capabilities before performi…
Browse files Browse the repository at this point in the history
…ng any queries for data related to it
  • Loading branch information
SaviorXTanren committed Sep 21, 2023
1 parent f3a9bd4 commit e9135e8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
31 changes: 17 additions & 14 deletions MixItUp.Base/Model/User/Platform/YouTubeUserPlatformV2Model.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,21 +95,24 @@ public void SetMessageProperties(LiveChatMessage message)

public async Task RefreshMembershipDetails()
{
Member membership = await ServiceManager.Get<YouTubeSessionService>().UserConnection.CheckIfMember(this.ID);
if (membership != null)
if (ServiceManager.Get<YouTubeSessionService>().HasMembershipCapabilities)
{
this.Roles.Add(UserRoleEnum.YouTubeMember);
this.Roles.Add(UserRoleEnum.Subscriber);
this.SubscribeDate = DateTime.Parse(membership.Snippet.MembershipsDetails.MembershipsDuration.MemberSince);
this.MemberLevels.Clear();
this.MemberLevels.AddRange(membership.Snippet.MembershipsDetails.AccessibleLevels);
}
else
{
this.Roles.Remove(UserRoleEnum.YouTubeMember);
this.Roles.Remove(UserRoleEnum.Subscriber);
this.SubscribeDate = null;
this.MemberLevels.Clear();
Member membership = await ServiceManager.Get<YouTubeSessionService>().UserConnection.CheckIfMember(this.ID);
if (membership != null)
{
this.Roles.Add(UserRoleEnum.YouTubeMember);
this.Roles.Add(UserRoleEnum.Subscriber);
this.SubscribeDate = DateTime.Parse(membership.Snippet.MembershipsDetails.MembershipsDuration.MemberSince);
this.MemberLevels.Clear();
this.MemberLevels.AddRange(membership.Snippet.MembershipsDetails.AccessibleLevels);
}
else
{
this.Roles.Remove(UserRoleEnum.YouTubeMember);
this.Roles.Remove(UserRoleEnum.Subscriber);
this.SubscribeDate = null;
this.MemberLevels.Clear();
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions MixItUp.Base/Services/YouTube/YouTubePlatformService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,6 @@ public YouTubePlatformService(YouTubeConnection connection)

public async Task<Video> UpdateVideo(Video video, string title = null, string description = null, string categoryId = null) { return await AsyncRunner.RunAsync(this.Connection.Videos.UpdateVideo(video, title, description, categoryId)); }

public async Task<IEnumerable<Member>> GetChannelMemberships(int maxResults = 1) { return await AsyncRunner.RunAsync(this.Connection.LiveChat.GetChannelMemberships(maxResults)); }

public async Task<IEnumerable<LiveChatModerator>> GetModerators(LiveBroadcast broadcast, int maxResults = 1) { return await AsyncRunner.RunAsync(this.Connection.LiveChat.GetModerators(broadcast, maxResults)); }

public async Task<IEnumerable<Subscription>> GetSubscribers(string channelID, int maxResults = 1) { return await AsyncRunner.RunAsync(this.Connection.Subscriptions.GetMyRecentSubscribers(maxResults)); }
Expand All @@ -115,6 +113,8 @@ public YouTubePlatformService(YouTubeConnection connection)

public async Task<IEnumerable<MembershipsLevel>> GetMembershipLevels() { return await AsyncRunner.RunAsync(this.Connection.Membership.GetMyMembershipLevels()); }

public async Task<IEnumerable<Member>> GetChannelMemberships(int maxResults = 1) { return await AsyncRunner.RunAsync(this.Connection.LiveChat.GetChannelMemberships(maxResults)); }

public async Task<IEnumerable<Member>> GetMembers(int maxResults = 1) { return await AsyncRunner.RunAsync(this.Connection.Membership.GetMembers(maxResults)); }

public async Task<Member> CheckIfMember(string userID) { return await AsyncRunner.RunAsync(this.Connection.Membership.CheckIfMember(userID)); }
Expand Down
2 changes: 2 additions & 0 deletions MixItUp.Base/Services/YouTube/YouTubeSessionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public class YouTubeSessionService : IStreamingPlatformSessionService
public string ChannelID { get { return this.User?.Id; } }
public string ChannelLink { get { return this.User?.Snippet?.CustomUrl; } }

public bool HasMembershipCapabilities { get { return this.MembershipLevels.Count > 0; } }

private DateTime launchDateTime = DateTime.Now;

public StreamingPlatformAccountModel UserAccount
Expand Down

0 comments on commit e9135e8

Please sign in to comment.