Skip to content

Commit

Permalink
Merge pull request #652 from zapcannon87/master
Browse files Browse the repository at this point in the history
feat: friendship
  • Loading branch information
zapcannon87 authored Jul 16, 2021
2 parents b204cda + 7a99d49 commit e897240
Show file tree
Hide file tree
Showing 12 changed files with 538 additions and 137 deletions.
8 changes: 8 additions & 0 deletions AVOS/AVOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,8 @@
D39724C424A5CD3C0099A518 /* RTMBaseTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = D39724C324A5CD3C0099A518 /* RTMBaseTestCase.swift */; };
D39724C624A852400099A518 /* IMClientTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = D39724C524A852400099A518 /* IMClientTestCase.swift */; };
D3A397F124A5A4670087D6F8 /* RTMConnectionTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3A397F024A5A4670087D6F8 /* RTMConnectionTestCase.swift */; };
D3A3FA39269ECD40002531C7 /* LCFriendship.h in Headers */ = {isa = PBXBuildFile; fileRef = D3A3FA37269ECD40002531C7 /* LCFriendship.h */; settings = {ATTRIBUTES = (Public, ); }; };
D3A3FA3A269ECD40002531C7 /* LCFriendship.m in Sources */ = {isa = PBXBuildFile; fileRef = D3A3FA38269ECD40002531C7 /* LCFriendship.m */; };
D3AD74AB24BC216200D1BBEE /* LCUserTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3AD74AA24BC216200D1BBEE /* LCUserTestCase.swift */; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -570,6 +572,8 @@
D39724C324A5CD3C0099A518 /* RTMBaseTestCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RTMBaseTestCase.swift; sourceTree = "<group>"; };
D39724C524A852400099A518 /* IMClientTestCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IMClientTestCase.swift; sourceTree = "<group>"; };
D3A397F024A5A4670087D6F8 /* RTMConnectionTestCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RTMConnectionTestCase.swift; sourceTree = "<group>"; };
D3A3FA37269ECD40002531C7 /* LCFriendship.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LCFriendship.h; sourceTree = "<group>"; };
D3A3FA38269ECD40002531C7 /* LCFriendship.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = LCFriendship.m; sourceTree = "<group>"; };
D3AD74AA24BC216200D1BBEE /* LCUserTestCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LCUserTestCase.swift; sourceTree = "<group>"; };
D3C53FCB2106D84A00D48686 /* LCIMClientProtocol.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LCIMClientProtocol.h; sourceTree = "<group>"; };
D3D6E43923544F520048E58F /* LCGPBExtensionRegistry.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LCGPBExtensionRegistry.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1016,6 +1020,8 @@
8C841A9E1A5A7A0000C5C6C4 /* LCUser.h */,
8C841AA01A5A7A0000C5C6C4 /* LCUser_Internal.h */,
8C841A9F1A5A7A0000C5C6C4 /* LCUser.m */,
D3A3FA37269ECD40002531C7 /* LCFriendship.h */,
D3A3FA38269ECD40002531C7 /* LCFriendship.m */,
);
path = User;
sourceTree = "<group>";
Expand Down Expand Up @@ -1391,6 +1397,7 @@
D30B6AB424A09E35006ABE09 /* LCDynamicObject_Internal.h in Headers */,
D30B6ACA24A09ED1006ABE09 /* LCIMConversationMemberInfo_Internal.h in Headers */,
D30B6A6B24A09D62006ABE09 /* LCQuery.h in Headers */,
D3A3FA39269ECD40002531C7 /* LCFriendship.h in Headers */,
D30B6B4024A09F84006ABE09 /* LCIMTypedMessage.h in Headers */,
D30B6A7C24A09DBE006ABE09 /* LCStatus.h in Headers */,
D30B6AE124A09F1E006ABE09 /* LCGPBCodedInputStream_PackagePrivate.h in Headers */,
Expand Down Expand Up @@ -1687,6 +1694,7 @@
D30B6AF024A09F1E006ABE09 /* LCGPBEmpty.pbobjc.m in Sources */,
D30B6A8B24A09DCA006ABE09 /* LCURLSessionManager.m in Sources */,
D30B6AAC24A09E35006ABE09 /* LCKeyValueStore.m in Sources */,
D3A3FA3A269ECD40002531C7 /* LCFriendship.m in Sources */,
D30B6B3F24A09F79006ABE09 /* LCIMConversationQueryCacheStore.m in Sources */,
D30B6B0D24A09F1F006ABE09 /* LCGPBUnknownFieldSet.m in Sources */,
D30B6B5224A09FAD006ABE09 /* LCIMBlockHelper.m in Sources */,
Expand Down
1 change: 1 addition & 0 deletions AVOS/LeanCloudObjc/Foundation.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

// User
#import "LCUser.h"
#import "LCFriendship.h"

// CloudCode
#import "LCCloud.h"
Expand Down
196 changes: 196 additions & 0 deletions AVOS/LeanCloudObjcTests/LCUserTestCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,200 @@ class LCUserTestCase: BaseTestCase {
LCUser.logOut()
*/
}

