Skip to content

Commit

Permalink
- Adding storage of last follower and subscriber ID to assist with lo…
Browse files Browse the repository at this point in the history
…ading in initial value for Label Overlay Widget
  • Loading branch information
Matthew Olivo committed Oct 7, 2024
1 parent 72f3d64 commit cadb74f
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 14 deletions.
44 changes: 30 additions & 14 deletions MixItUp.Base/Model/Overlay/OverlayLabelV3Model.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,20 +156,28 @@ public override async Task Initialize()
if (this.IsDisplayEnabled(OverlayLabelDisplayV3TypeEnum.LatestFollower))
{
UserV2ViewModel user = null;
if (ChannelSession.Settings.DefaultStreamingPlatform == StreamingPlatformTypeEnum.Twitch && ServiceManager.Get<TwitchSessionService>().IsConnected)
if (ChannelSession.Settings.LastFollowerUserID != Guid.Empty)
{
var followers = await ServiceManager.Get<TwitchSessionService>().UserConnection.GetNewAPIFollowers(ServiceManager.Get<TwitchSessionService>().User, maxResult: 1);
if (followers != null && followers.Count() > 0)
{
user = await ServiceManager.Get<UserService>().GetUserByPlatform(StreamingPlatformTypeEnum.Twitch, platformID: followers.First().user_id, performPlatformSearch: true);
}
user = await ServiceManager.Get<UserService>().GetUserByID(ChannelSession.Settings.DefaultStreamingPlatform, ChannelSession.Settings.LastFollowerUserID);
}
else if (ChannelSession.Settings.DefaultStreamingPlatform == StreamingPlatformTypeEnum.Trovo && ServiceManager.Get<TrovoSessionService>().IsConnected)

if (user == null)
{
var followers = await ServiceManager.Get<TrovoSessionService>().UserConnection.GetFollowers(ServiceManager.Get<TrovoSessionService>().ChannelID, maxResults: 1);
if (followers != null && followers.Count() > 0)
if (ChannelSession.Settings.DefaultStreamingPlatform == StreamingPlatformTypeEnum.Twitch && ServiceManager.Get<TwitchSessionService>().IsConnected)
{
user = await ServiceManager.Get<UserService>().GetUserByPlatform(StreamingPlatformTypeEnum.Trovo, platformID: followers.First().user_id, platformUsername: followers.First().nickname, performPlatformSearch: true);
var followers = await ServiceManager.Get<TwitchSessionService>().UserConnection.GetNewAPIFollowers(ServiceManager.Get<TwitchSessionService>().User, maxResult: 1);
if (followers != null && followers.Count() > 0)
{
user = await ServiceManager.Get<UserService>().GetUserByPlatform(StreamingPlatformTypeEnum.Twitch, platformID: followers.First().user_id, performPlatformSearch: true);
}
}
else if (ChannelSession.Settings.DefaultStreamingPlatform == StreamingPlatformTypeEnum.Trovo && ServiceManager.Get<TrovoSessionService>().IsConnected)
{
var followers = await ServiceManager.Get<TrovoSessionService>().UserConnection.GetFollowers(ServiceManager.Get<TrovoSessionService>().ChannelID, maxResults: 1);
if (followers != null && followers.Count() > 0)
{
user = await ServiceManager.Get<UserService>().GetUserByPlatform(StreamingPlatformTypeEnum.Trovo, platformID: followers.First().user_id, platformUsername: followers.First().nickname, performPlatformSearch: true);
}
}
}

Expand Down Expand Up @@ -209,12 +217,20 @@ public override async Task Initialize()
if (this.IsDisplayEnabled(OverlayLabelDisplayV3TypeEnum.LatestSubscriber))
{
UserV2ViewModel user = null;
if (ChannelSession.Settings.DefaultStreamingPlatform == StreamingPlatformTypeEnum.Twitch && ServiceManager.Get<TwitchSessionService>().IsConnected)
if (ChannelSession.Settings.LastSubscriberUserID != Guid.Empty)
{
user = await ServiceManager.Get<UserService>().GetUserByID(ChannelSession.Settings.DefaultStreamingPlatform, ChannelSession.Settings.LastSubscriberUserID);
}

if (user == null)
{
var subscribers = await ServiceManager.Get<TwitchSessionService>().UserConnection.GetSubscribers(ServiceManager.Get<TwitchSessionService>().User, maxResult: 1);
if (subscribers != null && subscribers.Count() > 0)
if (ChannelSession.Settings.DefaultStreamingPlatform == StreamingPlatformTypeEnum.Twitch && ServiceManager.Get<TwitchSessionService>().IsConnected)
{
user = await ServiceManager.Get<UserService>().GetUserByPlatform(StreamingPlatformTypeEnum.Twitch, platformID: subscribers.First().user_id, performPlatformSearch: true);
var subscribers = await ServiceManager.Get<TwitchSessionService>().UserConnection.GetSubscribers(ServiceManager.Get<TwitchSessionService>().User, maxResult: 1);
if (subscribers != null && subscribers.Count() > 0)
{
user = await ServiceManager.Get<UserService>().GetUserByPlatform(StreamingPlatformTypeEnum.Twitch, platformID: subscribers.First().user_id, performPlatformSearch: true);
}
}
}

Expand Down
5 changes: 5 additions & 0 deletions MixItUp.Base/Model/Settings/SettingsV3Model.cs
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,11 @@ public static async Task RestoreSettingsBackup()
[DataMember]
public Dictionary<string, object> LatestSpecialIdentifiersData { get; set; } = new Dictionary<string, object>();

[DataMember]
public Guid LastFollowerUserID { get; set; }
[DataMember]
public Guid LastSubscriberUserID { get; set; }

[DataMember]
public Dictionary<string, HotKeyConfiguration> HotKeys { get; set; } = new Dictionary<string, HotKeyConfiguration>();
[DataMember]
Expand Down
24 changes: 24 additions & 0 deletions MixItUp.Base/Services/EventService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,30 @@ public async Task<bool> PerformEvent(EventTypeEnum type, CommandParametersModel
{
try
{
switch (type)
{
case EventTypeEnum.TwitchChannelFollowed:
case EventTypeEnum.TrovoChannelFollowed:
ChannelSession.Settings.LastFollowerUserID = parameters.User.ID;
break;
case EventTypeEnum.TwitchChannelSubscribed:
case EventTypeEnum.YouTubeChannelNewMember:
case EventTypeEnum.TrovoChannelSubscribed:
case EventTypeEnum.TwitchChannelResubscribed:
case EventTypeEnum.YouTubeChannelMemberMilestone:
case EventTypeEnum.TrovoChannelResubscribed:
ChannelSession.Settings.LastSubscriberUserID = parameters.User.ID;
break;
case EventTypeEnum.TwitchChannelSubscriptionGifted:
case EventTypeEnum.YouTubeChannelMembershipGifted:
case EventTypeEnum.TrovoChannelSubscriptionGifted:
if (parameters.TargetUser != null)
{
ChannelSession.Settings.LastSubscriberUserID = parameters.TargetUser.ID;
}
break;
}

if (this.CanPerformEvent(type, parameters))
{
UserV2ViewModel user = parameters.User;
Expand Down
1 change: 1 addition & 0 deletions MixItUp.Base/Services/Twitch/TwitchEventService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1618,6 +1618,7 @@ private async Task ProcessMassGiftedSub(TwitchMassGiftedSubEventModel massGifted
parameters.SpecialIdentifiers["usersubplan"] = massGiftedSubEvent.PlanTier;
parameters.SpecialIdentifiers["isanonymous"] = massGiftedSubEvent.IsAnonymous.ToString();

parameters.TargetUser = massGiftedSubEvent.Subs.First().Receiver;
foreach (TwitchGiftedSubEventModel sub in massGiftedSubEvent.Subs)
{
parameters.Arguments.Add(sub.Receiver.Username);
Expand Down

0 comments on commit cadb74f

Please sign in to comment.