Compare commits
2 Commits
stable
...
av/multipl
Author | SHA1 | Date | |
---|---|---|---|
|
d1e2fe22ce | ||
|
be9d6de767 |
@ -556,9 +556,10 @@ final class ChatModel: ObservableObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// this function analyses "connected" events and assumes that each member will be there only once
|
// this function analyses "connected" events and assumes that each member will be there only once
|
||||||
func getConnectedMemberNames(_ chatItem: ChatItem) -> (Int, [String]) {
|
func getConnectedMemberNames(_ chatItem: ChatItem) -> (Int, [String], String?) {
|
||||||
var count = 0
|
var count = 0
|
||||||
var ns: [String] = []
|
var ns: [String] = []
|
||||||
|
var lastNonConnectedEvent: String? = nil
|
||||||
if let ciCategory = chatItem.mergeCategory,
|
if let ciCategory = chatItem.mergeCategory,
|
||||||
var i = getChatItemIndex(chatItem) {
|
var i = getChatItemIndex(chatItem) {
|
||||||
while i < reversedChatItems.count {
|
while i < reversedChatItems.count {
|
||||||
@ -566,12 +567,14 @@ final class ChatModel: ObservableObject {
|
|||||||
if ci.mergeCategory != ciCategory { break }
|
if ci.mergeCategory != ciCategory { break }
|
||||||
if let m = ci.memberConnected {
|
if let m = ci.memberConnected {
|
||||||
ns.append(m.displayName)
|
ns.append(m.displayName)
|
||||||
|
} else if count == 0 {
|
||||||
|
lastNonConnectedEvent = if let name = ci.memberDisplayName { name + " " + ci.text } else { ci.text }
|
||||||
}
|
}
|
||||||
count += 1
|
count += 1
|
||||||
i += 1
|
i += 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return (count, ns)
|
return (count, ns, lastNonConnectedEvent)
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns the index of the passed item and the next item (it has smaller index)
|
// returns the index of the passed item and the next item (it has smaller index)
|
||||||
|
@ -149,7 +149,7 @@ struct ChatItemContentView<Content: View>: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private var mergedGroupEventText: Text? {
|
private var mergedGroupEventText: Text? {
|
||||||
let (count, ns) = chatModel.getConnectedMemberNames(chatItem)
|
let (count, ns, lastNonConnectedEvent) = chatModel.getConnectedMemberNames(chatItem)
|
||||||
let members: LocalizedStringKey =
|
let members: LocalizedStringKey =
|
||||||
switch ns.count {
|
switch ns.count {
|
||||||
case 1: "\(ns[0]) connected"
|
case 1: "\(ns[0]) connected"
|
||||||
@ -162,6 +162,8 @@ struct ChatItemContentView<Content: View>: View {
|
|||||||
}
|
}
|
||||||
return if count <= 1 {
|
return if count <= 1 {
|
||||||
nil
|
nil
|
||||||
|
} else if let last = lastNonConnectedEvent {
|
||||||
|
Text(last) + Text(" ") + Text("and \(count - ns.count) other events")
|
||||||
} else if ns.count == 0 {
|
} else if ns.count == 0 {
|
||||||
Text("\(count) group events")
|
Text("\(count) group events")
|
||||||
} else if count > ns.count {
|
} else if count > ns.count {
|
||||||
|
@ -494,10 +494,11 @@ object ChatModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// this function analyses "connected" events and assumes that each member will be there only once
|
// this function analyses "connected" events and assumes that each member will be there only once
|
||||||
fun getConnectedMemberNames(cItem: ChatItem): Pair<Int, List<String>> {
|
fun getConnectedMemberNames(cItem: ChatItem): Triple<Int, List<String>, String?> {
|
||||||
var count = 0
|
var count = 0
|
||||||
val ns = mutableListOf<String>()
|
val ns = mutableListOf<String>()
|
||||||
var idx = getChatItemIndexOrNull(cItem)
|
var idx = getChatItemIndexOrNull(cItem)
|
||||||
|
var lastNonConnectedEvent: String? = null
|
||||||
if (cItem.mergeCategory != null && idx != null) {
|
if (cItem.mergeCategory != null && idx != null) {
|
||||||
val reversedChatItems = chatItems.asReversed()
|
val reversedChatItems = chatItems.asReversed()
|
||||||
while (idx < reversedChatItems.size) {
|
while (idx < reversedChatItems.size) {
|
||||||
@ -506,12 +507,14 @@ object ChatModel {
|
|||||||
val m = ci.memberConnected
|
val m = ci.memberConnected
|
||||||
if (m != null) {
|
if (m != null) {
|
||||||
ns.add(m.displayName)
|
ns.add(m.displayName)
|
||||||
|
} else if (count == 0) {
|
||||||
|
lastNonConnectedEvent = if (ci.memberDisplayName != null) ci.memberDisplayName + " " + ci.text else ci.text
|
||||||
}
|
}
|
||||||
count++
|
count++
|
||||||
idx++
|
idx++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return count to ns
|
return Triple(count, ns, lastNonConnectedEvent)
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns the index of the passed item and the next item (it has smaller index)
|
// returns the index of the passed item and the next item (it has smaller index)
|
||||||
|
@ -332,7 +332,7 @@ fun ChatItemView(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun mergedGroupEventText(chatItem: ChatItem): String? {
|
fun mergedGroupEventText(chatItem: ChatItem): String? {
|
||||||
val (count, ns) = chatModel.getConnectedMemberNames(chatItem)
|
val (count, ns, lastNonConnectedEvent) = chatModel.getConnectedMemberNames(chatItem)
|
||||||
val members = when {
|
val members = when {
|
||||||
ns.size == 1 -> String.format(generalGetString(MR.strings.rcv_group_event_1_member_connected), ns[0])
|
ns.size == 1 -> String.format(generalGetString(MR.strings.rcv_group_event_1_member_connected), ns[0])
|
||||||
ns.size == 2 -> String.format(generalGetString(MR.strings.rcv_group_event_2_members_connected), ns[0], ns[1])
|
ns.size == 2 -> String.format(generalGetString(MR.strings.rcv_group_event_2_members_connected), ns[0], ns[1])
|
||||||
@ -342,6 +342,8 @@ fun ChatItemView(
|
|||||||
}
|
}
|
||||||
return if (count <= 1) {
|
return if (count <= 1) {
|
||||||
null
|
null
|
||||||
|
} else if (lastNonConnectedEvent != null) {
|
||||||
|
lastNonConnectedEvent + " " + generalGetString(MR.strings.rcv_group_and_other_events).format(count - ns.size)
|
||||||
} else if (ns.isEmpty()) {
|
} else if (ns.isEmpty()) {
|
||||||
generalGetString(MR.strings.rcv_group_events_count).format(count)
|
generalGetString(MR.strings.rcv_group_events_count).format(count)
|
||||||
} else if (count > ns.size) {
|
} else if (count > ns.size) {
|
||||||
|
Loading…
Reference in New Issue
Block a user