Skip to content

Commit e897240

Browse files
authored
Merge pull request #652 from zapcannon87/master
feat: friendship
2 parents b204cda + 7a99d49 commit e897240

File tree

12 files changed

+538
-137
lines changed

12 files changed

+538
-137
lines changed

AVOS/AVOS.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,8 @@
305305
D39724C424A5CD3C0099A518 /* RTMBaseTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = D39724C324A5CD3C0099A518 /* RTMBaseTestCase.swift */; };
306306
D39724C624A852400099A518 /* IMClientTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = D39724C524A852400099A518 /* IMClientTestCase.swift */; };
307307
D3A397F124A5A4670087D6F8 /* RTMConnectionTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3A397F024A5A4670087D6F8 /* RTMConnectionTestCase.swift */; };
308+
D3A3FA39269ECD40002531C7 /* LCFriendship.h in Headers */ = {isa = PBXBuildFile; fileRef = D3A3FA37269ECD40002531C7 /* LCFriendship.h */; settings = {ATTRIBUTES = (Public, ); }; };
309+
D3A3FA3A269ECD40002531C7 /* LCFriendship.m in Sources */ = {isa = PBXBuildFile; fileRef = D3A3FA38269ECD40002531C7 /* LCFriendship.m */; };
308310
D3AD74AB24BC216200D1BBEE /* LCUserTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3AD74AA24BC216200D1BBEE /* LCUserTestCase.swift */; };
309311
/* End PBXBuildFile section */
310312

@@ -570,6 +572,8 @@
570572
D39724C324A5CD3C0099A518 /* RTMBaseTestCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RTMBaseTestCase.swift; sourceTree = "<group>"; };
571573
D39724C524A852400099A518 /* IMClientTestCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IMClientTestCase.swift; sourceTree = "<group>"; };
572574
D3A397F024A5A4670087D6F8 /* RTMConnectionTestCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RTMConnectionTestCase.swift; sourceTree = "<group>"; };
575+
D3A3FA37269ECD40002531C7 /* LCFriendship.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LCFriendship.h; sourceTree = "<group>"; };
576+
D3A3FA38269ECD40002531C7 /* LCFriendship.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = LCFriendship.m; sourceTree = "<group>"; };
573577
D3AD74AA24BC216200D1BBEE /* LCUserTestCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LCUserTestCase.swift; sourceTree = "<group>"; };
574578
D3C53FCB2106D84A00D48686 /* LCIMClientProtocol.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LCIMClientProtocol.h; sourceTree = "<group>"; };
575579
D3D6E43923544F520048E58F /* LCGPBExtensionRegistry.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LCGPBExtensionRegistry.m; sourceTree = "<group>"; };
@@ -1016,6 +1020,8 @@
10161020
8C841A9E1A5A7A0000C5C6C4 /* LCUser.h */,
10171021
8C841AA01A5A7A0000C5C6C4 /* LCUser_Internal.h */,
10181022
8C841A9F1A5A7A0000C5C6C4 /* LCUser.m */,
1023+
D3A3FA37269ECD40002531C7 /* LCFriendship.h */,
1024+
D3A3FA38269ECD40002531C7 /* LCFriendship.m */,
10191025
);
10201026
path = User;
10211027
sourceTree = "<group>";
@@ -1391,6 +1397,7 @@
13911397
D30B6AB424A09E35006ABE09 /* LCDynamicObject_Internal.h in Headers */,
13921398
D30B6ACA24A09ED1006ABE09 /* LCIMConversationMemberInfo_Internal.h in Headers */,
13931399
D30B6A6B24A09D62006ABE09 /* LCQuery.h in Headers */,
1400+
D3A3FA39269ECD40002531C7 /* LCFriendship.h in Headers */,
13941401
D30B6B4024A09F84006ABE09 /* LCIMTypedMessage.h in Headers */,
13951402
D30B6A7C24A09DBE006ABE09 /* LCStatus.h in Headers */,
13961403
D30B6AE124A09F1E006ABE09 /* LCGPBCodedInputStream_PackagePrivate.h in Headers */,
@@ -1687,6 +1694,7 @@
16871694
D30B6AF024A09F1E006ABE09 /* LCGPBEmpty.pbobjc.m in Sources */,
16881695
D30B6A8B24A09DCA006ABE09 /* LCURLSessionManager.m in Sources */,
16891696
D30B6AAC24A09E35006ABE09 /* LCKeyValueStore.m in Sources */,
1697+
D3A3FA3A269ECD40002531C7 /* LCFriendship.m in Sources */,
16901698
D30B6B3F24A09F79006ABE09 /* LCIMConversationQueryCacheStore.m in Sources */,
16911699
D30B6B0D24A09F1F006ABE09 /* LCGPBUnknownFieldSet.m in Sources */,
16921700
D30B6B5224A09FAD006ABE09 /* LCIMBlockHelper.m in Sources */,

