Skip to content

Commit

Permalink
fix: EventAPI channel sets & remove legacy cosmetics (#801)
Browse files Browse the repository at this point in the history
  • Loading branch information
Melonify authored Jul 28, 2023
1 parent 90a43a5 commit 512a5b5
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 119 deletions.
1 change: 0 additions & 1 deletion .env.dev
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ NODE_ENV=development
VITE_APP_SITE="http://localhost:4200"
VITE_APP_API="http://localhost:3100/v3"
VITE_APP_API_GQL="http://localhost:3000/v3/gql"
VITE_APP_API_REST_OLD="http://localhost:3100/v2"
VITE_APP_API_EVENTS="ws://localhost:3700/v3"
VITE_APP_API_EGVAULT="http://localhost:3444/v1"
VITE_APP_HOST="http://localhost:8080"
1 change: 0 additions & 1 deletion .env.production
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ NODE_ENV=production
VITE_APP_SITE="https://7tv.app"
VITE_APP_API="https://7tv.io/v3"
VITE_APP_API_GQL="https://7tv.io/v3/gql"
VITE_APP_API_REST_OLD="https://7tv.io/v2"
VITE_APP_API_EVENTS="wss://events.7tv.io/v3"
VITE_APP_API_EGVAULT="https://egvault.7tv.io/v1"
VITE_APP_HOST="https://extension.7tv.gg"
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG-nightly.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
- Fixed an issue where mentioning yourself would highlight the message
- Fixed an issue where replying to a thread starting from your own message would highlight the message
- Fixed an issue where emotes would take a long time to load if external emote providers gave slow response times
- Fixed a regression in previous nightly build causing channel emote sets to not receive EventAPI subscriptions
- Removed old deprecated fallback cosmetics fetching using the v2 API

### 3.0.14.1000

Expand Down
46 changes: 0 additions & 46 deletions src/common/Transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,52 +247,6 @@ export function convertFFZEmote(data: FFZ.Emote): SevenTV.Emote {
};
}

export function convertSeventvOldCosmetics(
data: SevenTV.OldCosmeticsResponse,
): [SevenTV.Cosmetic<"BADGE">[], SevenTV.Cosmetic<"PAINT">[]] {
const badges = [] as SevenTV.Cosmetic<"BADGE">[];
const paints = [] as SevenTV.Cosmetic<"PAINT">[];

for (const badge of data.badges) {
badges.push({
id: badge.id,
kind: "BADGE",
provider: "7TV",
user_ids: badge.users,
data: {
name: badge.name,
tooltip: badge.tooltip,
host: {
url: "//cdn.7tv.app/badge/" + badge.id,
files: [{ name: "1x" }, { name: "2x" }, { name: "3x" }],
},
},
} as SevenTV.Cosmetic<"BADGE">);
}

for (const paint of data.paints) {
paints.push({
id: paint.id,
kind: "PAINT",
provider: "7TV",
user_ids: paint.users,
data: {
name: paint.name,
angle: paint.angle,
color: paint.color,
function: paint.function.replace("-", "_").toUpperCase(),
image_url: paint.image_url ?? null,
repeat: paint.repeat ?? false,
shadows: paint.drop_shadows ?? [],
shape: paint.shape ?? null,
stops: paint.stops ?? [],
},
} as SevenTV.Cosmetic<"PAINT">);
}

return [badges, paints];
}

