Skip to content

Commit

Permalink
feat: Share mail link (#1483)
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippeWeidmann committed Jul 11, 2024
2 parents d75d3f4 + fecc7e4 commit 73339e2
Show file tree
Hide file tree
Showing 14 changed files with 118 additions and 4 deletions.
15 changes: 14 additions & 1 deletion Mail/Views/Bottom sheets/Actions/ActionsPanelViewModifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ struct ActionsPanelViewModifier: ViewModifier {
@ModalState private var reportedForPhishingMessage: Message?
@ModalState private var messagesToMove: [Message]?
@ModalState private var flushAlert: FlushAlertState?
@ModalState private var shareMailLink: ShareMailLinkResult?

@Binding var messages: [Message]?
let originFolder: Folder?
Expand All @@ -60,7 +61,8 @@ struct ActionsPanelViewModifier: ViewModifier {
nearestMessagesToMoveSheet: $messagesToMove,
nearestReportJunkMessageActionsPanel: $reportForJunkMessage,
nearestReportedForPhishingMessageAlert: $reportedForPhishingMessage,
nearestReportedForDisplayProblemMessageAlert: $reportedForDisplayProblemMessage
nearestReportedForDisplayProblemMessageAlert: $reportedForDisplayProblemMessage,
nearestShareMailLinkPanel: $shareMailLink
)
}

Expand Down Expand Up @@ -89,5 +91,16 @@ struct ActionsPanelViewModifier: ViewModifier {
.customAlert(item: $flushAlert) { item in
FlushFolderAlertView(flushAlert: item, folder: originFolder)
}
.sheet(item: $shareMailLink) { shareMailLinkResult in
if #available(iOS 16.0, *) {
ActivityView(activityItems: [shareMailLinkResult.url])
.ignoresSafeArea(edges: [.bottom])
.presentationDetents([.medium, .large])
} else {
ActivityView(activityItems: [shareMailLinkResult.url])
.ignoresSafeArea(edges: [.bottom])
.backport.presentationDetents([.medium, .large])
}
}
}
}
4 changes: 4 additions & 0 deletions MailCore/API/Endpoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -277,4 +277,8 @@ public extension Endpoint {
static func downloadAllSwissTransferAttachments(stUuid: String) -> Endpoint {
return .swissTransfer(stUuid: stUuid).appending(path: "/files/download")
}

static func share(messageResource: String) -> Endpoint {
return .resource(messageResource).appending(path: "/share")
}
}
5 changes: 5 additions & 0 deletions MailCore/API/MailApiFetcher/MailApiFetcher+Common.swift
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,9 @@ public extension MailApiFetcher {
method: .post,
parameters: attachmentsToForward))
}

