move shared chat logic to assets store, fix missing chat message badges
This commit is contained in:
parent
f7f0f22bb5
commit
ebe0342c56
3 changed files with 28 additions and 23 deletions
|
|
@ -6,6 +6,7 @@ import 'package:frosty/apis/seventv_api.dart';
|
|||
import 'package:frosty/apis/twitch_api.dart';
|
||||
import 'package:frosty/models/badges.dart';
|
||||
import 'package:frosty/models/emotes.dart';
|
||||
import 'package:frosty/models/user.dart';
|
||||
import 'package:mobx/mobx.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
|
|
@ -24,6 +25,8 @@ abstract class ChatAssetsStoreBase with Store {
|
|||
|
||||
String? sevenTvEmoteSetId;
|
||||
|
||||
final channelIdToUserTwitch = ObservableMap<String, UserTwitch>();
|
||||
|
||||
@computed
|
||||
List<Emote> get bttvEmotes =>
|
||||
_emoteToObject.values.where((emote) => isBTTV(emote)).toList();
|
||||
|
|
@ -138,6 +141,22 @@ abstract class ChatAssetsStoreBase with Store {
|
|||
//
|
||||
// Emotes
|
||||
Future.wait([
|
||||
twitchApi
|
||||
.getSharedChatSession(
|
||||
broadcasterId: channelId,
|
||||
headers: headers,
|
||||
)
|
||||
.then((sharedChatSession) {
|
||||
if (sharedChatSession == null) return;
|
||||
|
||||
for (final participant in sharedChatSession.participants) {
|
||||
twitchApi
|
||||
.getUser(id: participant.broadcasterId, headers: headers)
|
||||
.then((user) {
|
||||
channelIdToUserTwitch[participant.broadcasterId] = user;
|
||||
});
|
||||
}
|
||||
}).catchError(onBadgeError),
|
||||
Future.wait([
|
||||
if (showTwitchEmotes) ...[
|
||||
twitchApi
|
||||
|
|
@ -161,7 +180,7 @@ abstract class ChatAssetsStoreBase with Store {
|
|||
final (setId, emotes) = data;
|
||||
sevenTvEmoteSetId = setId;
|
||||
return emotes;
|
||||
}).catchError(onEmoteError),
|
||||
}).catchError(onBadgeError),
|
||||
],
|
||||
if (showBTTVEmotes) ...[
|
||||
bttvApi.getEmotesGlobal().catchError(onEmoteError),
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ import 'package:frosty/apis/twitch_api.dart';
|
|||
import 'package:frosty/models/emotes.dart';
|
||||
import 'package:frosty/models/events.dart';
|
||||
import 'package:frosty/models/irc.dart';
|
||||
import 'package:frosty/models/user.dart';
|
||||
import 'package:frosty/screens/channel/chat/details/chat_details_store.dart';
|
||||
import 'package:frosty/screens/channel/chat/stores/chat_assets_store.dart';
|
||||
import 'package:frosty/screens/settings/stores/auth_store.dart';
|
||||
|
|
@ -153,8 +152,6 @@ abstract class ChatStoreBase with Store {
|
|||
@observable
|
||||
IRCMessage? replyingToMessage;
|
||||
|
||||
final channelIdToUserTwitch = ObservableMap<String, UserTwitch>();
|
||||
|
||||
ChatStoreBase({
|
||||
required this.twitchApi,
|
||||
required this.auth,
|
||||
|
|
@ -207,24 +204,6 @@ abstract class ChatStoreBase with Store {
|
|||
|
||||
assetsStore.init();
|
||||
|
||||
// Get the shared chat session and the profile pictures of the participants.
|
||||
twitchApi
|
||||
.getSharedChatSession(
|
||||
broadcasterId: channelId,
|
||||
headers: auth.headersTwitch,
|
||||
)
|
||||
.then((sharedChatSession) {
|
||||
if (sharedChatSession == null) return;
|
||||
|
||||
for (final participant in sharedChatSession.participants) {
|
||||
twitchApi
|
||||
.getUser(id: participant.broadcasterId, headers: auth.headersTwitch)
|
||||
.then((user) {
|
||||
channelIdToUserTwitch[participant.broadcasterId] = user;
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
_messages.add(IRCMessage.createNotice(message: 'Connecting to chat...'));
|
||||
|
||||
if (settings.showVideo && settings.chatDelay > 0) {
|
||||
|
|
|
|||
|
|
@ -109,6 +109,8 @@ class ChatMessage extends StatelessWidget {
|
|||
useReadableColors: chatStore.settings.useReadableColors,
|
||||
launchExternal: chatStore.settings.launchUrlExternal,
|
||||
timestamp: chatStore.settings.timestampType,
|
||||
channelIdToUserTwitch:
|
||||
chatStore.assetsStore.channelIdToUserTwitch,
|
||||
),
|
||||
style: defaultTextStyle,
|
||||
),
|
||||
|
|
@ -173,7 +175,8 @@ class ChatMessage extends StatelessWidget {
|
|||
useReadableColors: chatStore.settings.useReadableColors,
|
||||
launchExternal: chatStore.settings.launchUrlExternal,
|
||||
timestamp: chatStore.settings.timestampType,
|
||||
channelIdToUserTwitch: chatStore.channelIdToUserTwitch,
|
||||
channelIdToUserTwitch:
|
||||
chatStore.assetsStore.channelIdToUserTwitch,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
|
@ -305,6 +308,8 @@ class ChatMessage extends StatelessWidget {
|
|||
useReadableColors: chatStore.settings.useReadableColors,
|
||||
launchExternal: chatStore.settings.launchUrlExternal,
|
||||
timestamp: chatStore.settings.timestampType,
|
||||
channelIdToUserTwitch:
|
||||
chatStore.assetsStore.channelIdToUserTwitch,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
|
@ -398,6 +403,8 @@ class ChatMessage extends StatelessWidget {
|
|||
chatStore.settings.useReadableColors,
|
||||
launchExternal: chatStore.settings.launchUrlExternal,
|
||||
timestamp: chatStore.settings.timestampType,
|
||||
channelIdToUserTwitch:
|
||||
chatStore.assetsStore.channelIdToUserTwitch,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue