Don't show translation status
It's too poppy
This commit is contained in:
@@ -40,22 +40,11 @@ struct TranslateView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func CheckingStatus(lang: String) -> some View {
|
|
||||||
return Button(String(format: NSLocalizedString("Translating from %@...", comment: "Button to indicate that the note is in the process of being translated from a different language."), lang)) {
|
|
||||||
show_translated_note = false
|
|
||||||
}
|
|
||||||
.translate_button_style()
|
|
||||||
}
|
|
||||||
|
|
||||||
func MainContent(note_lang: String) -> some View {
|
func MainContent(note_lang: String) -> some View {
|
||||||
return Group {
|
return Group {
|
||||||
let languageName = Locale.current.localizedString(forLanguageCode: note_lang)
|
let languageName = Locale.current.localizedString(forLanguageCode: note_lang)
|
||||||
if let lang = languageName, show_translated_note {
|
if let languageName, let translated_artifacts, show_translated_note {
|
||||||
if checkingTranslationStatus {
|
Translated(lang: languageName, artifacts: translated_artifacts)
|
||||||
CheckingStatus(lang: lang)
|
|
||||||
} else if let artifacts = translated_artifacts {
|
|
||||||
Translated(lang: lang, artifacts: artifacts)
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
TranslateButton
|
TranslateButton
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -489,38 +489,8 @@ class HomeModel: ObservableObject {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if handle_last_event(ev: ev, timeline: .notifications),
|
if handle_last_event(ev: ev, timeline: .notifications) {
|
||||||
damus_state.contacts.follow_state(ev.pubkey) == .follows,
|
process_local_notification(damus_state: damus_state, event: ev)
|
||||||
let type = ev.known_kind {
|
|
||||||
|
|
||||||
if type == .text,
|
|
||||||
damus_state.settings.mention_notification {
|
|
||||||
for block in ev.blocks(damus_state.keypair.privkey) {
|
|
||||||
if case .mention(let mention) = block, mention.ref.ref_id == damus_state.keypair.pubkey,
|
|
||||||
let displayName = damus_state.profiles.lookup(id: ev.pubkey)?.display_name {
|
|
||||||
let justContent = NSAttributedString(render_note_content(ev: ev, profiles: damus_state.profiles, privkey: damus_state.keypair.privkey).content).string
|
|
||||||
create_notification(displayName: displayName, conversation: justContent, type: type)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if type == .boost,
|
|
||||||
damus_state.settings.repost_notification,
|
|
||||||
let displayName = damus_state.profiles.lookup(id: ev.pubkey)?.display_name {
|
|
||||||
|
|
||||||
let justContent = NSAttributedString(render_note_content(ev: ev, profiles: damus_state.profiles, privkey: damus_state.keypair.privkey).content).string
|
|
||||||
if let jsonData = justContent.data(using: .utf8),
|
|
||||||
let jsonDict = try? JSONSerialization.jsonObject(with: jsonData, options: []) as? [String: Any],
|
|
||||||
let content = jsonDict["content"] as? String {
|
|
||||||
create_notification(displayName: displayName, conversation: content, type: type)
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if type == .like,
|
|
||||||
damus_state.settings.like_notification,
|
|
||||||
let displayName = damus_state.profiles.lookup(id: ev.pubkey)?.display_name,
|
|
||||||
let eRef = ev.referenced_ids.eRefs.first?.ref_id,
|
|
||||||
let content = damus_state.events.lookup(eRef)?.content {
|
|
||||||
|
|
||||||
create_notification(displayName: displayName, conversation: content, type: type)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -541,43 +511,6 @@ class HomeModel: ObservableObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func create_notification(displayName: String, conversation: String, type: NostrKind) {
|
|
||||||
let content = UNMutableNotificationContent()
|
|
||||||
var title = ""
|
|
||||||
var identifier = ""
|
|
||||||
switch type {
|
|
||||||
case .text:
|
|
||||||
title = String(format: NSLocalizedString("Mentioned by %@", comment: "Mentioned by heading in local notification"), displayName)
|
|
||||||
identifier = "myMentionNotification"
|
|
||||||
case .boost:
|
|
||||||
title = String(format: NSLocalizedString("Reposted by %@", comment: "Reposted by heading in local notification"), displayName)
|
|
||||||
identifier = "myBoostNotification"
|
|
||||||
case .like:
|
|
||||||
title = String(format: NSLocalizedString("Liked by %@", comment: "Liked by heading in local notification"), displayName)
|
|
||||||
identifier = "myLikeNotification"
|
|
||||||
case .dm:
|
|
||||||
title = String(format: NSLocalizedString("DM by %@", comment: "DM by heading in local notification"), displayName)
|
|
||||||
identifier = "myDMNotification"
|
|
||||||
default:
|
|
||||||
break
|
|
||||||
}
|
|
||||||
content.title = title
|
|
||||||
content.body = conversation
|
|
||||||
content.sound = UNNotificationSound.default
|
|
||||||
|
|
||||||
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 1, repeats: false)
|
|
||||||
|
|
||||||
let request = UNNotificationRequest(identifier: identifier, content: content, trigger: trigger)
|
|
||||||
|
|
||||||
UNUserNotificationCenter.current().add(request) { error in
|
|
||||||
if let error = error {
|
|
||||||
print("Error: \(error)")
|
|
||||||
} else {
|
|
||||||
print("Local notification scheduled")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
func handle_text_event(sub_id: String, _ ev: NostrEvent) {
|
func handle_text_event(sub_id: String, _ ev: NostrEvent) {
|
||||||
guard should_show_event(contacts: damus_state.contacts, ev: ev) else {
|
guard should_show_event(contacts: damus_state.contacts, ev: ev) else {
|
||||||
@@ -614,7 +547,7 @@ class HomeModel: ObservableObject {
|
|||||||
self.new_events = notifs
|
self.new_events = notifs
|
||||||
if damus_state.settings.dm_notification,
|
if damus_state.settings.dm_notification,
|
||||||
let displayName = damus_state.profiles.lookup(id: self.incoming_dms.last!.pubkey)?.display_name {
|
let displayName = damus_state.profiles.lookup(id: self.incoming_dms.last!.pubkey)?.display_name {
|
||||||
create_notification(displayName: displayName, conversation: "You have received a direct message", type: .dm)
|
create_local_notification(displayName: displayName, conversation: "You have received a direct message", type: .dm)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.incoming_dms = []
|
self.incoming_dms = []
|
||||||
@@ -1060,3 +993,70 @@ func create_in_app_zap_notification(profiles: Profiles, zap: Zap, locale: Locale
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func process_local_notification(damus_state: DamusState, event ev: NostrEvent) {
|
||||||
|
guard let type = ev.known_kind else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if type == .text && damus_state.settings.mention_notification {
|
||||||
|
for block in ev.blocks(damus_state.keypair.privkey) {
|
||||||
|
if case .mention(let mention) = block, mention.ref.ref_id == damus_state.keypair.pubkey,
|
||||||
|
let displayName = damus_state.profiles.lookup(id: ev.pubkey)?.display_name {
|
||||||
|
let justContent = NSAttributedString(render_note_content(ev: ev, profiles: damus_state.profiles, privkey: damus_state.keypair.privkey).content).string
|
||||||
|
create_local_notification(displayName: displayName, conversation: justContent, type: type)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if type == .boost && damus_state.settings.repost_notification,
|
||||||
|
let displayName = damus_state.profiles.lookup(id: ev.pubkey)?.display_name {
|
||||||
|
|
||||||
|
if let inner_ev = ev.inner_event {
|
||||||
|
create_local_notification(displayName: displayName, conversation: inner_ev.content, type: type)
|
||||||
|
}
|
||||||
|
} else if type == .like && damus_state.settings.like_notification,
|
||||||
|
let displayName = damus_state.profiles.lookup(id: ev.pubkey)?.display_name,
|
||||||
|
let e_ref = ev.referenced_ids.first?.ref_id,
|
||||||
|
let content = damus_state.events.lookup(e_ref)?.content {
|
||||||
|
|
||||||
|
create_local_notification(displayName: displayName, conversation: content, type: type)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func create_local_notification(displayName: String, conversation: String, type: NostrKind) {
|
||||||
|
let content = UNMutableNotificationContent()
|
||||||
|
var title = ""
|
||||||
|
var identifier = ""
|
||||||
|
switch type {
|
||||||
|
case .text:
|
||||||
|
title = String(format: NSLocalizedString("Mentioned by %@", comment: "Mentioned by heading in local notification"), displayName)
|
||||||
|
identifier = "myMentionNotification"
|
||||||
|
case .boost:
|
||||||
|
title = String(format: NSLocalizedString("Reposted by %@", comment: "Reposted by heading in local notification"), displayName)
|
||||||
|
identifier = "myBoostNotification"
|
||||||
|
case .like:
|
||||||
|
title = String(format: NSLocalizedString("Liked by %@", comment: "Liked by heading in local notification"), displayName)
|
||||||
|
identifier = "myLikeNotification"
|
||||||
|
case .dm:
|
||||||
|
title = String(format: NSLocalizedString("DM by %@", comment: "DM by heading in local notification"), displayName)
|
||||||
|
identifier = "myDMNotification"
|
||||||
|
default:
|
||||||
|
break
|
||||||
|
}
|
||||||
|
content.title = title
|
||||||
|
content.body = conversation
|
||||||
|
content.sound = UNNotificationSound.default
|
||||||
|
|
||||||
|
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 1, repeats: false)
|
||||||
|
|
||||||
|
let request = UNNotificationRequest(identifier: identifier, content: content, trigger: trigger)
|
||||||
|
|
||||||
|
UNUserNotificationCenter.current().add(request) { error in
|
||||||
|
if let error = error {
|
||||||
|
print("Error: \(error)")
|
||||||
|
} else {
|
||||||
|
print("Local notification scheduled")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user