@celljs/ta-channels 4.8.0 → 4.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +3 -2
- package/README.md +3 -2
- package/extension/index.mjs +109 -8
- package/host/index.mjs +281 -5
- package/package.json +13 -4
- package/web/index.js +992 -205
- package/web-src/agent-menu.tsx +0 -236
- package/web-src/channel-menu.tsx +0 -98
- package/web-src/channels-model.ts +0 -156
- package/web-src/channels-util.spec.ts +0 -312
- package/web-src/channels-util.ts +0 -556
- package/web-src/channels.ts +0 -235
- package/web-src/create.tsx +0 -273
- package/web-src/extension.ts +0 -91
- package/web-src/faces.tsx +0 -247
- package/web-src/host.ts +0 -12
- package/web-src/i18n.ts +0 -221
- package/web-src/index.tsx +0 -82
- package/web-src/members.tsx +0 -258
- package/web-src/more-menu.tsx +0 -113
- package/web-src/react.ts +0 -11
- package/web-src/room.tsx +0 -212
- package/web-src/sidebar.tsx +0 -295
- package/web-src/style.ts +0 -249
- package/web-src/team-tools.ts +0 -103
- package/web-src/team.spec.ts +0 -370
- package/web-src/team.ts +0 -560
- package/web-src/views.spec.ts +0 -89
- package/web-src/views.tsx +0 -239
package/web-src/members.tsx
DELETED
|
@@ -1,258 +0,0 @@
|
|
|
1
|
-
import type { Agent, Channel, MemberChange, Team } from './channels-util';
|
|
2
|
-
import { newAgent } from './create';
|
|
3
|
-
import { RoomFace } from './faces';
|
|
4
|
-
import { ChannelWords } from './i18n';
|
|
5
|
-
import { React } from './react';
|
|
6
|
-
import { AgentAvatar, type ChannelsContext, ChannelViews, membersOf, SidebarUtil, useChannels, useFaces, useSubmit, useUi } from './views';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* The members of the channel shown, a tool of the workbench: who leads, who is muted and what each does,
|
|
10
|
-
* with what the user does to them; or, while adding, the agents not in it yet.
|
|
11
|
-
*/
|
|
12
|
-
export function MembersView({ context }: { context: ChannelsContext }) {
|
|
13
|
-
const { pi, service, ui } = context;
|
|
14
|
-
const state = useChannels(service);
|
|
15
|
-
const { channelId, adding } = useUi(ui);
|
|
16
|
-
const faces = useFaces(state.team);
|
|
17
|
-
const w = ChannelViews.words(pi);
|
|
18
|
-
const channel = state.team.channels.find(candidate => candidate.id === channelId);
|
|
19
|
-
if (!channel) {
|
|
20
|
-
return (
|
|
21
|
-
<div className="tac-view tac-members">
|
|
22
|
-
<div className="tac-members-none">{state.loaded ? w.noChannel : ''}</div>
|
|
23
|
-
</div>
|
|
24
|
-
);
|
|
25
|
-
}
|
|
26
|
-
return adding ? (
|
|
27
|
-
<MemberPicker key={channel.id} context={context} team={state.team} channel={channel} faces={faces} />
|
|
28
|
-
) : (
|
|
29
|
-
<MemberList key={channel.id} context={context} team={state.team} channel={channel} faces={faces} working={state.working[channel.id] ?? []} />
|
|
30
|
-
);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
interface ListProps {
|
|
34
|
-
context: ChannelsContext;
|
|
35
|
-
team: Team;
|
|
36
|
-
channel: Channel;
|
|
37
|
-
faces: Map<string, number>;
|
|
38
|
-
working: string[];
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function MemberList({ context, team, channel, faces, working }: ListProps) {
|
|
42
|
-
const { pi, service, ui } = context;
|
|
43
|
-
const w = ChannelViews.words(pi);
|
|
44
|
-
const [busy, setBusy] = React.useState<string>();
|
|
45
|
-
const [confirming, setConfirming] = React.useState(false);
|
|
46
|
-
const UserPlus = ChannelViews.icon(pi, 'UserPlus');
|
|
47
|
-
const Crown = ChannelViews.icon(pi, 'Crown');
|
|
48
|
-
const BellOff = ChannelViews.icon(pi, 'BellOff');
|
|
49
|
-
const RotateCcw = ChannelViews.icon(pi, 'RotateCcw');
|
|
50
|
-
const X = ChannelViews.icon(pi, 'X');
|
|
51
|
-
const Trash = ChannelViews.icon(pi, 'Trash2');
|
|
52
|
-
const members = membersOf(team, channel);
|
|
53
|
-
const muted = channel.muted ?? [];
|
|
54
|
-
const run = (key: string, action: () => Promise<unknown>) => {
|
|
55
|
-
setBusy(key);
|
|
56
|
-
action()
|
|
57
|
-
.catch(error => pi.ui.notify(ChannelViews.message(error), 'error'))
|
|
58
|
-
.finally(() => setBusy(undefined));
|
|
59
|
-
};
|
|
60
|
-
const change = (agent: Agent, kind: MemberChange) => run(`${kind}:${agent.id}`, () => service.changeMember(channel.id, agent.id, kind));
|
|
61
|
-
const reset = (agent: Agent) =>
|
|
62
|
-
run(`reset:${agent.id}`, async () => {
|
|
63
|
-
await service.resetAgent(agent.id);
|
|
64
|
-
context.sessions.delete(agent.id);
|
|
65
|
-
pi.ui.notify(ChannelWords.format(w.resetDone, { name: agent.name }), 'info');
|
|
66
|
-
});
|
|
67
|
-
const remove = () => run('delete', () => service.deleteChannel(channel.id));
|
|
68
|
-
return (
|
|
69
|
-
<div className="tac-view tac-members">
|
|
70
|
-
<div className="tac-members-scroll">
|
|
71
|
-
<div className="tac-members-top">
|
|
72
|
-
<RoomFace members={members} faces={faces} size={44} working={working} />
|
|
73
|
-
<span className="tac-members-title">
|
|
74
|
-
<strong>{channel.name}</strong>
|
|
75
|
-
<span>{channel.topic ?? ChannelWords.format(w.memberCount, { count: String(members.length) })}</span>
|
|
76
|
-
</span>
|
|
77
|
-
</div>
|
|
78
|
-
<div className="tac-members-label">
|
|
79
|
-
{w.members} · {members.length}
|
|
80
|
-
</div>
|
|
81
|
-
<button type="button" className="tac-member-main" onClick={() => ui.set({ adding: true })}>
|
|
82
|
-
<span className="tac-member-plus">
|
|
83
|
-
<UserPlus size={16} />
|
|
84
|
-
</span>
|
|
85
|
-
<span className="tac-member-text">
|
|
86
|
-
<span className="tac-member-name">{w.addMembers}</span>
|
|
87
|
-
</span>
|
|
88
|
-
</button>
|
|
89
|
-
{members.map((agent, index) => {
|
|
90
|
-
const lead = index === 0;
|
|
91
|
-
const off = muted.includes(agent.id);
|
|
92
|
-
const answering = working.includes(agent.id);
|
|
93
|
-
const detail = answering ? w.replying : off ? w.muted : (agent.role.split('\n')[0] ?? '');
|
|
94
|
-
return (
|
|
95
|
-
<div key={agent.id} className={`tac-member${off ? ' tac-muted' : ''}`}>
|
|
96
|
-
<button
|
|
97
|
-
type="button"
|
|
98
|
-
className="tac-member-main"
|
|
99
|
-
title={`${w.open}\n${agent.role}`}
|
|
100
|
-
onClick={() => ChannelViews.openAgent(context, agent.id).catch(error => pi.ui.notify(ChannelViews.message(error), 'error'))}
|
|
101
|
-
>
|
|
102
|
-
<AgentAvatar agent={agent} faces={faces} size={32} working={answering} />
|
|
103
|
-
<span className="tac-member-text">
|
|
104
|
-
<span className="tac-member-name">
|
|
105
|
-
<span className="tac-member-label">{agent.name}</span>
|
|
106
|
-
{lead && (
|
|
107
|
-
<span className="tac-lead" title={w.leadHint}>
|
|
108
|
-
<Crown size={11} />
|
|
109
|
-
<span>{w.lead}</span>
|
|
110
|
-
</span>
|
|
111
|
-
)}
|
|
112
|
-
</span>
|
|
113
|
-
<span className={`tac-member-detail${answering ? ' tac-live' : ''}`}>{detail}</span>
|
|
114
|
-
</span>
|
|
115
|
-
</button>
|
|
116
|
-
<span className="tac-member-actions">
|
|
117
|
-
{!lead && (
|
|
118
|
-
<button
|
|
119
|
-
type="button"
|
|
120
|
-
className="tac-action"
|
|
121
|
-
title={w.makeLead}
|
|
122
|
-
aria-label={w.makeLead}
|
|
123
|
-
disabled={!!busy}
|
|
124
|
-
onClick={() => change(agent, 'lead')}
|
|
125
|
-
>
|
|
126
|
-
<Crown size={15} />
|
|
127
|
-
</button>
|
|
128
|
-
)}
|
|
129
|
-
<button
|
|
130
|
-
type="button"
|
|
131
|
-
className={`tac-action${off ? ' tac-on' : ''}`}
|
|
132
|
-
title={off ? w.unmute : w.mute}
|
|
133
|
-
aria-label={off ? w.unmute : w.mute}
|
|
134
|
-
aria-pressed={off}
|
|
135
|
-
disabled={!!busy}
|
|
136
|
-
onClick={() => change(agent, off ? 'unmute' : 'mute')}
|
|
137
|
-
>
|
|
138
|
-
<BellOff size={15} />
|
|
139
|
-
</button>
|
|
140
|
-
<button
|
|
141
|
-
type="button"
|
|
142
|
-
className="tac-action"
|
|
143
|
-
title={w.reset}
|
|
144
|
-
aria-label={w.reset}
|
|
145
|
-
disabled={!!busy}
|
|
146
|
-
onClick={() => reset(agent)}
|
|
147
|
-
>
|
|
148
|
-
<RotateCcw size={15} />
|
|
149
|
-
</button>
|
|
150
|
-
<button
|
|
151
|
-
type="button"
|
|
152
|
-
className="tac-action"
|
|
153
|
-
title={members.length === 1 ? w.onlyMember : w.remove}
|
|
154
|
-
aria-label={w.remove}
|
|
155
|
-
disabled={!!busy || members.length === 1}
|
|
156
|
-
onClick={() => change(agent, 'remove')}
|
|
157
|
-
>
|
|
158
|
-
<X size={15} />
|
|
159
|
-
</button>
|
|
160
|
-
</span>
|
|
161
|
-
</div>
|
|
162
|
-
);
|
|
163
|
-
})}
|
|
164
|
-
</div>
|
|
165
|
-
<div className="tac-members-foot">
|
|
166
|
-
{confirming ? (
|
|
167
|
-
<React.Fragment>
|
|
168
|
-
<span className="tac-members-ask">{ChannelWords.format(w.confirmDelete, { channel: channel.name })}</span>
|
|
169
|
-
<button type="button" className="tac-button" onClick={() => setConfirming(false)}>
|
|
170
|
-
{w.cancel}
|
|
171
|
-
</button>
|
|
172
|
-
<button type="button" className="tac-button tac-danger" disabled={!!busy} onClick={remove}>
|
|
173
|
-
{w.delete}
|
|
174
|
-
</button>
|
|
175
|
-
</React.Fragment>
|
|
176
|
-
) : (
|
|
177
|
-
<button type="button" className="tac-link tac-danger" onClick={() => setConfirming(true)}>
|
|
178
|
-
<Trash size={14} />
|
|
179
|
-
{w.deleteChannel}
|
|
180
|
-
</button>
|
|
181
|
-
)}
|
|
182
|
-
</div>
|
|
183
|
-
</div>
|
|
184
|
-
);
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
/** The agents not in the channel, to pick some of, or a new one to make. */
|
|
188
|
-
function MemberPicker({ context, team, channel, faces }: { context: ChannelsContext; team: Team; channel: Channel; faces: Map<string, number> }) {
|
|
189
|
-
const { pi, service, ui } = context;
|
|
190
|
-
const w = ChannelViews.words(pi);
|
|
191
|
-
const [query, setQuery] = React.useState('');
|
|
192
|
-
const [picked, setPicked] = React.useState<string[]>([]);
|
|
193
|
-
const ArrowLeft = ChannelViews.icon(pi, 'ArrowLeft');
|
|
194
|
-
const Search = ChannelViews.icon(pi, 'Search');
|
|
195
|
-
const Check = ChannelViews.icon(pi, 'Check');
|
|
196
|
-
const UserPlus = ChannelViews.icon(pi, 'UserPlus');
|
|
197
|
-
const back = () => ui.set({ adding: false });
|
|
198
|
-
const { busy, error, submit } = useSubmit(() => service.addMembers(channel.id, picked), back);
|
|
199
|
-
const others = team.agents.filter(agent => !channel.members.includes(agent.id));
|
|
200
|
-
const shown = others.filter(agent => SidebarUtil.matches(query, agent.name, agent.role));
|
|
201
|
-
const toggle = (id: string) => setPicked(picked.includes(id) ? picked.filter(other => other !== id) : [...picked, id]);
|
|
202
|
-
return (
|
|
203
|
-
<div className="tac-view tac-members">
|
|
204
|
-
<div className="tac-members-head">
|
|
205
|
-
<button type="button" className="tac-action" title={w.back} aria-label={w.back} onClick={back}>
|
|
206
|
-
<ArrowLeft size={16} />
|
|
207
|
-
</button>
|
|
208
|
-
<strong>{w.addMembers}</strong>
|
|
209
|
-
</div>
|
|
210
|
-
<label className="tac-search tac-members-search">
|
|
211
|
-
<Search size={14} />
|
|
212
|
-
<input value={query} placeholder={w.findAgent} aria-label={w.findAgent} onChange={event => setQuery(event.target.value)} />
|
|
213
|
-
</label>
|
|
214
|
-
<div className="tac-members-scroll">
|
|
215
|
-
<div className="tac-members-label">{ChannelWords.format(w.canAdd, { count: String(others.length) })}</div>
|
|
216
|
-
{others.length === 0 && <div className="tac-empty">{w.allMembers}</div>}
|
|
217
|
-
{others.length > 0 && shown.length === 0 && <div className="tac-empty">{w.noMatch}</div>}
|
|
218
|
-
{shown.map(agent => {
|
|
219
|
-
const on = picked.includes(agent.id);
|
|
220
|
-
return (
|
|
221
|
-
<button
|
|
222
|
-
key={agent.id}
|
|
223
|
-
type="button"
|
|
224
|
-
className={`tac-member-main tac-pick${on ? ' tac-on' : ''}`}
|
|
225
|
-
aria-pressed={on}
|
|
226
|
-
title={agent.role}
|
|
227
|
-
onClick={() => toggle(agent.id)}
|
|
228
|
-
>
|
|
229
|
-
<AgentAvatar agent={agent} faces={faces} size={32} />
|
|
230
|
-
<span className="tac-member-text">
|
|
231
|
-
<span className="tac-member-name">
|
|
232
|
-
<span className="tac-member-label">{agent.name}</span>
|
|
233
|
-
</span>
|
|
234
|
-
<span className="tac-member-detail">{agent.role.split('\n')[0]}</span>
|
|
235
|
-
</span>
|
|
236
|
-
<span className="tac-check">{on && <Check size={12} strokeWidth={3} />}</span>
|
|
237
|
-
</button>
|
|
238
|
-
);
|
|
239
|
-
})}
|
|
240
|
-
<div className="tac-members-sep" />
|
|
241
|
-
<button type="button" className="tac-member-main" onClick={() => newAgent(context)}>
|
|
242
|
-
<span className="tac-member-plus">
|
|
243
|
-
<UserPlus size={16} />
|
|
244
|
-
</span>
|
|
245
|
-
<span className="tac-member-text">
|
|
246
|
-
<span className="tac-member-name">{w.newAgent}</span>
|
|
247
|
-
</span>
|
|
248
|
-
</button>
|
|
249
|
-
</div>
|
|
250
|
-
{error && <div className="tac-empty tac-error">{error}</div>}
|
|
251
|
-
<div className="tac-members-foot">
|
|
252
|
-
<button type="button" className="tac-button tac-primary tac-wide" disabled={busy || picked.length === 0} onClick={submit}>
|
|
253
|
-
{picked.length > 0 ? ChannelWords.format(w.addCount, { count: String(picked.length) }) : w.add}
|
|
254
|
-
</button>
|
|
255
|
-
</div>
|
|
256
|
-
</div>
|
|
257
|
-
);
|
|
258
|
-
}
|
package/web-src/more-menu.tsx
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import type { WebExtensionAPI } from '@celljs/ta-web/lib/browser/extension/web-extension-api';
|
|
2
|
-
import { React } from './react';
|
|
3
|
-
import { ChannelViews } from './views';
|
|
4
|
-
|
|
5
|
-
/** About the height of the menu: below the button when there is that much room. */
|
|
6
|
-
const MENU_HEIGHT = 440;
|
|
7
|
-
|
|
8
|
-
export interface MoreItem {
|
|
9
|
-
key: string;
|
|
10
|
-
label: string;
|
|
11
|
-
icon?: React.ReactNode;
|
|
12
|
-
disabled?: boolean;
|
|
13
|
-
danger?: boolean;
|
|
14
|
-
run(): void;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* A … that shows on hover and opens a menu: sections of entries set apart by a line. A right click on the
|
|
19
|
-
* row it is in (its parent) opens it too. An entry closes the menu and runs; a click outside or Escape closes it.
|
|
20
|
-
*/
|
|
21
|
-
export function MoreMenu({ pi, label, items }: { pi: WebExtensionAPI; label: string; items: () => MoreItem[][] }) {
|
|
22
|
-
const w = ChannelViews.words(pi);
|
|
23
|
-
const [open, setOpen] = React.useState(false);
|
|
24
|
-
/** Opens upward when there is no room below the button. */
|
|
25
|
-
const [up, setUp] = React.useState(false);
|
|
26
|
-
const root = React.useRef<HTMLDivElement>(null);
|
|
27
|
-
const Ellipsis = ChannelViews.icon(pi, 'Ellipsis');
|
|
28
|
-
const show = React.useCallback((button: HTMLElement) => {
|
|
29
|
-
setUp(window.innerHeight - button.getBoundingClientRect().bottom < MENU_HEIGHT);
|
|
30
|
-
setOpen(true);
|
|
31
|
-
}, []);
|
|
32
|
-
React.useEffect(() => {
|
|
33
|
-
const row = root.current?.parentElement;
|
|
34
|
-
const button = root.current?.querySelector<HTMLElement>('.tac-action');
|
|
35
|
-
if (!row || !button) {
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
const onContextMenu = (event: MouseEvent) => {
|
|
39
|
-
event.preventDefault();
|
|
40
|
-
show(button);
|
|
41
|
-
};
|
|
42
|
-
row.addEventListener('contextmenu', onContextMenu);
|
|
43
|
-
return () => row.removeEventListener('contextmenu', onContextMenu);
|
|
44
|
-
}, [show]);
|
|
45
|
-
React.useEffect(() => {
|
|
46
|
-
if (!open) {
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
const close = (event: Event) => {
|
|
50
|
-
if (!root.current?.contains(event.target as Node)) {
|
|
51
|
-
setOpen(false);
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
const onKey = (event: KeyboardEvent) => {
|
|
55
|
-
if (event.key === 'Escape') {
|
|
56
|
-
setOpen(false);
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
document.addEventListener('pointerdown', close);
|
|
60
|
-
document.addEventListener('keydown', onKey);
|
|
61
|
-
return () => {
|
|
62
|
-
document.removeEventListener('pointerdown', close);
|
|
63
|
-
document.removeEventListener('keydown', onKey);
|
|
64
|
-
};
|
|
65
|
-
}, [open]);
|
|
66
|
-
return (
|
|
67
|
-
<div className="tac-item-more" ref={root}>
|
|
68
|
-
<button
|
|
69
|
-
type="button"
|
|
70
|
-
className={`tac-action${open ? ' tac-on' : ''}`}
|
|
71
|
-
title={w.more}
|
|
72
|
-
aria-label={w.more}
|
|
73
|
-
aria-haspopup="menu"
|
|
74
|
-
aria-expanded={open}
|
|
75
|
-
onClick={event => {
|
|
76
|
-
event.stopPropagation();
|
|
77
|
-
if (open) {
|
|
78
|
-
setOpen(false);
|
|
79
|
-
} else {
|
|
80
|
-
show(event.currentTarget);
|
|
81
|
-
}
|
|
82
|
-
}}
|
|
83
|
-
>
|
|
84
|
-
<Ellipsis size={15} />
|
|
85
|
-
</button>
|
|
86
|
-
{open && (
|
|
87
|
-
<div className={`tac-menu tac-agent-menu${up ? ' tac-up' : ''}`} role="menu" aria-label={label}>
|
|
88
|
-
{items().map((section, index) => (
|
|
89
|
-
<React.Fragment key={section[0]?.key ?? index}>
|
|
90
|
-
{index > 0 && <hr className="tac-menu-line" />}
|
|
91
|
-
{section.map(item => (
|
|
92
|
-
<button
|
|
93
|
-
key={item.key}
|
|
94
|
-
type="button"
|
|
95
|
-
role="menuitem"
|
|
96
|
-
className={item.danger ? 'tac-danger' : undefined}
|
|
97
|
-
disabled={item.disabled}
|
|
98
|
-
onClick={() => {
|
|
99
|
-
setOpen(false);
|
|
100
|
-
item.run();
|
|
101
|
-
}}
|
|
102
|
-
>
|
|
103
|
-
{item.icon}
|
|
104
|
-
<span className="tac-menu-label">{item.label}</span>
|
|
105
|
-
</button>
|
|
106
|
-
))}
|
|
107
|
-
</React.Fragment>
|
|
108
|
-
))}
|
|
109
|
-
</div>
|
|
110
|
-
)}
|
|
111
|
-
</div>
|
|
112
|
-
);
|
|
113
|
-
}
|
package/web-src/react.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type * as ReactModule from 'react';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* The React of the page, which a web extension cannot import: `activate` binds it before anything
|
|
5
|
-
* renders. The JSX of this package compiles to `React.createElement` (tsconfig.json).
|
|
6
|
-
*/
|
|
7
|
-
export let React: typeof ReactModule;
|
|
8
|
-
|
|
9
|
-
export function bind(react: typeof ReactModule): void {
|
|
10
|
-
React = react;
|
|
11
|
-
}
|
package/web-src/room.tsx
DELETED
|
@@ -1,212 +0,0 @@
|
|
|
1
|
-
import { type Agent, type ChannelMessage, ChannelsUtil, SYSTEM, TA, USER } from './channels-util';
|
|
2
|
-
import { Face, RoomFace } from './faces';
|
|
3
|
-
import { ChannelWords } from './i18n';
|
|
4
|
-
import { React } from './react';
|
|
5
|
-
import { AgentAvatar, type ChannelsContext, ChannelViews, MEMBERS_VIEW, membersOf, SidebarUtil, useChannels, useFaces, useUi } from './views';
|
|
6
|
-
|
|
7
|
-
/** A message as the group chat shows it. */
|
|
8
|
-
export interface RoomRow {
|
|
9
|
-
message: ChannelMessage;
|
|
10
|
-
/** The first of a run of one author: with its face and name. */
|
|
11
|
-
first: boolean;
|
|
12
|
-
/** A line with the time goes before it. */
|
|
13
|
-
separator: boolean;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/** A new run after this long without a word of the same author; a line with the time after a longer pause. */
|
|
17
|
-
const RUN_MS = 5 * 60 * 1000;
|
|
18
|
-
const PAUSE_MS = 15 * 60 * 1000;
|
|
19
|
-
|
|
20
|
-
export namespace RoomUtil {
|
|
21
|
-
export function rows(messages: ChannelMessage[]): RoomRow[] {
|
|
22
|
-
return messages.map((message, index) => {
|
|
23
|
-
const before = messages[index - 1];
|
|
24
|
-
const separator = !before || message.at - before.at > PAUSE_MS;
|
|
25
|
-
const first = separator || before.author !== message.author || before.author === SYSTEM || message.at - before.at > RUN_MS;
|
|
26
|
-
return { message, first, separator };
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/** The text of a message of the user, with the `@` names of members set apart. */
|
|
32
|
-
function Mentions({ text, agents }: { text: string; agents: Agent[] }) {
|
|
33
|
-
const names = new Set(agents.map(agent => agent.name.toLowerCase()));
|
|
34
|
-
const parts = text.split(/(@[^\s@#,,。::]+)/);
|
|
35
|
-
return (
|
|
36
|
-
<span>
|
|
37
|
-
{parts.map((part, index) =>
|
|
38
|
-
part.startsWith('@') && names.has(part.slice(1).toLowerCase()) ? (
|
|
39
|
-
<span key={index} className="tac-mention">
|
|
40
|
-
{part}
|
|
41
|
-
</span>
|
|
42
|
-
) : (
|
|
43
|
-
part
|
|
44
|
-
),
|
|
45
|
-
)}
|
|
46
|
-
</span>
|
|
47
|
-
);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/** The middle of the bar above the channel: its name and topic, and its members, which open their view on the right. */
|
|
51
|
-
export function ChannelHead({ context }: { context: ChannelsContext }) {
|
|
52
|
-
const { pi, service, ui } = context;
|
|
53
|
-
const state = useChannels(service);
|
|
54
|
-
const { channelId } = useUi(ui);
|
|
55
|
-
const faces = useFaces(state.team);
|
|
56
|
-
const w = ChannelViews.words(pi);
|
|
57
|
-
const shown = !!pi.ui.useView(MEMBERS_VIEW)?.shown;
|
|
58
|
-
const channel = state.team.channels.find(candidate => candidate.id === channelId);
|
|
59
|
-
if (!channel) {
|
|
60
|
-
return null;
|
|
61
|
-
}
|
|
62
|
-
const members = membersOf(state.team, channel);
|
|
63
|
-
const working = state.working[channel.id] ?? [];
|
|
64
|
-
return (
|
|
65
|
-
<div className="tac-head">
|
|
66
|
-
<div className="tac-head-title">
|
|
67
|
-
<strong>{channel.name}</strong>
|
|
68
|
-
<span className="tac-head-count">{ChannelWords.format(w.memberCount, { count: String(members.length) })}</span>
|
|
69
|
-
{channel.topic && <span className="tac-head-topic">{channel.topic}</span>}
|
|
70
|
-
</div>
|
|
71
|
-
<button
|
|
72
|
-
type="button"
|
|
73
|
-
className={`tac-head-members${shown ? ' tac-on' : ''}`}
|
|
74
|
-
title={w.showMembers}
|
|
75
|
-
aria-label={w.showMembers}
|
|
76
|
-
aria-pressed={shown}
|
|
77
|
-
onClick={() => context.showMembers()}
|
|
78
|
-
>
|
|
79
|
-
{members.slice(0, 5).map(agent => (
|
|
80
|
-
<span key={agent.id} className="tac-head-face">
|
|
81
|
-
<AgentAvatar agent={agent} faces={faces} size={24} working={working.includes(agent.id)} />
|
|
82
|
-
</span>
|
|
83
|
-
))}
|
|
84
|
-
{members.length > 5 && <span className="tac-head-more">+{members.length - 5}</span>}
|
|
85
|
-
</button>
|
|
86
|
-
</div>
|
|
87
|
-
);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/** A channel as a group chat: who said what, each with their face, the user on the right; a box to write to it. */
|
|
91
|
-
export function ChannelRoom({ context }: { context: ChannelsContext }) {
|
|
92
|
-
const { pi, service, ui } = context;
|
|
93
|
-
const state = useChannels(service);
|
|
94
|
-
const { channelId } = useUi(ui);
|
|
95
|
-
const faces = useFaces(state.team);
|
|
96
|
-
const w = ChannelViews.words(pi);
|
|
97
|
-
const list = React.useRef<HTMLDivElement>(null);
|
|
98
|
-
const channel = state.team.channels.find(candidate => candidate.id === channelId);
|
|
99
|
-
const messages = channel ? state.messages[channel.id] : undefined;
|
|
100
|
-
const working = channel ? (state.working[channel.id] ?? []) : [];
|
|
101
|
-
React.useEffect(() => {
|
|
102
|
-
if (channelId) {
|
|
103
|
-
void service.messages(channelId);
|
|
104
|
-
}
|
|
105
|
-
}, [service, channelId]);
|
|
106
|
-
// To the bottom when the chat grows or another channel shows.
|
|
107
|
-
React.useLayoutEffect(() => {
|
|
108
|
-
const element = list.current;
|
|
109
|
-
if (element) {
|
|
110
|
-
element.scrollTop = element.scrollHeight;
|
|
111
|
-
}
|
|
112
|
-
}, [channelId, messages?.length, working.length]);
|
|
113
|
-
const Markdown = pi.ui.Markdown;
|
|
114
|
-
const Composer = pi.ui.Composer;
|
|
115
|
-
const Avatar = pi.ui.Avatar;
|
|
116
|
-
if (!channel) {
|
|
117
|
-
return <div className="tac-room-none">{state.loaded ? w.pick : ''}</div>;
|
|
118
|
-
}
|
|
119
|
-
const members = membersOf(state.team, channel);
|
|
120
|
-
const agentOf = (id: string) => state.team.agents.find(agent => agent.id === id);
|
|
121
|
-
const name = (id: string) => ChannelsUtil.authorName(state.team, id, { user: w.you, ta: w.ta });
|
|
122
|
-
const time = (at: number) => SidebarUtil.time(at, pi.ui.language);
|
|
123
|
-
const mention = (agent: Agent) => ({
|
|
124
|
-
key: agent.id,
|
|
125
|
-
label: agent.name,
|
|
126
|
-
icon: <AgentAvatar agent={agent} faces={faces} size={20} />,
|
|
127
|
-
detail: agent.id === channel.members[0] ? w.lead : undefined,
|
|
128
|
-
insert: `@${agent.name} `,
|
|
129
|
-
});
|
|
130
|
-
return (
|
|
131
|
-
<div className="tac-room-page">
|
|
132
|
-
<div className="tac-chat" ref={list}>
|
|
133
|
-
<div className="tac-chat-col">
|
|
134
|
-
{messages && messages.length === 0 && (
|
|
135
|
-
<div className="tac-chat-empty">
|
|
136
|
-
<RoomFace members={members} faces={faces} size={56} working={working} />
|
|
137
|
-
<strong>{channel.name}</strong>
|
|
138
|
-
{channel.topic && <span>{channel.topic}</span>}
|
|
139
|
-
<span className="tac-chat-hint">{w.quiet}</span>
|
|
140
|
-
</div>
|
|
141
|
-
)}
|
|
142
|
-
{messages &&
|
|
143
|
-
RoomUtil.rows(messages).map(({ message, first, separator }) => (
|
|
144
|
-
<React.Fragment key={message.id}>
|
|
145
|
-
{separator && <div className="tac-chat-time">{time(message.at)}</div>}
|
|
146
|
-
{message.author === SYSTEM ? (
|
|
147
|
-
<div className="tac-notice" role="note">
|
|
148
|
-
{w.stopped}
|
|
149
|
-
</div>
|
|
150
|
-
) : message.author === USER ? (
|
|
151
|
-
<div className="ta-message ta-user tac-mine">
|
|
152
|
-
<div className="ta-bubble">
|
|
153
|
-
<Mentions text={message.text} agents={state.team.agents} />
|
|
154
|
-
</div>
|
|
155
|
-
</div>
|
|
156
|
-
) : (
|
|
157
|
-
<div className={`tac-msg${first ? ' tac-first' : ''}`}>
|
|
158
|
-
<div className="tac-msg-face">
|
|
159
|
-
{first &&
|
|
160
|
-
(message.author === TA ? (
|
|
161
|
-
<Avatar size={28} />
|
|
162
|
-
) : (
|
|
163
|
-
<AgentAvatar
|
|
164
|
-
agent={agentOf(message.author)}
|
|
165
|
-
faces={faces}
|
|
166
|
-
size={28}
|
|
167
|
-
working={working.includes(message.author)}
|
|
168
|
-
/>
|
|
169
|
-
))}
|
|
170
|
-
</div>
|
|
171
|
-
<div className="tac-msg-col">
|
|
172
|
-
{first && (
|
|
173
|
-
<div className="tac-msg-name">
|
|
174
|
-
{name(message.author)}
|
|
175
|
-
{message.author === channel.members[0] && <span className="tac-msg-lead">{w.lead}</span>}
|
|
176
|
-
</div>
|
|
177
|
-
)}
|
|
178
|
-
<div className={`tac-msg-bubble${message.failed ? ' tac-failed' : ''}`} title={time(message.at)}>
|
|
179
|
-
{message.failed && <div className="tac-msg-failed">{w.failed}</div>}
|
|
180
|
-
<Markdown text={ChannelsUtil.markMentions(message.text, state.team.agents)} />
|
|
181
|
-
</div>
|
|
182
|
-
</div>
|
|
183
|
-
</div>
|
|
184
|
-
)}
|
|
185
|
-
</React.Fragment>
|
|
186
|
-
))}
|
|
187
|
-
{working.length > 0 && (
|
|
188
|
-
<div className="tac-live" role="status">
|
|
189
|
-
<span className="tac-live-faces">
|
|
190
|
-
{working.map(id => (
|
|
191
|
-
<Face key={id} face={faces.get(id) ?? 0} size={18} working />
|
|
192
|
-
))}
|
|
193
|
-
</span>
|
|
194
|
-
{ChannelWords.format(w.answeringNow, { name: working.map(name).join('、') })}
|
|
195
|
-
</div>
|
|
196
|
-
)}
|
|
197
|
-
</div>
|
|
198
|
-
</div>
|
|
199
|
-
<div className="tac-chat-bottom">
|
|
200
|
-
<Composer
|
|
201
|
-
placeholder={ChannelWords.format(w.placeholder, { channel: channel.name })}
|
|
202
|
-
mentions={members.map(agent => ({ name: agent.name, detail: agent.role.split('\n')[0] }))}
|
|
203
|
-
actions={[
|
|
204
|
-
members.map(mention),
|
|
205
|
-
[{ key: 'add', label: w.addMembers, icon: ChannelViews.maybeIcon(pi, 'UserPlus', null, 16), run: () => context.showMembers(true) }],
|
|
206
|
-
]}
|
|
207
|
-
onSend={text => service.post(channel.id, text)}
|
|
208
|
-
/>
|
|
209
|
-
</div>
|
|
210
|
-
</div>
|
|
211
|
-
);
|
|
212
|
-
}
|