chore: import upstream snapshot with attribution

This commit is contained in:
wehub-resource-sync
2026-07-13 12:35:01 +08:00
commit a2e318a963
2974 changed files with 158180 additions and 0 deletions
@@ -0,0 +1,15 @@
//
// TLGroup+CreateAvatar.h
// TLChat
//
// Created by 李伯坤 on 2017/9/19.
// Copyright © 2017年 李伯坤. All rights reserved.
//
#import "TLGroup.h"
@interface TLGroup (CreateAvatar)
- (void)createGroupAvatarWithCompleteAction:(void (^)(NSString *groupID))completeAction;
@end
@@ -0,0 +1,89 @@
//
// TLGroup+CreateAvatar.m
// TLChat
//
// Created by 李伯坤 on 2017/9/19.
// Copyright © 2017年 李伯坤. All rights reserved.
//
#import "TLGroup+CreateAvatar.h"
#import "NSFileManager+TLChat.h"
#import "TLMacros.h"
@implementation TLGroup (CreateAvatar)
- (void)createGroupAvatarWithCompleteAction:(void (^)(NSString *groupID))completeAction
{
dispatch_async(dispatch_get_global_queue(0, 0), ^{
NSInteger usersCount = self.users.count > 9 ? 9 : self.users.count;
CGFloat viewWidth = 200;
CGFloat width = viewWidth / 3 * 0.85;
CGFloat space3 = (viewWidth - width * 3) / 4; // 三张图时的边距(图与图之间的边距)
CGFloat space2 = (viewWidth - width * 2 + space3) / 2; // 两张图时的边距
CGFloat space1 = (viewWidth - width) / 2; // 一张图时的边距
CGFloat y = ({
int ans = space1;
if (usersCount > 6) {
ans = space3;
}
else if (usersCount >= 3) {
ans = space2 - space3;
}
ans;
});
CGFloat x = ({
CGFloat ans = space1;
if (usersCount % 3 == 0) {
ans = usersCount == 3 ? space1 :space3;
}
else if (usersCount % 2 == 0) {
ans = space2 - space3;
}
ans;
});
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, viewWidth, viewWidth)];
[view setBackgroundColor:[UIColor colorWithWhite:0.8 alpha:0.6]];
__block NSInteger count = 0; // 下载完成图片计数器
for (NSInteger i = usersCount - 1; i >= 0; i--) {
TLUser *user = [self.users objectAtIndex:i];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(x, y, width, width)];
[view addSubview:imageView];
[imageView tt_setImageWithURL:user.avatarURL.toURL placeholderImage:[UIImage imageNamed:DEFAULT_AVATAR_PATH] completed:^(UIImage *image, NSError *error, TLImageCacheType cacheType, NSURL *imageURL) {
count ++;
if (count == usersCount) { // 图片全部下载完成
UIGraphicsBeginImageContextWithOptions(view.frame.size, NO, 2.0);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
CGImageRef imageRef = image.CGImage;
CGImageRef imageRefRect =CGImageCreateWithImageInRect(imageRef, CGRectMake(0, 0, view.width * 2, view.height * 2));
UIImage *ansImage = [[UIImage alloc] initWithCGImage:imageRefRect];
NSData *imageViewData = UIImagePNGRepresentation(ansImage);
NSString *savedImagePath = [NSFileManager pathUserAvatar:self.groupAvatarPath];
[imageViewData writeToFile:savedImagePath atomically:YES];
CGImageRelease(imageRefRect);
dispatch_async(dispatch_get_main_queue(), ^{
if (completeAction) {
completeAction(self.groupID);
}
});
}
}];
if (i % 3 == 0) { // 换行
y += (width + space3);
x = space3;
}
else if (i == 2 && usersCount == 3) { // 换行,只有三个时
y += (width + space3);
x = space2;
}
else {
x += (width + space3);
}
}
});
}
@end
@@ -0,0 +1,57 @@
//
// TLGroup.h
// TLChat
//
// Created by 李伯坤 on 16/3/7.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "TLUser.h"
@interface TLGroup : NSObject
/**
* 讨论组名称
*/
@property (nonatomic, strong) NSString *groupName;
@property (nonatomic, strong) NSString *groupAvatarPath;
/**
* 讨论组ID
*/
@property (nonatomic, strong) NSString *groupID;
/**
* 讨论组成员
*/
@property (nonatomic, strong) NSMutableArray *users;
/**
* 群公告
*/
@property (nonatomic, strong) NSString *post;
/**
* 我的群昵称
*/
@property (nonatomic, strong) NSString *myNikeName;
@property (nonatomic, strong) NSString *pinyin;
@property (nonatomic, strong) NSString *pinyinInitial;
@property (nonatomic, assign, readonly) NSInteger count;
@property (nonatomic, assign) BOOL showNameInChat;
- (void)addObject:(id)anObject;
- (id)objectAtIndex:(NSUInteger)index;
- (TLUser *)memberByUserID:(NSString *)uid;
@end
@@ -0,0 +1,99 @@
//
// TLGroup.m
// TLChat
//
// Created by 李伯坤 on 16/3/7.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import "TLGroup.h"
#import "NSString+PinYin.h"
#import "TLUserHelper.h"
@implementation TLGroup
- (id)init
{
if (self = [super init]) {
[TLGroup mj_setupObjectClassInArray:^NSDictionary *{
return @{ @"users" : @"TLUser" };
}];
}
return self;
}
- (NSInteger)count
{
return self.users.count;
}
- (void)addObject:(id)anObject
{
[self.users addObject:anObject];
}
- (id)objectAtIndex:(NSUInteger)index
{
return [self.users objectAtIndex:index];
}
- (TLUser *)memberByUserID:(NSString *)uid
{
for (TLUser *user in self.users) {
if ([user.userID isEqualToString:uid]) {
return user;
}
}
return nil;
}
- (NSString *)groupName
{
if (_groupName == nil || _groupName.length == 0) {
for (TLUser *user in self.users) {
if (user.showName.length > 0) {
if (_groupName == nil || _groupName.length <= 0) {
_groupName = user.showName;
}
else {
_groupName = [NSString stringWithFormat:@"%@,%@", _groupName, user.showName];
}
}
}
}
return _groupName;
}
- (NSString *)myNikeName
{
if (_myNikeName.length == 0) {
_myNikeName = [TLUserHelper sharedHelper].user.showName;
}
return _myNikeName;
}
- (NSString *)pinyin
{
if (_pinyin == nil) {
_pinyin = self.groupName.pinyin;
}
return _pinyin;
}
- (NSString *)pinyinInitial
{
if (_pinyinInitial == nil) {
_pinyinInitial = self.groupName.pinyinInitial;
}
return _pinyinInitial;
}
- (NSString *)groupAvatarPath
{
if (_groupAvatarPath == nil) {
_groupAvatarPath = [self.groupID stringByAppendingString:@".png"];
}
return _groupAvatarPath;
}
@end