-
Notifications
You must be signed in to change notification settings - Fork 66
Fix conversation attribute update #187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix conversation attribute update #187
Conversation
| - (instancetype)initWithConversationId:(NSString *)conversationId { | ||
| if (self = [super init]) { | ||
| self.conversationId = conversationId; | ||
| - (instancetype)init { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这是新添加的构造函数么?如果没有 conversationId 会不会和以前的逻辑有冲突?
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里为啥要添加这个函数?咱们不是已经不推荐这么使用了么?
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个接口的意义呢?如果需要的话其他端是不是也要添加一下?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里也是内部实现,主要是为了保证让属性容器不为空。
|
那我就没啥问题啦 |
该 PR 修复了 conversation 属性更新会导致 attr.attr... 这个 key path 不断增长的问题。导致这个 bug 的原因是 PR #104 中,对 attributes 属性进行了不兼容的修改:即更新完对话后,conversation.attributes 属性值变成了包含 attr 字段的字典,而不是像旧版本那样,是 attr 字段的值。随后,用户会拿着这个带有 attr 字段的字典去更新 attr 列,attr.attr... 就会增长一次。
这个 PR revert 了 #104。兼容了旧版本的行为,并重写了实现。 @leancloud/ios-group