添加 subtitle 支持。close: #48

This commit is contained in:
Fin 2024-12-11 17:17:09 +08:00
parent d97abb5c33
commit f155f655c7
10 changed files with 32 additions and 8 deletions

View File

@ -14,7 +14,7 @@ let kRealmDefaultConfiguration = {
let fileUrl = groupUrl?.appendingPathComponent("bark.realm") let fileUrl = groupUrl?.appendingPathComponent("bark.realm")
let config = Realm.Configuration( let config = Realm.Configuration(
fileURL: fileUrl, fileURL: fileUrl,
schemaVersion: 14, schemaVersion: 15,
migrationBlock: { migration, oldSchemaVersion in migrationBlock: { migration, oldSchemaVersion in
switch oldSchemaVersion { switch oldSchemaVersion {
case 0...13: case 0...13:

View File

@ -42,7 +42,7 @@ class MessageListViewModel: ViewModel, ViewModelType {
results = results.filter("group in %@", filterGroups) results = results.filter("group in %@", filterGroups)
} }
if let text = searchText, text.count > 0 { if let text = searchText, text.count > 0 {
results = results.filter("title CONTAINS[c] %@ OR body CONTAINS[c] %@", text, text) results = results.filter("title CONTAINS[c] %@ OR subtitle CONTAINS[c] %@ OR body CONTAINS[c] %@", text, text, text)
} }
return results return results
} }

View File

@ -12,6 +12,7 @@ import UIKit
class Message: Object { class Message: Object {
@objc dynamic var id = NSUUID().uuidString @objc dynamic var id = NSUUID().uuidString
@objc dynamic var title: String? @objc dynamic var title: String?
@objc dynamic var subtitle: String?
@objc dynamic var body: String? @objc dynamic var body: String?
@objc dynamic var url: String? @objc dynamic var url: String?
@objc dynamic var group: String? @objc dynamic var group: String?

View File

@ -26,6 +26,7 @@ class ArchiveProcessor: NotificationContentProcessor {
if isArchive { if isArchive {
let alert = (userInfo["aps"] as? [String: Any])?["alert"] as? [String: Any] let alert = (userInfo["aps"] as? [String: Any])?["alert"] as? [String: Any]
let title = alert?["title"] as? String let title = alert?["title"] as? String
let subtitle = alert?["subtitle"] as? String
let body = alert?["body"] as? String let body = alert?["body"] as? String
let url = userInfo["url"] as? String let url = userInfo["url"] as? String
let group = userInfo["group"] as? String let group = userInfo["group"] as? String
@ -33,6 +34,7 @@ class ArchiveProcessor: NotificationContentProcessor {
try? realm?.write { try? realm?.write {
let message = Message() let message = Message()
message.title = title message.title = title
message.subtitle = subtitle
message.body = body message.body = body
message.url = url message.url = url
message.group = group message.group = group

View File

@ -27,6 +27,10 @@ class CiphertextProcessor: NotificationContentProcessor {
bestAttemptContent.title = title bestAttemptContent.title = title
alert["title"] = title alert["title"] = title
} }
if let subtitle = map["subtitle"] as? String {
bestAttemptContent.title = subtitle
alert["subtitle"] = subtitle
}
if let body = map["body"] as? String { if let body = map["body"] as? String {
bestAttemptContent.body = body bestAttemptContent.body = body
alert["body"] = body alert["body"] = body

View File

@ -22,11 +22,11 @@ You can send GET or POST requests, and you'll receive a push notification immedi
URL structure: The first part is the key, followed by three matches URL structure: The first part is the key, followed by three matches
/:key/:body /:key/:body
/:key/:title/:body /:key/:title/:body
/:key/:category/:title/:body /:key/: title/:subtitle/:body
title: The push title, slightly larger than the body text title: The push title, slightly larger than the body text
subtitle: The push subtitle
body: The push content, use the newline character '\n' for line breaks body: The push content, use the newline character '\n' for line breaks
category: Reserved for additional features, currently not open for use, just ignore it
For POST requests, the parameter names are the same as above For POST requests, the parameter names are the same as above
``` ```

View File

@ -22,11 +22,11 @@ Bark 支持 iOS 通知的多项高级特性,包括推送分组、定制推送
URL 组成: 第一个部分是 key , 之后有三个匹配 URL 组成: 第一个部分是 key , 之后有三个匹配
/:key/:body /:key/:body
/:key/:title/:body /:key/:title/:body
/:key/:category/:title/:body /:key/:title/:subtitle/:body
title 推送标题 比 body 字号粗一点 title 推送标题 比 body 字号粗一点
subtitle 推送副标题
body 推送内容 换行请使用换行符 '\n' body 推送内容 换行请使用换行符 '\n'
category 另外的功能占用的字段,还没开放 忽略就行
post 请求 参数名也是上面这些 post 请求 参数名也是上面这些
``` ```

View File

@ -95,7 +95,7 @@ class MessageTableViewCell: BaseTableViewCell<MessageTableViewCellViewModel> {
override func bindViewModel(model: MessageTableViewCellViewModel) { override func bindViewModel(model: MessageTableViewCellViewModel) {
super.bindViewModel(model: model) super.bindViewModel(model: model)
Observable.combineLatest(model.title, model.body, model.url).subscribe {[weak self] title, body, url in Observable.combineLatest(model.title, model.subtitle, model.body, model.url).subscribe { [weak self] title, subtitle, body, url in
guard let self else { return } guard let self else { return }
let text = NSMutableAttributedString( let text = NSMutableAttributedString(
@ -103,6 +103,19 @@ class MessageTableViewCell: BaseTableViewCell<MessageTableViewCellViewModel> {
attributes: [.font: UIFont.preferredFont(ofSize: 14), .foregroundColor: BKColor.grey.darken4] attributes: [.font: UIFont.preferredFont(ofSize: 14), .foregroundColor: BKColor.grey.darken4]
) )
if subtitle.count > 0 {
// spacer
text.insert(NSAttributedString(
string: "\n",
attributes: [.font: UIFont.systemFont(ofSize: 6, weight: .medium)]
), at: 0)
text.insert(NSAttributedString(
string: subtitle + "\n",
attributes: [.font: UIFont.preferredFont(ofSize: 16, weight: .medium), .foregroundColor: BKColor.grey.darken4]
), at: 0)
}
if title.count > 0 { if title.count > 0 {
// spacer // spacer
text.insert(NSAttributedString( text.insert(NSAttributedString(

View File

@ -24,6 +24,7 @@ class MessageTableViewCellViewModel: ViewModel {
var identity: String var identity: String
let title: BehaviorRelay<String> let title: BehaviorRelay<String>
let subtitle: BehaviorRelay<String>
let body: BehaviorRelay<String> let body: BehaviorRelay<String>
let url: BehaviorRelay<String> let url: BehaviorRelay<String>
@ -34,6 +35,7 @@ class MessageTableViewCellViewModel: ViewModel {
self.message = message self.message = message
self.identity = message.id self.identity = message.id
self.title = BehaviorRelay<String>(value: message.title ?? "") self.title = BehaviorRelay<String>(value: message.title ?? "")
self.subtitle = BehaviorRelay<String>(value: message.subtitle ?? "")
self.body = BehaviorRelay<String>(value: message.body ?? "") self.body = BehaviorRelay<String>(value: message.body ?? "")
self.url = BehaviorRelay<String>(value: message.url ?? "") self.url = BehaviorRelay<String>(value: message.url ?? "")

View File

@ -7,11 +7,12 @@
可以发 GET 或者 POST 请求 ,请求成功会立即收到推送 可以发 GET 或者 POST 请求 ,请求成功会立即收到推送
## URL格式 ## URL格式
URL由推送key、参数 title、参数 body 组成。有下面两种组合方式 URL由推送key、参数 title、参数 subtitle、参数 body 组成。有下面三种组合方式
``` ```
/:key/:body /:key/:body
/:key/:title/:body /:key/:title/:body
/:key/:title/:subtitle/:body
``` ```
## 请求方式 ## 请求方式
@ -59,6 +60,7 @@ curl -X "POST" "https://api.day.app/push" \
| 参数 | 说明 | | 参数 | 说明 |
| ----- | ----------- | | ----- | ----------- |
| title | 推送标题 | | title | 推送标题 |
| subtitle | 推送副标题 |
| body | 推送内容 | | body | 推送内容 |
| level | 推送中断级别。 <br>active默认值系统会立即亮屏显示通知<br>timeSensitive时效性通知可在专注状态下显示通知。<br>passive仅将通知添加到通知列表不会亮屏提醒。 | | level | 推送中断级别。 <br>active默认值系统会立即亮屏显示通知<br>timeSensitive时效性通知可在专注状态下显示通知。<br>passive仅将通知添加到通知列表不会亮屏提醒。 |
| badge | 推送角标,可以是任意数字 | | badge | 推送角标,可以是任意数字 |