Compare commits
1 Commits
hide-hellt
...
tyiu/refac
| Author | SHA1 | Date | |
|---|---|---|---|
|
6cfb9f7c75
|
@@ -1203,7 +1203,7 @@ func create_local_notification(profiles: Profiles, notify: LocalNotification) {
|
|||||||
title = String(format: NSLocalizedString("Reposted by %@", comment: "Reposted by heading in local notification"), displayName)
|
title = String(format: NSLocalizedString("Reposted by %@", comment: "Reposted by heading in local notification"), displayName)
|
||||||
identifier = "myBoostNotification"
|
identifier = "myBoostNotification"
|
||||||
case .like:
|
case .like:
|
||||||
title = String(format: NSLocalizedString("%@ reacted with %@", comment: "Reacted by heading in local notification"), displayName, notify.event.content)
|
title = String(format: NSLocalizedString("%@ reacted with %@", comment: "Reacted by heading in local notification"), displayName, to_reaction_emoji(ev: notify.event) ?? "")
|
||||||
identifier = "myLikeNotification"
|
identifier = "myLikeNotification"
|
||||||
case .dm:
|
case .dm:
|
||||||
title = displayName
|
title = displayName
|
||||||
|
|||||||
@@ -492,11 +492,11 @@ func make_boost_event(pubkey: String, privkey: String, boosted: NostrEvent) -> N
|
|||||||
return ev
|
return ev
|
||||||
}
|
}
|
||||||
|
|
||||||
func make_like_event(pubkey: String, privkey: String, liked: NostrEvent) -> NostrEvent {
|
func make_like_event(pubkey: String, privkey: String, liked: NostrEvent, content: String = "🤙") -> NostrEvent {
|
||||||
var tags: [[String]] = liked.tags.filter { tag in tag.count >= 2 && (tag[0] == "e" || tag[0] == "p") }
|
var tags: [[String]] = liked.tags.filter { tag in tag.count >= 2 && (tag[0] == "e" || tag[0] == "p") }
|
||||||
tags.append(["e", liked.id])
|
tags.append(["e", liked.id])
|
||||||
tags.append(["p", liked.pubkey])
|
tags.append(["p", liked.pubkey])
|
||||||
let ev = NostrEvent(content: "🤙", pubkey: pubkey, kind: 7, tags: tags)
|
let ev = NostrEvent(content: content, pubkey: pubkey, kind: 7, tags: tags)
|
||||||
ev.calculate_id()
|
ev.calculate_id()
|
||||||
ev.sign(privkey: privkey)
|
ev.sign(privkey: privkey)
|
||||||
|
|
||||||
@@ -966,6 +966,28 @@ func first_eref_mention(ev: NostrEvent, privkey: String?) -> Mention? {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Transforms a `NostrEvent` of known kind `NostrKind.like`to a human-readable emoji.
|
||||||
|
If the known kind is not a `NostrKind.like`, it will return `nil`.
|
||||||
|
If the event content is an empty string or `+`, it will map that to a heart ❤️ emoji.
|
||||||
|
If the event content is a "-", it will map that to a dislike 👎 emoji.
|
||||||
|
Otherwise, it will return the event content at face value without transforming it.
|
||||||
|
*/
|
||||||
|
func to_reaction_emoji(ev: NostrEvent) -> String? {
|
||||||
|
guard ev.known_kind == NostrKind.like else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
switch ev.content {
|
||||||
|
case "", "+":
|
||||||
|
return "❤️"
|
||||||
|
case "-":
|
||||||
|
return "👎"
|
||||||
|
default:
|
||||||
|
return ev.content
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
extension [ReferencedId] {
|
extension [ReferencedId] {
|
||||||
var pRefs: [ReferencedId] {
|
var pRefs: [ReferencedId] {
|
||||||
get {
|
get {
|
||||||
|
|||||||
@@ -12,10 +12,7 @@ struct ReactionView: View {
|
|||||||
let reaction: NostrEvent
|
let reaction: NostrEvent
|
||||||
|
|
||||||
var content: String {
|
var content: String {
|
||||||
if reaction.content == "" || reaction.content == "+" {
|
return to_reaction_emoji(ev: reaction) ?? ""
|
||||||
return "❤️"
|
|
||||||
}
|
|
||||||
return reaction.content
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
|
|||||||
@@ -32,4 +32,26 @@ class LikeTests: XCTestCase {
|
|||||||
XCTAssertEqual(like_ev.last_refid()!.ref_id, id)
|
XCTAssertEqual(like_ev.last_refid()!.ref_id, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testToReactionEmoji() {
|
||||||
|
let privkey = "0fc2092231f958f8d57d66f5e238bb45b6a2571f44c0ce024bbc6f3a9c8a15fe"
|
||||||
|
let pubkey = "30c6d1dc7f7c156794fa15055e651b758a61b99f50fcf759de59386050bf6ae2"
|
||||||
|
let liked = NostrEvent(content: "awesome #[0] post", pubkey: "orig_pk", tags: [["p", "cindy"], ["e", "bob"]])
|
||||||
|
liked.calculate_id()
|
||||||
|
let id = liked.id
|
||||||
|
|
||||||
|
let emptyReaction = make_like_event(pubkey: pubkey, privkey: privkey, liked: liked, content: "")
|
||||||
|
let plusReaction = make_like_event(pubkey: pubkey, privkey: privkey, liked: liked, content: "+")
|
||||||
|
let minusReaction = make_like_event(pubkey: pubkey, privkey: privkey, liked: liked, content: "-")
|
||||||
|
let heartReaction = make_like_event(pubkey: pubkey, privkey: privkey, liked: liked, content: "❤️")
|
||||||
|
let thumbsUpReaction = make_like_event(pubkey: pubkey, privkey: privkey, liked: liked, content: "👍")
|
||||||
|
let shakaReaction = make_like_event(pubkey: pubkey, privkey: privkey, liked: liked, content: "🤙")
|
||||||
|
|
||||||
|
XCTAssertEqual(to_reaction_emoji(ev: emptyReaction), "❤️")
|
||||||
|
XCTAssertEqual(to_reaction_emoji(ev: plusReaction), "❤️")
|
||||||
|
XCTAssertEqual(to_reaction_emoji(ev: minusReaction), "👎")
|
||||||
|
XCTAssertEqual(to_reaction_emoji(ev: heartReaction), "❤️")
|
||||||
|
XCTAssertEqual(to_reaction_emoji(ev: thumbsUpReaction), "👍")
|
||||||
|
XCTAssertEqual(to_reaction_emoji(ev: shakaReaction), "🤙")
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user