Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS-2526 Analytics | Add extension for file objects if possible #1066

Merged
merged 5 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Anytype.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,7 @@
2E0A6CD92A3773F200A28AF2 /* LoginFlowOutput.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2E0A6CD82A3773F200A28AF2 /* LoginFlowOutput.swift */; };
2E0A6CDB2A3775D900A28AF2 /* LoginFlowCoordinatorAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2E0A6CDA2A3775D900A28AF2 /* LoginFlowCoordinatorAssembly.swift */; };
2E0A7D312BAC9F1800577AD6 /* ObjectImportType+Loc.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2E0A7D302BAC9F1800577AD6 /* ObjectImportType+Loc.swift */; };
2E0A7D332BB1FC0C00577AD6 /* FileDetails+Analytics.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2E0A7D322BB1FC0C00577AD6 /* FileDetails+Analytics.swift */; };
2E0B0D672B753B2A00ECC37F /* WalletRecoveryError+Localize.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2E0B0D662B753B2A00ECC37F /* WalletRecoveryError+Localize.swift */; };
2E0C65B62B9786FF00D33F5F /* RelationValueCoordinatorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2E0C65B52B9786FF00D33F5F /* RelationValueCoordinatorView.swift */; };
2E0C65B82B97870D00D33F5F /* RelationValueCoordinatorViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2E0C65B72B97870D00D33F5F /* RelationValueCoordinatorViewModel.swift */; };
Expand Down Expand Up @@ -2708,6 +2709,7 @@
2E0A6CD82A3773F200A28AF2 /* LoginFlowOutput.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginFlowOutput.swift; sourceTree = "<group>"; };
2E0A6CDA2A3775D900A28AF2 /* LoginFlowCoordinatorAssembly.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginFlowCoordinatorAssembly.swift; sourceTree = "<group>"; };
2E0A7D302BAC9F1800577AD6 /* ObjectImportType+Loc.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ObjectImportType+Loc.swift"; sourceTree = "<group>"; };
2E0A7D322BB1FC0C00577AD6 /* FileDetails+Analytics.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "FileDetails+Analytics.swift"; sourceTree = "<group>"; };
2E0B0D662B753B2A00ECC37F /* WalletRecoveryError+Localize.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "WalletRecoveryError+Localize.swift"; sourceTree = "<group>"; };
2E0C65B52B9786FF00D33F5F /* RelationValueCoordinatorView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RelationValueCoordinatorView.swift; sourceTree = "<group>"; };
2E0C65B72B97870D00D33F5F /* RelationValueCoordinatorViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RelationValueCoordinatorViewModel.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -6350,6 +6352,7 @@
2A39F3CC29ED9A7E005DE8F5 /* LayoutAlignment+Analytics.swift */,
2A1D2B3D2A42CD0300B07596 /* UIUserInterfaceStyle+Analytics.swift */,
2AAA09AC2AEBF2D200A446B8 /* BlockContentType+Analytics.swift */,
2E0A7D322BB1FC0C00577AD6 /* FileDetails+Analytics.swift */,
);
path = Converters;
sourceTree = "<group>";
Expand Down Expand Up @@ -11146,6 +11149,7 @@
53CC99A8280D6DD900C39CCF /* AnytypeAnalytics.swift in Sources */,
EAC5FD542657DD2E006BB24E /* EditorContentInsetsHelper.swift in Sources */,
3D3040F427E2193500FFE0EB /* ObjectHeaderFilledContentSwitfUIView.swift in Sources */,
2E0A7D332BB1FC0C00577AD6 /* FileDetails+Analytics.swift in Sources */,
537A73852677FA5F001FEBBB /* CustomTextView+UITextViewDelegate.swift in Sources */,
3DA7AD7E2712C7BF00EA45F6 /* CustomTextViewKeyboardAction.swift in Sources */,
2A80D0562ABAE17F00DB0513 /* EditorPageCoordinatorView.swift in Sources */,
Expand Down
3 changes: 3 additions & 0 deletions Anytype/Sources/Analytics/AnalyticsConstants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -344,12 +344,15 @@ enum AnalyticsWidgetSource {

enum AnalyticsObjectType {
case object(typeId: String)
case file(fileExt: String)
case custom

var analyticsId: String {
switch self {
case .object(let typeId):
return typeId
case .file(let fileExt):
return fileExt
case .custom:
return AnalyticsEventsTypeValues.customType
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ extension BlockContentType {
return "smartblock"
case .text:
return "text"
case let .file(fileType):
return fileType.rawValue
case let .file(data):
return data.fileExt.isEmpty ? data.contentType.rawValue : data.fileExt
case .divider:
return "divider"
case .bookmark:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Services

extension FileDetails {
var analyticsType: AnalyticsObjectType {
.file(fileExt: fileExt)
mgolovko marked this conversation as resolved.
Show resolved Hide resolved
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ final class ShareOptionsInteractor: ShareOptionsInteractorProtocol {
newObjectId = try await createBookmarkObject(url: AnytypeURL(url: url), spaceId: spaceId).id
blockInformation = BlockInformation.bookmark(targetId: newObjectId)
case let .file(url):
newObjectId = try await creatFileObject(url: url, spaceId: spaceId).id
newObjectId = try await createFileObject(url: url, spaceId: spaceId).id
blockInformation = BlockInformation.emptyLink(targetId: newObjectId)
}

Expand Down Expand Up @@ -144,12 +144,12 @@ final class ShareOptionsInteractor: ShareOptionsInteractorProtocol {
return newObject
}

private func creatFileObject(url: URL, spaceId: String) async throws -> FileDetails {
private func createFileObject(url: URL, spaceId: String) async throws -> FileDetails {
let data = FileData(path: url.relativePath, isTemporary: false)
let details = try await fileService.uploadFileObject(spaceId: spaceId, data: data, origin: .sharingExtension)

AnytypeAnalytics.instance().logCreateObject(
objectType: objectTypeProvider.analyticsType(id: details.type),
objectType: details.analyticsType,
route: .sharingExtension
)
return details
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ enum SlashActionMedia: CaseIterable {
var blockViewsType: BlockContentType {
switch self {
case .file:
return .file(.file)
return .file(FileBlockContentData(contentType: .file))
case .pictre:
return .file(.image)
return .file(FileBlockContentData(contentType: .image))
case .video:
return .file(.video)
return .file(FileBlockContentData(contentType: .video))
case .audio:
return .file(.audio)
return .file(FileBlockContentData(contentType: .audio))
case .bookmark:
return .bookmark(.page)
case .codeSnippet:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ struct BlockBuilder {
return .bookmark(.empty())
case let .divider(style):
return .divider(.init(style: style))
case let .file(type):
return .file(.empty(contentType: type))
case let .file(data):
return .file(.empty(contentType: data.contentType))
case .link:
return .link(.empty())
case let .relation(key: key):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ public enum BlockContent: Hashable {
case let .text(text):
return .text(text.contentType)
case let .file(file):
return .file(file.contentType)
return .file(
FileBlockContentData(
contentType: file.contentType,
fileExt: file.metadata.fileExt
)
)
case let .divider(divider):
return .divider(divider.style)
case let .bookmark(bookmark):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ public struct FileMetadata: Hashable {
self.mime = mime
self.addedAt = addedAt
}

public var fileExt: String {
mime.components(separatedBy: "/").last ?? ""
}
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
public enum BlockContentType: Hashable {
case smartblock(BlockSmartblock.Style)
case text(BlockText.Style)
case file(FileContentType)
case file(FileBlockContentData)
case divider(BlockDivider.Style)
case bookmark(BlockBookmark.Style)
case link(BlockLink.Appearance)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public struct BlockRestrictionsBuilder {
return build(textContentType: text)
case .divider:
return DividerBlockRestrictions()
case let .file(contentType):
switch contentType {
case let .file(data):
switch data.contentType {
case .image:
return ImageBlockRestrictions()
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,13 @@ public enum FileContentType: String, Hashable {
}
}
}

public struct FileBlockContentData: Hashable {
public let contentType: FileContentType
public let fileExt: String

public init(contentType: FileContentType, fileExt: String = "") {
self.contentType = contentType
self.fileExt = fileExt
}
}
Loading