func testFriendshipRequestAccept() {
let openid_1 = uuid
let openid_2 = uuid

let user_1 = LCUser()
expecting { exp in
user_1.login(withAuthData: ["openid": openid_1], platformId: "test", options: nil) { succeeded, error in
XCTAssertTrue(succeeded)
XCTAssertNil(error)
exp.fulfill()
}
}

guard let _ = user_1.objectId,
LCUser.current() === user_1 else {
XCTFail()
return
}
LCUser.logOut()

let user_2 = LCUser()
expecting { exp in
user_2.login(withAuthData: ["openid": openid_2], platformId: "test", options: nil) { succeeded, error in
XCTAssertTrue(succeeded)
XCTAssertNil(error)
exp.fulfill()
}
}

guard let _ = user_2.objectId,
LCUser.current() === user_2 else {
XCTFail()
return
}

expecting { exp in
LCFriendship.request(withUserId: user_1.objectId!, attributes: ["group": "sport"]) { succeeded, error in
XCTAssertTrue(succeeded)
XCTAssertNil(error)
exp.fulfill()
}
}

LCUser.logOut()

var query: LCQuery!
expecting(description: "Accept Friendship Request", count: 3) { exp in
user_1.login(withAuthData: ["openid": openid_1], platformId: "test", options: nil) { succeeded, error in
XCTAssertNil(error)
exp.fulfill()
if succeeded {
query = LCFriendshipRequest.query()
query.findObjectsInBackground { requests, error in
let request = requests?.first as? LCFriendshipRequest
let friend = request?["friend"] as? LCUser
let user = request?["user"] as? LCUser
XCTAssertNotNil(request)
XCTAssertNotNil(friend)
XCTAssertNotNil(user)
XCTAssertNil(error)
exp.fulfill()
if let request = request {
LCFriendship.accept(request, attributes: ["group": "music"]) { succeeded, error in
XCTAssertTrue(succeeded)
XCTAssertNil(error)
exp.fulfill()
}
}
}
}
}
}

expecting { exp in
query = user_1.followeeObjectsQuery()
query.findObjectsInBackground { followees, error in
let followee = followees?.first as? LCObject
XCTAssertNotNil(followee)
XCTAssertEqual(followee?["group"] as? String, "music")
XCTAssertNil(error)
exp.fulfill()
}
}

LCUser.logOut()

expecting(count: 4) { exp in
user_2.login(withAuthData: ["openid": openid_2], platformId: "test", options: nil) { succeeded, error in
XCTAssertNil(error)
exp.fulfill()
if succeeded {
query = user_2.followeeObjectsQuery()
query.findObjectsInBackground { followees, error in
let followee = followees?.first as? LCObject
XCTAssertNotNil(followee)
XCTAssertEqual(followee?["group"] as? String, "sport")
XCTAssertNil(error)
exp.fulfill()
if let followee = followee {
followee["group"] = "music"
followee.saveInBackground { succeeded, error in
XCTAssertNil(error)
exp.fulfill()
if succeeded {
user_2.unfollow(user_1.objectId!) { succeeded, error in
XCTAssertTrue(succeeded)
XCTAssertNil(error)
exp.fulfill()
}
}
}
}
}
}
}
}

LCUser.logOut()
}

func testFriendshipRequestDecline() {
let openid_1 = uuid
let openid_2 = uuid

let user_1 = LCUser()
expecting { exp in
user_1.login(withAuthData: ["openid": openid_1], platformId: "test", options: nil) { succeeded, error in
XCTAssertTrue(succeeded)
XCTAssertNil(error)
exp.fulfill()
}
}

guard let _ = user_1.objectId,
LCUser.current() === user_1 else {
XCTFail()
return
}
LCUser.logOut()

let user_2 = LCUser()
expecting { exp in
user_2.login(withAuthData: ["openid": openid_2], platformId: "test", options: nil) { succeeded, error in
XCTAssertTrue(succeeded)
XCTAssertNil(error)
exp.fulfill()
}
}

guard let _ = user_2.objectId,
LCUser.current() === user_2 else {
XCTFail()
return
}

expecting { exp in
LCFriendship.request(withUserId: user_1.objectId!, attributes: ["group": "sport"]) { succeeded, error in
XCTAssertTrue(succeeded)
XCTAssertNil(error)
exp.fulfill()
}
}

LCUser.logOut()

var query: LCQuery!
expecting(description: "Decline Friendship Request", count: 3) { exp in
user_1.login(withAuthData: ["openid": openid_1], platformId: "test", options: nil) { succeeded, error in
XCTAssertNil(error)
exp.fulfill()
if succeeded {
query = LCFriendshipRequest.query()
query.findObjectsInBackground { requests, error in
let request = requests?.first as? LCFriendshipRequest
let friend = request?["friend"] as? LCUser
let user = request?["user"] as? LCUser
XCTAssertNotNil(request)
XCTAssertNotNil(friend)
XCTAssertNotNil(user)
XCTAssertNil(error)
exp.fulfill()
if let request = request {
LCFriendship.declineRequest(request) { succeeded, error in
XCTAssertTrue(succeeded)
XCTAssertNil(error)
exp.fulfill()
}
}
}
}
}
}

LCUser.logOut()
}
}
12 changes: 6 additions & 6 deletions AVOS/Sources/Foundation/Object/LCObjectUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@


