mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2024-12-17 17:20:21 +01:00
large emojis, full contact names, contact createdAt, process profile updates, etc. (#268)
This commit is contained in:
committed by
GitHub
parent
214ecf605b
commit
e424e9328b
@@ -126,12 +126,26 @@ enum ChatInfo: Identifiable, Decodable {
|
||||
var localDisplayName: String {
|
||||
get {
|
||||
switch self {
|
||||
case let .direct(contact): return "@\(contact.localDisplayName)"
|
||||
case let .group(groupInfo): return "#\(groupInfo.localDisplayName)"
|
||||
case let .contactRequest(contactRequest): return "< @\(contactRequest.localDisplayName)"
|
||||
case let .direct(contact): return contact.localDisplayName
|
||||
case let .group(groupInfo): return groupInfo.localDisplayName
|
||||
case let .contactRequest(contactRequest): return contactRequest.localDisplayName
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var fullName: String {
|
||||
get {
|
||||
switch self {
|
||||
case let .direct(contact): return contact.profile.fullName
|
||||
case let .group(groupInfo): return groupInfo.groupProfile.fullName
|
||||
case let .contactRequest(contactRequest): return contactRequest.profile.fullName
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var chatViewName: String {
|
||||
get { localDisplayName + (fullName == "" || fullName == localDisplayName ? "" : " / \(fullName)") }
|
||||
}
|
||||
|
||||
var id: String {
|
||||
get {
|
||||
@@ -162,6 +176,14 @@ enum ChatInfo: Identifiable, Decodable {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var createdAt: Date {
|
||||
switch self {
|
||||
case let .direct(contact): return contact.createdAt
|
||||
case let .group(groupInfo): return groupInfo.createdAt
|
||||
case let .contactRequest(contactRequest): return contactRequest.createdAt
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let sampleDirectChatInfo = ChatInfo.direct(contact: sampleContact)
|
||||
@@ -200,6 +222,7 @@ struct Contact: Identifiable, Decodable {
|
||||
var profile: Profile
|
||||
var activeConn: Connection
|
||||
var viaGroup: Int64?
|
||||
var createdAt: Date
|
||||
|
||||
var id: String { get { "@\(contactId)" } }
|
||||
var apiId: Int64 { get { contactId } }
|
||||
@@ -210,7 +233,8 @@ let sampleContact = Contact(
|
||||
contactId: 1,
|
||||
localDisplayName: "alice",
|
||||
profile: sampleProfile,
|
||||
activeConn: sampleConnection
|
||||
activeConn: sampleConnection,
|
||||
createdAt: .now
|
||||
)
|
||||
|
||||
struct Connection: Decodable {
|
||||
@@ -223,6 +247,7 @@ struct UserContactRequest: Decodable {
|
||||
var contactRequestId: Int64
|
||||
var localDisplayName: ContactName
|
||||
var profile: Profile
|
||||
var createdAt: Date
|
||||
|
||||
var id: String { get { "<@\(contactRequestId)" } }
|
||||
|
||||
@@ -232,13 +257,15 @@ struct UserContactRequest: Decodable {
|
||||
let sampleContactRequest = UserContactRequest(
|
||||
contactRequestId: 1,
|
||||
localDisplayName: "alice",
|
||||
profile: sampleProfile
|
||||
profile: sampleProfile,
|
||||
createdAt: .now
|
||||
)
|
||||
|
||||
struct GroupInfo: Identifiable, Decodable {
|
||||
var groupId: Int64
|
||||
var localDisplayName: GroupName
|
||||
var groupProfile: GroupProfile
|
||||
var createdAt: Date
|
||||
|
||||
var id: String { get { "#\(groupId)" } }
|
||||
|
||||
@@ -248,7 +275,8 @@ struct GroupInfo: Identifiable, Decodable {
|
||||
let sampleGroupInfo = GroupInfo(
|
||||
groupId: 1,
|
||||
localDisplayName: "team",
|
||||
groupProfile: sampleGroupProfile
|
||||
groupProfile: sampleGroupProfile,
|
||||
createdAt: .now
|
||||
)
|
||||
|
||||
struct GroupProfile: Codable {
|
||||
|
||||
@@ -84,6 +84,7 @@ enum ChatResponse: Decodable, Error {
|
||||
case receivedContactRequest(contactRequest: UserContactRequest)
|
||||
case acceptingContactRequest(contact: Contact)
|
||||
case contactRequestRejected
|
||||
case contactUpdated(toContact: Contact)
|
||||
case newChatItem(chatItem: AChatItem)
|
||||
case chatCmdError(chatError: ChatError)
|
||||
|
||||
@@ -106,6 +107,7 @@ enum ChatResponse: Decodable, Error {
|
||||
case .receivedContactRequest: return "receivedContactRequest"
|
||||
case .acceptingContactRequest: return "acceptingContactRequest"
|
||||
case .contactRequestRejected: return "contactRequestRejected"
|
||||
case .contactUpdated: return "contactUpdated"
|
||||
case .newChatItem: return "newChatItem"
|
||||
case .chatCmdError: return "chatCmdError"
|
||||
}
|
||||
@@ -131,6 +133,7 @@ enum ChatResponse: Decodable, Error {
|
||||
case let .receivedContactRequest(contactRequest): return String(describing: contactRequest)
|
||||
case let .acceptingContactRequest(contact): return String(describing: contact)
|
||||
case .contactRequestRejected: return noDetails
|
||||
case let .contactUpdated(toContact): return String(describing: toContact)
|
||||
case let .newChatItem(chatItem): return String(describing: chatItem)
|
||||
case let .chatCmdError(chatError): return String(describing: chatError)
|
||||
}
|
||||
@@ -293,7 +296,7 @@ func apiRejectContactRequest(contactReqId: Int64) throws {
|
||||
|
||||
func processReceivedMsg(_ chatModel: ChatModel, _ res: ChatResponse) {
|
||||
DispatchQueue.main.async {
|
||||
chatModel.terminalItems.append(.resp(Date.now, res))
|
||||
chatModel.terminalItems.append(.resp(.now, res))
|
||||
switch res {
|
||||
case let .contactConnected(contact):
|
||||
let cInfo = ChatInfo.direct(contact: contact)
|
||||
@@ -307,6 +310,11 @@ func processReceivedMsg(_ chatModel: ChatModel, _ res: ChatResponse) {
|
||||
chatInfo: ChatInfo.contactRequest(contactRequest: contactRequest),
|
||||
chatItems: []
|
||||
))
|
||||
case let .contactUpdated(toContact):
|
||||
let cInfo = ChatInfo.direct(contact: toContact)
|
||||
if chatModel.hasChat(toContact.id) {
|
||||
chatModel.updateChatInfo(cInfo)
|
||||
}
|
||||
case let .newChatItem(aChatItem):
|
||||
chatModel.addChatItem(aChatItem.chatInfo, aChatItem.chatItem)
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user