Skip to content

Commit

Permalink
为反馈添加回复功能 (#277)
Browse files Browse the repository at this point in the history
* fix: Fixed send comment UI on iOS

* feat: Added reply to Radar

* fix: Fixed build issue for watchOS
  • Loading branch information
WindowsMEMZ authored Feb 24, 2024
1 parent a5c9d6c commit 34a3873
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 18 deletions.
35 changes: 35 additions & 0 deletions MeowBili/Errors/FeedbackView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ struct InAppFeedbackView: View {
@State var content = ""
@State var status = 8
@State var replies = [(status: Int, content: String, sender: String)]()
@State var isSendReplyPresented = false
@State var replyInput = ""
var body: some View {
List {
Section {
Expand Down Expand Up @@ -282,6 +284,39 @@ struct InAppFeedbackView: View {
}
}
}
.toolbar {
if #available(watchOS 10, *) {
Button(action: {
isSendReplyPresented = true
}, label: {
Image(systemName: "arrowshape.turn.up.left.fill")
})
.sheet(isPresented: $isSendReplyPresented) {
TextField("回复信息", text: $replyInput)
.onSubmit {
if replyInput != "" {
let enced = """
Content:\(replyInput)
Sender:User
""".base64Encoded().replacingOccurrences(of: "/", with: "{slash}")
DarockKit.Network.shared.requestString("https://api.darock.top/radar/reply/喵哩喵哩/\(id)/\(enced)") { respStr, isSuccess in
if isSuccess {
if respStr.apiFixed() == "Success" {
isSendReplyPresented = false
} else {
#if os(watchOS) || os(visionOS)
tipWithText("未知错误", symbol: "xmark.circle.fill")
#else
AlertKitAPI.present(title: "未知错误", subtitle: "可能未发送此回复", icon: .error, style: .iOS17AppleMusic, haptic: .error)
#endif
}
}
}
}
}
}
}
}
}
}
}
Expand Down
44 changes: 26 additions & 18 deletions MeowBili/GlobalView/CommentsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -495,27 +495,35 @@ struct CommentsView: View {
@State var isSendingComment = false
@State var id = ""
var body: some View {
VStack {
if !isSendingComment {
TextField("Comment.send", text: $sendCommentCache)
.onSubmit {
if sendCommentCache != "" {
let headers: HTTPHeaders = [
"cookie": "SESSDATA=\(sessdata)",
"User-Agent": "Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
]
AF.request("https://api.bilibili.com/x/v2/reply/add", method: .post, parameters: BiliSubmitComment(type: type, oid: id, message: sendCommentCache, csrf: biliJct), headers: headers).response { response in
sendCommentCache = ""
debugPrint(response)
isSendingComment = false
dismiss()
NavigationStack {
VStack {
if !isSendingComment {
TextField("Comment.send", text: $sendCommentCache)
#if !os(watchOS)
.textFieldStyle(.roundedBorder)
#endif
.submitLabel(.send)
.onSubmit {
if sendCommentCache != "" {
let headers: HTTPHeaders = [
"cookie": "SESSDATA=\(sessdata)",
"User-Agent": "Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
]
AF.request("https://api.bilibili.com/x/v2/reply/add", method: .post, parameters: BiliSubmitComment(type: type, oid: id, message: sendCommentCache, csrf: biliJct), headers: headers).response { response in
sendCommentCache = ""
debugPrint(response)
isSendingComment = false
dismiss()
}
}
}
}
Spacer()
} else {
ProgressView()
Spacer()
} else {
ProgressView()
}
}
.navigationTitle("发送评论")
.padding(.horizontal)
}
.onAppear {
if Int(oid) == nil, type == 1 {
Expand Down

0 comments on commit 34a3873

Please sign in to comment.