@@ -19,7 +19,7 @@ import * as widgets from '../widgets'
1919import { renderBookmarksButton } from './bookmarks'
2020import { authn , store } from 'solid-logic'
2121
22- import { mostRecentVersion } from './chatLogic'
22+ import { allVersions , mostRecentVersion , isDeleted } from './chatLogic'
2323import { switchToEditor } from './message'
2424
2525const dom = window . document
@@ -38,22 +38,48 @@ const REPLY_ICON = 'noun-reply-5506924.svg'
3838/**
3939 * Emoji in Unicode
4040 */
41- const emoji = { }
42- emoji [ ns . schema ( 'AgreeAction' ) ] = '👍'
43- emoji [ ns . schema ( 'DisagreeAction' ) ] = '👎'
44- emoji [ ns . schema ( 'EndorseAction' ) ] = '⭐️'
45- emoji [ ns . schema ( 'LikeAction' ) ] = '❤️'
41+ const emojiMap = { }
42+ emojiMap [ ns . schema ( 'AgreeAction' ) ] = '👍'
43+ emojiMap [ ns . schema ( 'DisagreeAction' ) ] = '👎'
44+ emojiMap [ ns . schema ( 'EndorseAction' ) ] = '⭐️'
45+ emojiMap [ ns . schema ( 'LikeAction' ) ] = '❤️'
46+
47+ export function emojiFromActionClass ( action ) {
48+ return emojiMap [ action ] || null
49+ }
50+
51+ export function ActionClassFromEmoji ( emoji ) {
52+ for ( a in emojiMap ) {
53+ if ( emojiMap [ a ] === emoji ) {
54+ return $rdf . sym ( a . slice ( 1 , - 1 ) ) // remove < >
55+ }
56+ }
57+ return null
58+ }
59+
60+ // Allow the qction to give its own emoji as content,
61+ // or get the emoji from the class lof action.
62+ export function emojiFromAction ( action ) {
63+ const content = store . any ( action , ns . sioc ( 'content' ) , null , action . doc ( ) )
64+ if ( content ) return content
65+ const klass = store . any ( action , ns . rdf ( 'type' ) , null , action . doc ( ) )
66+ if ( klass ) {
67+ const em = emojiFromActionClass ( klass ) ;
68+ if ( em ) return em ;
69+ }
70+ return '⬜️'
71+ }
4672
4773/**
4874 * Create strip of sentiments expressed
4975 */
5076export async function sentimentStrip ( target , doc ) { // alain seems not used
51- const latest = await mostRecentVersion ( target )
52- const actions = store . holds ( latest , ns . schema ( 'dateDeleted' ) . value , null , latest . doc ( ) ) ? store . each ( null , ns . schema ( ' target' ) , target , doc ) : [ ]
53- const sentiments = actions . map ( a => store . any ( a , ns . rdf ( 'type ') , null , doc ) )
54- sentiments . sort ( )
55- const strings = sentiments . map ( x => emoji [ x ] || '' )
56- return dom . createTextNode ( strings . join ( ' ' ) )
77+ const versions = await allVersions ( target )
78+ console . log ( 'sentimentStrip Versions for ' + target , versions )
79+ const actions = versions . map ( version => store . each ( null , ns . schema ( 'target ') , version , doc ) ) . flat ( )
80+ console . log ( 'sentimentStrip: Actions for ' + target , actions )
81+ const strings = sentiments . map ( action => emojiFromAction ( action ) || '' )
82+ return dom . createTextNode ( strings . join ( ' ' ) )
5783}
5884/**
5985 * Create strip of sentiments expressed, with hyperlinks
@@ -65,26 +91,35 @@ export async function sentimentStripLinked (target, doc) {
6591 const strip = dom . createElement ( 'span' )
6692 async function refresh ( ) {
6793 strip . innerHTML = ''
68- const actions = ( await mostRecentVersion ( target ) . uri !== ns . schema ( 'dateDeleted' ) . uri ) ? store . each ( null , ns . schema ( 'target' ) , target , doc ) : [ ]
94+ if ( isDeleted ( target ) ) return strip
95+ const versions = await allVersions ( target )
96+ console . log ( 'sentimentStripLinked: Versions for ' + target , versions )
97+ const actions = versions . map ( version => store . each ( null , ns . schema ( 'target' ) , version , doc ) ) . flat ( )
98+ console . log ( 'sentimentStripLinked: Actions for ' + target , actions )
99+ if ( actions . length == 0 ) return strip
69100 const sentiments = actions . map ( a => [
70101 store . any ( a , ns . rdf ( 'type' ) , null , doc ) ,
102+ store . any ( a , ns . sioc ( 'content' ) , null , doc ) ,
71103 store . any ( a , ns . schema ( 'agent' ) , null , doc )
72104 ] )
105+ console . log ( ' Actions sentiments ' , sentiments )
73106 sentiments . sort ( )
74107 sentiments . forEach ( ss => {
75- const [ theClass , agent ] = ss
108+ const [ theClass , content , agent ] = ss
76109 let res
77110 if ( agent ) {
78111 res = dom . createElement ( 'a' )
79112 res . setAttribute ( 'href' , agent . uri )
80113 } else {
81114 res = dom . createTextNode ( '' )
82115 }
83- res . textContent = emoji [ theClass ] || '* '
116+ res . textContent = content || emojiMap [ theClass ] || '⬜️ '
84117 strip . appendChild ( res )
85118 } )
119+ console . log ( ' Actions strip ' , strip )
120+
86121 }
87- refresh ( ) . then ( console . log ( 'sentimentStripLinked async refreshed' ) )
122+ refresh ( ) . then ( console . log ( 'sentimentStripLinked: sentimentStripLinked async refreshed' ) )
88123 strip . refresh = refresh
89124 return strip
90125}
0 commit comments