mirror of https://github.com/procxx/kepka.git
improved scheme serializer, fixed channel photo delete button, bad media update when message was sent
This commit is contained in:
parent
6321d22fc9
commit
425e2c2a81
|
@ -752,7 +752,7 @@ namespace App {
|
|||
}
|
||||
}
|
||||
|
||||
existing->setMedia(m.has_media() ? (&m.vmedia) : 0);
|
||||
existing->updateMedia(m.has_media() ? (&m.vmedia) : 0);
|
||||
|
||||
existing->setViewsCount(m.has_views() ? m.vviews.v : -1);
|
||||
}
|
||||
|
@ -1930,7 +1930,7 @@ namespace App {
|
|||
prepareCorners(InShadowCorners, st::msgRadius, st::msgInShadow);
|
||||
prepareCorners(InSelectedShadowCorners, st::msgRadius, st::msgInSelectShadow);
|
||||
prepareCorners(ForwardCorners, st::msgRadius, st::forwardBg);
|
||||
prepareCorners(MediaviewSaveCorners, st::msgRadius, st::emojiPanHover);
|
||||
prepareCorners(MediaviewSaveCorners, st::msgRadius, st::medviewSaveMsg);
|
||||
prepareCorners(EmojiHoverCorners, st::msgRadius, st::emojiPanHover);
|
||||
prepareCorners(StickerHoverCorners, st::msgRadius, st::emojiPanHover);
|
||||
prepareCorners(BotKeyboardCorners, st::msgRadius, st::botKbBg);
|
||||
|
|
|
@ -1338,14 +1338,8 @@ HistoryItem *History::createItem(HistoryBlock *block, const MTPMessage &msg, boo
|
|||
regged = true;
|
||||
}
|
||||
|
||||
const MTPMessageMedia *media = 0;
|
||||
switch (msg.type()) {
|
||||
case mtpc_message:
|
||||
media = msg.c_message().has_media() ? (&msg.c_message().vmedia) : 0;
|
||||
break;
|
||||
}
|
||||
if (media) {
|
||||
existing->updateMedia(*media);
|
||||
if (msg.type() == mtpc_message) {
|
||||
existing->updateMedia(msg.c_message().has_media() ? (&msg.c_message().vmedia) : 0);
|
||||
}
|
||||
return (returnExisting || regged) ? existing : 0;
|
||||
}
|
||||
|
|
|
@ -877,7 +877,7 @@ public:
|
|||
virtual bool serviceMsg() const {
|
||||
return false;
|
||||
}
|
||||
virtual void updateMedia(const MTPMessageMedia &media) {
|
||||
virtual void updateMedia(const MTPMessageMedia *media) {
|
||||
}
|
||||
|
||||
virtual QString selectedText(uint32 selection) const {
|
||||
|
@ -1531,9 +1531,11 @@ public:
|
|||
QString notificationHeader() const;
|
||||
QString notificationText() const;
|
||||
|
||||
void updateMedia(const MTPMessageMedia &media) {
|
||||
if (_media) {
|
||||
_media->updateFrom(media);
|
||||
void updateMedia(const MTPMessageMedia *media) {
|
||||
if (media && _media && _media->type() != MediaTypeWebPage) {
|
||||
_media->updateFrom(*media);
|
||||
} else {
|
||||
setMedia(media);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4149,7 +4149,7 @@ void MainWidget::feedUpdates(const MTPUpdates &updates, uint64 randomId) {
|
|||
}
|
||||
}
|
||||
|
||||
item->setMedia(d.has_media() ? (&d.vmedia) : 0);
|
||||
item->updateMedia(d.has_media() ? (&d.vmedia) : 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -328,7 +328,7 @@ void MediaView::updateDropdown() {
|
|||
_btnSaveAs->setVisible(true);
|
||||
_btnCopy->setVisible((_doc && !_current.isNull()) || (_photo && _photo->full->loaded()));
|
||||
_btnForward->setVisible(_canForward);
|
||||
_btnDelete->setVisible(_canDelete || (_photo && App::self() && App::self()->photoId == _photo->id) || (_photo && _photo->peer && _photo->peer->photoId == _photo->id));
|
||||
_btnDelete->setVisible(_canDelete || (_photo && App::self() && App::self()->photoId == _photo->id) || (_photo && _photo->peer && _photo->peer->photoId == _photo->id && (_photo->peer->isChat() || (_photo->peer->isChannel() && _photo->peer->asChannel()->amCreator()))));
|
||||
_btnViewAll->setVisible((_overview != OverviewCount) && _history);
|
||||
_btnViewAll->setText(lang(_doc ? lng_mediaview_files_all : lng_mediaview_photos_all));
|
||||
_dropdown.updateButtons();
|
||||
|
|
|
@ -33,7 +33,8 @@ funcsText = '';
|
|||
typesText = '';
|
||||
dataTexts = '';
|
||||
inlineMethods = '';
|
||||
textSerialize = '';
|
||||
textSerializeInit = '';
|
||||
textSerializeMethods = '';
|
||||
forwards = '';
|
||||
forwTypedefs = '';
|
||||
out = open('mtpScheme.h', 'w')
|
||||
|
@ -305,21 +306,19 @@ def addTextSerialize(lst, dct, dataLetter):
|
|||
conditionsList = data[5];
|
||||
conditions = data[6];
|
||||
|
||||
if len(result):
|
||||
result += '\n';
|
||||
result += '\t\t\tcase mtpc_' + name + ':\n';
|
||||
result += 'void _serialize_' + name + '(MTPStringLogger &to, int32 stage, int32 lev, Types &types, Types &vtypes, StagesFlags &stages, StagesFlags &flags, const mtpPrime *start, const mtpPrime *end, int32 flag) {\n';
|
||||
if (len(prms)):
|
||||
result += '\t\t\t\tif (stage) {\n';
|
||||
result += '\t\t\t\t\tto.add(",\\n").addSpaces(lev);\n';
|
||||
result += '\t\t\t\t} else {\n';
|
||||
result += '\t\t\t\t\tto.add("{ ' + name + '");\n';
|
||||
result += '\t\t\t\t\tto.add("\\n").addSpaces(lev);\n';
|
||||
result += '\t\t\t\t}\n';
|
||||
result += '\t\t\t\tswitch (stage) {\n';
|
||||
result += '\tif (stage) {\n';
|
||||
result += '\t\tto.add(",\\n").addSpaces(lev);\n';
|
||||
result += '\t} else {\n';
|
||||
result += '\t\tto.add("{ ' + name + '");\n';
|
||||
result += '\t\tto.add("\\n").addSpaces(lev);\n';
|
||||
result += '\t}\n';
|
||||
result += '\tswitch (stage) {\n';
|
||||
stage = 0;
|
||||
for k in prmsList:
|
||||
v = prms[k];
|
||||
result += '\t\t\t\tcase ' + str(stage) + ': to.add(" ' + k + ': "); ++stages.back(); ';
|
||||
result += '\tcase ' + str(stage) + ': to.add(" ' + k + ': "); ++stages.back(); ';
|
||||
if (k == hasFlags):
|
||||
result += 'if (start >= end) throw Exception("start >= end in flags"); else flags.back() = *start; ';
|
||||
if (k in conditionsList):
|
||||
|
@ -370,15 +369,27 @@ def addTextSerialize(lst, dct, dataLetter):
|
|||
result += '} else { to.add("[ SKIPPED BY BIT ' + conditions[k] + ' IN FIELD ' + hasFlags + ' ]"); } ';
|
||||
result += 'break;\n';
|
||||
stage = stage + 1;
|
||||
result += '\t\t\t\tdefault: to.add("}"); types.pop_back(); vtypes.pop_back(); stages.pop_back(); flags.pop_back(); break;\n';
|
||||
result += '\t\t\t\t}\n';
|
||||
result += '\tdefault: to.add("}"); types.pop_back(); vtypes.pop_back(); stages.pop_back(); flags.pop_back(); break;\n';
|
||||
result += '\t}\n';
|
||||
else:
|
||||
result += '\t\t\t\tto.add("{ ' + name + ' }"); types.pop_back(); vtypes.pop_back(); stages.pop_back(); flags.pop_back();\n';
|
||||
result += '\t\t\tbreak;\n';
|
||||
result += '\tto.add("{ ' + name + ' }"); types.pop_back(); vtypes.pop_back(); stages.pop_back(); flags.pop_back();\n';
|
||||
result += '}\n\n';
|
||||
return result;
|
||||
|
||||
textSerialize += addTextSerialize(typesList, typesDict, 'D') + '\n';
|
||||
textSerialize += addTextSerialize(funcsList, funcsDict, '');
|
||||
# text serialization: types and funcs
|
||||
def addTextSerializeInit(lst, dct):
|
||||
result = '';
|
||||
for restype in lst:
|
||||
v = dct[restype];
|
||||
for data in v:
|
||||
name = data[0];
|
||||
result += '\t\t_serializers.insert(mtpc_' + name + ', _serialize_' + name + ');\n';
|
||||
return result;
|
||||
|
||||
textSerializeMethods += addTextSerialize(typesList, typesDict, 'D');
|
||||
textSerializeInit += addTextSerializeInit(typesList, typesDict) + '\n';
|
||||
textSerializeMethods += addTextSerialize(funcsList, funcsDict, '');
|
||||
textSerializeInit += addTextSerializeInit(funcsList, funcsDict) + '\n';
|
||||
|
||||
for restype in typesList:
|
||||
v = typesDict[restype];
|
||||
|
@ -662,7 +673,55 @@ for restype in typesList:
|
|||
inlineMethods += creatorsText;
|
||||
typesText += 'typedef MTPBoxed<MTP' + restype + '> MTP' + resType + ';\n'; # boxed type definition
|
||||
|
||||
# manual types added here
|
||||
textSerializeMethods += 'void _serialize_rpc_result(MTPStringLogger &to, int32 stage, int32 lev, Types &types, Types &vtypes, StagesFlags &stages, StagesFlags &flags, const mtpPrime *start, const mtpPrime *end, int32 flag) {\n';
|
||||
textSerializeMethods += '\tif (stage) {\n';
|
||||
textSerializeMethods += '\t\tto.add(",\\n").addSpaces(lev);\n';
|
||||
textSerializeMethods += '\t} else {\n';
|
||||
textSerializeMethods += '\t\tto.add("{ rpc_result");\n';
|
||||
textSerializeMethods += '\t\tto.add("\\n").addSpaces(lev);\n';
|
||||
textSerializeMethods += '\t}\n';
|
||||
textSerializeMethods += '\tswitch (stage) {\n';
|
||||
textSerializeMethods += '\tcase 0: to.add(" req_msg_id: "); ++stages.back(); types.push_back(mtpc_long); vtypes.push_back(0); stages.push_back(0); flags.push_back(0); break;\n';
|
||||
textSerializeMethods += '\tcase 1: to.add(" result: "); ++stages.back(); types.push_back(0); vtypes.push_back(0); stages.push_back(0); flags.push_back(0); break;\n';
|
||||
textSerializeMethods += '\tdefault: to.add("}"); types.pop_back(); vtypes.pop_back(); stages.pop_back(); flags.pop_back(); break;\n';
|
||||
textSerializeMethods += '\t}\n';
|
||||
textSerializeMethods += '}\n\n';
|
||||
textSerializeInit += '\t\t_serializers.insert(mtpc_rpc_result, _serialize_rpc_result);\n';
|
||||
|
||||
textSerializeMethods += 'void _serialize_msg_container(MTPStringLogger &to, int32 stage, int32 lev, Types &types, Types &vtypes, StagesFlags &stages, StagesFlags &flags, const mtpPrime *start, const mtpPrime *end, int32 flag) {\n';
|
||||
textSerializeMethods += '\tif (stage) {\n';
|
||||
textSerializeMethods += '\t\tto.add(",\\n").addSpaces(lev);\n';
|
||||
textSerializeMethods += '\t} else {\n';
|
||||
textSerializeMethods += '\t\tto.add("{ msg_container");\n';
|
||||
textSerializeMethods += '\t\tto.add("\\n").addSpaces(lev);\n';
|
||||
textSerializeMethods += '\t}\n';
|
||||
textSerializeMethods += '\tswitch (stage) {\n';
|
||||
textSerializeMethods += '\tcase 0: to.add(" messages: "); ++stages.back(); types.push_back(mtpc_vector); vtypes.push_back(mtpc_core_message); stages.push_back(0); flags.push_back(0); break;\n';
|
||||
textSerializeMethods += '\tdefault: to.add("}"); types.pop_back(); vtypes.pop_back(); stages.pop_back(); flags.pop_back(); break;\n';
|
||||
textSerializeMethods += '\t}\n';
|
||||
textSerializeMethods += '}\n\n';
|
||||
textSerializeInit += '\t\t_serializers.insert(mtpc_msg_container, _serialize_msg_container);\n';
|
||||
|
||||
textSerializeMethods += 'void _serialize_core_message(MTPStringLogger &to, int32 stage, int32 lev, Types &types, Types &vtypes, StagesFlags &stages, StagesFlags &flags, const mtpPrime *start, const mtpPrime *end, int32 flag) {\n';
|
||||
textSerializeMethods += '\tif (stage) {\n';
|
||||
textSerializeMethods += '\t\tto.add(",\\n").addSpaces(lev);\n';
|
||||
textSerializeMethods += '\t} else {\n';
|
||||
textSerializeMethods += '\t\tto.add("{ core_message");\n';
|
||||
textSerializeMethods += '\t\tto.add("\\n").addSpaces(lev);\n';
|
||||
textSerializeMethods += '\t}\n';
|
||||
textSerializeMethods += '\tswitch (stage) {\n';
|
||||
textSerializeMethods += '\tcase 0: to.add(" msg_id: "); ++stages.back(); types.push_back(mtpc_long); vtypes.push_back(0); stages.push_back(0); flags.push_back(0); break;\n';
|
||||
textSerializeMethods += '\tcase 1: to.add(" seq_no: "); ++stages.back(); types.push_back(mtpc_int); vtypes.push_back(0); stages.push_back(0); flags.push_back(0); break;\n';
|
||||
textSerializeMethods += '\tcase 2: to.add(" bytes: "); ++stages.back(); types.push_back(mtpc_int); vtypes.push_back(0); stages.push_back(0); flags.push_back(0); break;\n';
|
||||
textSerializeMethods += '\tcase 3: to.add(" body: "); ++stages.back(); types.push_back(0); vtypes.push_back(0); stages.push_back(0); flags.push_back(0); break;\n';
|
||||
textSerializeMethods += '\tdefault: to.add("}"); types.pop_back(); vtypes.pop_back(); stages.pop_back(); flags.pop_back(); break;\n';
|
||||
textSerializeMethods += '\t}\n';
|
||||
textSerializeMethods += '}\n\n';
|
||||
textSerializeInit += '\t\t_serializers.insert(mtpc_core_message, _serialize_core_message);\n';
|
||||
|
||||
textSerializeFull = '\nvoid mtpTextSerializeType(MTPStringLogger &to, const mtpPrime *&from, const mtpPrime *end, mtpPrime cons, uint32 level, mtpPrime vcons) {\n';
|
||||
textSerializeFull += '\tif (_serializers.isEmpty()) initTextSerializers();\n\n';
|
||||
textSerializeFull += '\tQVector<mtpTypeId> types, vtypes;\n';
|
||||
textSerializeFull += '\tQVector<int32> stages, flags;\n';
|
||||
textSerializeFull += '\ttypes.reserve(20); vtypes.reserve(20); stages.reserve(20); flags.reserve(20);\n';
|
||||
|
@ -686,56 +745,13 @@ textSerializeFull += '\t\t\t\ttypes.back() = type = *from;\n';
|
|||
textSerializeFull += '\t\t\t\tstart = ++from;\n';
|
||||
textSerializeFull += '\t\t\t}\n\n';
|
||||
textSerializeFull += '\t\t\tint32 lev = level + types.size() - 1;\n';
|
||||
textSerializeFull += '\t\t\tswitch (type) {\n' + textSerialize + '\n';
|
||||
|
||||
# manual types added here
|
||||
textSerializeFull += '\t\t\tcase mtpc_rpc_result:\n';
|
||||
textSerializeFull += '\t\t\t\tif (stage) {\n';
|
||||
textSerializeFull += '\t\t\t\t\tto.add(",\\n").addSpaces(lev);\n';
|
||||
textSerializeFull += '\t\t\t\t} else {\n';
|
||||
textSerializeFull += '\t\t\t\t\tto.add("{ rpc_result");\n';
|
||||
textSerializeFull += '\t\t\t\t\tto.add("\\n").addSpaces(lev);\n';
|
||||
textSerializeFull += '\t\t\t\t}\n';
|
||||
textSerializeFull += '\t\t\t\tswitch (stage) {\n';
|
||||
textSerializeFull += '\t\t\t\tcase 0: to.add(" req_msg_id: "); ++stages.back(); types.push_back(mtpc_long); vtypes.push_back(0); stages.push_back(0); flags.push_back(0); break;\n';
|
||||
textSerializeFull += '\t\t\t\tcase 1: to.add(" result: "); ++stages.back(); types.push_back(0); vtypes.push_back(0); stages.push_back(0); flags.push_back(0); break;\n';
|
||||
textSerializeFull += '\t\t\t\tdefault: to.add("}"); types.pop_back(); vtypes.pop_back(); stages.pop_back(); flags.pop_back(); break;\n';
|
||||
textSerializeFull += '\t\t\t\t}\n';
|
||||
textSerializeFull += '\t\t\tbreak;\n\n';
|
||||
textSerializeFull += '\t\t\tcase mtpc_msg_container:\n';
|
||||
textSerializeFull += '\t\t\t\tif (stage) {\n';
|
||||
textSerializeFull += '\t\t\t\t\tto.add(",\\n").addSpaces(lev);\n';
|
||||
textSerializeFull += '\t\t\t\t} else {\n';
|
||||
textSerializeFull += '\t\t\t\t\tto.add("{ msg_container");\n';
|
||||
textSerializeFull += '\t\t\t\t\tto.add("\\n").addSpaces(lev);\n';
|
||||
textSerializeFull += '\t\t\t\t}\n';
|
||||
textSerializeFull += '\t\t\t\tswitch (stage) {\n';
|
||||
textSerializeFull += '\t\t\t\tcase 0: to.add(" messages: "); ++stages.back(); types.push_back(mtpc_vector); vtypes.push_back(mtpc_core_message); stages.push_back(0); flags.push_back(0); break;\n';
|
||||
textSerializeFull += '\t\t\t\tdefault: to.add("}"); types.pop_back(); vtypes.pop_back(); stages.pop_back(); flags.pop_back(); break;\n';
|
||||
textSerializeFull += '\t\t\t\t}\n';
|
||||
textSerializeFull += '\t\t\tbreak;\n\n';
|
||||
|
||||
textSerializeFull += '\t\t\tcase mtpc_core_message: {\n';
|
||||
textSerializeFull += '\t\t\t\tif (stage) {\n';
|
||||
textSerializeFull += '\t\t\t\t\tto.add(",\\n").addSpaces(lev);\n';
|
||||
textSerializeFull += '\t\t\t\t} else {\n';
|
||||
textSerializeFull += '\t\t\t\t\tto.add("{ core_message");\n';
|
||||
textSerializeFull += '\t\t\t\t\tto.add("\\n").addSpaces(lev);\n';
|
||||
textSerializeFull += '\t\t\t\t}\n';
|
||||
textSerializeFull += '\t\t\t\tswitch (stage) {\n';
|
||||
textSerializeFull += '\t\t\t\tcase 0: to.add(" msg_id: "); ++stages.back(); types.push_back(mtpc_long); vtypes.push_back(0); stages.push_back(0); flags.push_back(0); break;\n';
|
||||
textSerializeFull += '\t\t\t\tcase 1: to.add(" seq_no: "); ++stages.back(); types.push_back(mtpc_int); vtypes.push_back(0); stages.push_back(0); flags.push_back(0); break;\n';
|
||||
textSerializeFull += '\t\t\t\tcase 2: to.add(" bytes: "); ++stages.back(); types.push_back(mtpc_int); vtypes.push_back(0); stages.push_back(0); flags.push_back(0); break;\n';
|
||||
textSerializeFull += '\t\t\t\tcase 3: to.add(" body: "); ++stages.back(); types.push_back(0); vtypes.push_back(0); stages.push_back(0); flags.push_back(0); break;\n';
|
||||
textSerializeFull += '\t\t\t\tdefault: to.add("}"); types.pop_back(); vtypes.pop_back(); stages.pop_back(); flags.pop_back(); break;\n';
|
||||
textSerializeFull += '\t\t\t\t}\n';
|
||||
textSerializeFull += '\t\t\t\t} break;\n\n';
|
||||
|
||||
textSerializeFull += '\t\t\tdefault:\n';
|
||||
textSerializeFull += '\t\t\tTextSerializers::const_iterator it = _serializers.constFind(type);\n';
|
||||
textSerializeFull += '\t\t\tif (it != _serializers.cend()) {\n';
|
||||
textSerializeFull += '\t\t\t\t(*it.value())(to, stage, lev, types, vtypes, stages, flags, start, end, flag);\n';
|
||||
textSerializeFull += '\t\t\t} else {\n';
|
||||
textSerializeFull += '\t\t\t\tmtpTextSerializeCore(to, from, end, type, lev, vtype);\n';
|
||||
textSerializeFull += '\t\t\t\ttypes.pop_back(); vtypes.pop_back(); stages.pop_back(); flags.pop_back();\n';
|
||||
textSerializeFull += '\t\t\tbreak;\n';
|
||||
textSerializeFull += '\t\t\t}\n';
|
||||
textSerializeFull += '\t\t\t\t}\n';
|
||||
textSerializeFull += '\t\t}\n';
|
||||
textSerializeFull += '\t} catch (Exception &e) {\n';
|
||||
textSerializeFull += '\t\tto.add("[ERROR] ");\n';
|
||||
|
@ -776,6 +792,14 @@ outCpp.write('Copyright (c) 2014 John Preston, https://desktop.telegram.org\n');
|
|||
outCpp.write('*/\n');
|
||||
outCpp.write('#include "stdafx.h"\n#include "mtpScheme.h"\n\n');
|
||||
outCpp.write('#if (defined _DEBUG || defined _WITH_DEBUG)\n\n');
|
||||
outCpp.write('typedef QVector<mtpTypeId> Types;\ntypedef QVector<int32> StagesFlags;\n\n');
|
||||
outCpp.write(textSerializeMethods);
|
||||
outCpp.write('namespace {\n');
|
||||
outCpp.write('\ttypedef void(*mtpTextSerializer)(MTPStringLogger &to, int32 stage, int32 lev, Types &types, Types &vtypes, StagesFlags &stages, StagesFlags &flags, const mtpPrime *start, const mtpPrime *end, int32 flag);\n');
|
||||
outCpp.write('\ttypedef QMap<mtpTypeId, mtpTextSerializer> TextSerializers;\n\tTextSerializers _serializers;\n\n');
|
||||
outCpp.write('\tvoid initTextSerializers() {\n');
|
||||
outCpp.write(textSerializeInit);
|
||||
outCpp.write('\t}\n}\n');
|
||||
outCpp.write(textSerializeFull + '\n#endif\n');
|
||||
|
||||
print('Done, written {0} constructors, {1} functions.'.format(consts, funcs));
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue