Skip to content

Commit

Permalink
Merge pull request #133 from TwidereProject/fix/user-relationship
Browse files Browse the repository at this point in the history
Fix protected user timeline
  • Loading branch information
MainasuK committed May 12, 2023
2 parents d5c9371 + e8e7a9d commit 8c2169b
Show file tree
Hide file tree
Showing 39 changed files with 551 additions and 236 deletions.
2 changes: 1 addition & 1 deletion NotificationService/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<key>CFBundlePackageType</key>
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<key>CFBundleVersion</key>
<string>128</string>
<string>129</string>
<key>NSExtension</key>
<dict>
<key>NSExtensionPointIdentifier</key>
Expand Down
2 changes: 1 addition & 1 deletion ShareExtension/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<key>CFBundleShortVersionString</key>
<string>2.0.0</string>
<key>CFBundleVersion</key>
<string>128</string>
<string>129</string>
<key>NSExtension</key>
<dict>
<key>NSExtensionAttributes</key>
Expand Down
2 changes: 1 addition & 1 deletion TwidereSDK/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ let package = Package(
.package(url: "https://github.com/krzyzanowskim/CryptoSwift.git", from: "1.6.0"),
.package(url: "https://github.com/tid-kijyun/Kanna.git", from: "5.2.7"),
.package(url: "https://github.com/JohnSundell/CollectionConcurrencyKit.git", from: "0.2.0"),
.package(url: "https://github.com/TwidereProject/TwitterSDK.git", exact: "0.7.0"),
.package(url: "https://github.com/TwidereProject/TwitterSDK.git", exact: "0.8.0"),
.package(name: "ArkanaKeys", path: "../dependencies/ArkanaKeys"),
.package(name: "CoverFlowStackLayout", path: "../CoverFlowStackLayout"),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ public class ManagedObjectRecord<T: Managed>: Hashable {
}

public func object(in managedObjectContext: NSManagedObjectContext) -> T? {
return managedObjectContext.object(with: objectID) as? T
do {
return try managedObjectContext.existingObject(with: objectID) as? T
} catch {
assertionFailure(error.localizedDescription)
return nil
}
}

public static func == (lhs: ManagedObjectRecord<T>, rhs: ManagedObjectRecord<T>) -> Bool {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"images" : [
{
"filename" : "message.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"preserves-vector-representation" : true
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"images" : [
{
"filename" : "message.mini.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"preserves-vector-representation" : true
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"images" : [
{
"filename" : "lock and repeat.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"preserves-vector-representation" : true
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"images" : [
{
"filename" : "lock and repeat.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"preserves-vector-representation" : true
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"images" : [
{
"filename" : "Retweet-Off.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"preserves-vector-representation" : true
}
}
Binary file not shown.
7 changes: 6 additions & 1 deletion TwidereSDK/Sources/TwidereAsset/Generated/Assets.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ public enum Asset {
public static let ellipsisBubblePlus = ImageAsset(name: "Communication/ellipsis.bubble.plus")
public static let mail = ImageAsset(name: "Communication/mail")
public static let mailMiniInline = ImageAsset(name: "Communication/mail.mini.inline")
public static let textBubble = ImageAsset(name: "Communication/text.bubble")
public static let textBubbleMini = ImageAsset(name: "Communication/text.bubble.mini")
public static let textBubbleSmall = ImageAsset(name: "Communication/text.bubble.small")
}
public enum Editing {
Expand Down Expand Up @@ -148,9 +150,12 @@ public enum Asset {
public static let altRectangle = ImageAsset(name: "Media/alt.rectangle")
public static let gifRectangle = ImageAsset(name: "Media/gif.rectangle")
public static let playerRectangle = ImageAsset(name: "Media/player.rectangle")
public static let repeatOff = ImageAsset(name: "Media/repeat-off")
public static let `repeat` = ImageAsset(name: "Media/repeat")
public static let repeatLock = ImageAsset(name: "Media/repeat.lock")
public static let repeatLockMini = ImageAsset(name: "Media/repeat.lock.mini")
public static let repeatMini = ImageAsset(name: "Media/repeat.mini")
public static let repeatOff = ImageAsset(name: "Media/repeat.off")
public static let repeatOffMini = ImageAsset(name: "Media/repeat.off.mini")
}
public enum ObjectTools {
public static let bell = ImageAsset(name: "Object&Tools/bell")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ extension Twitter.API.Error.TwitterAPIError: LocalizedError {

public var errorDescription: String? {
switch self {
case .notAuthorizedToViewTheSpecifiedUser:
return L10n.Common.Alerts.PermissionDeniedNotAuthorized.title
case .userHasBeenSuspended:
return L10n.Common.Alerts.AccountSuspended.title
case .rateLimitExceeded:
Expand All @@ -32,6 +34,8 @@ extension Twitter.API.Error.TwitterAPIError: LocalizedError {

public var failureReason: String? {
switch self {
case .notAuthorizedToViewTheSpecifiedUser:
return L10n.Common.Alerts.PermissionDeniedNotAuthorized.message
case .userHasBeenSuspended:
let twitterRules = L10n.Common.Alerts.AccountSuspended.twitterRules
return L10n.Common.Alerts.AccountSuspended.message(twitterRules)
Expand Down
9 changes: 9 additions & 0 deletions TwidereSDK/Sources/TwidereCore/Model/User/UserObject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,15 @@ extension UserObject {
return object.avatar.flatMap { URL(string: $0) }
}
}

public var protected: Bool {
switch self {
case .twitter(let object):
return object.protected
case .mastodon(let object):
return object.locked
}
}
}

extension UserObject {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ extension StatusFetchViewModel.Timeline.User {
public struct TwitterFetchContext: Hashable {
public let authenticationContext: TwitterAuthenticationContext
public let userID: Twitter.Entity.V2.User.ID
public let protected: Bool
public let paginationToken: String?
public let maxID: Twitter.Entity.V2.Tweet.ID?
public let maxResults: Int?
Expand All @@ -37,6 +38,7 @@ extension StatusFetchViewModel.Timeline.User {
public init(
authenticationContext: TwitterAuthenticationContext,
userID: Twitter.Entity.V2.User.ID,
protected: Bool,
paginationToken: String?,
maxID: Twitter.Entity.V2.Tweet.ID?,
maxResults: Int?,
Expand All @@ -45,6 +47,7 @@ extension StatusFetchViewModel.Timeline.User {
) {
self.authenticationContext = authenticationContext
self.userID = userID
self.protected = protected
self.paginationToken = paginationToken
self.maxID = maxID
self.maxResults = maxResults
Expand All @@ -56,6 +59,7 @@ extension StatusFetchViewModel.Timeline.User {
return TwitterFetchContext(
authenticationContext: authenticationContext,
userID: userID,
protected: protected,
paginationToken: paginationToken,
maxID: maxID,
maxResults: maxResults,
Expand All @@ -68,6 +72,7 @@ extension StatusFetchViewModel.Timeline.User {
return TwitterFetchContext(
authenticationContext: authenticationContext,
userID: userID,
protected: protected,
paginationToken: paginationToken,
maxID: maxID,
maxResults: maxResults,
Expand Down Expand Up @@ -157,6 +162,9 @@ extension StatusFetchViewModel.Timeline.User {
switch fetchContext.timelineKind {
case .status, .media:
do {
guard !fetchContext.protected else {
throw Twitter.API.Error.ResponseError(httpResponseStatus: .ok, twitterAPIError: .rateLimitExceeded)
}
guard !fetchContext.needsAPIFallback else {
throw Twitter.API.Error.ResponseError(httpResponseStatus: .ok, twitterAPIError: .rateLimitExceeded)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,25 +50,26 @@ extension StatusFetchViewModel.Timeline.Kind {

public class UserTimelineContext {
public let timelineKind: TimelineKind
@Published public var protected: Bool?
@Published public var userIdentifier: UserIdentifier?

public init(
timelineKind: TimelineKind,
userIdentifier: Published<UserIdentifier?>.Publisher?
protected protectedPublisher: Published<Bool?>.Publisher?,
userIdentifier userIdentifierPublisher: Published<UserIdentifier?>.Publisher?
) {
self.timelineKind = timelineKind

if let userIdentifier = userIdentifier {
userIdentifier.assign(to: &self.$userIdentifier)

}
protectedPublisher?.assign(to: &$protected)
userIdentifierPublisher?.assign(to: &$userIdentifier)
}

public init(
timelineKind: TimelineKind,
protected: Bool,
userIdentifier: UserIdentifier?
) {
self.timelineKind = timelineKind
self.protected = protected
self.userIdentifier = userIdentifier
}

Expand Down Expand Up @@ -450,6 +451,7 @@ extension StatusFetchViewModel.Timeline {
return .user(.twitter(.init(
authenticationContext: authenticationContext,
userID: userIdentifier.id,
protected: userTimelineContext.protected ?? false,
paginationToken: nil,
maxID: nil,
maxResults: nil,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,23 @@ public struct MediaStackContainerView: View {
let dimension = min(root.size.width, root.size.height)
switch viewModel.items.count {
case 1:
MediaView(viewModel: viewModel.items[0])
.frame(width: dimension, height: dimension)
.clipShape(RoundedRectangle(cornerRadius: 12))
.overlay(alignment: .bottom) {
MediaMetaIndicatorView(viewModel: viewModel.items[0])
}
.overlay(
RoundedRectangle(cornerRadius: 12)
.stroke(Color(uiColor: .placeholderText).opacity(0.5), lineWidth: 1)
)
.onTapGesture {
handler(viewModel.items[0], .preview)
}
VStack {
Spacer()
MediaView(viewModel: viewModel.items[0])
.frame(width: dimension, height: dimension)
.clipShape(RoundedRectangle(cornerRadius: 12))
.overlay(alignment: .bottom) {
MediaMetaIndicatorView(viewModel: viewModel.items[0])
}
.overlay(
RoundedRectangle(cornerRadius: 12)
.stroke(Color(uiColor: .placeholderText).opacity(0.5), lineWidth: 1)
)
.onTapGesture {
handler(viewModel.items[0], .preview)
}
Spacer()
}
default:
CoverFlowStackScrollView {
HStack(spacing: .zero) {
Expand Down

0 comments on commit 8c2169b

Please sign in to comment.