217 lines
7.0 KiB
TypeScript
217 lines
7.0 KiB
TypeScript
// Metro module 4867 (f4868).
|
|
import SpotifyStore from "../modules/spotify/SpotifyStore";
|
|
import UserSettingsProtoStore from "../modules/user_settings/UserSettingsProtoStore";
|
|
import DetectableGameStore from "./DetectableGameStore";
|
|
import IdleStore from "./IdleStore";
|
|
import LibraryApplicationStore from "./LibraryApplicationStore";
|
|
import LocalActivityStore from "./LocalActivityStore";
|
|
import PresenceStore, { sortActivity } from "./PresenceStore";
|
|
import SessionsStore from "./SessionsStore";
|
|
import { ActivityFlags, ActivityTypes, AppStates, StatusTypes } from "../Constants";
|
|
import { shouldShareApplicationActivity } from "../utils/LibraryApplicationUtils";
|
|
import { ShowCurrentGame, StatusSetting } from "../modules/user_settings/UserSettings";
|
|
import { hasFlag } from "../_bundle/Module1384";
|
|
import isListeningOnSpotify from "../modules/activities/utils/isListeningOnSpotify";
|
|
import isUndefinedOrNull from "../_bundle/isUndefinedOrNull";
|
|
import Module12 from "../_bundle/Module12";
|
|
import Module589 from "../_bundle/Module589";
|
|
import Dispatcher from "../Dispatcher";
|
|
let invisible, ONLINE, UNKNOWN, since, c2998_20, activities, isAFK, c2998_23, remoteActivities, hiddenActivities, c2998_26, c2998_27, shouldShowActivity, handleUpdate;
|
|
const filterPlayingActivities = function filterPlayingActivities(a0) {
|
|
if (a0.length === 0) {
|
|
return a0;
|
|
}
|
|
const r24 = [];
|
|
const r2 = [];
|
|
for (const item of a0) {
|
|
if (item.type === ActivityTypes.PLAYING) {
|
|
r2.push(item);
|
|
} else {
|
|
r24.push(item);
|
|
}
|
|
}
|
|
if (r2.length === 0) {
|
|
return a0;
|
|
}
|
|
if (r2.length === 1) {
|
|
return a0;
|
|
}
|
|
return [...r24, [...r2].sort(sortActivity)[0]].sort(sortActivity);
|
|
};
|
|
shouldShowActivity = function shouldShowActivity(a0) {
|
|
let r37;
|
|
let flags = a0.flags;
|
|
if (flags == null) {
|
|
flags = 0;
|
|
}
|
|
if (hasFlag(flags, ActivityFlags.CONTEXTLESS)) {
|
|
return true;
|
|
}
|
|
const type = a0.type;
|
|
if (ActivityTypes.LISTENING === type) {
|
|
return isListeningOnSpotify(a0) ? SpotifyStore.shouldShowActivity() : a0.application_id != null && shouldShareApplicationActivity(a0.application_id, LibraryApplicationStore);
|
|
}
|
|
if (ActivityTypes.PLAYING === type) {
|
|
if (a0.application_id != null) {
|
|
r37 = shouldShareApplicationActivity(a0.application_id, LibraryApplicationStore);
|
|
} else {
|
|
const r31 = DetectableGameStore.searchGamesByName(a0.name);
|
|
r37 = r31.length === 1 ? shouldShareApplicationActivity(r31[0], LibraryApplicationStore) : ShowCurrentGame.getSetting();
|
|
}
|
|
return r37;
|
|
}
|
|
if (ActivityTypes.STREAMING !== type) {
|
|
ActivityTypes.WATCHING;
|
|
}
|
|
return a0.application_id == null || shouldShareApplicationActivity(a0.application_id, LibraryApplicationStore);
|
|
};
|
|
handleUpdate = function handleUpdate() {
|
|
let r8;
|
|
let r14 = IdleStore.getIdleSince();
|
|
if (r14 == null) {
|
|
r14 = 0;
|
|
}
|
|
since = r14;
|
|
isAFK = IdleStore.isAFK();
|
|
if (c2998_23) {
|
|
ONLINE = UNKNOWN;
|
|
r8 = UNKNOWN;
|
|
} else if (invisible) {
|
|
const INVISIBLE = StatusTypes.INVISIBLE;
|
|
ONLINE = INVISIBLE;
|
|
r8 = INVISIBLE;
|
|
} else {
|
|
r8 = StatusSetting.getSetting();
|
|
if (r8 === StatusTypes.UNKNOWN) {
|
|
r8 = StatusTypes.ONLINE;
|
|
}
|
|
ONLINE = r8;
|
|
}
|
|
if (r8 === StatusTypes.ONLINE && since > 0) {
|
|
ONLINE = StatusTypes.IDLE;
|
|
}
|
|
const r9 = !c2998_23 && ONLINE !== StatusTypes.INVISIBLE ? LocalActivityStore.getActivities().filter(shouldShowActivity) : [];
|
|
const isUndefinedOrNull2 = isUndefinedOrNull(c2998_20, r9);
|
|
let r3 = false;
|
|
if (!isUndefinedOrNull2) {
|
|
c2998_20 = r9;
|
|
activities = filterPlayingActivities(r9);
|
|
r3 = true;
|
|
}
|
|
const remoteActivities2 = SessionsStore.getRemoteActivities();
|
|
if (remoteActivities !== remoteActivities2) {
|
|
remoteActivities = remoteActivities2;
|
|
r3 = true;
|
|
}
|
|
const hiddenActivities2 = SessionsStore.getHiddenActivities();
|
|
if (hiddenActivities !== hiddenActivities2) {
|
|
hiddenActivities = hiddenActivities2;
|
|
}
|
|
if (r3) {
|
|
const r78 = Module12([...c2998_20, ...remoteActivities.filter((remoteActivity) => remoteActivity.type !== ActivityTypes.CUSTOM_STATUS)].sort(sortActivity)).uniqBy((item) => `${item.type}:${item.application_id}:${item.name}`).value();
|
|
c2998_26 = r78;
|
|
c2998_27 = filterPlayingActivities(r78);
|
|
}
|
|
};
|
|
const handleConnectionOpen = function handleConnectionOpen() {
|
|
c2998_23 = false;
|
|
UNKNOWN = StatusTypes.UNKNOWN;
|
|
handleUpdate();
|
|
PresenceStore.setCurrentUserOnConnectionOpen(ONLINE, c2998_26);
|
|
};
|
|
invisible = false;
|
|
ONLINE = StatusTypes.ONLINE;
|
|
UNKNOWN = StatusTypes.UNKNOWN;
|
|
since = 0;
|
|
c2998_20 = [];
|
|
activities = [];
|
|
isAFK = false;
|
|
c2998_23 = true;
|
|
remoteActivities = Object.freeze([]);
|
|
hiddenActivities = Object.freeze([]);
|
|
c2998_26 = [];
|
|
c2998_27 = [];
|
|
class SelfPresenceStore extends Module589.Store {
|
|
static displayName = "SelfPresenceStore";
|
|
initialize() {
|
|
this.waitFor(DetectableGameStore, IdleStore, LibraryApplicationStore, LocalActivityStore, PresenceStore, SessionsStore, SpotifyStore, UserSettingsProtoStore);
|
|
this.syncWith([LocalActivityStore], handleUpdate);
|
|
}
|
|
getLocalPresence() {
|
|
return {
|
|
status: ONLINE,
|
|
since,
|
|
activities,
|
|
afk: isAFK
|
|
};
|
|
}
|
|
getStatus() {
|
|
return ONLINE;
|
|
}
|
|
getActivities(r1 = true) {
|
|
return r1 ? c2998_27 : activities;
|
|
}
|
|
getUnfilteredActivities(r1 = true) {
|
|
return r1 ? c2998_26 : c2998_20;
|
|
}
|
|
getHiddenActivities() {
|
|
return hiddenActivities;
|
|
}
|
|
getPrimaryActivity(r3 = true) {
|
|
return this.getActivities(r3)[0];
|
|
}
|
|
getApplicationActivity(c14478_0, r4 = true) {
|
|
return this.findActivity((a0) => a0.application_id === c14478_0, r4);
|
|
}
|
|
findActivity(a0, r4 = true) {
|
|
return this.getActivities(r4).find(a0);
|
|
}
|
|
}
|
|
const selfPresenceStore = new SelfPresenceStore(Dispatcher, {
|
|
START_SESSION: handleUpdate,
|
|
CONNECTION_OPEN: function handleConnectionOpenTracked() {
|
|
c2998_23 = false;
|
|
UNKNOWN = StatusTypes.UNKNOWN;
|
|
handleUpdate();
|
|
PresenceStore.setCurrentUserOnConnectionOpen(ONLINE, c2998_26);
|
|
},
|
|
CONNECTION_OPEN_SUPPLEMENTAL: handleConnectionOpen,
|
|
OVERLAY_INITIALIZE: handleConnectionOpen,
|
|
CONNECTION_CLOSED: handleUpdate,
|
|
IDLE: handleUpdate,
|
|
AFK: handleUpdate,
|
|
RUNNING_GAMES_CHANGE: handleUpdate,
|
|
STREAMING_UPDATE: handleUpdate,
|
|
USER_SETTINGS_PROTO_UPDATE: handleUpdate,
|
|
LOCAL_ACTIVITY_UPDATE: handleUpdate,
|
|
SPOTIFY_PLAYER_STATE: handleUpdate,
|
|
SPOTIFY_PLAYER_PLAY: handleUpdate,
|
|
USER_CONNECTIONS_UPDATE: handleUpdate,
|
|
SESSIONS_REPLACE: handleUpdate,
|
|
RPC_APP_DISCONNECTED: handleUpdate,
|
|
LIBRARY_FETCH_SUCCESS: handleUpdate,
|
|
LIBRARY_APPLICATION_FLAGS_UPDATE_SUCCESS: handleUpdate,
|
|
LOGOUT: function handleLogout() {
|
|
c2998_23 = true;
|
|
UNKNOWN = ONLINE;
|
|
handleUpdate();
|
|
},
|
|
FORCE_INVISIBLE: function handleForceInvisible(a0) {
|
|
invisible = a0.invisible;
|
|
handleUpdate();
|
|
},
|
|
WINDOW_FOCUS: function handleWindowFocus() {
|
|
invisible = false;
|
|
handleUpdate();
|
|
},
|
|
APP_STATE_UPDATE: function handleAppStateUpdate(a0) {
|
|
if (a0.state === AppStates.ACTIVE && invisible) {
|
|
invisible = false;
|
|
handleUpdate();
|
|
return void 0;
|
|
}
|
|
return false;
|
|
}
|
|
});
|
|
export default selfPresenceStore;
|