AVOS/LeanCloudObjc/Foundation.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242

4343
// User
4444
#import "LCUser.h"
45+
#import "LCFriendship.h"
4546

4647
// CloudCode
4748
#import "LCCloud.h"

AVOS/LeanCloudObjcTests/LCUserTestCase.swift

Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,200 @@ class LCUserTestCase: BaseTestCase {
109109
LCUser.logOut()
110110
*/
111111
}
112+
113+
func testFriendshipRequestAccept() {
114+
let openid_1 = uuid
115+
let openid_2 = uuid
116+
117+
let user_1 = LCUser()
118+
expecting { exp in
119+
user_1.login(withAuthData: ["openid": openid_1], platformId: "test", options: nil) { succeeded, error in
120+
XCTAssertTrue(succeeded)
121+
XCTAssertNil(error)
122+
exp.fulfill()
123+
}
124+
}
125+
126+
guard let _ = user_1.objectId,
127+
LCUser.current() === user_1 else {
128+
XCTFail()
129+
return
130+
}
131+
LCUser.logOut()
132+
133+
let user_2 = LCUser()
134+
expecting { exp in
135+
user_2.login(withAuthData: ["openid": openid_2], platformId: "test", options: nil) { succeeded, error in
136+
XCTAssertTrue(succeeded)
137+
XCTAssertNil(error)
138+
exp.fulfill()
139+
}
140+
}
141+
142+
guard let _ = user_2.objectId,
143+
LCUser.current() === user_2 else {
144+
XCTFail()
145+
return
146+
}
147+
148+
expecting { exp in
149+
LCFriendship.request(withUserId: user_1.objectId!, attributes: ["group": "sport"]) { succeeded, error in
150+
XCTAssertTrue(succeeded)
151+
XCTAssertNil(error)
152+
exp.fulfill()
153+
}
154+
}
155+
156+
LCUser.logOut()
157+
158+
var query: LCQuery!
159+
expecting(description: "Accept Friendship Request", count: 3) { exp in
160+
user_1.login(withAuthData: ["openid": openid_1], platformId: "test", options: nil) { succeeded, error in
161+
XCTAssertNil(error)
162+
exp.fulfill()
163+
if succeeded {
164+
query = LCFriendshipRequest.query()
165+
query.findObjectsInBackground { requests, error in
166+
let request = requests?.first as? LCFriendshipRequest
167+
let friend = request?["friend"] as? LCUser
168+
let user = request?["user"] as? LCUser
169+
XCTAssertNotNil(request)
170+
XCTAssertNotNil(friend)
171+
XCTAssertNotNil(user)
172+
XCTAssertNil(error)
173+
exp.fulfill()
174+
if let request = request {
175+
LCFriendship.accept(request, attributes: ["group": "music"]) { succeeded, error in
176+
XCTAssertTrue(succeeded)
177+
XCTAssertNil(error)
178+
exp.fulfill()
179+
}
180+
}
181+
}
182+
}
183+
}
184+
}
185+
186+
expecting { exp in
187+
query = user_1.followeeObjectsQuery()
188+
query.findObjectsInBackground { followees, error in
189+
let followee = followees?.first as? LCObject
190+
XCTAssertNotNil(followee)
191+
XCTAssertEqual(followee?["group"] as? String, "music")
192+
XCTAssertNil(error)
193+
exp.fulfill()
194+
}
195+
}
196+
197+
LCUser.logOut()
198+
199+
expecting(count: 4) { exp in
200+
user_2.login(withAuthData: ["openid": openid_2], platformId: "test", options: nil) { succeeded, error in
201+
XCTAssertNil(error)
202+
exp.fulfill()
203+
if succeeded {
204+
query = user_2.followeeObjectsQuery()
205+
query.findObjectsInBackground { followees, error in
206+
let followee = followees?.first as? LCObject
207+
XCTAssertNotNil(followee)
208+
XCTAssertEqual(followee?["group"] as? String, "sport")
209+
XCTAssertNil(error)
210+
exp.fulfill()
211+
if let followee = followee {
212+
followee["group"] = "music"
213+
followee.saveInBackground { succeeded, error in
214+
XCTAssertNil(error)
215+
exp.fulfill()
216+
if succeeded {
217+
user_2.unfollow(user_1.objectId!) { succeeded, error in
218+
XCTAssertTrue(succeeded)
219+
XCTAssertNil(error)
220+
exp.fulfill()
221+
}
222+
}
223+
}
224+
}
225+
}
226+
}
227+
}
228+
}
229+
230+
LCUser.logOut()
231+
}
232+
233+
func testFriendshipRequestDecline() {
234+
let openid_1 = uuid
235+
let openid_2 = uuid
236+
237+
let user_1 = LCUser()
238+
expecting { exp in
239+
user_1.login(withAuthData: ["openid": openid_1], platformId: "test", options: nil) { succeeded, error in
240+
XCTAssertTrue(succeeded)
241+
XCTAssertNil(error)
242+
exp.fulfill()
243+
}
244+
}
245+
246+
guard let _ = user_1.objectId,
247+
LCUser.current() === user_1 else {
248+
XCTFail()
249+
return
250+
}
251+
LCUser.logOut()
252+
253+
let user_2 = LCUser()
254+
expecting { exp in
255+
user_2.login(withAuthData: ["openid": openid_2], platformId: "test", options: nil) { succeeded, error in
256+
XCTAssertTrue(succeeded)
257+
XCTAssertNil(error)
258+
exp.fulfill()
259+
}
260+
}
261+
262+
guard let _ = user_2.objectId,
263+
LCUser.current() === user_2 else {
264+
XCTFail()
265+
return
266+
}
267+
268+
expecting { exp in
269+
LCFriendship.request(withUserId: user_1.objectId!, attributes: ["group": "sport"]) { succeeded, error in
270+
XCTAssertTrue(succeeded)
271+
XCTAssertNil(error)
272+
exp.fulfill()
273+
}
274+
}
275+
276+
LCUser.logOut()
277+
278+
var query: LCQuery!
279+
expecting(description: "Decline Friendship Request", count: 3) { exp in
280+
user_1.login(withAuthData: ["openid": openid_1], platformId: "test", options: nil) { succeeded, error in
281+
XCTAssertNil(error)
282+
exp.fulfill()
283+
if succeeded {
284+
query = LCFriendshipRequest.query()
285+
query.findObjectsInBackground { requests, error in
286+
let request = requests?.first as? LCFriendshipRequest
287+
let friend = request?["friend"] as? LCUser
288+
let user = request?["user"] as? LCUser
289+
XCTAssertNotNil(request)
290+
XCTAssertNotNil(friend)
291+
XCTAssertNotNil(user)
292+
XCTAssertNil(error)
293+
exp.fulfill()
294+
if let request = request {
295+
LCFriendship.declineRequest(request) { succeeded, error in
296+
XCTAssertTrue(succeeded)
297+
XCTAssertNil(error)
298+
exp.fulfill()
299+
}
300+
}
301+
}
302+
}
303+
}
304+
}
305+
306+
LCUser.logOut()
307+
}
112308
}

