1
0
mirror of https://github.com/danog/Telegram.git synced 2024-12-04 02:17:51 +01:00
Telegram/Telegraph/TGConversationChangeTitleRequestActor.m

90 lines
2.8 KiB
Mathematica
Raw Normal View History

2014-07-10 16:11:09 +02:00
#import "TGConversationChangeTitleRequestActor.h"
#import "TGTelegraph.h"
#import "TGTelegramNetworking.h"
#import "ActionStage.h"
#import "SGraphObjectNode.h"
#import "TGUserDataRequestBuilder.h"
#import "TGConversation+Telegraph.h"
#import "TGMessage+Telegraph.h"
#import "TGConversationAddMessagesActor.h"
2015-10-01 18:19:52 +02:00
#import "TLUpdates+TG.h"
2014-07-10 16:11:09 +02:00
@implementation TGConversationChangeTitleRequestActor
@synthesize currentTitle = _currentTitle;
+ (NSString *)genericPath
{
return @"/tg/conversation/@/changeTitle/@";
}
- (void)execute:(NSDictionary *)options
{
NSString *title = [options objectForKey:@"title"];
if (title == nil)
{
[ActionStageInstance() actionFailed:self.path reason:-1];
return;
}
_currentTitle = title;
2015-10-01 18:19:52 +02:00
int64_t conversationId = [[options objectForKey:@"conversationId"] longLongValue];
2014-07-10 16:11:09 +02:00
2015-10-01 18:19:52 +02:00
[TGTelegraphInstance doChangeConversationTitle:conversationId accessHash:[[options objectForKey:@"accessHash"] longLongValue] title:title actor:self];
2014-07-10 16:11:09 +02:00
}
2015-10-01 18:19:52 +02:00
- (void)conversationTitleChangeSuccess:(TLUpdates *)updates
2014-07-10 16:11:09 +02:00
{
2015-10-01 18:19:52 +02:00
[TGUserDataRequestBuilder executeUserDataUpdate:updates.users];
2014-07-10 16:11:09 +02:00
2015-10-01 18:19:52 +02:00
if (updates.chats.count != 0)
2014-07-10 16:11:09 +02:00
{
TGConversation *chatConversation = nil;
2015-10-01 18:19:52 +02:00
if (updates.chats.count != 0)
2014-07-10 16:11:09 +02:00
{
NSMutableDictionary *chats = [[NSMutableDictionary alloc] init];
2015-10-01 18:19:52 +02:00
for (TLChat *chatDesc in updates.chats)
2014-07-10 16:11:09 +02:00
{
TGConversation *conversation = [[TGConversation alloc] initWithTelegraphChatDesc:chatDesc];
if (conversation != nil)
{
if (chatConversation == nil)
chatConversation = conversation;
[chats setObject:conversation forKey:[[NSNumber alloc] initWithLongLong:conversation.conversationId]];
}
}
2015-10-01 18:19:52 +02:00
TGMessage *message = nil;
if (updates.messages.count != 0)
message = [[TGMessage alloc] initWithTelegraphMessageDesc:updates.messages.firstObject];
2014-07-10 16:11:09 +02:00
static int actionId = 0;
2015-10-01 18:19:52 +02:00
[[[TGConversationAddMessagesActor alloc] initWithPath:[[NSString alloc] initWithFormat:@"/tg/addmessage/(changeTitle%d)", actionId++]] execute:[[NSDictionary alloc] initWithObjectsAndKeys:chats, @"chats", message == nil ? @[] : @[message], @"messages", nil]];
2014-07-10 16:11:09 +02:00
}
2015-10-01 18:19:52 +02:00
[[TGTelegramNetworking instance] addUpdates:updates];
2014-07-10 16:11:09 +02:00
[ActionStageInstance() actionCompleted:self.path result:[[SGraphObjectNode alloc] initWithObject:chatConversation]];
}
else
{
[ActionStageInstance() actionFailed:self.path reason:-1];
}
}
- (void)conversationTitleChangeFailed
{
[ActionStageInstance() actionFailed:self.path reason:-1];
}
@end