Skip to content

Commit

Permalink
Merge branch 'master' into crowdin/master
Browse files Browse the repository at this point in the history
  • Loading branch information
rinsuki committed Jul 18, 2024
2 parents 84c22e2 + 70caa51 commit 2a98471
Show file tree
Hide file tree
Showing 24 changed files with 319 additions and 71 deletions.
30 changes: 30 additions & 0 deletions Sources/Core/Mastodon/API/MastodonPost.swift
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ public struct MastodonPost: Codable, EmojifyProtocol, Hashable, MastodonIDAvaila

}

public enum MastodonReactionType {
case boost
case favorite
}

public struct MastodonCustomEmoji: Codable, Sendable {
public let shortcode: String
public let url: String
Expand Down Expand Up @@ -486,4 +491,29 @@ extension MastodonEndpoint {
self.postId = post.id
}
}

public struct GetPostReactedUsers: MastodonEndpointWithPagingProtocol {
public typealias Response = MastodonEndpointResponseWithPaging<[MastodonAccount]>

public var endpoint: String { "/api/v1/statuses/\(postId.string)/\(type == .boost ? "reblogged" : "favourited")_by" }
public let method = "GET"

public var query: [URLQueryItem] {
var q = [URLQueryItem]()
paging?.addToQuery(&q)
return q
}

public var type: MastodonReactionType
public var postId: MastodonID
public var limit: Int?
public var paging: MastodonPagingOption?

public init(post: MastodonPost, type: MastodonReactionType, limit: Int? = nil, paging: MastodonPagingOption? = nil) {
self.limit = limit
self.paging = paging
self.postId = post.id
self.type = type
}
}
}
4 changes: 2 additions & 2 deletions Sources/Mac/App/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
<key>CFBundlePackageType</key>
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<key>CFBundleShortVersionString</key>
<string>8.1</string>
<string>9.0</string>
<key>CFBundleVersion</key>
<string>289</string>
<string>291</string>
<key>LSMinimumSystemVersion</key>
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
<key>NSHumanReadableCopyright</key>
Expand Down
4 changes: 2 additions & 2 deletions Sources/Mac/Core/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
<key>CFBundlePackageType</key>
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<key>CFBundleShortVersionString</key>
<string>8.1</string>
<string>9.0</string>
<key>CFBundleVersion</key>
<string>289</string>
<string>291</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2019 rinsuki. All rights reserved.</string>
</dict>
Expand Down
4 changes: 2 additions & 2 deletions Sources/Mac/Extensions/iMastMacShare/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
<key>CFBundlePackageType</key>
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<key>CFBundleShortVersionString</key>
<string>8.1</string>
<string>9.0</string>
<key>CFBundleVersion</key>
<string>289</string>
<string>291</string>
<key>LSMinimumSystemVersion</key>
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
<key>NSExtension</key>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
//
// MastodonPostDetailReactedUsersViewController.swift
//
// iMast https://github.com/cinderella-project/iMast
//
// Created by user on 2024/07/18.
//
// ------------------------------------------------------------------------
//
// Copyright 2017-2021 rinsuki and other contributors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import UIKit
import Mew
import iMastiOSCore

class MastodonPostDetailReactedUsersViewController: UITableViewController, Instantiatable {
typealias Input = (type: MastodonReactionType, post: MastodonPost)
typealias Environment = MastodonUserToken

private var input: Input
internal let environment: Environment

let readmoreView = ReadmoreView()

var users: [MastodonAccount] = []
var paging: MastodonPagingOption? {
didSet {
readmoreView.state = paging == nil ? .allLoaded : .moreLoadable
}
}

required init(with input: Input, environment: Environment) {
self.input = input
self.environment = environment
super.init(style: .plain)
}

required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

override func viewDidLoad() {
super.viewDidLoad()

title = input.type == .boost ? L10n.Localizable.PostDetail.boost : L10n.Localizable.PostDetail.favorite
readmoreView.target = self
readmoreView.action = #selector(readMore)
readmoreView.setTableView(tableView)
tableView.tableFooterView = readmoreView
Task {
await load()
}
}

@MainActor func load(paging: MastodonPagingOption? = nil) async {
self.readmoreView.state = .loading
do {
let res = try await MastodonEndpoint.GetPostReactedUsers(
post: input.post,
type: input.type,
paging: paging
).request(with: environment)
users.append(contentsOf: res.content)
self.paging = res.paging.next
readmoreView.state = res.paging.next == nil ? .allLoaded : .moreLoadable
tableView.reloadData()
} catch {
readmoreView.state = .withError
readmoreView.lastError = error
}
}

@objc func readMore() {
guard readmoreView.state == .moreLoadable else {
return
}
Task {
await load(paging: paging)
}
}

// MARK: - Table view data source

override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return users.count
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let user = self.users[indexPath.row]
let cell = MastodonUserCell.getInstance()
cell.load(user: user)
return cell
}

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
self.tableView.deselectRow(at: indexPath, animated: true)
let newVC = UserProfileTopViewController.instantiate(self.users[indexPath.row], environment: self.environment)
navigationController?.pushViewController(newVC, animated: true)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,6 @@ class MastodonPostDetailReactionsViewController: UIViewController, Instantiatabl

