Skip to content

Commit

Permalink
Regular Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Lakr233 committed Mar 24, 2024
1 parent 62f4e1d commit 0a8f48b
Show file tree
Hide file tree
Showing 37 changed files with 269 additions and 249 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,13 @@ enum MultipartFormDataBoundaryGenerator {
}

static func boundary(forBoundaryType boundaryType: BoundaryType, boundaryKey: String) -> String {
let boundary: String
switch boundaryType {
let boundary = switch boundaryType {
case .initial:
boundary = "--\(boundaryKey)\(EncodingCharacters.crlf)"
"--\(boundaryKey)\(EncodingCharacters.crlf)"
case .encapsulated:
boundary = "\(EncodingCharacters.crlf)--\(boundaryKey)\(EncodingCharacters.crlf)"
"\(EncodingCharacters.crlf)--\(boundaryKey)\(EncodingCharacters.crlf)"
case .final:
boundary = "\(EncodingCharacters.crlf)--\(boundaryKey)--\(EncodingCharacters.crlf)"
"\(EncodingCharacters.crlf)--\(boundaryKey)--\(EncodingCharacters.crlf)"
}
return boundary
}
Expand Down
4 changes: 3 additions & 1 deletion Foundation/Source/Sources/Network/Network.swift
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,9 @@ public extension Network {
return
}

for (key, value) in dic { dictionaryBuilder[key] = value }
for (key, value) in dic {
dictionaryBuilder[key] = value
}
guard let newData = try? JSONSerialization
.data(withJSONObject: dictionaryBuilder, options: .fragmentsAllowed)
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,11 @@ extension TimelineSource {
guard !downloadResult.isEmpty, !isCancelled else { return }

let downloadAnchor = Anchor(dataset: downloadResult, ctx: base.ctx)
let inheritExists: Bool
switch direction {
let inheritExists: Bool = switch direction {
case .older:
inheritExists = true
true
case .newer:
inheritExists = downloadAnchor?.hasIntersection(to: base.anchor, withinCtx: base.ctx)
downloadAnchor?.hasIntersection(to: base.anchor, withinCtx: base.ctx)
?? false
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,48 @@
import Foundation

private let requestPermission = [
"read:admin",
"write:admin",

"read:account",
"write:account",
"read:blocks",
"write:blocks",
"read:channels",
"read:clip",
"read:drive",
"write:drive",
"read:favorites",
"write:favorites",
"read:federation",
"read:flash",
"read:following",
"write:following",
"read:gallery",
"read:invite",
"read:messaging",
"write:messaging",
"read:mutes",
"read:notifications",
"read:page",
"read:pages",
"read:reactions",
"read:user",

"write:account",
"write:blocks",
"write:channels",
"write:clip",
"write:drive",
"write:favorites",
"write:flash",
"write:following",
"write:gallery",
"write:invite",
"write:messaging",
"write:mutes",
"write:notes",
"read:notifications",
"write:notifications",
"read:reactions",
"write:page",
"write:pages",
"write:reactions",
"write:report-abuse",
"write:user",
"write:votes",
"read:pages",
"write:pages",
"write:page-likes",
"read:page-likes",
"read:user-groups",
"write:user-groups",
"read:channels",
"write:channels",
"read:gallery",
"write:gallery",
"read:gallery-likes",
]
.joined(separator: ",")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,10 @@ public extension Source.NetworkWrapper {
@discardableResult
func requestNoteReaction(reactionIdentifier emoji: String?, forNote noteId: NoteID?) -> Note? {
guard let ctx, let noteId else { return nil }
let result: NMNote?
if let emoji {
result = ctx.network.requestForReactionCreate(with: noteId, reaction: emoji)
let result: NMNote? = if let emoji {
ctx.network.requestForReactionCreate(with: noteId, reaction: emoji)
} else {
result = ctx.network.requestForReactionDelete(with: noteId)
ctx.network.requestForReactionDelete(with: noteId)
}
ctx.spider.spidering(result)
if let result { return .converting(result) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ class NoteTreeResolver {
let incompleteFather = iras.first?.incompleteFather
// incomplete 标记位应该是全部都统一的 不然不会是一个 father
#if DEBUG
for ira in iras { assert(ira.incompleteFather == incompleteFather) }
for ira in iras {
assert(ira.incompleteFather == incompleteFather)
}
#endif
// 将所有路径混合添加
let irb = IRB(father: fatherRoot, incompleteFather: incompleteFather)
Expand Down
80 changes: 40 additions & 40 deletions Foundation/Source/Tests/SourceTest/SourceTest+Meta.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,59 +45,59 @@ extension SourceTest {
private extension Network.RequestTarget {
var underlyingTestCase: Any? {
switch self {
case .meta: return SourceTest.test_200_api_instance.self
case .emojis: return SourceTest.test_200_api_instance.self
case .meta: SourceTest.test_200_api_instance.self
case .emojis: SourceTest.test_200_api_instance.self

case .account_i: return SourceTest.test_201_api_user.self
case .account_i: SourceTest.test_201_api_user.self

case .i_favorites: return SourceTest.test_202_api_i_favorites.self
case .i_notification: return SourceTest.test_204_api_i_notification.self
case .i_favorites: SourceTest.test_202_api_i_favorites.self
case .i_notification: SourceTest.test_204_api_i_notification.self

case .following_create: return SourceTest.test_203_api_following.self
case .following_delete: return SourceTest.test_203_api_following.self
case .following_requests_accept: return SourceTest.test_203_api_following.self
case .following_requests_reject: return SourceTest.test_203_api_following.self
case .following_requests_cancel: return SourceTest.test_203_api_following.self
case .following_invalidate: return SourceTest.test_203_api_following.self
case .following_create: SourceTest.test_203_api_following.self
case .following_delete: SourceTest.test_203_api_following.self
case .following_requests_accept: SourceTest.test_203_api_following.self
case .following_requests_reject: SourceTest.test_203_api_following.self
case .following_requests_cancel: SourceTest.test_203_api_following.self
case .following_invalidate: SourceTest.test_203_api_following.self

case .users: return SourceTest.test_203_api_following.self
case .users_report_abuse: return SourceTest.test_215_report_abuse.self
case .user_show: return SourceTest.test_203_api_following.self
case .users_followers: return SourceTest.test_203_api_following.self
case .users_following: return SourceTest.test_203_api_following.self
case .users: SourceTest.test_203_api_following.self
case .users_report_abuse: SourceTest.test_215_report_abuse.self
case .user_show: SourceTest.test_203_api_following.self
case .users_followers: SourceTest.test_203_api_following.self
case .users_following: SourceTest.test_203_api_following.self

case .user_notes: return SourceTest.test_205_api_user.self
case .user_notes: SourceTest.test_205_api_user.self

case .blocking_create: return SourceTest.test_206_api_block.self
case .blocking_delete: return SourceTest.test_206_api_block.self
case .blocking_create: SourceTest.test_206_api_block.self
case .blocking_delete: SourceTest.test_206_api_block.self

case .notes_create: return SourceTest.test_207_notes_create_delete.self
case .notes_delete: return SourceTest.test_207_notes_create_delete.self
case .notes_create: SourceTest.test_207_notes_create_delete.self
case .notes_delete: SourceTest.test_207_notes_create_delete.self

case .notes_show: return SourceTest.test_208_notes_status.self
case .notes_state: return SourceTest.test_208_notes_status.self
case .notes_show: SourceTest.test_208_notes_status.self
case .notes_state: SourceTest.test_208_notes_status.self

case .notes_reactions: return SourceTest.test_208_notes_status.self
case .notes_reactions_create: return SourceTest.test_208_notes_status.self
case .notes_reactions_delete: return SourceTest.test_208_notes_status.self
case .notes_favorites_create: return SourceTest.test_208_notes_status.self
case .notes_favorites_delete: return SourceTest.test_208_notes_status.self
case .notes_reactions: SourceTest.test_208_notes_status.self
case .notes_reactions_create: SourceTest.test_208_notes_status.self
case .notes_reactions_delete: SourceTest.test_208_notes_status.self
case .notes_favorites_create: SourceTest.test_208_notes_status.self
case .notes_favorites_delete: SourceTest.test_208_notes_status.self

case .notes_timeline: return SourceTest.test_209_timeline.self
case .notes_global_timeline: return SourceTest.test_209_timeline.self
case .notes_hybrid_timeline: return SourceTest.test_209_timeline.self
case .notes_local_timeline: return SourceTest.test_209_timeline.self
case .notes_timeline: SourceTest.test_209_timeline.self
case .notes_global_timeline: SourceTest.test_209_timeline.self
case .notes_hybrid_timeline: SourceTest.test_209_timeline.self
case .notes_local_timeline: SourceTest.test_209_timeline.self

case .notes_replies: return SourceTest.test_210_notes_replies.self
case .notes_search_by_tag: return SourceTest.test_211_notes_search.self
case .notes_polls_vote: return SourceTest.test_212_notes_polls_vote.self
case .notes_search: return SourceTest.test_211_notes_search.self
case .notes_replies: SourceTest.test_210_notes_replies.self
case .notes_search_by_tag: SourceTest.test_211_notes_search.self
case .notes_polls_vote: SourceTest.test_212_notes_polls_vote.self
case .notes_search: SourceTest.test_211_notes_search.self

case .hashtags_trend: return SourceTest.test_213_hashtag_trand.self
case .hashtags_trend: SourceTest.test_213_hashtag_trand.self

case .drive_files: return SourceTest.test_214_drive_file.self
case .drive_files_create: return SourceTest.test_214_drive_file.self
case .drive_files_update: return SourceTest.test_214_drive_file.self
case .drive_files: SourceTest.test_214_drive_file.self
case .drive_files_create: SourceTest.test_214_drive_file.self
case .drive_files_update: SourceTest.test_214_drive_file.self

// @unknown default: return nil
}
Expand Down
8 changes: 4 additions & 4 deletions Foundation/Source/Tests/SourceTest/Tests/User.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ extension SourceTest {
let ans = source.network.requestForUserFollowing(userId: userId)
unwrapOrFail(ans) { item in
var found = false
item.forEach { record in
for record in item {
XCTAssertEqual(record.followerId, userId)
if record.followeeId == user2.userId { found = true }
}
Expand All @@ -107,7 +107,7 @@ extension SourceTest {
let ans = source.network.requestForUserFollowing(userId: userId)
unwrapOrFail(ans) { item in
var found = false
item.forEach { record in
for record in item {
XCTAssertEqual(record.followeeId, userId)
if record.followeeId == user2.userId { found = true }
}
Expand Down Expand Up @@ -162,7 +162,7 @@ extension SourceTest {
let ans = source.network.requestForUserFollowers(userId: userId)
unwrapOrFail(ans) { item in
var found = false
item.forEach { record in
for record in item {
XCTAssertEqual(record.followeeId, userId)
if record.followerId == user2.userId { found = true }
}
Expand All @@ -185,7 +185,7 @@ extension SourceTest {
let ans = source.network.requestForUserFollowers(userId: userId)
unwrapOrFail(ans) { item in
var found = false
item.forEach { record in
for record in item {
XCTAssertEqual(record.followeeId, userId)
if record.followerId == user3.userId { found = true }
}
Expand Down
16 changes: 12 additions & 4 deletions Kimis/Backend/TextParser/TextParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,18 @@ extension TextParser {
replaceAttributeForSimpleUsername(with: string, defaultHost: defaultHost)
replaceAttributeForLinks(with: string)
replaceTinyEmoji(from: string, defaultHost: defaultHost)
while string.string.hasPrefix(" ") { string.deleteCharacters(in: NSRange(location: 0, length: 1)) }
while string.string.hasPrefix("\n") { string.deleteCharacters(in: NSRange(location: 0, length: 1)) }
while string.string.hasSuffix(" ") { string.deleteCharacters(in: NSRange(location: string.length - 1, length: 1)) }
while string.string.hasSuffix("\n") { string.deleteCharacters(in: NSRange(location: string.length - 1, length: 1)) }
while string.string.hasPrefix(" ") {
string.deleteCharacters(in: NSRange(location: 0, length: 1))
}
while string.string.hasPrefix("\n") {
string.deleteCharacters(in: NSRange(location: 0, length: 1))
}
while string.string.hasSuffix(" ") {
string.deleteCharacters(in: NSRange(location: string.length - 1, length: 1))
}
while string.string.hasSuffix("\n") {
string.deleteCharacters(in: NSRange(location: string.length - 1, length: 1))
}
attributeFullFill(string)
return string
}
Expand Down
5 changes: 3 additions & 2 deletions Kimis/Extension/Generic/Swift.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ import Foundation
@inline(__always)
func debugPrint(_ items: Any..., separator: String = " ", terminator: String = "\n") {
#if DEBUG
items.forEach {
Swift.print($0, separator: separator, terminator: terminator)
for item in items {
Swift.print(item, separator: separator, terminator: terminator)
}
#endif
}

#if DEBUG
import SDWebImage

func clearSDWebImageCache() {
SDImageCache.shared.clearMemory()
SDImageCache.shared.clearDisk()
Expand Down
8 changes: 4 additions & 4 deletions Kimis/Extension/Menu/ChidoriMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,14 @@ class ChidoriMenu: UIViewController {
let menuChildren: [UIMenu] = [wrapperMenu]
snapshot.appendSections(menuChildren)

menuChildren.forEach {
snapshot.appendItems($0.children as! [UIAction], toSection: $0)
for menuChild in menuChildren {
snapshot.appendItems(menuChild.children as! [UIAction], toSection: menuChild)
}
} else if let menuChildren = menu.children as? [UIMenu] {
snapshot.appendSections(menuChildren)

menuChildren.forEach {
snapshot.appendItems($0.children as! [UIAction], toSection: $0)
for menuChild in menuChildren {
snapshot.appendItems(menuChild.children as! [UIAction], toSection: menuChild)
}
} else {
preconditionFailure("Incorrect format. Do not mix UIAction and UIMenu in menu children for ChidoriMenu use.")
Expand Down
8 changes: 3 additions & 5 deletions Kimis/Extension/Menu/ChidoriPresentationController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,13 @@ class ChidoriPresentationController: UIPresentationController {
return min(rightMostPermissableXPosition, max(leftShiftedPoint, lowestPermissableXPosition))
}()

let y: CGFloat = {
// Check if we have enough room to place it below the touch point
let y: CGFloat = // Check if we have enough room to place it below the touch point
if summonPoint.y + menuSize.height + offsetFromFinger + requiredSidePadding < containerView.bounds.height - containerView.safeAreaInsets.bottom {
return summonPoint.y + offsetFromFinger
summonPoint.y + offsetFromFinger
} else {
// If not, iOS tries to keep as much in the bottom half of the screen as possible (to be closer to where the thumb normally is, presumably) so mimic that
return containerView.bounds.height - requiredSidePadding - containerView.safeAreaInsets.bottom - menuSize.height
containerView.bounds.height - requiredSidePadding - containerView.safeAreaInsets.bottom - menuSize.height
}
}()

return CGPoint(x: x, y: y)
}
Expand Down
Loading

0 comments on commit 0a8f48b

Please sign in to comment.