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

[CIS-1459] Make Data Formatters Configurable #1742

Conversation

nuno-vieira
Copy link
Member

@nuno-vieira nuno-vieira commented Dec 29, 2021

🔗 Issue Link

CIS-1459
#1739

🎯 Goal

Provide a way to change the data formatting in the SDK.

🛠 Implementation

Expose all formatters in the Appearance configuration through the Appearance.default.formatters. Each formatter is represented by a Protocol so that the customer can provide their own implementation or change the default ones.

🎨 Changes

N/A

🧪 Testing

Example on how to change a default formatter:

let defaultTimestampFormatter = DefaultMessageTimestampFormatter()
defaultTimestampFormatter.dateFormatter.timeStyle = .medium
Appearance.default.formatters.messageTimestamp = defaultTimestampFormatter

Example on how to provide a custom formatter:

class CustomUserLastActivityFormatter: UserLastActivityFormatter {
    public lazy var dateFormatter: DateFormatter = {
        let formatter = DateFormatter()
        formatter.dateStyle = .short
        formatter.timeStyle = .short
        formatter.doesRelativeDateFormatting = true
        formatter.locale = .autoupdatingCurrent
        return formatter
    }()

    func format(_ date: Date) -> String? {
        "last active: " + dateFormatter.string(from: date)
    }
}
...
Appearance.default.formatters.userLastActivity = CustomUserLastActivityFormatter()

☑️ Checklist

  • I have signed the Stream CLA (required)
  • This change follows zero ⚠️ policy (required)
  • Changelog is updated with client-facing changes

@nuno-vieira nuno-vieira requested review from evsaev and a team December 29, 2021 14:14
@codecov
Copy link

codecov bot commented Dec 29, 2021

Codecov Report

Merging #1742 (84c64ae) into develop (fe82d44) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff            @@
##           develop    #1742   +/-   ##
========================================
  Coverage    85.39%   85.39%           
========================================
  Files          234      234           
  Lines        11247    11247           
========================================
  Hits          9604     9604           
  Misses        1643     1643           
Flag Coverage Δ
llc-tests 85.39% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...treamChat/Models/Attachments/AttachmentTypes.swift 86.66% <ø> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fe82d44...84c64ae. Read the comment docs.

CHANGELOG.md Outdated Show resolved Hide resolved
Copy link
Member

@tbarbugli tbarbugli left a comment

Choose a reason for hiding this comment

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

We should add something to the SDK docs about this

@nuno-vieira nuno-vieira changed the title [CIS-1459] Make Date Formatters mutable to allow customization [CIS-1459] Make Date Formatters Configurable Dec 29, 2021
@nuno-vieira
Copy link
Member Author

We should add something to the SDK docs about this

Will add the docs once we define the final API 👍

@emerge-tools
Copy link

emerge-tools bot commented Jan 8, 2022

Congratulations! This change reduces app size by 1.6 MB

Image of diff

🗂 See the Emerge breakdown
Item Size change
StreamChatUI.framework/StreamChatUI.GalleryVC.setUpAppearance -56.3 kB
StreamChatUI.framework/StreamChatUI.ChatMessageActionControl.updateContent -45.5 kB
StreamChatUI.framework/StreamChatUI.ChatMessageContentView.updateContent -34.4 kB
StreamChatUI.framework/StreamChatUI.ChatChannelListItemView.setUpAppearance -33.7 kB
StreamChatUI.framework/StreamChatUI.FileAttachmentView.setUpAppearance -33.6 kB
StreamChatUI.framework/StreamChatUI.ChatMentionSuggestionView.setUpAppearance -33.6 kB
StreamChatUI.framework/StreamChatUI.CommandLabelView.setUpAppearance -28.9 kB
StreamChatUI.framework/StreamChatUI.ChatChannelListVC.swipeableViewActionViews(for) -28.1 kB
StreamChatUI.framework/StreamChatUI.ChatMessageFileAttachmentListView.ItemView.setUpAppearance -28.1 kB
StreamChatUI.framework/StreamChatUI.AttachmentActionButton.updateContent -28.0 kB
StreamChatUI.framework/StreamChatUI.ChatChannelAvatarView.loadAvatarsFrom(urls,channelId,completion) -22.5 kB
StreamChatUI.framework/StreamChatUI.VideoAttachmentComposerPreview.setUpAppearance -22.5 kB
StreamChatUI.framework/StreamChatUI.ChatMessageLinkPreviewView.setUpAppearance -22.4 kB
StreamChatUI.framework/StreamChatUI.ChatCommandSuggestionView.setUpAppearance -22.4 kB
StreamChatUI.framework/StreamChatUI.TitleContainerView.setUpAppearance -22.4 kB
StreamChatUI.framework/StreamChatUI.ChatSuggestionsHeaderView.setUpAppearance -21.4 kB
StreamChatUI.framework/StreamChatUI.CheckboxControl.updateContent -17.3 kB
StreamChatUI.framework/StreamChatUI.InputChatMessageView.setUpAppearance -17.3 kB
StreamChatUI.framework/StreamChatUI.ChatChannelAvatarView.loadMergedAvatars(channel) -16.9 kB
StreamChatUI.framework/StreamChatUI.ChatMessageReactionAuthorsVC.setUpAppearance -16.9 kB

🔎 See the full analysis (84c64ae) merging into develop (fe82d44)

Provide a base_sha with your upload to ensure diffs are correct. Read more in the docs

@nuno-vieira nuno-vieira marked this pull request as draft January 10, 2022 12:25
@nuno-vieira
Copy link
Member Author

Converted to draft, since there will be some team discussions on the API

@nuno-vieira nuno-vieira changed the title [CIS-1459] Make Date Formatters Configurable [CIS-1459] Make Data Formatters Configurable Jan 24, 2022
@nuno-vieira nuno-vieira marked this pull request as ready for review January 24, 2022 19:24
Copy link
Contributor

@bielikb bielikb left a comment

Choose a reason for hiding this comment

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

Great job @nuno-vieira. I left two doc suggestions

@nuno-vieira
Copy link
Member Author

We should add something to the SDK docs about this

Docs are now available 👍

@nuno-vieira nuno-vieira dismissed tbarbugli’s stale review January 26, 2022 15:36

Docs are now part of the PR

@nuno-vieira nuno-vieira merged commit ae69fd2 into develop Jan 26, 2022
@nuno-vieira nuno-vieira deleted the feature/CIS-1459-Make-dateformatters-mutable-to-allow-customization branch January 26, 2022 16:18
@bielikb bielikb mentioned this pull request Feb 1, 2022
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.

None yet

5 participants