Skip to content

Commit

Permalink
move more relay code to the relay dir
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Jul 7, 2024
1 parent 4c8aced commit 02ed544
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 20 deletions.
22 changes: 20 additions & 2 deletions ui/analyse/src/study/relay/chatHandler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { BroadcastChatHandler } from 'chat/src/interfaces';
import { BroadcastChatHandler, Line } from 'chat/src/interfaces';
import AnalyseCtrl from '../../ctrl';
import { VNode, h } from 'snabbdom';
import { bind } from 'common/snabbdom';

export function broadcastChatHandler(ctrl: AnalyseCtrl): BroadcastChatHandler {
// '\ue666' was arbitrarily chosen from the unicode private use area to separate the text from the chapterId and ply
Expand Down Expand Up @@ -44,10 +46,26 @@ export function broadcastChatHandler(ctrl: AnalyseCtrl): BroadcastChatHandler {
return null;
};

const jumpButton = (line: Line): VNode | null => {
const msgPly = canJumpToMove(line.t);
return msgPly
? h(
'button.jump',
{
hook: bind('click', () => jumpToMove(line.t)),
attrs: {
title: `Jump to move ${msgPly}`,
},
},
'#',
)
: null;
};

return {
encodeMsg,
cleanMsg,
jumpToMove,
canJumpToMove,
jumpButton,
};
}
20 changes: 3 additions & 17 deletions ui/chat/src/discussion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import * as enhance from 'common/richText';
import { userLink } from 'common/userLink';
import * as spam from './spam';
import { Line } from './interfaces';
import { bind } from 'common/snabbdom';
import { h, thunk, VNode, VNodeData } from 'snabbdom';
import { lineAction as modLineAction, report } from './moderation';
import { presetView } from './preset';
Expand Down Expand Up @@ -205,20 +204,7 @@ function renderLine(ctrl: ChatCtrl, line: Line): VNode {
.match(enhance.userPattern)
?.find(mention => mention.trim().toLowerCase() == `@${ctrl.data.userId}`);

const msgPly = ctrl.broadcastChatHandler?.canJumpToMove(line.t);

const jumpToPly = msgPly
? h(
'button.jump',
{
hook: bind('click', ctrl.broadcastChatHandler.jumpToMove.bind(null, line.t)),
attrs: {
title: `Jump to move ${msgPly}`,
},
},
'#',
)
: null;
const jumpButton = ctrl.broadcastChatHandler?.jumpButton(line);

return h(
'li',
Expand All @@ -230,15 +216,15 @@ function renderLine(ctrl: ChatCtrl, line: Line): VNode {
},
},
ctrl.moderation
? [h('div.actions', [line.u ? modLineAction() : null, jumpToPly]), userNode, ' ', textNode]
? [h('div.actions', [line.u ? modLineAction() : null, jumpButton]), userNode, ' ', textNode]
: [
h('div.actions', [
myUserId && line.u && myUserId != line.u
? h('action.flag', {
attrs: { 'data-icon': licon.CautionTriangle, title: 'Report' },
})
: null,
jumpToPly,
jumpButton,
]),
userNode,
' ',
Expand Down
2 changes: 1 addition & 1 deletion ui/chat/src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export interface BroadcastChatHandler {
encodeMsg(msg: string): string;
cleanMsg(msg: string): string;
jumpToMove(msg: string): void;
canJumpToMove(msg: string): string | null;
jumpButton(line: Line): VNode | null;
}

export interface Permissions {
Expand Down

0 comments on commit 02ed544

Please sign in to comment.