Skip to content

Conversation

@tang3w
Copy link
Contributor

@tang3w tang3w commented Mar 7, 2017

该 PR 修复了 conversation 属性更新会导致 attr.attr... 这个 key path 不断增长的问题。导致这个 bug 的原因是 PR #104 中,对 attributes 属性进行了不兼容的修改:即更新完对话后,conversation.attributes 属性值变成了包含 attr 字段的字典,而不是像旧版本那样,是 attr 字段的值。随后,用户会拿着这个带有 attr 字段的字典去更新 attr 列,attr.attr... 就会增长一次。

这个 PR revert 了 #104。兼容了旧版本的行为,并重写了实现。 @leancloud/ios-group

@tang3w tang3w requested review from daweibayu and leeyeh March 7, 2017 17:09
- (instancetype)initWithConversationId:(NSString *)conversationId {
if (self = [super init]) {
self.conversationId = conversationId;
- (instancetype)init {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这是新添加的构造函数么?如果没有 conversationId 会不会和以前的逻辑有冲突?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不会有冲突,其实以前也可以通过调用父类的不带参数的构造函数来创建 conversation。这里重载不带参数的构造函数只是为了把公共的初始化逻辑放到这里,作为 designated initializer,其他带参数的构造函数调用 [self init] 来完成公共的初始化逻辑。

return self.properties[KEY_ATTR];
}

- (void)setAttributes:(NSDictionary *)attributes {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里为啥要添加这个函数?咱们不是已经不推荐这么使用了么?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个 setter 对外部是不可见的,是内部实现。这里主要是为了把 attributes 属性放到另一个属性容器(self.properties)中。引入 self.properties 的目的是为了保存 Conversation 未预定义的属性。这个改动实际是把预定义属性和未预定义属性统一放到一个地方。对预定义属性(即这里的 attributes 属性)来说,改动对用户是透明的。

_members = members;
}

- (void)setProperties:(NSMutableDictionary *)properties {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个接口的意义呢?如果需要的话其他端是不是也要添加一下?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里也是内部实现,主要是为了保证让属性容器不为空。

@daweibayu
Copy link

那我就没啥问题啦

@tang3w
Copy link
Contributor Author

tang3w commented Mar 8, 2017

Reviewed

Approved with PullApprove

@tang3w tang3w merged commit 3a4e8c5 into leancloud:master Mar 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants