Skip to content

Commit

Permalink
Merge pull request #1371 from HomerSp/fix-google-chat-attachment-msgs
Browse files Browse the repository at this point in the history
Fix message content disappearing
  • Loading branch information
HomerSp committed Jul 28, 2021
2 parents 8cb37dc + 6f599ee commit e9e061b
Showing 1 changed file with 22 additions and 21 deletions.
43 changes: 22 additions & 21 deletions src/ui/models/conv.coffee
Expand Up @@ -14,39 +14,40 @@ preprocessMessage = (msg) ->

# Workaround for attachments sent through google chat not appearing correctly
if cont? and embed?.type_?[0] is 456
href = null
for seg in cont.segment ? []
index = -1
url = null
for seg, i in cont.segment ? []
if seg.type is "LINK" and seg.link_data?.link_target?
href = seg.link_data?.link_target
break
u = new URL(seg.link_data.link_target)
if u.hostname.includes 'chat.google.com'
url = u
index = i
break

if href?
url = new URL(href)
params = new URLSearchParams(url.search);
if url?
# Remove the 'I shared ...' message, newline and link
if index - 2 >= 0
cont.segment.splice(index - 2, 3)

isVideo = params.get('url_type') is 'STREAMING_URL'
thumburl = url
thumburl.searchParams.set 'url_type', 'FIFE_URL'
thumburl.searchParams.set 'sz', 's512'

params.set 'url_type', 'FIFE_URL'
params.set 'sz', 's512'

url.search = params.toString()
thumb = url.toString()

cont.segment = null
embed.type_[0] = 249
embed.data = "and0"
embed.plus_photo = {}
embed.plus_photo.data = {}
embed.plus_photo.data.thumbnail = {}
embed.plus_photo.data.thumbnail.image_url = href
embed.plus_photo.data.thumbnail.thumb_url = thumb
embed.plus_photo.data.thumbnail.image_url = url.toString()
embed.plus_photo.data.thumbnail.thumb_url = thumburl.toString()
embed.plus_photo.data.original_content_url = null
embed.plus_photo.data.media_type = if isVideo then 'MEDIA_TYPE_VIDEO' else 'MEDIA_TYPE_PHOTO'
embed.plus_photo.data.media_type = 'MEDIA_TYPE_PHOTO'

if isVideo
if url.searchParams.get('url_type') is 'STREAMING_URL'
embed.plus_photo.data.media_type = 'MEDIA_TYPE_VIDEO'
embed.plus_photo.videoinformation = {}
embed.plus_photo.videoinformation.thumb = url.toString()
embed.plus_photo.videoinformation.url = href
embed.plus_photo.videoinformation.thumb = thumburl.toString()
embed.plus_photo.videoinformation.url = url.toString()
embed.plus_photo.videoinformation.public = false
msg

Expand Down

0 comments on commit e9e061b

Please sign in to comment.