1
0
mirror of https://github.com/danog/Telegram.git synced 2024-12-02 09:27:55 +01:00
Telegram/Telegraph/TGConversationDeleteActor.m

68 lines
2.3 KiB
Mathematica
Raw Normal View History

2014-07-10 16:11:09 +02:00
#import "TGConversationDeleteActor.h"
#import "ActionStage.h"
#import "TGTelegraph.h"
#import "TGDatabase.h"
#import "TGUpdateStateRequestBuilder.h"
#import "TGDownloadManager.h"
2015-10-01 18:19:52 +02:00
#import "TGPeerIdAdapter.h"
#import "TGChannelManagementSignals.h"
2014-07-10 16:11:09 +02:00
@implementation TGConversationDeleteActor
+ (NSString *)genericPath
{
return @"/tg/conversation/@/delete";
}
- (void)execute:(NSDictionary *)options
{
int64_t conversationId = [[options objectForKey:@"conversationId"] longLongValue];
if (conversationId == 0)
{
[ActionStageInstance() actionFailed:self.path reason:-1];
return;
}
[[TGDownloadManager instance] cancelItemsWithGroupId:conversationId];
2015-10-01 18:19:52 +02:00
if (TGPeerIdIsChannel(conversationId)) {
[TGDatabaseInstance() enqueueLeaveChannel:conversationId];
} else {
TGUser *user = conversationId > 0 ? [TGDatabaseInstance() loadUser:(int)conversationId] : nil;
if ([options[@"block"] boolValue] && user != nil && (user.kind == TGUserKindBot || user.kind == TGUserKindSmartBot))
{
static int actionId = 0;
[ActionStageInstance() requestActor:[[NSString alloc] initWithFormat:@"/tg/changePeerBlockedStatus/(auto%d)", actionId++] options:@{@"peerId": @(conversationId), @"block": @(true)} watcher:TGTelegraphInstance];
}
[TGDatabaseInstance() deleteConversation:conversationId populateActionQueue:true];
}
2014-07-10 16:11:09 +02:00
dispatch_async([ActionStageInstance() globalStageDispatchQueue], ^
{
[ActionStageInstance() requestActor:@"/tg/service/synchronizeactionqueue/(global)" options:nil watcher:TGTelegraphInstance];
NSArray *sendMessageActors = [ActionStageInstance() executingActorsWithPathPrefix:[NSString stringWithFormat:@"/tg/sendCommonMessage/(%lld)/", conversationId]];
for (TGActor *actor in sendMessageActors)
{
[ActionStageInstance() removeAllWatchersFromPath:actor.path];
}
sendMessageActors = [ActionStageInstance() executingActorsWithPathPrefix:[NSString stringWithFormat:@"/tg/sendSecretMessage/(%lld)/", conversationId]];
for (TGActor *actor in sendMessageActors)
{
[ActionStageInstance() removeAllWatchersFromPath:actor.path];
}
});
[ActionStageInstance() actionCompleted:self.path result:nil];
}
@end