mirror of
https://github.com/kotatogram/kotatogram-desktop
synced 2025-08-31 06:35:14 +00:00
Enable story actions in channels.
This commit is contained in:
@@ -547,16 +547,25 @@ bool ChannelData::canDeleteMessages() const {
|
||||
}
|
||||
|
||||
bool ChannelData::canPostStories() const {
|
||||
if (!isBroadcast()) {
|
||||
return false;
|
||||
}
|
||||
return amCreator()
|
||||
|| (adminRights() & AdminRight::PostStories);
|
||||
}
|
||||
|
||||
bool ChannelData::canEditStories() const {
|
||||
if (!isBroadcast()) {
|
||||
return false;
|
||||
}
|
||||
return amCreator()
|
||||
|| (adminRights() & AdminRight::EditStories);
|
||||
}
|
||||
|
||||
bool ChannelData::canDeleteStories() const {
|
||||
if (!isBroadcast()) {
|
||||
return false;
|
||||
}
|
||||
return amCreator()
|
||||
|| (adminRights() & AdminRight::DeleteStories);
|
||||
}
|
||||
|
@@ -1536,35 +1536,39 @@ void Stories::savedLoadMore(PeerId peerId) {
|
||||
}
|
||||
|
||||
void Stories::deleteList(const std::vector<FullStoryId> &ids) {
|
||||
if (ids.empty()) {
|
||||
return;
|
||||
}
|
||||
const auto peer = session().data().peer(ids.front().peer);
|
||||
auto list = QVector<MTPint>();
|
||||
list.reserve(ids.size());
|
||||
const auto selfId = session().userPeerId();
|
||||
for (const auto &id : ids) {
|
||||
if (id.peer == selfId) {
|
||||
if (id.peer == peer->id) {
|
||||
list.push_back(MTP_int(id.story));
|
||||
}
|
||||
}
|
||||
if (!list.empty()) {
|
||||
const auto api = &_owner->session().api();
|
||||
api->request(MTPstories_DeleteStories(
|
||||
MTP_inputPeerSelf(),
|
||||
MTP_vector<MTPint>(list)
|
||||
)).done([=](const MTPVector<MTPint> &result) {
|
||||
for (const auto &id : result.v) {
|
||||
applyDeleted(_owner->session().user(), id.v);
|
||||
}
|
||||
}).send();
|
||||
}
|
||||
const auto api = &_owner->session().api();
|
||||
api->request(MTPstories_DeleteStories(
|
||||
peer->input,
|
||||
MTP_vector<MTPint>(list)
|
||||
)).done([=](const MTPVector<MTPint> &result) {
|
||||
for (const auto &id : result.v) {
|
||||
applyDeleted(peer, id.v);
|
||||
}
|
||||
}).send();
|
||||
}
|
||||
|
||||
void Stories::togglePinnedList(
|
||||
const std::vector<FullStoryId> &ids,
|
||||
bool pinned) {
|
||||
if (ids.empty()) {
|
||||
return;
|
||||
}
|
||||
const auto peer = session().data().peer(ids.front().peer);
|
||||
auto list = QVector<MTPint>();
|
||||
list.reserve(ids.size());
|
||||
const auto selfId = session().userPeerId();
|
||||
for (const auto &id : ids) {
|
||||
if (id.peer == selfId) {
|
||||
if (id.peer == peer->id) {
|
||||
list.push_back(MTP_int(id.story));
|
||||
}
|
||||
}
|
||||
@@ -1573,11 +1577,12 @@ void Stories::togglePinnedList(
|
||||
}
|
||||
const auto api = &_owner->session().api();
|
||||
api->request(MTPstories_TogglePinned(
|
||||
MTP_inputPeerSelf(),
|
||||
peer->input,
|
||||
MTP_vector<MTPint>(list),
|
||||
MTP_bool(pinned)
|
||||
)).done([=](const MTPVector<MTPint> &result) {
|
||||
auto &saved = _saved[selfId];
|
||||
const auto peerId = peer->id;
|
||||
auto &saved = _saved[peerId];
|
||||
const auto loaded = saved.loaded;
|
||||
const auto lastId = !saved.ids.list.empty()
|
||||
? saved.ids.list.back()
|
||||
@@ -1586,7 +1591,7 @@ void Stories::togglePinnedList(
|
||||
: std::numeric_limits<StoryId>::max();
|
||||
auto dirty = false;
|
||||
for (const auto &id : result.v) {
|
||||
if (const auto maybeStory = lookup({ selfId, id.v })) {
|
||||
if (const auto maybeStory = lookup({ peerId, id.v })) {
|
||||
const auto story = *maybeStory;
|
||||
story->setPinned(pinned);
|
||||
if (pinned) {
|
||||
@@ -1610,9 +1615,9 @@ void Stories::togglePinnedList(
|
||||
}
|
||||
}
|
||||
if (dirty) {
|
||||
savedLoadMore(selfId);
|
||||
savedLoadMore(peerId);
|
||||
} else {
|
||||
_savedChanged.fire_copy(selfId);
|
||||
_savedChanged.fire_copy(peerId);
|
||||
}
|
||||
}).send();
|
||||
}
|
||||
|
@@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "api/api_text_entities.h"
|
||||
#include "data/data_document.h"
|
||||
#include "data/data_changes.h"
|
||||
#include "data/data_channel.h"
|
||||
#include "data/data_file_origin.h"
|
||||
#include "data/data_photo.h"
|
||||
#include "data/data_photo_media.h"
|
||||
@@ -354,6 +355,10 @@ bool Story::canShare() const {
|
||||
}
|
||||
|
||||
bool Story::canDelete() const {
|
||||
if (const auto channel = _peer->asChannel()) {
|
||||
return channel->canDeleteStories()
|
||||
|| (out() && channel->canPostStories());
|
||||
}
|
||||
return _peer->isSelf();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user