diff --git a/package.json b/package.json index c98d07b..0e72131 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "@shopify/flash-list": "^1.6.3", "date-fns": "^3.3.1", "expo": "~50.0.8", + "expo-clipboard": "~5.0.1", "expo-notifications": "~0.27.6", "expo-updates": "~0.24.11", "react": "18.2.0", diff --git a/src/lib/weechat/connection.ts b/src/lib/weechat/connection.ts index dde6e16..4817f02 100644 --- a/src/lib/weechat/connection.ts +++ b/src/lib/weechat/connection.ts @@ -100,7 +100,7 @@ export default class WeechatConnection { } onmessage(event: WebSocketMessageEvent): void { - const parsed = protocol.parse(event.data) as WeechatResponse; + const parsed = protocol.parse(event.data); if (parsed.id == 'version') { this.authenticating = false; diff --git a/src/lib/weechat/parser.d.ts b/src/lib/weechat/parser.d.ts index 677d202..7ac15aa 100644 --- a/src/lib/weechat/parser.d.ts +++ b/src/lib/weechat/parser.d.ts @@ -1,5 +1,5 @@ export class WeeChatProtocol { - static rawText2Rich(input); + static rawText2Rich(input: string): AttributedStringNode[]; - parse(data, optionsValues?); + parse(data: ArrayBuffer): WeechatResponse; } diff --git a/src/usecase/buffers/ui/Buffer.tsx b/src/usecase/buffers/ui/Buffer.tsx index 5dea4a3..0d902db 100644 --- a/src/usecase/buffers/ui/Buffer.tsx +++ b/src/usecase/buffers/ui/Buffer.tsx @@ -9,7 +9,7 @@ import BufferLine from './BufferLine'; interface Props { lines: WeechatLine[]; lastReadLine?: string; - onLongPress: () => void; + onLongPress: (line: WeechatLine) => void; parseArgs: ParseShape[]; bufferId: string; fetchMoreLines: (lines: number) => void; diff --git a/src/usecase/buffers/ui/BufferContainer.tsx b/src/usecase/buffers/ui/BufferContainer.tsx index 66caf55..e69ee86 100644 --- a/src/usecase/buffers/ui/BufferContainer.tsx +++ b/src/usecase/buffers/ui/BufferContainer.tsx @@ -20,6 +20,8 @@ import { renderWeechatFormat } from '../../../lib/weechat/color-formatter'; import { StoreState } from '../../../store'; import Buffer from './Buffer'; import UndoTextInput from './UndoTextInput'; +import * as Clipboard from 'expo-clipboard'; +import { WeeChatProtocol } from '../../../lib/weechat/parser'; const connector = connect( (state: StoreState, { bufferId }: { bufferId: string }) => ({ @@ -165,8 +167,23 @@ class BufferContainer extends React.Component { this.setState({ selection }); }; - onLongPress = () => { - // not implemented + onLongPress = (line: WeechatLine) => { + const formattedPrefix = WeeChatProtocol.rawText2Rich(line.prefix); + const prefix = formattedPrefix.map((node) => node.text); + const formattedMessage = WeeChatProtocol.rawText2Rich(line.message); + const message = formattedMessage.map((node) => node.text); + + ActionSheetIOS.showActionSheetWithOptions( + { options: ['Copy', 'Cancel'], cancelButtonIndex: 2 }, + () => { + const encloseNick = + line.tags_array.includes('irc_privmsg') && + !line.tags_array.includes('irc_action'); + Clipboard.setStringAsync( + `${encloseNick ? '<' : ''}${prefix.join('')}${encloseNick ? '>' : ''} ${message.join('')}` + ); + } + ); }; render() { diff --git a/yarn.lock b/yarn.lock index 441f544..79190f3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5043,6 +5043,11 @@ expo-asset@~9.0.2: invariant "^2.2.4" md5-file "^3.2.3" +expo-clipboard@~5.0.1: + version "5.0.1" + resolved "https://registry.yarnpkg.com/expo-clipboard/-/expo-clipboard-5.0.1.tgz#a62a021a9444740d180d60f915cca8242a323716" + integrity sha512-JH853QJPr5W3h87If3aDTnMK+ESSIrwzU2TdfZrqZttVDY2pMIf/w37mVHHNYodXM4ATHXadtOkjKbAa0DWwUg== + expo-constants@~15.4.0: version "15.4.5" resolved "https://registry.yarnpkg.com/expo-constants/-/expo-constants-15.4.5.tgz#81756a4c4e1c020f840a419cd86a124a6d1fb35b"