func shareMailLink(message: Message) async throws -> ShareMailLinkResult {
try await perform(request: authenticatedRequest(.share(messageResource: message.resource),
method: .post))
}
}
7 changes: 7 additions & 0 deletions MailCore/Cache/Actions/Action+List.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ extension Action: CaseIterable {
archive ? .archive : .moveToInbox,
star ? .unstar : .star,
print ? .print : nil,
.shareMailLink,
userIsStaff ? .reportDisplayProblem : nil
]
return (Action.quickActions, tempListActions.compactMap { $0 })
Expand Down Expand Up @@ -340,4 +341,10 @@ public extension Action {
iconResource: MailResourcesAsset.emailActionSend,
matomoName: ""
)
static let shareMailLink = Action(
id: "shareMailLink",
title: MailResourcesStrings.Localizable.shareEmail,
iconResource: MailResourcesAsset.emailActionShare,
matomoName: "shareLink"
)
}
11 changes: 8 additions & 3 deletions MailCore/Cache/Actions/ActionOrigin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public struct ActionOrigin {
private(set) var nearestReportJunkMessageActionsPanel: Binding<Message?>?
private(set) var nearestReportedForPhishingMessageAlert: Binding<Message?>?
private(set) var nearestReportedForDisplayProblemMessageAlert: Binding<Message?>?
private(set) var nearestShareMailLinkPanel: Binding<ShareMailLinkResult?>?

init(
type: ActionOriginType,
Expand All @@ -51,7 +52,8 @@ public struct ActionOrigin {
nearestMessagesToMoveSheet: Binding<[Message]?>? = nil,
nearestReportJunkMessageActionsPanel: Binding<Message?>? = nil,
nearestReportedForPhishingMessageAlert: Binding<Message?>? = nil,
nearestReportedForDisplayProblemMessageAlert: Binding<Message?>? = nil
nearestReportedForDisplayProblemMessageAlert: Binding<Message?>? = nil,
nearestShareMailLinkPanel: Binding<ShareMailLinkResult?>? = nil
) {
self.type = type
frozenFolder = folder?.freezeIfNeeded()
Expand All @@ -61,6 +63,7 @@ public struct ActionOrigin {
self.nearestReportJunkMessageActionsPanel = nearestReportJunkMessageActionsPanel
self.nearestReportedForPhishingMessageAlert = nearestReportedForPhishingMessageAlert
self.nearestReportedForDisplayProblemMessageAlert = nearestReportedForDisplayProblemMessageAlert
self.nearestShareMailLinkPanel = nearestShareMailLinkPanel
}

public static func toolbar(originFolder: Folder? = nil,
Expand All @@ -74,15 +77,17 @@ public struct ActionOrigin {
nearestMessagesToMoveSheet: Binding<[Message]?>? = nil,
nearestReportJunkMessageActionsPanel: Binding<Message?>? = nil,
nearestReportedForPhishingMessageAlert: Binding<Message?>? = nil,
nearestReportedForDisplayProblemMessageAlert: Binding<Message?>? = nil) -> ActionOrigin {
nearestReportedForDisplayProblemMessageAlert: Binding<Message?>? = nil,
nearestShareMailLinkPanel: Binding<ShareMailLinkResult?>? = nil) -> ActionOrigin {
return ActionOrigin(
type: .floatingPanel(source: source),
folder: originFolder,
nearestFlushAlert: nearestFlushAlert,
nearestMessagesToMoveSheet: nearestMessagesToMoveSheet,
nearestReportJunkMessageActionsPanel: nearestReportJunkMessageActionsPanel,
nearestReportedForPhishingMessageAlert: nearestReportedForPhishingMessageAlert,
nearestReportedForDisplayProblemMessageAlert: nearestReportedForDisplayProblemMessageAlert
nearestReportedForDisplayProblemMessageAlert: nearestReportedForDisplayProblemMessageAlert,
nearestShareMailLinkPanel: nearestShareMailLinkPanel
)
}

Expand Down
6 changes: 6 additions & 0 deletions MailCore/Cache/Actions/ActionsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,12 @@ public class ActionsManager: ObservableObject {
guard let message = messagesWithDuplicates.first else { return }
try await mailboxManager.apiFetcher.blockSender(message: message)
snackbarPresenter.show(message: MailResourcesStrings.Localizable.snackbarSenderBlacklisted(1))
case .shareMailLink:
guard let message = messagesWithDuplicates.first else { return }
let result = try await mailboxManager.apiFetcher.shareMailLink(message: message)
Task { @MainActor in
origin.nearestShareMailLinkPanel?.wrappedValue = result
}
default:
break
}
Expand Down
27 changes: 27 additions & 0 deletions MailCore/Models/ShareMailLinkResult.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
Infomaniak Mail - iOS App
Copyright (C) 2024 Infomaniak Network SA
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import Foundation

@frozen public struct ShareMailLinkResult: Codable, Identifiable {
public var id: String {
return url
}

public var url: String
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"images" : [
{
"filename" : "email-action-share.svg",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"preserves-vector-representation" : true,
"template-rendering-intent" : "template"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions MailResources/Localizable/de.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -1426,6 +1426,9 @@
/* loco:627a547ad27ea17771565867 */
"settingsTransferInBody" = "Im Nachrichtentext";

/* loco:668cdbc1a27f04dd51065022 */
"shareEmail" = "E-Mail austauschen";

/* loco:6538a602e0eb783378001bb2 */
"shortcutNextAction" = "Weiter";

Expand Down
3 changes: 3 additions & 0 deletions MailResources/Localizable/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -1426,6 +1426,9 @@
/* loco:627a547ad27ea17771565867 */
"settingsTransferInBody" = "In the message body";

/* loco:668cdbc1a27f04dd51065022 */
"shareEmail" = "Share email";

/* loco:6538a602e0eb783378001bb2 */
"shortcutNextAction" = "Next";

Expand Down
3 changes: 3 additions & 0 deletions MailResources/Localizable/es.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -1426,6 +1426,9 @@
/* loco:627a547ad27ea17771565867 */
"settingsTransferInBody" = "En el cuerpo del mensaje";

/* loco:668cdbc1a27f04dd51065022 */
"shareEmail" = "Compartir correo electrónico";

/* loco:6538a602e0eb783378001bb2 */
"shortcutNextAction" = "Siguiente";

Expand Down
3 changes: 3 additions & 0 deletions MailResources/Localizable/fr.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -1426,6 +1426,9 @@
/* loco:627a547ad27ea17771565867 */
"settingsTransferInBody" = "Dans le corps du message";

/* loco:668cdbc1a27f04dd51065022 */
"shareEmail" = "Partager l’e-mail";

/* loco:6538a602e0eb783378001bb2 */
"shortcutNextAction" = "Suivant";

Expand Down
3 changes: 3 additions & 0 deletions MailResources/Localizable/it.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -1426,6 +1426,9 @@
/* loco:627a547ad27ea17771565867 */
"settingsTransferInBody" = "Nel corpo del messaggio";

/* loco:668cdbc1a27f04dd51065022 */
"shareEmail" = "Condividi e-mail";

/* loco:6538a602e0eb783378001bb2 */
"shortcutNextAction" = "Avanti";

Expand Down

0 comments on commit 73339e2

Please sign in to comment.