1
0
mirror of https://github.com/danog/Telegram.git synced 2025-01-22 05:52:06 +01:00
Telegram/Telegraph/TGBridgeStickersService.m
2015-10-01 19:19:52 +03:00

64 lines
2.0 KiB
Objective-C

#import "TGBridgeStickersService.h"
#import "TGBridgeServer.h"
#import "TGStickersSignals.h"
#import "TGBridgeStickerPack+TGStickerPack.h"
NSString *const TGBridgeStickersDataFileName = @"stickers.data";
NSString *const TGBridgeStickersSentImagesFileName = @"stickers.imgs";
@interface TGBridgeStickersService ()
{
SSignal *_stickersSignal;
SMetaDisposable *_disposable;
}
@property (nonatomic, weak) TGBridgeServer *server;
@end
@implementation TGBridgeStickersService
- (instancetype)initWithServer:(TGBridgeServer *)server
{
self = [super init];
if (self != nil)
{
self.server = server;
_stickersSignal = [server serviceSignalForKey:@"stickers" producer:^SSignal *
{
return [TGStickersSignals stickerPacks];
}];
__weak TGBridgeStickersService *weakSelf = self;
_disposable = [[SMetaDisposable alloc] init];
[_disposable setDisposable:[_stickersSignal startWithNext:^(NSDictionary *next)
{
__strong TGBridgeStickersService *strongSelf = weakSelf;
if (strongSelf == nil)
return;
NSArray *stickerPacks = next[@"packs"];
NSMutableArray *bridgeStickerPacks = [[NSMutableArray alloc] init];
for (TGStickerPack *stickerPack in stickerPacks)
{
TGBridgeStickerPack *bridgeStickerPack = [TGBridgeStickerPack stickerPackWithTGStickerPack:stickerPack];
if (bridgeStickerPack != nil)
[bridgeStickerPacks addObject:bridgeStickerPack];
}
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:bridgeStickerPacks];
NSURL *url = [NSURL URLWithString:TGBridgeStickersDataFileName relativeToURL:strongSelf.server.temporaryFilesURL];
[data writeToURL:url atomically:true];
[server sendFileWithURL:url key:@"stickers"];
}]];
}
return self;
}
@end