Skip to content

Commit

Permalink
Update AmityUIKit v4.0.0-beta29
Browse files Browse the repository at this point in the history
  • Loading branch information
ZayYarHtun committed Nov 22, 2024
1 parent 227f851 commit 4547b94
Show file tree
Hide file tree
Showing 24 changed files with 821 additions and 630 deletions.
8 changes: 4 additions & 4 deletions UpstraUIKit/AmityUIKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
1AF0D2CA251371780083D12C /* Log.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1AF0D2C9251371780083D12C /* Log.swift */; };
68251A632ADEA16200395696 /* AmityPreviewLinkCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 68251A612ADEA16200395696 /* AmityPreviewLinkCell.swift */; };
68251A642ADEA16200395696 /* AmityPreviewLinkCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 68251A622ADEA16200395696 /* AmityPreviewLinkCell.xib */; };
682E02182CF0AE4D00FE1042 /* SharedFrameworks in Frameworks */ = {isa = PBXBuildFile; productRef = 682E02172CF0AE4D00FE1042 /* SharedFrameworks */; };
6860B01B2ADE3D650042ED45 /* AmityPreviewLinkWizard.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6860B01A2ADE3D650042ED45 /* AmityPreviewLinkWizard.swift */; };
686E488F2B19A44900591E2D /* AmityStoryTabViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 686E488D2B19A44900591E2D /* AmityStoryTabViewController.swift */; };
686E48902B19A44900591E2D /* AmityStoryTabViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 686E488E2B19A44900591E2D /* AmityStoryTabViewController.xib */; };
Expand Down Expand Up @@ -659,7 +660,6 @@
D4D7683E26006D7000AD4367 /* AmitySettingContentIcon.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4D7683D26006D7000AD4367 /* AmitySettingContentIcon.swift */; };
D4EC11E525B93DCE0095F507 /* AmityPostSharingSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4EC11E425B93DCE0095F507 /* AmityPostSharingSettings.swift */; };
D4EC11EA25B93E000095F507 /* AmityPostSharingTarget.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4EC11E925B93E000095F507 /* AmityPostSharingTarget.swift */; };
ED5232192CDE38FB00ABA50D /* SharedFrameworks in Frameworks */ = {isa = PBXBuildFile; productRef = ED5232182CDE38FB00ABA50D /* SharedFrameworks */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -1340,7 +1340,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
ED5232192CDE38FB00ABA50D /* SharedFrameworks in Frameworks */,
682E02182CF0AE4D00FE1042 /* SharedFrameworks in Frameworks */,
68F5D9FA2B481E4000A9FA0D /* AmityUIKit4.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -4507,7 +4507,7 @@
);
name = AmityUIKit;
packageProductDependencies = (
ED5232182CDE38FB00ABA50D /* SharedFrameworks */,
682E02172CF0AE4D00FE1042 /* SharedFrameworks */,
);
productName = UpstraUIKit;
productReference = 72A3503024EA811500DA9D46 /* AmityUIKit.framework */;
Expand Down Expand Up @@ -5523,7 +5523,7 @@
/* End XCConfigurationList section */

