Skip to content

Commit

Permalink
render tenor gifs locally - needs DCE 2.42.3+ exports
Browse files Browse the repository at this point in the history
  • Loading branch information
slatinsky committed Nov 12, 2023
1 parent a23b7d1 commit 5c772f8
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
13 changes: 12 additions & 1 deletion backend/preprocess/JsonProcessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,21 @@ def process_messages(self, messages, guild_id, channel_id, channel_name):
embed["thumbnail"] = self.asset_processor.process(embed["thumbnail"]["url"], is_searchable=False)

# restore some fields, because we are losing them in the asset preprocess if url is remote
if "originalWidth" in locals():
if "original_width" in locals():
embed["thumbnail"]["width"] = original_width
embed["thumbnail"]["height"] = original_height

if "video" in embed:
if "width" in embed["video"] and "height" in embed["video"]:
original_width2 = embed["video"]["width"]
original_height2 = embed["video"]["height"]
embed["video"] = self.asset_processor.process(embed["video"]["url"], is_searchable=False)

# restore some fields, because we are losing them in the asset preprocess if url is remote
if "original_width2" in locals():
embed["video"]["width"] = original_width2
embed["video"]["height"] = original_height2

# embed.image field is redundant - merge with embed.images field and remove duplicate images
# note - this field is not always duplicated with the first item in embed.images field - discordless uses only image field without creating embed.images field
if "image" in embed:
Expand Down
2 changes: 1 addition & 1 deletion backend/preprocess/main_mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def wipe_database(database: MongoDatabase):
Deletes all collections on version bump (on program update)
Change EXPECTED_VERSION to force wipe on incompatible schema changes
"""
EXPECTED_VERSION = 14 # <---- change this to wipe database
EXPECTED_VERSION = 15 # <---- change this to wipe database
config = database.get_collection("config")

# add empty whitelisted_guild_ids config if it does not exist
Expand Down
10 changes: 9 additions & 1 deletion frontend/src/components/messages/MessageEmbeds.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@
</script>

{#each embeds as embed}
{#if tenorId && $online && $gifs}
{#if tenorId && embed.hasOwnProperty('video')}
<!-- render video gifs locally, video field was added in DCE 2.42.3 -->
<video class="chatlog__embed-thumbnail-video" src="{checkUrl(embed.video)}" autoplay loop muted playsinline/>
{:else if tenorId && $online && $gifs && !embed.hasOwnProperty('video')}
<!-- workaround for older exports (embed tenor iframe) -->
<div class="embed-tenor-container" style="aspect-ratio: {embed.thumbnail?.width ?? 1} / {embed.thumbnail?.height ?? 1};">
<iframe class="embed-tenor" src="https://tenor.com/embed/{tenorId}" frameBorder="0" allowfullscreen style="aspect-ratio: {embed.thumbnail?.width ?? 1} / {embed.thumbnail?.height ?? 1};"></iframe>
</div>
Expand Down Expand Up @@ -196,4 +200,8 @@
max-width: 100%;
max-height: 100%;
}
.chatlog__embed-thumbnail-video {
max-width: 100%;
}
</style>
4 changes: 0 additions & 4 deletions frontend/src/components/messages/NewMessage.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -533,10 +533,6 @@
border-radius: 3px
}
.chatlog__embed-thumbnail-video {
max-width: 100%;
}
.chatlog__message-container--pinned {
background-color: #444037;
border-left: 2px solid #F0B132;
Expand Down

0 comments on commit 5c772f8

Please sign in to comment.