Skip to content

Commit bd2be7d

Browse files
committed
OPENRECの「ユーザーID」が未設定のユーザのコメントを取得した場合に発生する不具合を修正
1 parent 9937365 commit bd2be7d

File tree

3 files changed

+36
-14
lines changed

3 files changed

+36
-14
lines changed

OpenrecSitePlugin/API.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,13 @@ public static async Task<List<string>> GetBanList(IDataSource dataSource, Contex
132132
var packet = Packet.Parse(str) as PacketOpen;
133133
return packet.Context;
134134
}
135-
public static async Task<Low.Chats.RootObject[]> GetChats(IDataSource dataSource, string liveId, DateTime toCreatedAt, CookieContainer cc)
135+
public static async Task<(Low.Chats.RootObject[], string raw)> GetChats(IDataSource dataSource, string liveId, DateTime toCreatedAt, CookieContainer cc)
136136
{
137137
//https://public.openrec.tv/external/api/v5/movies/9PgmVnlqtMz/chats?to_created_at=2018-07-24T19:32:50.395Z
138138
var url = "https://public.openrec.tv/external/api/v5/movies/" + liveId + "/chats?to_created_at=" + toCreatedAt.ToString("yyyy-MM-ddTHH:mm:ss.fffZ");
139139
var res = await dataSource.GetAsync(url, cc);
140140
var obj = Tools.Deserialize<Low.Chats.RootObject[]>(res);
141-
return obj;
141+
return (obj, res);
142142
}
143143
/// <summary>
144144
///

OpenrecSitePlugin/CommentProvider.cs

+28-11
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,8 @@ protected virtual CookieContainer CreateCookieContainer(IBrowserProfile browserP
103103
return cc;
104104
}
105105
//protected virtual Extract()
106-
public async Task ConnectAsync(string input, IBrowserProfile browserProfile)
106+
private async Task ConnectInternalAsync(string input, IBrowserProfile browserProfile)
107107
{
108-
BeforeConnecting();
109108
if (_ws != null)
110109
{
111110
throw new InvalidOperationException("");
@@ -146,17 +145,24 @@ public async Task ConnectAsync(string input, IBrowserProfile browserProfile)
146145
_startAt = movieContext2.StartedAt.DateTime;
147146
_500msTimer.Enabled = true;
148147

149-
var chats = await GetChats(movieContext2);
150-
foreach (var item in chats)
148+
var (chats, raw) = await GetChats(movieContext2);
149+
try
151150
{
152-
var comment = Tools.Parse(item);
153-
var commentData = Tools.CreateCommentData(comment, _startAt, _siteOptions);
154-
var messageContext = CreateMessageContext(comment, commentData, true);
155-
if (messageContext != null)
151+
foreach (var item in chats)
156152
{
157-
MessageReceived?.Invoke(this, messageContext);
153+
var comment = Tools.Parse(item);
154+
var commentData = Tools.CreateCommentData(comment, _startAt, _siteOptions);
155+
var messageContext = CreateMessageContext(comment, commentData, true);
156+
if (messageContext != null)
157+
{
158+
MessageReceived?.Invoke(this, messageContext);
159+
}
158160
}
159161
}
162+
catch (Exception ex)
163+
{
164+
_logger.LogException(ex, "", "raw=" + raw);
165+
}
160166
foreach (var user in _userStoreManager.GetAllUsers(SiteType.Openrec))
161167
{
162168
if (!(user is IUser2 user2)) continue;
@@ -231,7 +237,18 @@ public async Task ConnectAsync(string input, IBrowserProfile browserProfile)
231237
goto Reconnect;
232238
}
233239
}
234-
AfterDisconnected();
240+
}
241+
public async Task ConnectAsync(string input, IBrowserProfile browserProfile)
242+
{
243+
BeforeConnecting();
244+
try
245+
{
246+
await ConnectInternalAsync(input, browserProfile);
247+
}
248+
finally
249+
{
250+
AfterDisconnected();
251+
}
235252
}
236253

237254
protected virtual IBlackListProvider CreateBlacklistProvider()
@@ -244,7 +261,7 @@ protected virtual IOpenrecWebsocket CreateOpenrecWebsocket()
244261
return new OpenrecWebsocket(_logger);
245262
}
246263

247-
protected virtual async Task<Low.Chats.RootObject[]> GetChats(MovieInfo movieContext2)
264+
protected virtual async Task<(Low.Chats.RootObject[], string raw)> GetChats(MovieInfo movieContext2)
248265
{
249266
return await API.GetChats(_dataSource, movieContext2.Id, DateTime.Now, _cc);
250267
}

OpenrecSitePlugin/Tools.cs

+6-1
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,12 @@ public static IComment Parse(Low.Chats.RootObject obj)
232232
Nickname = obj.User.Nickname,
233233
PostedAt = obj.PostedAt.DateTime,
234234
StampUrl = obj.Stamp?.ImageUrl,
235-
UserId = obj.User.Id,
235+
//2019/07/09 obj.User.Idはnullの場合があったため変更した
236+
//User.Idはユーザページの「ユーザ情報」で変更できる。
237+
//「 ユーザーIDを設定すると、チャットやコメントが可能になります。」との記載があるため、
238+
//コメントを投稿できている時点でnullは無いと思っていた。
239+
//恐らく設定直後で反映されていないんだろう。
240+
UserId = obj.User.OpenrecUserId.ToString(),
236241
YellPoints = obj.Yell?.Points,
237242
UserIconUrl=obj.User.IconImageUrl,
238243
};

0 commit comments

Comments
 (0)