Skip to content

Commit ebe0342

Browse files
committed
move shared chat logic to assets store, fix missing chat message badges
1 parent f7f0f22 commit ebe0342

File tree

3 files changed

+28
-23
lines changed

3 files changed

+28
-23
lines changed

lib/screens/channel/chat/stores/chat_assets_store.dart

+20-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import 'package:frosty/apis/seventv_api.dart';
66
import 'package:frosty/apis/twitch_api.dart';
77
import 'package:frosty/models/badges.dart';
88
import 'package:frosty/models/emotes.dart';
9+
import 'package:frosty/models/user.dart';
910
import 'package:mobx/mobx.dart';
1011
import 'package:shared_preferences/shared_preferences.dart';
1112

@@ -24,6 +25,8 @@ abstract class ChatAssetsStoreBase with Store {
2425

2526
String? sevenTvEmoteSetId;
2627

28+
final channelIdToUserTwitch = ObservableMap<String, UserTwitch>();
29+
2730
@computed
2831
List<Emote> get bttvEmotes =>
2932
_emoteToObject.values.where((emote) => isBTTV(emote)).toList();
@@ -138,6 +141,22 @@ abstract class ChatAssetsStoreBase with Store {
138141
//
139142
// Emotes
140143
Future.wait([
144+
twitchApi
145+
.getSharedChatSession(
146+
broadcasterId: channelId,
147+
headers: headers,
148+
)
149+
.then((sharedChatSession) {
150+
if (sharedChatSession == null) return;
151+
152+
for (final participant in sharedChatSession.participants) {
153+
twitchApi
154+
.getUser(id: participant.broadcasterId, headers: headers)
155+
.then((user) {
156+
channelIdToUserTwitch[participant.broadcasterId] = user;
157+
});
158+
}
159+
}).catchError(onBadgeError),
141160
Future.wait([
142161
if (showTwitchEmotes) ...[
143162
twitchApi
@@ -161,7 +180,7 @@ abstract class ChatAssetsStoreBase with Store {
161180
final (setId, emotes) = data;
162181
sevenTvEmoteSetId = setId;
163182
return emotes;
164-
}).catchError(onEmoteError),
183+
}).catchError(onBadgeError),
165184
],
166185
if (showBTTVEmotes) ...[
167186
bttvApi.getEmotesGlobal().catchError(onEmoteError),

lib/screens/channel/chat/stores/chat_store.dart

-21
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import 'package:frosty/apis/twitch_api.dart';
66
import 'package:frosty/models/emotes.dart';
77
import 'package:frosty/models/events.dart';
88
import 'package:frosty/models/irc.dart';
9-
import 'package:frosty/models/user.dart';
109
import 'package:frosty/screens/channel/chat/details/chat_details_store.dart';
1110
import 'package:frosty/screens/channel/chat/stores/chat_assets_store.dart';
1211
import 'package:frosty/screens/settings/stores/auth_store.dart';
@@ -153,8 +152,6 @@ abstract class ChatStoreBase with Store {
153152
@observable
154153
IRCMessage? replyingToMessage;
155154

156-
final channelIdToUserTwitch = ObservableMap<String, UserTwitch>();
157-
158155
ChatStoreBase({
159156
required this.twitchApi,
160157
required this.auth,
@@ -207,24 +204,6 @@ abstract class ChatStoreBase with Store {
207204

208205
assetsStore.init();
209206

210-
// Get the shared chat session and the profile pictures of the participants.
211-
twitchApi
212-
.getSharedChatSession(
213-
broadcasterId: channelId,
214-
headers: auth.headersTwitch,
215-
)
216-
.then((sharedChatSession) {
217-
if (sharedChatSession == null) return;
218-
219-
for (final participant in sharedChatSession.participants) {
220-
twitchApi
221-
.getUser(id: participant.broadcasterId, headers: auth.headersTwitch)
222-
.then((user) {
223-
channelIdToUserTwitch[participant.broadcasterId] = user;
224-
});
225-
}
226-
});
227-
228207
_messages.add(IRCMessage.createNotice(message: 'Connecting to chat...'));
229208

230209
if (settings.showVideo && settings.chatDelay > 0) {

lib/screens/channel/chat/widgets/chat_message.dart

+8-1
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ class ChatMessage extends StatelessWidget {
109109
useReadableColors: chatStore.settings.useReadableColors,
110110
launchExternal: chatStore.settings.launchUrlExternal,
111111
timestamp: chatStore.settings.timestampType,
112+
channelIdToUserTwitch:
113+
chatStore.assetsStore.channelIdToUserTwitch,
112114
),
113115
style: defaultTextStyle,
114116
),
@@ -173,7 +175,8 @@ class ChatMessage extends StatelessWidget {
173175
useReadableColors: chatStore.settings.useReadableColors,
174176
launchExternal: chatStore.settings.launchUrlExternal,
175177
timestamp: chatStore.settings.timestampType,
176-
channelIdToUserTwitch: chatStore.channelIdToUserTwitch,
178+
channelIdToUserTwitch:
179+
chatStore.assetsStore.channelIdToUserTwitch,
177180
),
178181
),
179182
);
@@ -305,6 +308,8 @@ class ChatMessage extends StatelessWidget {
305308
useReadableColors: chatStore.settings.useReadableColors,
306309
launchExternal: chatStore.settings.launchUrlExternal,
307310
timestamp: chatStore.settings.timestampType,
311+
channelIdToUserTwitch:
312+
chatStore.assetsStore.channelIdToUserTwitch,
308313
),
309314
),
310315
),
@@ -398,6 +403,8 @@ class ChatMessage extends StatelessWidget {
398403
chatStore.settings.useReadableColors,
399404
launchExternal: chatStore.settings.launchUrlExternal,
400405
timestamp: chatStore.settings.timestampType,
406+
channelIdToUserTwitch:
407+
chatStore.assetsStore.channelIdToUserTwitch,
401408
),
402409
),
403410
),

0 commit comments

Comments
 (0)