AVOS/Sources/Foundation/Object/LCObjectUtils.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,12 @@
7272

7373

7474
#pragma mark - batch request from operation list
75-
+(BOOL)isUserClass:(NSString *)className;
76-
+(BOOL)isRoleClass:(NSString *)className;
77-
+(BOOL)isFileClass:(NSString *)className;
78-
+(BOOL)isInstallationClass:(NSString *)className;
79-
+(NSString *)objectPath:(NSString *)className
80-
objectId:(NSString *)objectId;
75+
+ (BOOL)isUserClass:(NSString *)className;
76+
+ (BOOL)isRoleClass:(NSString *)className;
77+
+ (BOOL)isFileClass:(NSString *)className;
78+
+ (BOOL)isInstallationClass:(NSString *)className;
79+
+ (BOOL)isFriendshipRequestClass:(NSString *)className;
80+
+ (NSString *)objectPath:(NSString *)className objectId:(NSString *)objectId;
8181

8282
#pragma mark - Array utils
8383
+(BOOL)safeAdd:(NSDictionary *)dict

AVOS/Sources/Foundation/Object/LCObjectUtils.m

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#import "LCGeoPoint_Internal.h"
2222
#import "LCRelation_Internal.h"
2323
#import "LCUtils.h"
24+
#import "LCFriendship.h"
2425

