Skip to content

Commit

Permalink
Passed languageCode in groupMetadata
Browse files Browse the repository at this point in the history
  • Loading branch information
joshi-kt committed Aug 25, 2023
1 parent 8143598 commit 4a1c811
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Sources/Kommunicate/Classes/KMConversationService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public enum ChannelMetadataKeys {
static let teamId = "KM_TEAM_ID"
static let conversationMetaData = "conversationMetadata" // dictionary mapped with this key will be shown on ConversationInfo section
static let groupCreationURL = "GROUP_CREATION_URL"
static let kmUserLocale = "kmUserLocale"
}

enum LocalizationKey {
Expand Down Expand Up @@ -365,6 +366,20 @@ public class KMConversationService: KMConservationServiceable, Localizable {
let originName = "iOS: " + appID
metadata.setValue(originName, forKey: ChannelMetadataKeys.groupCreationURL)
}

do {
var languageDict : [String:String] = [:]
let languageCode = NSLocale.preferredLanguages.first?.prefix(2)
if let languageCodeString = languageCode.map(String.init) {
languageDict[ChannelMetadataKeys.kmUserLocale] = languageCodeString
}
let messageInfoData = try JSONSerialization.data(withJSONObject: languageDict, options: .prettyPrinted)
let messageInfoString = String(data: messageInfoData, encoding: .utf8) ?? ""
metadata[ChannelMetadataKeys.chatContext] = messageInfoString
} catch {
print("error while setting group metadata : \(error.localizedDescription)")
}


guard let messageMetadata = Kommunicate.defaultConfiguration.messageMetadata,
!messageMetadata.isEmpty
Expand Down

0 comments on commit 4a1c811

Please sign in to comment.