#pragma mark - batch request from operation list
+(BOOL)isUserClass:(NSString *)className;
+(BOOL)isRoleClass:(NSString *)className;
+(BOOL)isFileClass:(NSString *)className;
+(BOOL)isInstallationClass:(NSString *)className;
+(NSString *)objectPath:(NSString *)className
objectId:(NSString *)objectId;
+ (BOOL)isUserClass:(NSString *)className;
+ (BOOL)isRoleClass:(NSString *)className;
+ (BOOL)isFileClass:(NSString *)className;
+ (BOOL)isInstallationClass:(NSString *)className;
+ (BOOL)isFriendshipRequestClass:(NSString *)className;
+ (NSString *)objectPath:(NSString *)className objectId:(NSString *)objectId;

#pragma mark - Array utils
+(BOOL)safeAdd:(NSDictionary *)dict
Expand Down
7 changes: 7 additions & 0 deletions AVOS/Sources/Foundation/Object/LCObjectUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#import "LCGeoPoint_Internal.h"
#import "LCRelation_Internal.h"
#import "LCUtils.h"
#import "LCFriendship.h"

@implementation LCDate

Expand Down Expand Up @@ -570,6 +571,8 @@ +(LCObject *)lcObjectForClass:(NSString *)className {
} else if ([LCObjectUtils isRoleClass:className]) {
// TODO
object = [LCRole role];
} else if ([LCObjectUtils isFriendshipRequestClass:className]) {
object = [[LCFriendshipRequest alloc] init];
} else {
object = [LCObject objectWithClassName:className];
}
Expand Down Expand Up @@ -705,6 +708,10 @@ +(BOOL)isInstallationClass:(NSString *)className
return [className isEqualToString:[LCInstallation className]];
}

+ (BOOL)isFriendshipRequestClass:(NSString *)className {
return [className isEqualToString:[LCFriendshipRequest className]];
}

+(NSString *)classEndPoint:(NSString *)className
objectId:(NSString *)objectId
{
Expand Down
90 changes: 0 additions & 90 deletions AVOS/Sources/Foundation/Status/LCStatus.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,96 +164,6 @@ typedef void (^LCStatusResultBlock)(LCStatus * _Nullable status, NSError * _Null
-(void)sendInBackgroundWithBlock:(LCBooleanResultBlock)block;
@end

/**
* 用户好友关系
*/
@interface LCUser(Friendship)

/* @name 好友关系 */

/**
* 获取用户粉丝LCQuery
*
* @param userObjectId 用户ID
*
* @return 用于查询的LCQuery
*/
+(LCQuery*)followerQuery:(NSString*)userObjectId;

/**
* 获取本用户粉丝LCQuery
*
* @return 用于查询的LCQuery
*/
-(LCQuery*)followerQuery;

/**
* 获取用户关注LCQuery
*
* @param userObjectId 用户ID
*
* @return 用于查询的LCQuery
*/
+(LCQuery*)followeeQuery:(NSString*)userObjectId;

/**
* 获取本用户关注LCQuery
*
* @return 用于查询的LCQuery
*/
-(LCQuery*)followeeQuery;

/**
* 通过ID来关注其他用户
* @warning 如果需要被关注者收到消息 需要手动给他发送一条LCStatus.
* @param userId 要关注的用户objectId
* @param callback 回调结果
*/
-(void)follow:(NSString*)userId andCallback:(LCBooleanResultBlock)callback;

/**
* 通过ID来关注其他用户
* @warning 如果需要被关注者收到消息 需要手动给他发送一条LCStatus.
* @param userId 要关注的用户objectId
* @param dictionary 添加的自定义属性
* @param callback 回调结果
*/
-(void)follow:(NSString*)userId userDictionary:(nullable NSDictionary *)dictionary andCallback:(LCBooleanResultBlock)callback;

/**
* 通过ID来取消关注其他用户
*
* @param userId 要取消关注的用户objectId
* @param callback 回调结果
*
*/
-(void)unfollow:(NSString*)userId andCallback:(LCBooleanResultBlock)callback;

/**
* 获取当前用户粉丝的列表
*
* @param callback 回调结果
*/
-(void)getFollowers:(LCArrayResultBlock)callback;

/**
* 获取当前用户所关注的列表
*
* @param callback 回调结果
*
*/
-(void)getFollowees:(LCArrayResultBlock)callback;

/**
* 同时获取当前用户的粉丝和关注列表
*
* @param callback 回调结果, 列表字典包含`followers`数组和`followees`数组
*/
-(void)getFollowersAndFollowees:(LCDictionaryResultBlock)callback;


@end

/**
* 查询LCStatus
*/
Expand Down
Loading

0 comments on commit e897240

Please sign in to comment.