/* Begin XCSwiftPackageProductDependency section */
ED5232182CDE38FB00ABA50D /* SharedFrameworks */ = {
682E02172CF0AE4D00FE1042 /* SharedFrameworks */ = {
isa = XCSwiftPackageProductDependency;
productName = SharedFrameworks;
};
Expand Down
22 changes: 19 additions & 3 deletions UpstraUIKit/AmityUIKit4/AmityUIKit4.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
68124D9F2B1748DE009B5B4C /* AmityProgressBarElement.swift in Sources */ = {isa = PBXBuildFile; fileRef = 68124D9E2B1748DE009B5B4C /* AmityProgressBarElement.swift */; };
682C76172B3208CC00018F80 /* StoryPermissionChecker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 682C76162B3208CC00018F80 /* StoryPermissionChecker.swift */; };
682C761B2B3302AB00018F80 /* AmityUIKitConfig.json in Resources */ = {isa = PBXBuildFile; fileRef = 682C761A2B3302AB00018F80 /* AmityUIKitConfig.json */; };
682E020E2CEE6A7900FE1042 /* AmityViewStoryPageViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 682E020D2CEE6A7900FE1042 /* AmityViewStoryPageViewModel.swift */; };
682E02122CEE6A8200FE1042 /* StoryCoreViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 682E020F2CEE6A8200FE1042 /* StoryCoreViewModel.swift */; };
682E02132CEE6A8200FE1042 /* StoryImageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 682E02102CEE6A8200FE1042 /* StoryImageView.swift */; };
682E02142CEE6A8200FE1042 /* StoryVideoView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 682E02112CEE6A8200FE1042 /* StoryVideoView.swift */; };
682E02162CF0AE3D00FE1042 /* SharedFrameworks in Frameworks */ = {isa = PBXBuildFile; productRef = 682E02152CF0AE3D00FE1042 /* SharedFrameworks */; };
683B9D642C995AFF005619FE /* AmityUserProfileHeaderComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 683B9D632C995AFF005619FE /* AmityUserProfileHeaderComponent.swift */; };
683DF10A2C6B1CAD005BF06C /* AmityCommunityAddUserPage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 683DF1092C6B1CAD005BF06C /* AmityCommunityAddUserPage.swift */; };
683DF10C2C6B27A4005BF06C /* AmityUserModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 683DF10B2C6B27A4005BF06C /* AmityUserModel.swift */; };
Expand Down Expand Up @@ -494,7 +499,6 @@
ED2D02712CB6354C00BF94FA /* PostContentPollView.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED2D02702CB6354C00BF94FA /* PostContentPollView.swift */; };
ED4FA84A2BA01123005D6871 /* AmityLiveChatHeaderViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED4FA8492BA01123005D6871 /* AmityLiveChatHeaderViewModel.swift */; };
ED4FA84C2BA01169005D6871 /* ChannelManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED4FA84B2BA01169005D6871 /* ChannelManager.swift */; };
ED5232172CDE38EF00ABA50D /* SharedFrameworks in Frameworks */ = {isa = PBXBuildFile; productRef = ED5232162CDE38EF00ABA50D /* SharedFrameworks */; };
ED6EFA112CB39DB6003A176F /* AmityPollPostComposerPage.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED6EFA102CB39DB6003A176F /* AmityPollPostComposerPage.swift */; };
ED6EFA142CB3D3D2003A176F /* PollAnswerResultView.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED6EFA132CB3D3D2003A176F /* PollAnswerResultView.swift */; };
ED6EFA612CB4FE0F003A176F /* PollOptionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED6EFA602CB4FE0F003A176F /* PollOptionView.swift */; };
Expand All @@ -519,6 +523,10 @@
68124D9E2B1748DE009B5B4C /* AmityProgressBarElement.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AmityProgressBarElement.swift; sourceTree = "<group>"; };
682C76162B3208CC00018F80 /* StoryPermissionChecker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StoryPermissionChecker.swift; sourceTree = "<group>"; };
682C761A2B3302AB00018F80 /* AmityUIKitConfig.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = AmityUIKitConfig.json; sourceTree = "<group>"; };
682E020D2CEE6A7900FE1042 /* AmityViewStoryPageViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AmityViewStoryPageViewModel.swift; sourceTree = "<group>"; };
682E020F2CEE6A8200FE1042 /* StoryCoreViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StoryCoreViewModel.swift; sourceTree = "<group>"; };
682E02102CEE6A8200FE1042 /* StoryImageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StoryImageView.swift; sourceTree = "<group>"; };
682E02112CEE6A8200FE1042 /* StoryVideoView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StoryVideoView.swift; sourceTree = "<group>"; };
683B9D632C995AFF005619FE /* AmityUserProfileHeaderComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AmityUserProfileHeaderComponent.swift; sourceTree = "<group>"; };
683DF1092C6B1CAD005BF06C /* AmityCommunityAddUserPage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AmityCommunityAddUserPage.swift; sourceTree = "<group>"; };
683DF10B2C6B27A4005BF06C /* AmityUserModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AmityUserModel.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1034,7 +1042,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
ED5232172CDE38EF00ABA50D /* SharedFrameworks in Frameworks */,
682E02162CF0AE3D00FE1042 /* SharedFrameworks in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -1949,6 +1957,7 @@
68D11A312B2239440046D0FB /* ViewStory */ = {
isa = PBXGroup;
children = (
682E020D2CEE6A7900FE1042 /* AmityViewStoryPageViewModel.swift */,
68CC6A642B1733D10052B77E /* AmityViewStoryPage.swift */,
68D11A322B22399A0046D0FB /* ChildViews */,
);
Expand All @@ -1958,6 +1967,9 @@
68D11A322B22399A0046D0FB /* ChildViews */ = {
isa = PBXGroup;
children = (
682E020F2CEE6A8200FE1042 /* StoryCoreViewModel.swift */,
682E02102CEE6A8200FE1042 /* StoryImageView.swift */,
682E02112CEE6A8200FE1042 /* StoryVideoView.swift */,
68D11A332B2239C50046D0FB /* StoryCoreView.swift */,
68D11A352B223A000046D0FB /* ProgressBarView.swift */,
68D9BCC82C32FC2B0082685B /* StoryAdView.swift */,
Expand Down Expand Up @@ -2889,9 +2901,13 @@
6840981F2B313A6F00697E1B /* VideoCacheManager.swift in Sources */,
685F16CA2BFCAD060016685F /* MessageReactionConfiguration.swift in Sources */,
684AE10C2B0C5CFE00FD7270 /* AmityUIKit4.swift in Sources */,
682E020E2CEE6A7900FE1042 /* AmityViewStoryPageViewModel.swift in Sources */,
6877D37B2C75DA2F008B3598 /* AmityCommunityMembershipPage.swift in Sources */,
6861984C2C116AF900BA81BE /* AmityPostComposerPage.swift in Sources */,
686830332C993D52009B1694 /* AmityUserProfilePage.swift in Sources */,
682E02122CEE6A8200FE1042 /* StoryCoreViewModel.swift in Sources */,
682E02132CEE6A8200FE1042 /* StoryImageView.swift in Sources */,
682E02142CEE6A8200FE1042 /* StoryVideoView.swift in Sources */,
689EE6A22BEDCB4E00927D51 /* PostManager.swift in Sources */,
68EE70C42C1AD40B005A7002 /* AmityMediaAttachmentViewModel.swift in Sources */,
A9CEB8212C7F19A10062823A /* AmityTrendingCommunitiesComponent.swift in Sources */,
Expand Down Expand Up @@ -3646,7 +3662,7 @@
/* End XCConfigurationList section */

/* Begin XCSwiftPackageProductDependency section */
ED5232162CDE38EF00ABA50D /* SharedFrameworks */ = {
682E02152CF0AE3D00FE1042 /* SharedFrameworks */ = {
isa = XCSwiftPackageProductDependency;
productName = SharedFrameworks;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,19 +101,29 @@ class TargetSelectionViewModel: ObservableObject {
communities.map { community -> AnyPublisher<AmityCommunityModel?, Never> in
let communityModel = AmityCommunityModel(object: community)

if community.onlyAdminCanPost {
// Story permission specifically need to check without considering onlyAdminCanPost
if contentType == .story {
return Future<AmityCommunityModel?, Never> { promise in
let permission: AmityPermission

switch contentType {
case .post, .poll:
permission = .createPrivilegedPost

case .story:
permission = .manageStoryCommunity
AmityUIKit4Manager.client.hasPermission(.manageStoryCommunity, forCommunity: community.communityId) { success in
let hasPermission = success
let allowAllUserCreation = AmityUIKitManagerInternal.shared.client.getSocialSettings()?.story?.allowAllUserToCreateStory ?? false
let hasStoryManagePermission = (allowAllUserCreation || hasPermission) && communityModel.isJoined

if hasStoryManagePermission {
promise(.success(communityModel))
} else {
promise(.success(nil))
}
}

AmityUIKit4Manager.client.hasPermission(permission, forCommunity: community.communityId) { success in
}
.eraseToAnyPublisher()
}

// Check for post permission
if community.onlyAdminCanPost {
return Future<AmityCommunityModel?, Never> { promise in
AmityUIKit4Manager.client.hasPermission(.createPrivilegedPost, forCommunity: community.communityId) { success in
if success {
promise(.success(communityModel))
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ public struct Pager<Element, ID, PageView>: View where PageView: View, Element:
/*** Constants ***/

/// Angle of rotation when should rotate
let rotationDegrees: Double = 20
let rotationDegrees: Double = -90

/// Axis of rotation when should rotate
let rotationAxis: (x: CGFloat, y: CGFloat, z: CGFloat) = (0, 1, 0)
let rotationAxis: (x: CGFloat, y: CGFloat, z: CGFloat) = (0, 1, 0.001)

/*** Dependencies ***/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ extension Pager {
/*** Constants ***/

/// Angle of rotation when should rotate
let rotationDegrees: Double = 20
let rotationDegrees: Double = -90

/// Axis of rotation when should rotate
let rotationAxis: (x: CGFloat, y: CGFloat, z: CGFloat) = (0, 1, 0)
let rotationAxis: (x: CGFloat, y: CGFloat, z: CGFloat) = (0, 1, 0.001)

/*** Dependencies ***/

Expand Down Expand Up @@ -197,6 +197,9 @@ extension Pager {
}
}
.offset(x: self.xOffset, y : self.yOffset)
.onChange(of: pagerModel.index) { index in
onPageChanged?(index)
}
}
.frame(size: size)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ extension String {
}

var isValidURL: Bool {
let detector = try! NSDataDetector(types: NSTextCheckingResult.CheckingType.link.rawValue)
if let match = detector.firstMatch(in: self, options: [], range: NSRange(location: 0, length: self.utf16.count)) {
let detector = try? NSDataDetector(types: NSTextCheckingResult.CheckingType.link.rawValue)
if let match = detector?.firstMatch(in: self, options: [], range: NSRange(location: 0, length: self.utf16.count)) {
// it is a link, if the match covers the whole string
return match.range.length == self.utf16.count
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public struct AmityCreatePostMenuComponent: AmityComponentView {
@Binding private var isPresented: Bool

@State private var showPostCreationMenuScaleEffect: Bool = false
private let allowAllUserToCreateStory = AmityUIKitManagerInternal.shared.client.getSocialSettings()?.story?.allowAllUserToCreateStory ?? false

public var id: ComponentId {
.createPostMenu
Expand Down Expand Up @@ -80,6 +81,7 @@ public struct AmityCreatePostMenuComponent: AmityComponentView {
.onTapGesture {
goToStoryCreation()
}
.isHidden(!allowAllUserToCreateStory)
.accessibilityIdentifier(AccessibilityID.Social.CreatePostMenu.createStoryButton)
case .poll:
let icon = AmityIcon.createPollMenuIcon
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ public class CommunityProfileViewModel: ObservableObject {
loadStories()
loadPinnedFeed()

Task { @MainActor in
hasStoryManagePermission = await StoryPermissionChecker.checkUserHasManagePermission(communityId: communityId)
}
}

deinit {
Expand All @@ -69,6 +66,14 @@ public class CommunityProfileViewModel: ObservableObject {

self?.pendingPostCount = community.pendingPostCount

// Check StoryManage Permission
Task { @MainActor [weak self] in
let hasPermission = await StoryPermissionChecker.checkUserHasManagePermission(communityId: community.communityId)
let allowAllUserCreation = AmityUIKitManagerInternal.shared.client.getSocialSettings()?.story?.allowAllUserToCreateStory ?? false

self?.hasStoryManagePermission = (allowAllUserCreation || hasPermission) && community.isJoined
}

if communityObject.onlyAdminCanPost {
AmityUIKit4Manager.client.hasPermission(.createPrivilegedPost, forCommunity: community.communityId) { success in
self?.hasCreatePostPermission = success && community.isJoined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ class AmityPostDetailPageViewModel: ObservableObject {
postObject = postManager.getPost(withId: postId)
token = postObject?.observe({ livePost, error in

if let snapshot = livePost.snapshot, let _ = snapshot.getPollInfo() {
if let snapshot = livePost.snapshot {
self.post = AmityPostModel(post: snapshot)
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,16 +163,25 @@ class AmityStoryTabComponentViewModel: ObservableObject {
}

private func loadCommunityStoryTarget(_ communityId: String) {
Task { @MainActor in
self.hasManagePermission = await StoryPermissionChecker.checkUserHasManagePermission(communityId: communityId)
}

storyTargetObject = storyManager.getStoryTarget(targetType: .community, targetId: communityId)
cancellable = nil
cancellable = storyTargetObject?.$snapshot
.sink(receiveValue: { [weak self] target in
guard let target else { return }

// Check StoryManage Permission
Task { @MainActor [weak self] in
let hasPermission = await StoryPermissionChecker.checkUserHasManagePermission(communityId: communityId)
let allowAllUserCreation = AmityUIKitManagerInternal.shared.client.getSocialSettings()?.story?.allowAllUserToCreateStory ?? false

guard let community = target.community else {
self?.hasManagePermission = false
return
}

self?.hasManagePermission = (allowAllUserCreation || hasPermission) && community.isJoined
}

if let existingModel = self?.communityFeedStoryTarget {
existingModel.updateModel(target)
} else {
Expand Down
Loading

0 comments on commit 4547b94

Please sign in to comment.