func input(_ input: Input) {
var sections: [String] = []
if input.repostCount > 0 {
sections.append("\(input.repostCount)件のブースト")
}
if input.favouritesCount > 0 {
sections.append("\(input.favouritesCount)件のふぁぼ")
}
if let app = input.application {
sections.append("via \(app.name)")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ class MastodonPostDetailViewController: UITableViewController, Instantiatable, I
case boostedUser
case content
case poll
case reactions
case via
case boostsCount
case favouritesCount
case reactionBar
}

Expand Down Expand Up @@ -67,10 +69,16 @@ class MastodonPostDetailViewController: UITableViewController, Instantiatable, I
if input.originalPost.poll != nil {
dataSource.append(.poll)
}
if input.originalPost.repostCount > 0 || input.originalPost.favouritesCount > 0 || input.application != nil {
dataSource.append(.reactions)
if input.application != nil {
dataSource.append(.via)
}
dataSource.append(.reactionBar)
if input.originalPost.repostCount > 0 {
dataSource.append(.boostsCount)
}
if input.originalPost.favouritesCount > 0 {
dataSource.append(.favouritesCount)
}
self.dataSource = dataSource
}

Expand All @@ -80,6 +88,7 @@ class MastodonPostDetailViewController: UITableViewController, Instantiatable, I
// Do any additional setup after loading the view.
self.tableView.tableHeaderView = UIView(frame: .init(x: 0, y: 0, width: 0, height: 0.01)) // remove header space
self.tableView.cellLayoutMarginsFollowReadableWidth = true
self.tableView.separatorInset = .zero
TableViewCell<MastodonPostDetailBoostedUserViewController>.register(to: tableView)
TableViewCell<MastodonPostDetailContentViewController>.register(to: tableView)
TableViewCell<MastodonPostDetailPollViewController>.register(to: tableView)
Expand Down Expand Up @@ -167,13 +176,25 @@ class MastodonPostDetailViewController: UITableViewController, Instantiatable, I
input: self.input.originalPost,
parentViewController: self
)
case .reactions:
cell = TableViewCell<MastodonPostDetailReactionsViewController>.dequeued(
from: tableView,
for: indexPath,
input: self.input.originalPost,
parentViewController: self
)
case .via:
cell = .init(style: .subtitle, reuseIdentifier: nil)
cell.contentConfiguration = UIListContentConfiguration.cell() {
if let app = input.originalPost.application {
$0.text = "via \(app.name)"
}
}
case .boostsCount:
cell = .init(style: .subtitle, reuseIdentifier: nil)
cell.accessoryType = .disclosureIndicator
cell.contentConfiguration = UIListContentConfiguration.cell() {
$0.text = L10n.Localizable.Count.boost(input.originalPost.repostCount)
}
case .favouritesCount:
cell = .init(style: .default, reuseIdentifier: nil)
cell.accessoryType = .disclosureIndicator
cell.contentConfiguration = UIListContentConfiguration.cell() {
$0.text = L10n.Localizable.Count.favorites(input.originalPost.favouritesCount)
}
case .reactionBar:
cell = TableViewCell<MastodonPostDetailReactionBarViewController>.dequeued(
from: tableView,
Expand All @@ -185,6 +206,16 @@ class MastodonPostDetailViewController: UITableViewController, Instantiatable, I
return cell
}