export function convertFfzBadges(data: FFZ.BadgesResponse): SevenTV.Cosmetic<"BADGE">[] {
const badges = [] as SevenTV.Cosmetic<"BADGE">[];

Expand Down
28 changes: 0 additions & 28 deletions src/types/app.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,34 +287,6 @@ declare namespace SevenTV {
ref_id: ObjectID;
}

interface OldCosmeticsResponse {
t: number;
badges: OldCosmeticBadge[];
paints: OldCosmeticPaint[];
}

interface OldCosmeticBadge {
id: ObjectID;
users: string[];
name: string;
tooltip: string;
urls: string[][];
}

interface OldCosmeticPaint {
id: ObjectID;
users: string[];
name: string;
function: string;
color: number | null;
stops: CosmeticPaintGradientStop[];
repeat: boolean;
angle: number;
shape?: string;
image_url?: string;
drop_shadows: CosmeticPaintShadow[];
}

type UserType = "" | "BOT" | "SYSTEM";

type ImageFormat = "AVIF" | "WEBP" | "PNG" | "GIF";
Expand Down
60 changes: 17 additions & 43 deletions src/worker/worker.http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,13 @@
import { BitField, EmoteSetFlags } from "@/common/Flags";
import { imageHostToSrcset } from "@/common/Image";
import { log } from "@/common/Logger";
import {
convertBttvEmoteSet,
convertFFZEmoteSet,
convertFfzBadges,
convertSeventvOldCosmetics,
} from "@/common/Transform";
import { convertBttvEmoteSet, convertFFZEmoteSet, convertFfzBadges } from "@/common/Transform";
import { db } from "@/db/idb";
import type { WorkerDriver } from "./worker.driver";
import type { WorkerPort } from "./worker.port";

namespace API_BASE {
export const SEVENTV = import.meta.env.VITE_APP_API;
export const SEVENTV_OLD = import.meta.env.VITE_APP_API_REST_OLD;
export const FFZ = "https://api.frankerfacez.com/v1";
export const BTTV = "https://api.betterttv.net/3";
}
Expand Down Expand Up @@ -124,6 +118,17 @@ export class WorkerHttp {
.where("id")
.equals(channel.id)
.modify((x) => x.set_ids.push(set.id));

if (set.provider == "7TV") {
this.driver.eventAPI.subscribe(
"emote_set.*",
{
object_id: set.id,
},
port,
channel.id,
);
}
};

// iterate results and store sets to DB
Expand Down Expand Up @@ -170,29 +175,24 @@ export class WorkerHttp {
this.writePresence(port.platform, port.user.id, channel.id, true);
}

// Send the legacy static cosmetics to the port
// Fetch 3rd party static cosmetics if relevant
Promise.all([
await this.API()
.seventv.loadOldCosmetics("twitch_id", this.driver.cache)
.catch((err) => log.error("Failed to load old cosmetics", err)),
port.providerExtensions.has("FFZ") // load ffz badges if their extension is installed
? await this.API()
.frankerfacez.loadCosmetics()
.catch(() => void 0)
: void 0,
]).then(([seventv, ffz]) => {
const converted = seventv ? convertSeventvOldCosmetics(seventv) : [];
const badges = [...(seventv ? converted[0] : []), ...(ffz ? convertFfzBadges(ffz) : [])];
const paints = converted[1] ?? [];
]).then(([ffz]) => {
const badges = [...(ffz ? convertFfzBadges(ffz) : [])];

setTimeout(() => {
port.postMessage("STATIC_COSMETICS_FETCHED", {
badges,
paints,
paints: [],
});
}, 5000);

log.info(`<Static Cosmetics> ${badges.length} badges, ${paints.length} paints`);
log.info(`<3rd Party Cosmetics> ${badges.length} badges`);
});
}

Expand Down Expand Up @@ -292,32 +292,6 @@ export const seventv = {

return Promise.resolve(userConn.user);
},

async loadOldCosmetics(
identifier: "twitch_id" | "login" | "object_id",
cache?: Cache | null,
): Promise<SevenTV.OldCosmeticsResponse> {
if (cache) {
const cached = await cache.match(API_BASE.SEVENTV_OLD + `/cosmetics?user_identifier=${identifier}`);
if (cached) {
log.debug("<API/Old> Old Cosmetics cache hit");
return Promise.resolve<SevenTV.OldCosmeticsResponse>(await cached.json());
}
}

const resp = await doRequest(API_BASE.SEVENTV_OLD, `cosmetics?user_identifier=${identifier}`).catch((err) =>
Promise.reject(err),
);
if (!resp || resp.status !== 200) {
return Promise.reject(resp);
}

if (cache) {
cache.add(resp.url);
}

return Promise.resolve<SevenTV.OldCosmeticsResponse>(await resp.json());
},
};

export const frankerfacez = {
Expand Down

0 comments on commit 512a5b5

Please sign in to comment.