Skip to content

Commit

Permalink
Merge pull request #392 from Darock-Studio/feat/comment-picture
Browse files Browse the repository at this point in the history
feat: Show pictures in comment
  • Loading branch information
Mark Chan authored Jul 28, 2024
2 parents f32bbaf + 4cf0da6 commit a69e7fe
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
2 changes: 1 addition & 1 deletion DarockBili.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 56;
objectVersion = 70;
objects = {

/* Begin PBXAggregateTarget section */
Expand Down
3 changes: 0 additions & 3 deletions Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -8941,9 +8941,6 @@
}
}
}
},
"手记建议" : {

},
"扩展的触感反馈" : {
"localizations" : {
Expand Down
6 changes: 6 additions & 0 deletions MeowBili/Extension/CodeExt.swift
Original file line number Diff line number Diff line change
Expand Up @@ -638,3 +638,9 @@ public func debugPrint(_ items: Any..., separator: String = " ", terminator: Str
}
}
}

extension String: @retroactive Identifiable {
public var id: Self {
self
}
}
23 changes: 22 additions & 1 deletion MeowBili/GlobalView/CommentsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ struct CommentsView: View {
@State var presentRepliesGoto = ""
@State var presentRepliesRootData = [String: String]()
@State var isCommentRepliesPresented = false
@State var presentImageItem: String?
var body: some View {
ScrollView {
LazyVStack {
Expand Down Expand Up @@ -93,6 +94,19 @@ struct CommentsView: View {
#endif
Spacer()
}
if !comments[i]["Pictures"]!.isEmpty {
let picUrls = comments[i]["Pictures"]!.components(separatedBy: "|")
ForEach(0..<picUrls.count, id: \.self) { i in
WebImage(url: URL(string: picUrls[i]))
.resizable()
.scaledToFit()
.cornerRadius(10)
.frame(maxHeight: 150)
.onTapGesture {
presentImageItem = picUrls[i]
}
}
}
if commentReplies[i].count != 0 {
VStack {
ForEach(0...commentReplies[i].count - 1, id: \.self) { j in
Expand Down Expand Up @@ -180,6 +194,9 @@ struct CommentsView: View {
#endif
.sheet(isPresented: $isCommentRepliesPresented, content: { CommentRepliesView(avid: id, type: type, goto: $presentRepliesGoto, rootData: $presentRepliesRootData) })
}
.sheet(item: $presentImageItem) { url in
ImageViewerView(url: url)
}
.toolbar {
ToolbarItem(placement: .topBarTrailing) {
Button(action: {
Expand Down Expand Up @@ -228,7 +245,11 @@ struct CommentsView: View {
commentReplies[calNum].append(["Text": sigReply.1["content"]["message"].string ?? "[加载失败]", "Sender": sigReply.1["member"]["uname"].string ?? "[加载失败]", "SenderPic": sigReply.1["member"]["avatar"].string ?? "E", "SenderID": sigReply.1["member"]["mid"].string ?? "E", "IP": sigReply.1["reply_control"]["location"].string ?? "", "UserAction": String(sigReply.1["action"].int ?? 0), "Rpid": String(sigReply.1["rpid"].int ?? -1), "Like": String(sigReply.1["like"].int ?? -1)])
}
let text = reply.1["content"]["message"].string ?? "[加载失败]"
comments.append(["Text": text, "Sender": reply.1["member"]["uname"].string ?? "[加载失败]", "SenderPic": reply.1["member"]["avatar"].string ?? "E", "SenderID": reply.1["member"]["mid"].string ?? "E", "IP": reply.1["reply_control"]["location"].string ?? "", "UserAction": String(reply.1["action"].int ?? 0), "Rpid": reply.1["rpid_str"].string ?? "-1", "Like": String(reply.1["like"].int ?? -1)])
var pictures = [String]()
for pic in reply.1["content"]["pictures"].arrayValue {
pictures.append(pic["img_src"].string ?? "[加载失败]")
}
comments.append(["Text": text, "Sender": reply.1["member"]["uname"].string ?? "[加载失败]", "SenderPic": reply.1["member"]["avatar"].string ?? "E", "SenderID": reply.1["member"]["mid"].string ?? "E", "IP": reply.1["reply_control"]["location"].string ?? "", "UserAction": String(reply.1["action"].int ?? 0), "Rpid": reply.1["rpid_str"].string ?? "-1", "Like": String(reply.1["like"].int ?? -1), "Pictures": pictures.joined(separator: "|")])
calNum += 1
}
}
Expand Down

0 comments on commit a69e7fe

Please sign in to comment.