Skip to content

Commit

Permalink
Fix 3484/3489/3502/3503
Browse files Browse the repository at this point in the history
  • Loading branch information
rehez committed Jan 12, 2017
1 parent d77097d commit 5b7c068
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 6 deletions.
4 changes: 2 additions & 2 deletions app/page/template/detail-view.htm
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<img class="detail-view-image" data-bind="attr: {src: image_src()}" data-uie-name="status-picture"/>
</div>
<footer class="detail-view-footer">
<!-- ko if: message_et().has_asset() && !message_et().is_ephemeral() -->
<!-- ko if: message_et().get_first_asset().download && !message_et().is_ephemeral() -->
<span class="detail-view-action-button" data-bind="click: click_on_download">
<span class="icon-download"></span>
<span data-bind="l10n_text: z.string.conversation_context_menu_download"></span>
Expand All @@ -30,7 +30,7 @@
<span data-bind="l10n_text: z.string.conversation_context_menu_delete"></span>
</span>
<!-- /ko -->
<!-- ko if: message_et().user().is_me && message_et.status() !== z.message.StatusType.SENDING && !conversation_et().removed_from_conversation() -->
<!-- ko if: message_et().user().is_me && message_et().status() !== z.message.StatusType.SENDING && !conversation_et().removed_from_conversation() -->
<span class="detail-view-action-button" data-bind="click: click_on_delete_for_everyone">
<span class="icon-delete-for-everyone"></span>
<span data-bind="l10n_text: z.string.conversation_context_menu_delete_everyone"></span>
Expand Down
2 changes: 2 additions & 0 deletions app/script/conversation/EventMapper.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,8 @@ class z.conversation.EventMapper
###
_map_asset_medium_image: (event, should_create_dummy_image) ->
asset_et = new z.entity.MediumImage event.data.id
asset_et.file_size = event.data.content_length
asset_et.file_type = event.data.content_type
asset_et.width = event.data.info.width
asset_et.height = event.data.info.height
asset_et.ratio = asset_et.height / asset_et.width
Expand Down
5 changes: 4 additions & 1 deletion app/script/entity/message/File.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ class z.entity.File extends z.entity.Asset
@preview_resource = ko.observable()

@download_progress = ko.pureComputed => @original_resource()?.download_progress()
@cancel_download = => @original_resource()?.cancel_download()

@upload_id = ko.observable()
@upload_progress = ko.observable()
Expand Down Expand Up @@ -116,6 +115,10 @@ class z.entity.File extends z.entity.Asset
@logger.error 'Failed to download asset', error
amplify.publish z.event.WebApp.ANALYTICS.EVENT, z.tracking.EventName.FILE.DOWNLOAD_FAILED, tracking_data

cancel_download: =>
@status z.assets.AssetTransferState.UPLOADED
@original_resource()?.cancel_download()

cancel: (message_et) =>
amplify.publish z.event.WebApp.CONVERSATION.ASSET.CANCEL, message_et

Expand Down
18 changes: 18 additions & 0 deletions app/script/entity/message/MediumImage.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,23 @@ class z.entity.MediumImage extends z.entity.Asset
@width = '0px'
@height = '0px'

@file_name = ''
@file_size = ''
@file_type = ''

# z.assets.AssetRemoteData
@resource = ko.observable()

###
# TODO combine with file
Loads and decrypts otr asset as initiates download
@return [Promise] Returns a promise that resolves with the asset as blob
###
download: (file_name) =>
@resource()?.load().then (blob) =>
if file_name? or not @file_name
file_extension = @file_type.split('/').pop()
file_name = "#{file_name}.#{file_extension}"
else
file_name = @file_name
return z.util.download_blob blob, file_name
4 changes: 3 additions & 1 deletion app/script/view_model/ImageDetailViewViewModel.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ class z.ViewModel.ImageDetailViewViewModel
@image_modal.hide()

click_on_download: ->
message_et?.get_first_asset()?.download()
date = moment @message_et().timestamp
name = "Wire #{date.format('YYYY-MM-DD')} at #{date.format('h.mm.ss')}"
@message_et().get_first_asset().download name

click_on_like: =>
@conversation_repository.toggle_like @conversation_et(), @message_et()
Expand Down
6 changes: 4 additions & 2 deletions app/script/view_model/MessageListViewModel.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ class z.ViewModel.MessageListViewModel

@_track_context_menu message_et

if message_et.has_asset() and not message_et.is_ephemeral()
if message_et.get_first_asset()?.download? and not message_et.is_ephemeral()
entries.push {label: z.string.conversation_context_menu_download, action: 'download'}

if message_et.is_reactable() and not @conversation().removed_from_conversation()
Expand Down Expand Up @@ -427,7 +427,9 @@ class z.ViewModel.MessageListViewModel
amplify.publish z.event.WebApp.WARNING.MODAL, z.ViewModel.ModalType.DELETE_EVERYONE_MESSAGE,
action: => @conversation_repository.delete_message_everyone @conversation(), message_et
when 'download'
message_et?.get_first_asset()?.download()
date = moment message_et.timestamp
name = "Wire #{date.format('YYYY-MM-DD')} at #{date.format('h.mm.ss')}"
message_et?.get_first_asset()?.download name
when 'edit'
amplify.publish z.event.WebApp.CONVERSATION.MESSAGE.EDIT, message_et
when 'react'
Expand Down
1 change: 1 addition & 0 deletions app/style/components/asset/file-asset.less
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ file-asset {
position: relative;
display: flex;
align-items: center;
width: 100%;
}

.file-icon {
Expand Down

0 comments on commit 5b7c068

Please sign in to comment.