Skip to content

Commit

Permalink
直播信息流消息类型增加 (#449)
Browse files Browse the repository at this point in the history
增加了高能榜变动消息,每五次触发后会刷新高能用户贡献榜(大约三分钟)
修复了一个打开直播间时获取主播抽奖信息的bug
其他外观更改
  • Loading branch information
GD-Slime authored Dec 24, 2023
1 parent f95a789 commit 6dac57a
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 4 deletions.
5 changes: 5 additions & 0 deletions src/BiliLite.UWP/Models/Common/Enumerates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -395,5 +395,10 @@ public enum MessageType
/// 红包抽奖赢家
/// </summary>
RedPocketLotteryWinner,

/// <summary>
/// 高能榜变动
/// </summary>
OnlineRankChange,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public LiveMessageHandleActionsMap()
{ MessageType.WatchedChange, WatchedChange },
{ MessageType.RedPocketLotteryStart, RedPocketLotteryStart},
{ MessageType.RedPocketLotteryWinner, RedPocketLotteryWinner},
{ MessageType.OnlineRankChange, OnlineRankChange},
};
}

Expand Down Expand Up @@ -210,7 +211,7 @@ private void WaringOrCutOff(LiveRoomViewModel viewModel, object message)
{
UserName = info.Command switch
{
"WARNING" => "⛔直播间警告",
"WARNING" => "⚠️直播间警告",
"CUT_OFF" => "⛔直播间切断",
_ => null,
},
Expand All @@ -231,5 +232,10 @@ private async void StartLive(LiveRoomViewModel viewModel, object room_Id)
UserName = $"{room_Id} 直播间开始直播",
});
}

private void OnlineRankChange(LiveRoomViewModel viewModel, object message)
{
viewModel.Ranks.Where(rank => rank.RankType == "contribution-rank").ToList()?[0]?.ReloadData().RunWithoutAwait();
}
}
}
9 changes: 8 additions & 1 deletion src/BiliLite.UWP/Modules/Live/LiveMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -444,12 +444,19 @@ private void ParseMessage(string jsonMessage)
NewMessage?.Invoke(MessageType.WatchedChange, obj["data"]["text_large"].ToString());
}
}
else if (cmd == "ONLINE_RANK_V2")
{
if (obj["data"] != null)
{
NewMessage?.Invoke(MessageType.OnlineRankChange, obj["data"]["list"].ToString());
}
}
}
catch (Exception ex)
{
if (ex is JsonReaderException)
{
logger.Error("直播解析JSON包出错", ex);
logger.Log("直播解析JSON包出错", LogType.Error ,ex);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/BiliLite.UWP/Pages/LiveDetailPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ private void Timer_focus_Tick(object sender, object e)
private void LiveRoomViewModelAnchorLotteryStart(object sender, LiveRoomAnchorLotteryInfoModel e)
{
AnchorLotteryWinnerList.Content = e.WinnerList;
m_liveRoomViewModel.ShowAnchorLotteryWinnerList = e.AwardUsers.Count > 0;
m_liveRoomViewModel.ShowAnchorLotteryWinnerList = e.AwardUsers != null && e.AwardUsers.Count > 0;
}

private void LiveRoomViewModelAnchorLotteryEnd(object sender, LiveRoomEndAnchorLotteryInfoModel e)
Expand Down
16 changes: 15 additions & 1 deletion src/BiliLite.UWP/ViewModels/Live/LiveRoomRankViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public LiveRoomRankViewModel(int roomId, long uid, string title, string type)

public bool CanLoadMore { get; set; }

public int Next { get; set; } = 0;
public int ReloadFlag { get; set; } = 0;

#endregion

Expand Down Expand Up @@ -137,6 +137,20 @@ public async Task LoadData()
}
}

public async Task ReloadData()
{
if (ReloadFlag > 5) // 大约三分钟刷新一次
{
Items.Clear();
Page = 1;
await LoadData();
ReloadFlag = 0;
} else
{
ReloadFlag++;
}
}

#endregion
}
}

0 comments on commit 6dac57a

Please sign in to comment.