diff --git a/ui/chat/src/ctrl.ts b/ui/chat/src/ctrl.ts index 1fbf0e1496e37..fbbec1f4b1282 100644 --- a/ui/chat/src/ctrl.ts +++ b/ui/chat/src/ctrl.ts @@ -43,6 +43,9 @@ export default class ChatCtrl { loaded: false, enabled: prop(!!this.data.palantir), }; + console.log('site-study', site.analysis.study); + console.log('site-burl', site.analysis.study.baseUrl()); + console.log('site-pos', site.analysis.study.position()); this.trans = site.trans(this.opts.i18n); const noChat = site.storage.get('nochat'); this.vm = { @@ -97,11 +100,36 @@ export default class ChatCtrl { post = (text: string): boolean => { text = text.trim(); if (!text) return false; + if (text.startsWith('<<<<')) return false; if (text == 'You too!' && !this.data.lines.some(l => l.u != this.data.userId)) return false; if (text.length > 140) { alert('Max length: 140 chars. ' + text.length + ' chars used.'); return false; } + + if (site.analysis) { + // let roundId = 'static-round-id'; + let roundId = site.analysis.study.relay.currentRound().id; + let roundSlug = site.analysis.study.relay.currentRound().slug; + // let gameId = 'static-game-id'; + let gameId = site.analysis.study.currentChapter().id; + let moveNo = site.analysis.study.currentNode().ply; + // roundId = site.analysis.study.roundId(); + // gameId = site.analysis.study.gameId(); + // moveNo = site.analysis.study.moveNo(); + console.log('site-study', site.analysis.study); + console.log('site-relay-tourShow', site.analysis.study.relay); + console.log('site-relay-tourShow', site.analysis.study.relay.tourShow); + console.log('site-round', site.analysis.study.relay.currentRound().id); + console.log('site-round', site.analysis.study.relay.currentRound().slug); + console.log('site-pos', site.analysis.study.position()); + console.log('site-game', site.analysis.study.currentChapter().id); + console.log('site-shr-node', site.analysis.study.currentNode()); + console.log('site-shr-node', site.analysis.study.currentNode().ply); + text = '<<<<' + roundSlug + '|' + roundId + '|' + gameId + '|' + moveNo + '>>>> ' + text; + } + + console.log('chat post', text); site.pubsub.emit('socket.send', 'talk', text); return true; }; @@ -131,6 +159,9 @@ export default class ChatCtrl { onMessage = (line: Line) => { this.data.lines.push(line); const nb = this.data.lines.length; + console.log('chat message', line); + console.log('chat lines', nb); + console.log(this.data); if (nb > this.maxLines) { this.data.lines.splice(0, nb - this.maxLines + this.maxLinesDrop); this.vm.domVersion++; diff --git a/ui/chat/src/discussion.ts b/ui/chat/src/discussion.ts index b11894d3151da..8dd1c262af7fc 100644 --- a/ui/chat/src/discussion.ts +++ b/ui/chat/src/discussion.ts @@ -30,6 +30,7 @@ export default function (ctrl: ChatCtrl): Array { attrs: { role: 'log', 'aria-live': 'polite', 'aria-atomic': 'false' }, hook: { insert(vnode) { + // console.log('vnode', vnode); const $el = $(vnode.elm as HTMLElement).on('click', 'a.jump', (e: Event) => { site.pubsub.emit('jump', (e.target as HTMLElement).getAttribute('data-ply')); }); @@ -188,6 +189,24 @@ const userThunk = (name: string, title?: string, patron?: boolean, flair?: Flair userLink({ name, title, patron, line: !!patron, flair }); function renderLine(ctrl: ChatCtrl, line: Line): VNode { + if (line.t.startsWith('<<<<')) { + // line.t looks like '<<<>>> text' + //text = '<<<<' + roundSlug+'|' roundId + '|' + gameId + '|' + moveNo + '>>>> ' + text; + const parts = line.t.match(/^<<<<([^|]+)\|([^|]+)\|([^|]+)\|([^|]+)>>>>\s(.+)$/); + if (parts) { + const [_, roundSlug, roundId, gameId, moveNo, text] = parts; + // console.log('_',_); + const broadcastSlug= site.analysis.study.relayData.tour.slug; + const broadcastURL = `/broadcast/${broadcastSlug}/${roundSlug}/${roundId}/${gameId}#${moveNo}`; + // const ply = `${roundId}/${gameId}/${moveNo}`; + // console.log('ply', ply); + line.t = text; + line.ply = broadcastURL; + console.log('line', broadcastURL); + } + } + + // console.log('line', line); const textNode = renderText(line.t, ctrl.opts.enhance); if (line.u === 'lichess') return h('li.system', textNode); @@ -204,6 +223,8 @@ function renderLine(ctrl: ChatCtrl, line: Line): VNode { .match(enhance.userPattern) ?.find(mention => mention.trim().toLowerCase() == `@${ctrl.data.userId}`); + const plyy = line.ply ? h('a', { attrs: { 'href': line.ply } }, ' -->') : null; + // console.log('plyy', plyy); return h( 'li', { @@ -214,7 +235,8 @@ function renderLine(ctrl: ChatCtrl, line: Line): VNode { }, }, ctrl.moderation - ? [line.u ? modLineAction() : null, userNode, ' ', textNode] + ? [line.u ? modLineAction() : null, userNode, ' ', textNode, + plyy] : [ myUserId && line.u && myUserId != line.u ? h('action.flag', { @@ -224,6 +246,7 @@ function renderLine(ctrl: ChatCtrl, line: Line): VNode { userNode, ' ', textNode, + plyy ], ); } diff --git a/ui/chat/src/interfaces.ts b/ui/chat/src/interfaces.ts index 5f440de1e0c7f..8f6b0fecc357d 100644 --- a/ui/chat/src/interfaces.ts +++ b/ui/chat/src/interfaces.ts @@ -52,6 +52,7 @@ export interface Line { p?: boolean; // patron f?: Flair; title?: string; + ply?: any; } export interface Permissions {