CNWitnessSearchPresent.m
7.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
//
// CNWitnessSearchPresent.m
// CNLiveVideoClassifyKit
//
// Created by CNLive on 2022/6/16.
//
#import "CNWitnessSearchPresent.h"
#import "CNWitnessSearchModel.h"
@implementation CNWitnessSearchPresent
+ (void)requestHotListResponse:(void (^)(NSArray * _Nonnull, NSString * _Nonnull))response{
[CNLiveNetworking setAllowRequestDefaultArgument:YES];
[CNLiveNetworking setupShowDataResult:YES];
[CNLiveNetworking requestNetworkWithMethod:CNLiveRequestMethodGET URLString:cn_API_Classify(@"/ugcApi/getHotList") Param:@{} CacheType:CNLiveNetworkCacheTypeCacheNetwork CompletionBlock:^(NSURLSessionTask *requestTask, id responseObject, NSError *error) {
NSMutableArray *listArr = [NSMutableArray array];
if (responseObject && [responseObject isKindOfClass:[NSArray class]]) {
NSArray *modelArray = [CNWitnessHotModel mj_objectArrayWithKeyValuesArray:responseObject];
for (CNWitnessHotModel *model in modelArray) {
[listArr addObject:model.value];
}
}
if (response) {
response(listArr.copy, error.localizedDescription);
}
}];
}
+ (void)saveSearchHistories:(NSMutableArray *)data
{
NSString *Path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSString *filePath = [Path stringByAppendingPathComponent:@"WitnessSearchHistories.data"];
[NSKeyedArchiver archiveRootObject:data toFile:filePath];
}
+ (NSMutableArray *)readSearchHistories{
NSString *path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSString *filePath = [path stringByAppendingPathComponent:@"WitnessSearchHistories.data"];
//解档
NSMutableArray *data = [NSKeyedUnarchiver unarchiveObjectWithFile:filePath];
return data;
}
+ (NSArray *)dealHots:(NSArray *)hots isShowAll:(BOOL)isShowAll allHistories:(NSArray *)histories{
if (!isShowAll&&histories.count >2) {
histories = [histories subarrayWithRange:NSMakeRange(0, 2)];
}
NSArray *dataArray = @[
@{
@"title":@"",
@"list":histories?histories:@[]
},
@{
@"title":@"热门搜索",
@"list":hots?hots:@[]
}
];
NSArray *modelArray = [CNWitnessSearchModel mj_objectArrayWithKeyValuesArray:dataArray];
return modelArray;
}
+ (void)requestSearchVideoListWithTS:(NSString *)ts type:(NSString *)type searchType:(NSInteger)searchType tagId:(NSString *)tagId keyword:(NSString *)keyword page:(NSInteger)page responseBlock:(void (^)(NSArray *, BOOL, NSString *))responseBlock{
NSDictionary *params = @{
@"ts":ts?ts:@"",
@"userId":CNUserShareModelUid,
@"keyword":keyword?keyword:@"",
@"searchType":@(searchType),
@"type":type,
@"tagId":tagId?tagId:@"",
@"page":@(page),
@"pageSize":@(10)
};
[CNLiveNetworking setAllowRequestDefaultArgument:YES];
[CNLiveNetworking setupShowDataResult:YES];
[CNLiveNetworking requestNetworkWithMethod:CNLiveRequestMethodGET URLString:cn_API_Classify(@"/ugcApi/ugcVideoList") Param:params CacheType:CNLiveNetworkCacheTypeNetworkOnly CompletionBlock:^(NSURLSessionTask *requestTask, id responseObject, NSError *error) {
BOOL lastPage = NO;
NSArray *dataArr = nil;
if (responseObject&& [responseObject isKindOfClass:[NSDictionary class]]) {
NSArray *array = responseObject[@"list"];
if (array &&[array isKindOfClass:[NSArray class]]) {
if (array.count == 0) {
lastPage = YES;
}else{
if (searchType == 1) {
dataArr = [CNWitnessSearchDetailModel mj_objectArrayWithKeyValuesArray:array];
}else{
dataArr = [CNPersonMessageModel mj_objectArrayWithKeyValuesArray:array];
}
}
}
}
if (responseBlock) {
responseBlock(dataArr,lastPage ,error.localizedDescription);
}
}];
}
+ (void)requestWitnessLikeMomentWithPid:(NSString *)pid ContentSid:(NSString *)contentSid support:(NSString *)support contentTag:(NSString *)contentTag responseBlock:(void (^)(BOOL ))responseBlock{
NSDictionary *params = @{@"contentId":pid?pid:@"",
@"appId":AppId,
@"sid":CNLiveStringIsEmpty(CNUserShareModel.uid)? @"":CNUserShareModel.uid,
@"contentTag":contentTag?contentTag:@"",
@"contentSid":contentSid?contentSid:@"",
@"support":support,
@"isRank":@"false"
};
[CNLiveNetworking setAllowRequestDefaultArgument:YES];
[CNLiveNetworking setupShowDataResult:NO];
[CNLiveNetworking requestNetworkWithMethod:CNLiveRequestMethodPOST URLString:CNGetWitnessFavoriteMomentUrl Param:params CacheType:CNLiveNetworkCacheTypeNetworkOnly CompletionBlock:^(NSURLSessionTask *requestTask, id responseObject, NSError *error) {
if (!error) {
if (responseObject && [responseObject isKindOfClass:[NSDictionary class]]) {
NSString *errorCode = [NSString stringWithFormat:@"%@",responseObject[@"errorCode"]];
NSString *errorMessage = responseObject[@"errorMessage"];
if ([errorCode isEqualToString:@"0"]) {
!responseBlock?:responseBlock(YES);
}else {
[QMUITips showWithText:errorMessage inView:AppKeyWindow hideAfterDelay:1.5f];
!responseBlock?:responseBlock(NO);;
}
}else{
[QMUITips showWithText:error.localizedDescription inView:AppKeyWindow hideAfterDelay:1.5f];
!responseBlock?:responseBlock(NO);;
}
}else{
!responseBlock?:responseBlock(NO);;
}
}];
}
/// 对显示的用户进行关注
/// @param isFocus 是否关注
/// @param toSid 显示sid
/// @param responseBlock 完成回调
+(void)requestContentGetContentHeaderFocusType:(BOOL)isFocus ToSid:(NSString *)toSid responseBlock:(void (^)(BOOL ))responseBlock
{
NSDictionary * dict = @{
@"toSid":toSid,
@"type":isFocus?@"focus":@"cancelFollow"
};
[CNLiveNetworking setAllowRequestDefaultArgument:YES];
[CNLiveNetworking setupShowDataResult:NO];
[CNLiveNetworking setupShowResult:YES];
[CNLiveNetworking requestNetworkWithMethod:CNLiveRequestMethodPOST URLString:CNGetWitnessFollowsContent Param:dict CacheType:CNLiveNetworkCacheTypeNetworkOnly CompletionBlock:^(NSURLSessionTask *requestTask, id responseObject, NSError *error) {
if (!error) {
if (responseObject && [responseObject isKindOfClass:[NSDictionary class]]) {
NSString *errorCode = [NSString stringWithFormat:@"%@",responseObject[@"errorCode"]];
NSString *errorMessage = responseObject[@"errorMessage"];
if ([errorCode isEqualToString:@"0"]) {
!responseBlock?:responseBlock(YES);
}else {
[QMUITips showWithText:errorMessage inView:AppKeyWindow hideAfterDelay:1.5f];
!responseBlock?:responseBlock(NO);;
}
}else{
[QMUITips showWithText:error.localizedDescription inView:AppKeyWindow hideAfterDelay:1.5f];
!responseBlock?:responseBlock(NO);;
}
}else{
!responseBlock?:responseBlock(NO);;
}
}];
}
@end