Skip to content

Commit

Permalink
Sync Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Lakr233 committed Jul 19, 2023
1 parent d4a5667 commit 7f275e3
Show file tree
Hide file tree
Showing 33 changed files with 598 additions and 128 deletions.
1 change: 1 addition & 0 deletions Foundation/Source/Sources/Network/Network.swift
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ public extension Network {
setTask(task)
task.resume()
sem.wait()
session.finishTasksAndInvalidate()
}

func decodeRequest<T: Codable>(with data: Data?) -> T? {
Expand Down
19 changes: 19 additions & 0 deletions Foundation/Source/Sources/Network/Request/Request+Notes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,25 @@ public extension Network {
return requestForNote(with: noteId)
}

func requestForReactionUserList(with noteId: String, reaction: String, limit: Int) -> [NMUserLite]? {
var request = prepareRequest(for: .notes_reactions)
injectBodyForPost(for: &request, with: ["noteId": noteId])
injectBodyForPost(for: &request, with: ["type": reaction])
injectBodyForPost(for: &request, with: ["limit": limit])
var responseData: Data?
makeRequest(with: request) { data in
responseData = data
}
guard let responseData else { return nil }
guard let firstDecode = (
try? JSONSerialization.jsonObject(with: responseData)
) as? [[String: Any]] else { return nil }
let list = firstDecode.compactMap { $0["user"] }
return list.compactMap { element in // get key inside user
decodeRequest(with: try? JSONSerialization.data(withJSONObject: element))
}
}

/// get replies for this note
/// - Parameter noteId: id
/// - Returns: replies and extracted notes for cache
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ public class NotificationSource: ObservableObject {
}
}

@Published public internal(set) var badge: Int = 0
@Published public internal(set) var badgeCount: Int = 0
@Published public internal(set) var badge: Bool = false