2526
@implementation LCDate
2627

@@ -570,6 +571,8 @@ +(LCObject *)lcObjectForClass:(NSString *)className {
570571
} else if ([LCObjectUtils isRoleClass:className]) {
571572
// TODO
572573
object = [LCRole role];
574+
} else if ([LCObjectUtils isFriendshipRequestClass:className]) {
575+
object = [[LCFriendshipRequest alloc] init];
573576
} else {
574577
object = [LCObject objectWithClassName:className];
575578
}
@@ -705,6 +708,10 @@ +(BOOL)isInstallationClass:(NSString *)className
705708
return [className isEqualToString:[LCInstallation className]];
706709
}
707710

711+
+ (BOOL)isFriendshipRequestClass:(NSString *)className {
712+
return [className isEqualToString:[LCFriendshipRequest className]];
713+
}
714+
708715
+(NSString *)classEndPoint:(NSString *)className
709716
objectId:(NSString *)objectId
710717
{

AVOS/Sources/Foundation/Status/LCStatus.h

Lines changed: 0 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -164,96 +164,6 @@ typedef void (^LCStatusResultBlock)(LCStatus * _Nullable status, NSError * _Null
164164
-(void)sendInBackgroundWithBlock:(LCBooleanResultBlock)block;
165165
@end
166166

167-
/**
168-
* 用户好友关系
169-
*/
170-
@interface LCUser(Friendship)
171-
172-
/* @name 好友关系 */
173-
174-
/**
175-
* 获取用户粉丝LCQuery
176-
*
177-
* @param userObjectId 用户ID
178-
*
179-
* @return 用于查询的LCQuery
180-
*/
181-
+(LCQuery*)followerQuery:(NSString*)userObjectId;
182-
183-
/**
184-
* 获取本用户粉丝LCQuery
185-
*
186-
* @return 用于查询的LCQuery
187-
*/
188-
-(LCQuery*)followerQuery;
189-
190-
/**
191-
* 获取用户关注LCQuery
192-
*
193-
* @param userObjectId 用户ID
194-
*
195-
* @return 用于查询的LCQuery
196-
*/
197-
+(LCQuery*)followeeQuery:(NSString*)userObjectId;
198-
199-
/**
200-
* 获取本用户关注LCQuery
201-
*
202-
* @return 用于查询的LCQuery
203-
*/
204-
-(LCQuery*)followeeQuery;
205-
206-
/**
207-
* 通过ID来关注其他用户
208-
* @warning 如果需要被关注者收到消息 需要手动给他发送一条LCStatus.
209-
* @param userId 要关注的用户objectId
210-
* @param callback 回调结果
211-
*/
212-
-(void)follow:(NSString*)userId andCallback:(LCBooleanResultBlock)callback;
213-
214-
/**
215-
* 通过ID来关注其他用户
216-
* @warning 如果需要被关注者收到消息 需要手动给他发送一条LCStatus.
217-
* @param userId 要关注的用户objectId
218-
* @param dictionary 添加的自定义属性
219-
* @param callback 回调结果
220-
*/
221-
-(void)follow:(NSString*)userId userDictionary:(nullable NSDictionary *)dictionary andCallback:(LCBooleanResultBlock)callback;
222-
223-
/**
224-
* 通过ID来取消关注其他用户
225-
*
226-
* @param userId 要取消关注的用户objectId
227-
* @param callback 回调结果
228-
*
229-
*/
230-
-(void)unfollow:(NSString*)userId andCallback:(LCBooleanResultBlock)callback;
231-
232-
/**
233-
* 获取当前用户粉丝的列表
234-
*
235-
* @param callback 回调结果
236-
*/
237-
-(void)getFollowers:(LCArrayResultBlock)callback;
238-
239-
/**
240-
* 获取当前用户所关注的列表
241-
*
242-
* @param callback 回调结果
243-
*
244-
*/
245-
-(void)getFollowees:(LCArrayResultBlock)callback;
246-
247-
/**
248-
* 同时获取当前用户的粉丝和关注列表
249-
*
250-
* @param callback 回调结果, 列表字典包含`followers`数组和`followees`数组
251-
*/
252-
-(void)getFollowersAndFollowees:(LCDictionaryResultBlock)callback;
253-
254-
255-
@end
256-
257167
/**
258168
* 查询LCStatus
259169
*/

0 commit comments

Comments
 (0)