Skip to content
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

[CommunicationIdentifier] Introduce new rawId and creation of identifer #1255

Closed
wants to merge 10 commits into from

Conversation

JoshuaLai
Copy link
Member

The CommunicationIdentifier design provides a good abstraction of Azure Communication Services internal id format with better type safety, auto-complete and hides internal knowledge.

Create new rawId in CommunicationIdentifier protocol
Introduce CommunicationIdentifierHelper help deserialize the mri and convenient way to create appropriate identifiers

Details Internal wiki

Helper class to easily create CommunicationIdentifiers
*/
@objcMembers
public class CommunicationIdentifierHelper: NSObject {
Copy link
Member

Choose a reason for hiding this comment

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

I'm never a fan of anything that ends in Helper, Util or Manager :-).

@tjprescott Any suggestions for good Swift-idiomatic naming?

Ideally we would have liked a static factory method on CommunicationIdentifier itself but can't do it because it's a protocol. Another alternative is a free function.

Copy link
Member

Choose a reason for hiding this comment

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

Why not add a required init to the protocol that takes a rawId and then provide the contents of createCommunicationIdentifier(from:) as a default implementation via extension?

Copy link
Member

Choose a reason for hiding this comment

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

But I agree you don't really want this helper thingy as part of the public API.

Copy link
Member Author

Choose a reason for hiding this comment

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

That was something I was trying. I initially was thinking something like this

@objc public protocol CommunicationIdentifier: NSObjectProtocol {
    @objc var rawId: String { get }
    static func createCommunicationIdentifier(from rawId: String) -> CommunicationIdentifier
}
extension CommunicationIdentifier {
    public static func createCommunicationIdentifier(from rawId: String) -> CommunicationIdentifier {
        
    }
}

But because the CommunicationIdentifier needed to be exposed to Obj-C I can't create a function inside my extension nicely.
Otherwise I would be forcing the identifiers to all require this method and every method would do the exact same thing.

Copy link
Member Author

Choose a reason for hiding this comment

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

@tjprescott @DominikMe Had a discussion about this implementation. I think in terms of functionality this approah that we have with the helper most closely aligns with the other platforms.
That being said, the only reason we are doing this is because of obj-c support. I do think we should slowly start exploring having 2 implementations. One design to favour swift, and this implementation to favour obj-c. We can have in the documentation to guide the developers which approach they should use.

sdk/communication/AzureCommunicationCommon/CHANGELOG.md Outdated Show resolved Hide resolved
Helper class to easily create CommunicationIdentifiers
*/
@objcMembers
public class CommunicationIdentifierHelper: NSObject {
Copy link
Member

Choose a reason for hiding this comment

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

Why not add a required init to the protocol that takes a rawId and then provide the contents of createCommunicationIdentifier(from:) as a default implementation via extension?

Helper class to easily create CommunicationIdentifiers
*/
@objcMembers
public class CommunicationIdentifierHelper: NSObject {
Copy link
Member

Choose a reason for hiding this comment

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

But I agree you don't really want this helper thingy as part of the public API.

@@ -30,11 +30,15 @@ import Foundation
Common Communication Identifier protocol for all Azure Communication Services.
All Communication Identifiers conform to this protocol.
*/
@objc public protocol CommunicationIdentifier: NSObjectProtocol {}
@objc public protocol CommunicationIdentifier: NSObjectProtocol {
var rawId: String { get }
Copy link
Member

Choose a reason for hiding this comment

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

You should be able to require:
init?(from rawId: String)

Copy link
Member Author

Choose a reason for hiding this comment

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

Another suggestion that was brought up by @tjprescott that I really like is including a new enum or string to represent the kind. @DominikMe I know we have a similar concept in the TS library.

@check-enforcer
Copy link

This repository is protected by Check Enforcer. The check-enforcer check-run will not pass until there is at least one more check-run successfully passing. Check Enforcer supports the following comment commands:

  • /check-enforcer evaluate; tells Check Enforcer to evaluate this pull request.
  • /check-enforcer override; by-pass Check Enforcer (approvals still required).

@JoshuaLai
Copy link
Member Author

/check-enforcer evaluate

@JoshuaLai JoshuaLai requested a review from tjprescott May 19, 2022 15:53
@JoshuaLai
Copy link
Member Author

/check-enforcer override

@JoshuaLai JoshuaLai requested a review from petrsvihlik May 19, 2022 15:54
@@ -1,5 +1,13 @@
# Release History

## 1.1.0 (upcoming)
### New Features
- Introduce new `CommunicationIdentifierHelper` to create `CommunicationIdentifier` based on rawIds

Choose a reason for hiding this comment

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

@JoshuaLai
Copy link
Member Author

Closing this PR in favour of (#1312)

@JoshuaLai JoshuaLai closed this Jul 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants