1
0
mirror of https://github.com/danog/Telegram.git synced 2024-12-04 02:17:51 +01:00
Telegram/Watch/Extension/TGNeoConversationStaticRowController.m
2015-10-01 19:19:52 +03:00

85 lines
2.1 KiB
Objective-C

#import "TGNeoConversationStaticRowController.h"
#import "TGBridgeMessage.h"
#import "TGBridgeUserCache.h"
#import "TGChatInfo.h"
#import "TGNeoServiceMessageViewModel.h"
#import <SSignalKit/SSignalKit.h>
NSString *const TGNeoConversationStaticRowIdentifier = @"TGNeoConversationStaticRow";
@interface TGNeoConversationStaticRowController ()
{
TGNeoMessageViewModel *_viewModel;
SMetaDisposable *_renderDisposable;
TGChatInfo *_currentChatInfo;
}
@end
@implementation TGNeoConversationStaticRowController
- (instancetype)init
{
self = [super init];
if (self != nil)
{
_renderDisposable = [[SMetaDisposable alloc] init];
}
return self;
}
- (void)dealloc
{
[_renderDisposable dispose];
}
- (void)updateWithChatInfo:(TGChatInfo *)chatInfo
{
if (_viewModel != nil)
return;
_viewModel = [TGNeoConversationStaticRowController viewModelForChatInfo:chatInfo];
CGSize containerSize = [[WKInterfaceDevice currentDevice] screenBounds].size;
CGSize contentSize = [_viewModel layoutWithContainerSize:containerSize];
self.contentGroup.width = contentSize.width;
self.contentGroup.height = contentSize.height;
__weak TGNeoConversationStaticRowController *weakSelf = self;
[_renderDisposable setDisposable:[[[[TGNeoRenderableViewModel renderSignalForViewModel:_viewModel] startOn:[SQueue concurrentDefaultQueue]] deliverOn:[SQueue mainQueue]] startWithNext:^(UIImage *image)
{
__strong TGNeoConversationStaticRowController *strongSelf = weakSelf;
if (strongSelf == nil)
return;
[strongSelf.contentGroup setBackgroundImage:image];
}]];
}
- (bool)shouldUpdateChatInfoFrom:(TGChatInfo *)oldChatInfo to:(TGChatInfo *)newChatInfo
{
if (oldChatInfo == nil)
return true;
if (![oldChatInfo.text isEqualToString:newChatInfo.text])
return true;
return false;
}
+ (TGNeoMessageViewModel *)viewModelForChatInfo:(TGChatInfo *)chatInfo
{
return [[TGNeoServiceMessageViewModel alloc] initWithChatInfo:chatInfo];
}
+ (NSString *)identifier
{
return TGNeoConversationStaticRowIdentifier;
}
@end