Skip to content

Commit

Permalink
remote recent stickers and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
overtake committed Jul 22, 2016
1 parent 560588f commit ab66948
Show file tree
Hide file tree
Showing 32 changed files with 305 additions and 173 deletions.
1 change: 1 addition & 0 deletions TGDatacenterWatchdogActor.m
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ - (void)processConfig:(TL_config *)config fromDatacenterId:(NSInteger)datacenter
setMegagroupSizeMax(config.megagroup_size_max);
set_edit_time_limit(config.edit_time_limit);
set_rating_e_decay(config.rating_e_decay);
set_stickers_recent_limit(config.stickers_recent_limit);

#if TARGET_IPHONE_SIMULATOR
NSMutableArray *dcOptions = [[NSMutableArray alloc] init];
Expand Down
4 changes: 2 additions & 2 deletions TelegramTest/ClassStore.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// ClassStore.m
// Telegram
//
// Created by keepcoder on 21.07.16.
// Created by keepcoder on 22.07.16.
// Copyright (c) 2015 keepcoder. All rights reserved.
//

Expand Down Expand Up @@ -533,7 +533,7 @@ +(void)initialize {
[cs_classes setObject:[TL_keyboardButtonRequestGeoLocation class] forKey:[NSNumber numberWithInt:-59151553]];
[cs_classes setObject:[TL_keyboardButtonSwitchInline class] forKey:[NSNumber numberWithInt:-367298028]];
[cs_classes setObject:[TL_replyInlineMarkup class] forKey:[NSNumber numberWithInt:1218642516]];
[cs_classes setObject:[TL_messages_botCallbackAnswer class] forKey:[NSNumber numberWithInt:838723300]];
[cs_classes setObject:[TL_messages_botCallbackAnswer class] forKey:[NSNumber numberWithInt:-1324486149]];
[cs_classes setObject:[TL_messages_messageEditData class] forKey:[NSNumber numberWithInt:649453030]];
[cs_classes setObject:[TL_updateEditMessage class] forKey:[NSNumber numberWithInt:-469536605]];
[cs_classes setObject:[TL_inputBotInlineMessageMediaGeo class] forKey:[NSNumber numberWithInt:-190472735]];
Expand Down
7 changes: 7 additions & 0 deletions TelegramTest/DialogsManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,9 @@ - (void)setTopMessageToDialog:(NSNotification *)notify {

[self checkAndProccessGifMessage:message];

if(message.isN_out && message.media.document.isSticker) {
[MessageSender addRecentSticker:message.media.document];
}

[self updateTop:message needUpdate:YES update_real_date:update_real_date];

Expand Down Expand Up @@ -927,6 +930,10 @@ - (void)setTopMessagesToDialogs:(NSNotification *)notify {
[messages enumerateObjectsUsingBlock:^(TL_localMessage *message, NSUInteger idx, BOOL * _Nonnull stop) {

[self checkAndProccessGifMessage:message];

if(message.isN_out && message.media.document.isSticker) {
[MessageSender addRecentSticker:message.media.document];
}

TL_conversation *dialog = message.conversation;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
"images" : [
{
"idiom" : "universal",
"scale" : "1x",
"filename" : "NewMsg.png"
"filename" : "[email protected]",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x",
"filename" : "[email protected]"
"filename" : "[email protected]",
"scale" : "2x"
},
{
"idiom" : "universal",
Expand Down
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
"images" : [
{
"idiom" : "universal",
"scale" : "1x",
"filename" : "NewMsg_Active.png"
"filename" : "[email protected]",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x",
"filename" : "[email protected]"
"filename" : "[email protected]",
"scale" : "2x"
},
{
"idiom" : "universal",
Expand Down
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion TelegramTest/MTProto.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// MTProto.h
// Telegram
//
// Auto created by Mikhail Filimonov on 21.07.16.
// Auto created by Mikhail Filimonov on 22.07.16.
// Copyright (c) 2013 Telegram for OS X. All rights reserved.
//

Expand Down
8 changes: 4 additions & 4 deletions TelegramTest/MTProto.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// MTProto.m
// Telegram
//
// Auto created by Mikhail Filimonov on 21.07.16.
// Auto created by Mikhail Filimonov on 22.07.16.
// Copyright (c) 2013 Telegram for OS X. All rights reserved.
//

Expand Down Expand Up @@ -26091,13 +26091,13 @@ -(void)serialize:(SerializedData*)stream {
[stream writeInt:self.flags];

if(self.flags & (1 << 0)) {[stream writeString:self.message];}
if(self.flags & (1 << 3)) {[stream writeString:self.url];}
if(self.flags & (1 << 2)) {[stream writeString:self.url];}
}
-(void)unserialize:(SerializedData*)stream {
super.flags = [stream readInt];

if(self.flags & (1 << 0)) {super.message = [stream readString];}
if(self.flags & (1 << 3)) {super.url = [stream readString];}
if(self.flags & (1 << 2)) {super.url = [stream readString];}
}

-(TL_messages_botCallbackAnswer *)copy {
Expand Down Expand Up @@ -26140,7 +26140,7 @@ -(void)setUrl:(NSString*)url
{
super.url = url;

if(super.url == nil) { super.flags&= ~ (1 << 3) ;} else { super.flags|= (1 << 3); }
if(super.url == nil) { super.flags&= ~ (1 << 2) ;} else { super.flags|= (1 << 2); }
}

@end
Expand Down
3 changes: 3 additions & 0 deletions TelegramTest/MessageSender.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,7 @@ typedef enum {
+(void)addRatingForPeer:(TLPeer *)peer;
+(void)syncTopCategories:(void (^)(NSArray *categories))completeHandler;
+(SSignal *)addStickerPack:(TL_messages_stickerSet *)pack;

+(void)addRecentSticker:(TLDocument *)sticker ;

@end
67 changes: 67 additions & 0 deletions TelegramTest/MessageSender.m
Original file line number Diff line number Diff line change
Expand Up @@ -1017,6 +1017,73 @@ +(SSignal *)addStickerPack:(TL_messages_stickerSet *)pack {



}

+(void)addRecentSticker:(TLDocument *)sticker {
[[Storage yap] asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {


NSMutableArray *sc = [transaction objectForKey:@"remoteRecentStickers" inCollection:STICKERS_COLLECTION];

if(!sc) {
sc = [NSMutableArray array];
}

__block TLDocument *hasSticker = sticker;

[sc enumerateObjectsUsingBlock:^(TLDocument *obj, NSUInteger idx, BOOL * _Nonnull stop) {
if(obj.n_id == sticker.n_id) {
hasSticker = obj;
*stop = YES;
}
}];

if([sc indexOfObject:hasSticker] != NSNotFound) {
[sc removeObject:hasSticker];
}

[sc insertObject:hasSticker atIndex:0];

[transaction setObject:sc forKey:@"remoteRecentStickers" inCollection:STICKERS_COLLECTION];

[Notification perform:STICKERS_REORDER data:@{}];


// NSMutableDictionary *sc = [transaction objectForKey:@"recentStickers" inCollection:STICKERS_COLLECTION];
//
// if(!sc)
// {
// sc = [[NSMutableDictionary alloc] init];
// }
//
// TL_documentAttributeSticker *attr = (TL_documentAttributeSticker *) [sticker attributeWithClass:[TL_documentAttributeSticker class]];
//
//
// if(!sc[@(attr.stickerset.n_id)]) {
// sc[@(attr.stickerset.n_id)] = [NSMutableDictionary dictionary];
// }
//
// __block int max = 1;
//
// [sc enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, NSMutableDictionary *obj, BOOL * _Nonnull stop) {
//
// [obj enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, NSNumber *value, BOOL * _Nonnull stop) {
//
// max = MAX(max,[value intValue]);
//
// }];
//
// }];
//
// max++;
//
//
// sc[@(attr.stickerset.n_id)][@(sticker.n_id)] = @(max);
//
// [transaction setObject:sc forKey:@"recentStickers" inCollection:STICKERS_COLLECTION];

}];

}


Expand Down
37 changes: 1 addition & 36 deletions TelegramTest/MessagesViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -4060,42 +4060,7 @@ -(void)sendSticker:(TLDocument *)sticker forConversation:(TL_conversation *)conv
if(self.conversation.type == DialogTypeSecretChat && self.conversation.encryptedChat.encryptedParams.layer < 23)
return;

[[Storage yap] asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {

NSMutableDictionary *sc = [transaction objectForKey:@"recentStickers" inCollection:STICKERS_COLLECTION];

if(!sc)
{
sc = [[NSMutableDictionary alloc] init];
}

TL_documentAttributeSticker *attr = (TL_documentAttributeSticker *) [sticker attributeWithClass:[TL_documentAttributeSticker class]];


if(!sc[@(attr.stickerset.n_id)]) {
sc[@(attr.stickerset.n_id)] = [NSMutableDictionary dictionary];
}

__block int max = 1;

[sc enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, NSMutableDictionary *obj, BOOL * _Nonnull stop) {

[obj enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, NSNumber *value, BOOL * _Nonnull stop) {

max = MAX(max,[value intValue]);

}];

}];

max++;


sc[@(attr.stickerset.n_id)][@(sticker.n_id)] = @(max);

[transaction setObject:sc forKey:@"recentStickers" inCollection:STICKERS_COLLECTION];

}];
[MessageSender addRecentSticker:sticker];

[self setHistoryFilter:self.defHFClass force:self.historyController.prevState != ChatHistoryStateFull];

Expand Down
41 changes: 23 additions & 18 deletions TelegramTest/StandartViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,8 @@ -(void)setFrameSize:(NSSize)newSize {

[super setFrameSize:newSize];

[self.controller.searchTextField setFrameSize:NSMakeSize(self.frame.size.width-70, 31)];

[self.controller.topButton setFrameOrigin:NSMakePoint(self.frame.size.width == 70 ? 15 : (self.controller.searchTextField.frame.origin.y + self.controller.searchTextField.frame.size.width+11), 9)];


[self.controller.searchTextField setHidden:newSize.width == 70];
TMView *topView = self.subviews[0];


Expand All @@ -57,10 +55,15 @@ -(void)setFrameSize:(NSSize)newSize {

if(newSize.width == 70)
{
[self.controller.topButton setFrameOrigin:NSMakePoint(15, NSMinY(self.controller.topButton.frame))];
} else if(NSWidth(self.controller.view.frame) == 200) {
[self.controller.topButton setFrameOrigin:NSMakePoint(self.controller.searchTextField.frame.origin.y + self.controller.searchTextField.frame.size.width+11, NSMinY(self.controller.topButton.frame))];
[self.controller.topButton setCenterByView:self.controller.topButton.superview];
} else if(NSWidth(self.controller.view.frame) > 70) {


int x = NSMaxX(_controller.searchTextField.frame) + roundf((NSWidth(topView.frame) - NSMaxX(_controller.searchTextField.frame) - NSWidth(_controller.topButton.frame))/2.0f);
[self.controller.topButton setFrameOrigin:NSMakePoint(x, NSMinY(self.controller.topButton.frame))];
}



}

Expand Down Expand Up @@ -102,29 +105,31 @@ -(void)loadView {
[self.view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];


self.searchTextField = [[TMSearchTextField alloc] initWithFrame:NSMakeRect(10, 8 , 205, 29)];

self.searchTextField = [[TMSearchTextField alloc] initWithFrame:NSMakeRect(10, 8 , 220, 31)];

[self.searchTextField setCenteredYByView:topView];


self.searchTextField.delegate = self;
[self.searchTextField setAutoresizingMask:NSViewWidthSizable];
[topView addSubview:self.searchTextField];

int buttonX = self.view.frame.size.width == 70 ? 15 : (self.searchTextField.frame.origin.y + self.searchTextField.frame.size.width+11);


NSImage *compose = [NSImage imageNamed:@"ComposeNewMsg"];
NSImage *composeActive = [NSImage imageNamed:@"ComposeNewMsgActive"];

self.topButton = [[BTRButton alloc] initWithFrame:NSMakeRect(buttonX, 9, 38, 29)];

[self.topButton setBackgroundImage:compose forControlState:BTRControlStateNormal];
[self.topButton setBackgroundImage:composeActive forControlState:BTRControlStateSelected];
[self.topButton setBackgroundImage:composeActive forControlState:BTRControlStateSelected | BTRControlStateHover];
[self.topButton setBackgroundImage:composeActive forControlState:BTRControlStateHighlighted];
[self.topButton setFrameSize:compose.size];
int buttonX = self.view.frame.size.width == 70 ? 22 : NSMaxX(_searchTextField.frame) + roundf((NSWidth(topView.frame) - NSMaxX(_searchTextField.frame) - compose.size.width)/2.0f);


self.topButton = [[BTRButton alloc] initWithFrame:NSMakeRect(buttonX, 9, 26, 26)];


[self.topButton setImage:compose forControlState:BTRControlStateNormal];
[self.topButton setImage:composeActive forControlState:BTRControlStateSelected];
[self.topButton setImage:composeActive forControlState:BTRControlStateSelected | BTRControlStateHover];
[self.topButton setImage:composeActive forControlState:BTRControlStateHighlighted];

[_topButton setCenteredYByView:topView];

[self.topButton setAutoresizingMask:NSViewMinXMargin];

Expand Down
20 changes: 16 additions & 4 deletions TelegramTest/StickerSenderItem.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,17 @@ -(void)performRequest {
request = [TLAPI_messages_sendBroadcast createWithContacts:[broadcast inputContacts] random_id:[broadcast generateRandomIds] message:self.message.message media:media];
}

[RPCRequest sendRequest:request successHandler:^(RPCRequest *request, TLUpdates * response) {
NSMutableArray *signals = [NSMutableArray array];

[signals addObject:[[MTNetwork instance] requestSignal:request queue:[ASQueue globalQueue]]];
[signals addObject:[[MTNetwork instance] requestSignal:[TLAPI_messages_saveRecentSticker createWithN_id:[TL_inputDocument createWithN_id:self.message.media.document.n_id access_hash:self.message.media.document.access_hash] unsave:NO] queue:[ASQueue globalQueue]]];


[[[SSignal combineSignals:signals] map:^id(NSArray *next) {

return next[0];

}] startWithNext:^(TLUpdates * response) {

[self updateMessageId:response];

Expand All @@ -59,12 +68,15 @@ -(void)performRequest {
[self.message save:YES];

self.state = MessageSendingStateSent;




} errorHandler:^(RPCRequest *request, RpcError *error) {
} error:^(id error) {
self.state = MessageSendingStateError;
} completed:^{

} timeout:0 queue:[ASQueue globalQueue]._dispatch_queue];
}];

}

@end
2 changes: 2 additions & 0 deletions TelegramTest/TGAllStickersTableView.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@

-(void)scrollToStickerPack:(long)packId completionHandler:(dispatch_block_t)completionHandler;

+(void)addRecentSticker:(TLDocument *)document;

@end
Loading

0 comments on commit ab66948

Please sign in to comment.