FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
tdesktop/Telegram/SourceFiles/data/data_drafts.cpp at dev · dmitry/tdesktop · GitHub
dmitry
tdesktop
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
tdesktop
/
Telegram
/
SourceFiles
/
data
/
data_drafts.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
185 lines (172 loc) · 5.32 KB
Breadcrumbs
tdesktop
/
Telegram
/
SourceFiles
/
data
/
data_drafts.cpp
Copy path
File metadata and controls
185 lines (172 loc) · 5.32 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#
include
"
data/data_drafts.h
"
#
include
"
api/api_text_entities.h
"
#
include
"
ui/widgets/fields/input_field.h
"
#
include
"
chat_helpers/message_field.h
"
#
include
"
history/history.h
"
#
include
"
history/history_widget.h
"
#
include
"
history/history_item_components.h
"
#
include
"
main/main_session.h
"
#
include
"
data/data_changes.h
"
#
include
"
data/data_session.h
"
#
include
"
data/data_web_page.h
"
#
include
"
mainwidget.h
"
#
include
"
storage/localstorage.h
"
namespace
Data
{
WebPageDraft
WebPageDraft::FromItem
(not_null<HistoryItem*> item) {
const
auto
previewMedia = item->
media
();
const
auto
previewPage = previewMedia
? previewMedia->
webpage
()
:
nullptr
;
using
PageFlag = MediaWebPageFlag;
const
auto
previewFlags = previewMedia
? previewMedia->
webpageFlags
()
:
PageFlag
();
return
{
.
id
= previewPage ? previewPage->
id
:
0
,
.
url
= previewPage ? previewPage->
url
:
QString
(),
.
forceLargeMedia
= !!(previewFlags & PageFlag::ForceLargeMedia),
.
forceSmallMedia
= !!(previewFlags & PageFlag::ForceSmallMedia),
.
invert
= item->
invertMedia
(),
.
manual
= !!(previewFlags & PageFlag::Manual),
.
removed
= !previewPage,
};
}
Draft::Draft
(
const
TextWithTags &textWithTags,
FullReplyTo reply,
SuggestOptions suggest,
const
MessageCursor &cursor,
WebPageDraft webpage,
mtpRequestId saveRequestId)
: textWithTags(textWithTags)
, reply(std::move(reply))
, suggest(suggest)
, cursor(cursor)
, webpage(webpage)
, saveRequestId(saveRequestId) {
}
Draft::Draft
(
not_null<
const
Ui::InputField*> field,
FullReplyTo reply,
SuggestOptions suggest,
WebPageDraft webpage,
mtpRequestId saveRequestId)
: textWithTags(field->
getTextWithTags
())
, reply(std::move(reply))
, suggest(suggest)
, cursor(field)
, webpage(webpage) {
}
void
ApplyPeerCloudDraft
(
not_null<Main::Session*> session,
PeerId peerId,
MsgId topicRootId,
PeerId monoforumPeerId,
const
MTPDdraftMessage &draft) {
const
auto
history = session->
data
().
history
(peerId);
const
auto
date = draft.
vdate
().
v
;
if
(history->
skipCloudDraftUpdate
(topicRootId, monoforumPeerId, date)) {
return
;
}
const
auto
textWithTags = TextWithTags{
qs
(draft.
vmessage
()),
TextUtilities::ConvertEntitiesToTextTags
(
Api::EntitiesFromMTP
(
session,
draft.
ventities
().
value_or_empty
()))
};
auto
replyTo = draft.
vreply_to
()
?
ReplyToFromMTP
(history, *draft.
vreply_to
())
:
FullReplyTo
();
replyTo.
topicRootId
= topicRootId;
replyTo.
monoforumPeerId
= monoforumPeerId;
auto
webpage = WebPageDraft{
.
invert
= draft.
is_invert_media
(),
.
removed
= draft.
is_no_webpage
(),
};
if
(
const
auto
media = draft.
vmedia
()) {
media->
match
([&](
const
MTPDmessageMediaWebPage &data) {
const
auto
parsed = session->
data
().
processWebpage
(
data.
vwebpage
());
if
(!parsed->
failed
) {
webpage.
forceLargeMedia
= data.
is_force_large_media
();
webpage.
forceSmallMedia
= data.
is_force_small_media
();
webpage.
manual
= data.
is_manual
();
webpage.
url
= parsed->
url
;
webpage.
id
= parsed->
id
;
}
}, [](
const
auto
&) {});
}
auto
suggest =
SuggestOptions
();
if
(!history->
suggestDraftAllowed
()) {
//
Don't apply suggest options in unsupported chats.
}
else
if
(
const
auto
suggested = draft.
vsuggested_post
()) {
const
auto
&data = suggested->
data
();
suggest.
exists
=
1
;
suggest.
date
= data.
vschedule_date
().
value_or_empty
();
const
auto
price =
CreditsAmountFromTL
(data.
vprice
());
suggest.
priceWhole
= price.
whole
();
suggest.
priceNano
= price.
nano
();
suggest.
ton
= price.
ton
() ?
1
:
0
;
}
auto
cloudDraft = std::make_unique<Draft>(
textWithTags,
replyTo,
suggest,
MessageCursor
(Ui::
kQFixedMax
, Ui::
kQFixedMax
, Ui::
kQFixedMax
),
std::move
(webpage));
cloudDraft->
date
= date;
history->
setCloudDraft
(
std::move
(cloudDraft));
history->
applyCloudDraft
(topicRootId, monoforumPeerId);
}
void
ClearPeerCloudDraft
(
not_null<Main::Session*> session,
PeerId peerId,
MsgId topicRootId,
PeerId monoforumPeerId,
TimeId date) {
const
auto
history = session->
data
().
history
(peerId);
if
(history->
skipCloudDraftUpdate
(topicRootId, monoforumPeerId, date)) {
return
;
}
history->
clearCloudDraft
(topicRootId, monoforumPeerId);
history->
applyCloudDraft
(topicRootId, monoforumPeerId);
}
void
SetChatLinkDraft
(not_null<PeerData*> peer, TextWithEntities draft) {
static
const
auto
kInlineStart
=
QRegularExpression
(
"
^@[a-zA-Z0-9_]
"
);
if
(
kInlineStart
.
match
(draft.
text
).
hasMatch
()) {
draft =
TextWithEntities
().
append
(
'
'
).
append
(
std::move
(draft));
}
const
auto
textWithTags = TextWithTags{
draft.
text
,
TextUtilities::ConvertEntitiesToTextTags
(draft.
entities
)
};
const
auto
cursor = MessageCursor{
int
(textWithTags.
text
.
size
()),
int
(textWithTags.
text
.
size
()),
Ui::
kQFixedMax
};
const
auto
history = peer->
owner
().
history
(peer->
id
);
const
auto
topicRootId =
MsgId
();
const
auto
monoforumPeerId =
PeerId
();
history->
setLocalDraft
(std::make_unique<Draft>(
textWithTags,
FullReplyTo{
.
topicRootId
= topicRootId,
.
monoforumPeerId
= monoforumPeerId,
},
SuggestOptions
(),
cursor,
WebPageDraft
()));
history->
clearLocalEditDraft
(topicRootId, monoforumPeerId);
history->
session
().
changes
().
entryUpdated
(
history,
EntryUpdate::Flag::LocalDraftSet);
}
}
//
namespace Data
Back
|
FazBrowse Home
|
New Git URL