1
0
mirror of https://github.com/danog/Telegram.git synced 2024-12-11 08:59:48 +01:00
Telegram/Telegraph/TGChangePeerSettingsActor.m

55 lines
2.5 KiB
Mathematica
Raw Normal View History

2014-07-10 16:11:09 +02:00
#import "TGChangePeerSettingsActor.h"
#import "ActionStage.h"
#import "SGraphObjectNode.h"
#import "TGDatabase.h"
#import "TGTelegraph.h"
#import "TGStringUtils.h"
@implementation TGChangePeerSettingsActor
+ (NSString *)genericPath
{
return @"/tg/changePeerSettings/@/@";
}
- (void)execute:(NSDictionary *)options
{
int64_t peerId = [[options objectForKey:@"peerId"] longLongValue];
if (peerId == 0)
{
[ActionStageInstance() actionFailed:self.path reason:-1];
return;
}
int currentSoundId = 0;
int currentMuteUntil = 0;
bool currentPreviewText = true;
2016-02-25 01:03:51 +01:00
bool currentMessagesMuted = false;
[TGDatabaseInstance() loadPeerNotificationSettings:peerId soundId:&currentSoundId muteUntil:&currentMuteUntil previewText:&currentPreviewText messagesMuted:&currentMessagesMuted notFound:NULL];
2014-07-10 16:11:09 +02:00
NSNumber *nMuteUntil = [options objectForKey:@"muteUntil"];
NSNumber *nSoundId = [options objectForKey:@"soundId"];
NSNumber *nPreviewText = [options objectForKey:@"previewText"];
2016-02-25 01:03:51 +01:00
NSNumber *nMessagesMuted = options[@"messagesMuted"];
2014-07-10 16:11:09 +02:00
2016-02-25 01:03:51 +01:00
if (nMuteUntil != nil || nSoundId != nil || nPreviewText != nil || nMessagesMuted != nil)
2014-07-10 16:11:09 +02:00
{
int serverSoundId = nSoundId != nil ? [nSoundId intValue] : currentSoundId;
2016-02-25 01:03:51 +01:00
[TGDatabaseInstance() storePeerNotificationSettings:peerId soundId:serverSoundId muteUntil:(nMuteUntil != nil ? [nMuteUntil intValue] : currentMuteUntil) previewText:(nPreviewText != nil ? [nPreviewText boolValue] : currentPreviewText) messagesMuted:[nMessagesMuted boolValue] writeToActionQueue:true completion:nil];
2014-07-10 16:11:09 +02:00
2016-02-25 01:03:51 +01:00
[ActionStageInstance() dispatchResource:[[NSString alloc] initWithFormat:@"/tg/peerSettings/(%lld)", peerId] resource:[[SGraphObjectNode alloc] initWithObject:[[NSDictionary alloc] initWithObjectsAndKeys:[[NSNumber alloc] initWithInt:nSoundId != nil ? [nSoundId intValue] : currentSoundId], @"soundId", [[NSNumber alloc] initWithInt:nMuteUntil != nil ? [nMuteUntil intValue] : currentMuteUntil], @"muteUntil", [[NSNumber alloc] initWithBool:nPreviewText != nil ? [nPreviewText boolValue] : currentPreviewText], @"previewText", nMessagesMuted == nil ? @(currentMessagesMuted) : nMessagesMuted, @"messagesMuted", nil]]];
2014-07-10 16:11:09 +02:00
[ActionStageInstance() requestActor:@"/tg/service/synchronizeserviceactions/(settings)" options:nil watcher:TGTelegraphInstance];
2015-10-01 18:19:52 +02:00
[TGDatabaseInstance() processAndScheduleMute];
2014-07-10 16:11:09 +02:00
}
[ActionStageInstance() actionCompleted:self.path result:nil];
}
@end