Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: copy msg selection addition metadata #358

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Deploy

on:
push:
branches: ['master']
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [20.x]

steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: master

- name: Setup pnpm
uses: pnpm/action-setup@v2

- name: Setup node
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
registry-url: https://registry.npmjs.com/
cache: 'pnpm'

- name: Install dependencies
run: pnpm i --frozen-lockfile

- name: Build
run: |
pnpm run build
cp -r dist/* public

- name: Deploy to GitHub Pages
uses: JamesIves/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
folder: public
git-config-name: github-actions[bot]
git-config-email: github-actions[bot]@users.noreply.github.com
31 changes: 23 additions & 8 deletions src/components/chat/contextMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import findUpClassName from '../../helpers/dom/findUpClassName';
import cancelEvent from '../../helpers/dom/cancelEvent';
import {attachClickEvent, simulateClickEvent} from '../../helpers/dom/clickEvent';
import isSelectionEmpty from '../../helpers/dom/isSelectionEmpty';
import {Message, Poll, Chat as MTChat, MessageMedia, AvailableReaction, MessageEntity, InputStickerSet, StickerSet, Document, Reaction, Photo, SponsoredMessage, ChannelParticipant, TextWithEntities} from '../../layer';
import {Message, Poll, Chat as MTChat, MessageMedia, AvailableReaction, MessageEntity, InputStickerSet, StickerSet, Document, Reaction, Photo, SponsoredMessage, ChannelParticipant, TextWithEntities, User} from '../../layer';
import PopupReportMessages from '../popups/reportMessages';
import assumeType from '../../helpers/assumeType';
import PopupSponsored from '../popups/sponsored';
Expand Down Expand Up @@ -75,6 +75,8 @@ import getRichValueWithCaret from '../../helpers/dom/getRichValueWithCaret';
import deepEqual from '../../helpers/object/deepEqual';
import wrapDraftText from '../../lib/richTextProcessor/wrapDraftText';
import flatten from '../../helpers/array/flatten';
import {logger} from '../../lib/logger'
import DEBUG from '../../config/debug';

type ChatContextMenuButton = ButtonMenuItemOptions & {
verify: () => boolean | Promise<boolean>,
Expand Down Expand Up @@ -128,13 +130,16 @@ export default class ChatContextMenu {
private canViewReadTime: boolean;
private messageLanguage: TranslatableLanguageISO;

private log: ReturnType<typeof logger>;

constructor(
private chat: Chat,
private managers: AppManagers
) {
this.listenerSetter = new ListenerSetter();
this.attachListenerSetter = new ListenerSetter();
this.middleware = getMiddleware();
this.log = logger('ContextMenu')
}

public attachTo(element: HTMLElement) {
Expand Down Expand Up @@ -1262,24 +1267,34 @@ export default class ChatContextMenu {
if(this.isSponsored) {
messages = [this.sponsoredMessage];
} else {
messages = fullMids.map((fullMid) => this.chat.getMessage(fullMid) as Message.message);
messages = fullMids.map((fullMid) => this.chat.getMessage(fullMid) as Message.message).sort((a, b)=> a.date - b.date);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sort by date asc

}

const formatter = async(message: typeof messages[number]) => {
let prefix = ''
if(message._ === 'message') {
const peer = await this.managers.appPeersManager.getPeer(message?.fromId) as User.user
prefix += `${peer.first_name}, [${new Date(message.date * 1000).toLocaleString()}]`
DEBUG && this.log('peer', peer)
DEBUG && this.log('message', message)
prefix += '\n'
}
return [prefix, message?.message].join('')
}

const htmlParts = messages.map((message) => {
const htmlParts = await Promise.all(messages.map(async(message) => {
if(!message?.message) {
return;
}

const wrapped = wrapRichText(message.message, {
const wrapped = wrapRichText(await formatter(message), {
entities: (message as Message.message).totalEntities || message.entities,
wrappingDraft: true
});
return documentFragmentToHTML(wrapped);
});
}));

const parts: string[] = messages.map((message) => {
return message?.message;
});
const parts: string[] = await Promise.all(messages.map(formatter));

return {
text: parts.filter(Boolean).join('\n'),
Expand Down