override func tableView(_ tableView: UITableView, willSelectRowAt indexPath: IndexPath) -> IndexPath? {
let source = self.dataSource[indexPath.row]
switch source {
case .editedWarning, .boostedUser, .boostsCount, .favouritesCount:
return indexPath
default:
return nil
}
}

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let source = self.dataSource[indexPath.row]
switch source {
Expand All @@ -194,6 +225,12 @@ class MastodonPostDetailViewController: UITableViewController, Instantiatable, I
case .boostedUser:
let vc = UserProfileTopViewController.instantiate(input.account, environment: environment)
self.navigationController?.pushViewController(vc, animated: true)
case .boostsCount:
let vc = MastodonPostDetailReactedUsersViewController.instantiate((type: .boost, post: input.originalPost), environment: environment)
self.navigationController?.pushViewController(vc, animated: true)
case .favouritesCount:
let vc = MastodonPostDetailReactedUsersViewController.instantiate((type: .favorite, post: input.originalPost), environment: environment)
self.navigationController?.pushViewController(vc, animated: true)
default:
break
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/iOS/App/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>8.1</string>
<string>9.0</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
Expand All @@ -30,7 +30,7 @@
</dict>
</array>
<key>CFBundleVersion</key>
<string>289</string>
<string>291</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.social-networking</string>
<key>LSApplicationQueriesSchemes</key>
Expand Down
14 changes: 8 additions & 6 deletions Sources/iOS/App/Screens/Login/AddAccountIndexView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,14 @@ struct _AddAccountIndexView: View {
})
.navigationTitle(L10n.Login.title)
.toolbar {
ToolbarItem(placement: .topBarLeading) {
Button(action: {
viewModel.cancel()
}, label: {
Text(L10n.Localizable.cancel)
})
if viewModel.latestToken != nil {
ToolbarItem(placement: .topBarLeading) {
Button(action: {
viewModel.cancel()
}, label: {
Text(L10n.Localizable.cancel)
})
}
}
}
.background {
Expand Down
4 changes: 3 additions & 1 deletion Sources/iOS/App/Screens/NewPost/NewPostViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ class NewPostViewController: UIViewController, UITextViewDelegate, ObservableObj
contentView.textInput.becomeFirstResponder()

if let userActivity {
contentView.textInput.text = userActivity.newPostCurrentText ?? ""
if let newPostCurrentText = userActivity.newPostCurrentText {
contentView.textInput.text = newPostCurrentText
}
// メンションとかの後を選択する
let nowCount = contentView.textInput.text.nsLength
DispatchQueue.main.async {
Expand Down
14 changes: 14 additions & 0 deletions Sources/iOS/Core/Generated/strings_ios.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,16 @@ public enum L10n {
/// 文脈
public static let title = L10n.tr("Localizable", "bunmyaku.title")
}
public enum Count {
/// Plural format key: "%#@count@"
public static func boost(_ p1: Int) -> String {
return L10n.tr("Localizable", "count.boost", p1)
}
/// Plural format key: "%#@count@"
public static func favorites(_ p1: Int) -> String {
return L10n.tr("Localizable", "count.favorites", p1)
}
}
public enum CustomEmojis {
/// カスタム絵文字一覧
public static let title = L10n.tr("Localizable", "customEmojis.title")
Expand Down Expand Up @@ -168,8 +178,12 @@ public enum L10n {
public static let short = L10n.tr("Localizable", "localTimeline.short")
}
public enum PostDetail {
/// ブースト
public static let boost = L10n.tr("Localizable", "postDetail.boost")
/// 削除
public static let delete = L10n.tr("Localizable", "postDetail.delete")
/// ふぁぼ
public static let favorite = L10n.tr("Localizable", "postDetail.favorite")
/// 通報
public static let reportAbuse = L10n.tr("Localizable", "postDetail.reportAbuse")
/// 共有
Expand Down
4 changes: 2 additions & 2 deletions Sources/iOS/Core/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
<key>CFBundlePackageType</key>
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<key>CFBundleShortVersionString</key>
<string>8.1</string>
<string>9.0</string>
<key>CFBundleVersion</key>
<string>289</string>
<string>291</string>
</dict>
</plist>
Loading

0 comments on commit 2a98471

Please sign in to comment.