@Published public internal(set) var readDate = Date(timeIntervalSince1970: 0) {
didSet {
Expand Down Expand Up @@ -82,10 +83,11 @@ public class NotificationSource: ObservableObject {

func recalculateBadgeValueAndUpdate() {
DispatchQueue.global().async {
self.badge = self.dataSource.filter {
let filteredList = self.dataSource.filter {
$0.createdAt > self.readDate
}
.count
self.badgeCount = filteredList.count
self.badge = !filteredList.isEmpty
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,16 @@ public extension Source.NetworkWrapper {
return nil
}

@discardableResult
func requestNoteReactionUserList(reactionIdentifier emoji: String?, forNote noteId: NoteID?) -> [User] {
guard let ctx, let noteId, let emoji else { return [] }
let result = ctx.network.requestForReactionUserList(with: noteId, reaction: emoji, limit: 100) ?? []
ctx.spider.spidering(result)
return result.map { userLite -> User in
User.converting(userLite, defaultHost: ctx.receipt.host)
}
}

@discardableResult
func requestForUserNotes(userHandler: String, type: Network.UserNoteFetchType, untilId: String?) -> [NoteID] {
guard let ctx else { return [] }
Expand Down
29 changes: 29 additions & 0 deletions Foundation/Source/Tests/SourceTest/Tests/Note.swift
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,14 @@ extension SourceTest {
}
}

// check reaction
dispatchAndWait {
let ans = source.network.requestForReactionUserList(with: nid, reaction: emoji, limit: 100)
unwrapOrFail(ans) { lst in
XCTAssert(lst.count == 0)
}
}

// reaction create
dispatchAndWait {
_ = source.network.requestForReactionCreate(with: nid, reaction: emoji)
Expand All @@ -202,6 +210,19 @@ extension SourceTest {
}
}

// check reaction
dispatchAndWait {
let ans = source.network.requestForReactionUserList(with: nid, reaction: emoji, limit: 100)
unwrapOrFail(ans) { reactionUserList in
XCTAssert(reactionUserList.count == 1)
let note = source.network.requestForNote(with: nid)
unwrapOrFail(note) { note in
XCTAssert(note.user.username.count > 0)
XCTAssert(note.user.username.lowercased() == reactionUserList.first?.username.lowercased())
}
}
}

// reaction delete
dispatchAndWait {
_ = source.network.requestForReactionDelete(with: nid)
Expand All @@ -212,6 +233,14 @@ extension SourceTest {
}
}

// check reaction again
dispatchAndWait {
let ans = source.network.requestForReactionUserList(with: nid, reaction: emoji, limit: 100)
unwrapOrFail(ans) { lst in
XCTAssert(lst.count == 0)
}
}

// favorite create
dispatchAndWait {
source.network.requestForNoteFavoriteCreate(with: nid)
Expand Down
16 changes: 12 additions & 4 deletions Kimis.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
504519CD296DB997009D613D /* SpoilerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 504519CC296DB997009D613D /* SpoilerView.swift */; };
504519D1296E8560009D613D /* UploadRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 504519D0296E855F009D613D /* UploadRequest.swift */; };
504519D3296E8588009D613D /* UploadCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 504519D2296E8588009D613D /* UploadCell.swift */; };
5046C92C2A67B7100039676B /* ReactionStrip+UserList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5046C92B2A67B7100039676B /* ReactionStrip+UserList.swift */; };
504E87C62937596500BDE03C /* NotificationTableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 504E87C52937596500BDE03C /* NotificationTableView.swift */; };
504E87CA2937783E00BDE03C /* NotificationCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 504E87C92937783E00BDE03C /* NotificationCell.swift */; };
504E87CC293779AA00BDE03C /* NotificationTableView+Footer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 504E87CB293779AA00BDE03C /* NotificationTableView+Footer.swift */; };
Expand Down Expand Up @@ -248,6 +249,7 @@
50E8DFD5297B19C600657910 /* PaddedTextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50E8DFD4297B19C600657910 /* PaddedTextField.swift */; };
50E8DFD8297B433100657910 /* LicenseController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50E8DFD7297B433100657910 /* LicenseController.swift */; };
50E8DFDC297B43C500657910 /* LICENSE in Resources */ = {isa = PBXBuildFile; fileRef = 50E8DFDB297B43C500657910 /* LICENSE */; };
50FAC1F32A651B4000125B2A /* ReactionStrip+BaseView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50FAC1F22A651B4000125B2A /* ReactionStrip+BaseView.swift */; };
50FD825B29757AC300738C27 /* TextParser+RegEx.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50FD825A29757AC300738C27 /* TextParser+RegEx.swift */; };
50FE1B1229336250000CE139 /* HashtagNoteController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50FE1B1129336250000CE139 /* HashtagNoteController.swift */; };
50FE1B152933ADE5000CE139 /* TrendingTableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50FE1B142933ADE5000CE139 /* TrendingTableView.swift */; };
Expand Down Expand Up @@ -314,6 +316,7 @@
504519CC296DB997009D613D /* SpoilerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SpoilerView.swift; sourceTree = "<group>"; };
504519D0296E855F009D613D /* UploadRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UploadRequest.swift; sourceTree = "<group>"; };
504519D2296E8588009D613D /* UploadCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UploadCell.swift; sourceTree = "<group>"; };
5046C92B2A67B7100039676B /* ReactionStrip+UserList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ReactionStrip+UserList.swift"; sourceTree = "<group>"; };
504E87C52937596500BDE03C /* NotificationTableView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationTableView.swift; sourceTree = "<group>"; };
504E87C92937783E00BDE03C /* NotificationCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationCell.swift; sourceTree = "<group>"; };
504E87CB293779AA00BDE03C /* NotificationTableView+Footer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NotificationTableView+Footer.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -494,6 +497,7 @@
50E8DFD4297B19C600657910 /* PaddedTextField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaddedTextField.swift; sourceTree = "<group>"; };
50E8DFD7297B433100657910 /* LicenseController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LicenseController.swift; sourceTree = "<group>"; };
50E8DFDB297B43C500657910 /* LICENSE */ = {isa = PBXFileReference; lastKnownFileType = text; path = LICENSE; sourceTree = "<group>"; };
50FAC1F22A651B4000125B2A /* ReactionStrip+BaseView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ReactionStrip+BaseView.swift"; sourceTree = "<group>"; };
50FD825A29757AC300738C27 /* TextParser+RegEx.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "TextParser+RegEx.swift"; sourceTree = "<group>"; };
50FE1B1129336250000CE139 /* HashtagNoteController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HashtagNoteController.swift; sourceTree = "<group>"; };
50FE1B142933ADE5000CE139 /* TrendingTableView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TrendingTableView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -556,11 +560,13 @@
isa = PBXGroup;
children = (
50443F952927ED270077523F /* ReactionStrip.swift */,
50FAC1F22A651B4000125B2A /* ReactionStrip+BaseView.swift */,
50126254292F7763002E1636 /* ReactionStrip+Snapshot.swift */,
5012624C292F76F2002E1636 /* ReactionStrip+Element.swift */,
50126252292F7752002E1636 /* ReactionStrip+EmojiView.swift */,
50126250292F7738002E1636 /* ReactionStrip+MoreView.swift */,
5012624E292F771A002E1636 /* ReactionStrip+ImageView.swift */,
5046C92B2A67B7100039676B /* ReactionStrip+UserList.swift */,
);
path = Reactions;
sourceTree = "<group>";
Expand Down Expand Up @@ -1526,6 +1532,7 @@
502F6E582968738F003691BE /* ToolbarView.swift in Sources */,
50AFDFE929305E9B00BEC741 /* NoteOperationStrip+More.swift in Sources */,
508FC83029632AB200B032D8 /* AnySnapshot.swift in Sources */,
50FAC1F32A651B4000125B2A /* ReactionStrip+BaseView.swift in Sources */,
504E87CE293779C200BDE03C /* NotificationTableView+Publisher.swift in Sources */,
504519A6296D55EC009D613D /* Toolbar+User.swift in Sources */,
50BED20129277D0E00C9D7E2 /* TextParser+TinyEmoji.swift in Sources */,
Expand Down Expand Up @@ -1638,6 +1645,7 @@
5069EBC0295EEA3B00677A3F /* UserCell+Render.swift in Sources */,
50AFDFE329305E8B00BEC741 /* NoteOperationStrip+Renote.swift in Sources */,
50BED1B729277D0E00C9D7E2 /* AES.swift in Sources */,
5046C92C2A67B7100039676B /* ReactionStrip+UserList.swift in Sources */,
5069EBB7295EE2B800677A3F /* UsersListTableView.swift in Sources */,
504E87D029377A1300BDE03C /* NotificationTableView+Render.swift in Sources */,
5057A9442961CFD10088A6D4 /* ChoiceView.swift in Sources */,
Expand Down Expand Up @@ -1863,7 +1871,7 @@
CODE_SIGN_ENTITLEMENTS = Kimis/KimisDebug.entitlements;
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "-";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 130;
CURRENT_PROJECT_VERSION = 140;
DEVELOPMENT_TEAM = 6CMYQQFFT8;
"ENABLE_HARDENED_RUNTIME[sdk=macosx*]" = YES;
GENERATE_INFOPLIST_FILE = YES;
Expand All @@ -1881,7 +1889,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.13;
MARKETING_VERSION = 1.14;
PRODUCT_BUNDLE_IDENTIFIER = wiki.qaq.kimis.inhouse;
PRODUCT_NAME = "$(TARGET_NAME)";
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
Expand All @@ -1902,7 +1910,7 @@
CODE_SIGN_ENTITLEMENTS = Kimis/Kimis.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 130;
CURRENT_PROJECT_VERSION = 140;
DEVELOPMENT_TEAM = 6CMYQQFFT8;
"ENABLE_HARDENED_RUNTIME[sdk=macosx*]" = YES;
GENERATE_INFOPLIST_FILE = YES;
Expand All @@ -1920,7 +1928,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.13;
MARKETING_VERSION = 1.14;
PRODUCT_BUNDLE_IDENTIFIER = as.wiki.qaq.kimis;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down
4 changes: 2 additions & 2 deletions Kimis/Interface/Component/ImageView/MKImageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,9 @@ class MKImageRenderView: UIView {
withMainActor { [weak self] in
assert(Thread.isMainThread)
if let self, ticket == self.ticket, let thumbnail {
self.imageView.image = thumbnail
imageView.image = thumbnail
self.imageData = imageData
self.blurView.setImage(withBlurHash: nil)
blurView.setImage(withBlurHash: nil)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Kimis/Interface/Component/Misc/BlurHashView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ class BlurHashView: UIView {
session = builderSession
loadImage(forHash: hash) { [weak self] image in
assert(Thread.isMainThread)
guard let self, self.session == builderSession else {
guard let self, session == builderSession else {
return
}
self.imageView.image = image
imageView.image = image
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,37 @@ extension NoteCell.Context {
note.attachments.map { .init(with: $0) }
}

static func createReactionStripElemetns(withNote note: Note, source: Source?) -> [ReactionStrip.Element] {
static func createReactionStripElemetns(withNote note: Note, source: Source?) -> [ReactionStrip.ReactionElement] {
guard let source else { return [] }
var buildReactions = [ReactionStrip.Element]()
var buildReactions = [ReactionStrip.ReactionElement]()
for (key, value) in note.reactions {
if key.hasPrefix(":"), key.hasSuffix(":") {
let name = String(key.dropFirst().dropLast())
let url = source.host
.appendingPathComponent("emoji")
.appendingPathComponent(name)
.appendingPathExtension("webp")
buildReactions.append(.init(text: nil, url: url, count: value, highlight: note.userReaction == key))
buildReactions.append(.init(
noteId: note.noteId,
text: nil,
url: url,
count: value,
highlight: note.userReaction == key,
representReaction: name
))
} else {
buildReactions.append(.init(text: key, url: nil, count: value, highlight: note.userReaction == key))
buildReactions.append(.init(
noteId: note.noteId,
text: key,
url: nil,
count: value,
highlight: note.userReaction == key
))
}
}
buildReactions.sort {
if $0.highlight { return true }
if $1.highlight { return false }
if $0.isUserReaction { return true }
if $1.isUserReaction { return false }
return ($0.text ?? $0.url?.absoluteString ?? "")
< ($1.text ?? $1.url?.absoluteString ?? "")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ extension NoteCell {
icon.contentMode = .scaleAspectFit
icon.image = UIImage.fluent(.arrow_collapse_all_filled)
label.text = "Load More Replies"
label.font = .systemFont(ofSize: CGFloat(AppConfig.current.defaultNoteFontSize), weight: .regular)
label.textColor = .accent
label.textAlignment = .left
label.numberOfLines = 1
Expand Down Expand Up @@ -94,7 +93,6 @@ extension NoteCell {
)

let horizontalSpacing = padding

label.frame = CGRect(
x: padding + avatarSize + horizontalSpacing,
y: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,22 @@ extension NoteCell {
icon.image = .fluent(.arrow_maximize_vertical_filled)
label.text = "Expend Collapsed Replies"
}

override func layoutSubviews() {
super.layoutSubviews()

let bounds = container.bounds
let padding = IH.preferredPadding(usingWidth: bounds.width)
let avatarSize = NotePreview.defaultAvatarSize + IH.preferredAvatarSizeOffset(usingWidth: width)
label.frame = CGRect(
x: padding + avatarSize + NotePreview.verticalSpacing,
y: 0,
width: 200,
height: bounds.height
)
let fontSize = CGFloat(AppConfig.current.defaultNoteFontSize)
+ IH.preferredFontSizeOffset(usingWidth: bounds.width - 2 * padding)
label.font = .systemFont(ofSize: fontSize, weight: .regular)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import UIKit

extension NoteCell {
class MoreReplyPaddedCell: NoteCell {
let label = UILabel()
var connectorAttach: LeftBottomCurveLine!
let connectorBall = UIView()
let connectorDown = UIView()
Expand All @@ -25,12 +24,6 @@ extension NoteCell {
container.addSubview(connectorAttach)
container.addSubview(connectorDown)
container.addSubview(connectorPass)
container.addSubview(label)

label.text = "Expend Collapsed Replies"
label.font = .systemFont(ofSize: CGFloat(AppConfig.current.defaultNoteFontSize), weight: .regular)
label.textColor = .accent
label.textAlignment = .left

connectorBall.backgroundColor = .separator
connectorDown.layer.maskedCorners = [
Expand Down Expand Up @@ -82,13 +75,6 @@ extension NoteCell {
width: connectorBall.frame.minX - 4 - connectorPass.frame.minX,
height: bounds.height / 2 + IH.connectorWidth / 2
)
let horizontalSpacing = padding
label.frame = CGRect(
x: connectorBall.frame.midX + smallerAvatarSize / 2 + horizontalSpacing,
y: 0,
width: 200,
height: bounds.height
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ extension NoteTableView {
)
.receive(on: DispatchQueue.main)
.sink { [weak self] value in
guard let self, self.option.useBuiltinRender else { return }
guard let self, option.useBuiltinRender else { return }
let ticket = UUID()
self.renderTicket = ticket
self.renderQueue.async {
renderTicket = ticket
renderQueue.async {
self.requestRenderUpdateReload(
target: value.0,
width: value.1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ extension NoteOperationStrip {

private func reactionCreate() {
let picker = EmojiPickerViewController(sourceView: reactButton) { [weak self] emoji in
guard let self, let source = self.source, let noteId = self.noteId else { return }
self.callingReactionUpdate(source: source, onNote: noteId, emojiOrDelete: emoji.emoji)
guard let self, let source, let noteId else { return }
callingReactionUpdate(source: source, onNote: noteId, emojiOrDelete: emoji.emoji)
}
associatedControllers.append(picker)
parentViewController?.present(picker, animated: true)
Expand Down
Loading

0 comments on commit 7f275e3

Please sign in to comment.