This commit is contained in:
Ali 2020-12-04 17:01:54 +00:00
parent 195734d4ab
commit 8549684667
5 changed files with 135 additions and 117 deletions

View File

@ -118,6 +118,8 @@ private func mappedInsertEntries(context: AccountContext, presentationData: Item
}), directionHint: entry.directionHint)
case let .displayTabInfo(theme, text):
return ListViewInsertItem(index: entry.index, previousIndex: entry.previousIndex, item: ItemListTextItem(presentationData: presentationData, text: .plain(text), sectionId: 0), directionHint: entry.directionHint)
case let .groupCall(_, peer):
preconditionFailure()
case let .messageEntry(topMessage, messages, theme, strings, dateTimeFormat, editing, hasActiveRevealControls):
return ListViewInsertItem(index: entry.index, previousIndex: entry.previousIndex, item: CallListCallItem(presentationData: presentationData, dateTimeFormat: dateTimeFormat, context: context, style: showSettings ? .blocks : .plain, topMessage: topMessage, messages: messages, editing: editing, revealed: hasActiveRevealControls, interaction: nodeInteraction), directionHint: entry.directionHint)
case let .holeEntry(_, theme):
@ -135,6 +137,8 @@ private func mappedUpdateEntries(context: AccountContext, presentationData: Item
}), directionHint: entry.directionHint)
case let .displayTabInfo(theme, text):
return ListViewUpdateItem(index: entry.index, previousIndex: entry.previousIndex, item: ItemListTextItem(presentationData: presentationData, text: .plain(text), sectionId: 0), directionHint: entry.directionHint)
case let .groupCall(_, peer):
preconditionFailure()
case let .messageEntry(topMessage, messages, theme, strings, dateTimeFormat, editing, hasActiveRevealControls):
return ListViewUpdateItem(index: entry.index, previousIndex: entry.previousIndex, item: CallListCallItem(presentationData: presentationData, dateTimeFormat: dateTimeFormat, context: context, style: showSettings ? .blocks : .plain, topMessage: topMessage, messages: messages, editing: editing, revealed: hasActiveRevealControls, interaction: nodeInteraction), directionHint: entry.directionHint)
case let .holeEntry(_, theme):

View File

@ -8,42 +8,9 @@ import MergeLists
enum CallListNodeEntryId: Hashable {
case setting(Int32)
case groupCall(PeerId)
case hole(MessageIndex)
case message(MessageIndex)
var hashValue: Int {
switch self {
case let .setting(value):
return value.hashValue
case let .hole(index):
return index.hashValue
case let .message(index):
return index.hashValue
}
}
static func ==(lhs: CallListNodeEntryId, rhs: CallListNodeEntryId) -> Bool {
switch lhs {
case let .setting(value):
if case .setting(value) = rhs {
return true
} else {
return false
}
case let .hole(index):
if case .hole(index) = rhs {
return true
} else {
return false
}
case let .message(index):
if case .message(index) = rhs {
return true
} else {
return false
}
}
}
}
private func areMessagesEqual(_ lhsMessage: Message, _ rhsMessage: Message) -> Bool {
@ -57,38 +24,14 @@ private func areMessagesEqual(_ lhsMessage: Message, _ rhsMessage: Message) -> B
}
enum CallListNodeEntry: Comparable, Identifiable {
case displayTab(PresentationTheme, String, Bool)
case displayTabInfo(PresentationTheme, String)
case messageEntry(topMessage: Message, messages: [Message], theme: PresentationTheme, strings: PresentationStrings, dateTimeFormat: PresentationDateTimeFormat, editing: Bool, hasActiveRevealControls: Bool)
case holeEntry(index: MessageIndex, theme: PresentationTheme)
enum SortIndex: Comparable {
case displayTab
case displayTabInfo
case groupCall(ChatListIndex)
case message(MessageIndex)
case hole(MessageIndex)
var index: MessageIndex {
switch self {
case .displayTab:
return MessageIndex.absoluteUpperBound()
case .displayTabInfo:
return MessageIndex.absoluteUpperBound().predecessor()
case let .messageEntry(message, _, _, _, _, _, _):
return message.index
case let .holeEntry(index, _):
return index
}
}
var stableId: CallListNodeEntryId {
switch self {
case .displayTab:
return .setting(0)
case .displayTabInfo:
return .setting(1)
case let .messageEntry(message, _, _, _, _, _, _):
return .message(message.index)
case let .holeEntry(index, _):
return .hole(index)
}
}
static func <(lhs: CallListNodeEntry, rhs: CallListNodeEntry) -> Bool {
static func <(lhs: SortIndex, rhs: SortIndex) -> Bool {
switch lhs {
case .displayTab:
return false
@ -99,28 +42,79 @@ enum CallListNodeEntry: Comparable, Identifiable {
default:
return false
}
case let .holeEntry(lhsIndex, _):
case let .groupCall(lhsIndex):
switch rhs {
case let .holeEntry(rhsIndex, _):
return lhsIndex < rhsIndex
case let .messageEntry(topMessage, _, _, _, _, _, _):
return lhsIndex < topMessage.index
default:
case .displayTab, .displayTabInfo:
return false
case let .groupCall(rhsIndex):
return lhsIndex > rhsIndex
case .message, .hole:
return true
}
case let .messageEntry(lhsTopMessage, _, _, _, _, _, _):
let lhsIndex = lhsTopMessage.index
case let .hole(lhsIndex):
switch rhs {
case let .holeEntry(rhsIndex, _):
case .displayTab, .displayTabInfo, .groupCall:
return false
case let .hole(rhsIndex):
return lhsIndex < rhsIndex
case let .message(rhsIndex):
return lhsIndex < rhsIndex
}
case let .message(lhsIndex):
switch rhs {
case .displayTab, .displayTabInfo, .groupCall:
return false
case let .hole(rhsIndex):
return lhsIndex < rhsIndex
case let .message(rhsIndex):
return lhsIndex < rhsIndex
case let .messageEntry(topMessage, _, _, _, _, _, _):
return lhsIndex < topMessage.index
default:
return true
}
}
}
}
case displayTab(PresentationTheme, String, Bool)
case displayTabInfo(PresentationTheme, String)
case groupCall(index: ChatListIndex, peer: Peer)
case messageEntry(topMessage: Message, messages: [Message], theme: PresentationTheme, strings: PresentationStrings, dateTimeFormat: PresentationDateTimeFormat, editing: Bool, hasActiveRevealControls: Bool)
case holeEntry(index: MessageIndex, theme: PresentationTheme)
var sortIndex: SortIndex {
switch self {
case .displayTab:
return .displayTab
case .displayTabInfo:
return .displayTabInfo
case let .groupCall(index, _):
return .groupCall(index)
case let .messageEntry(message, _, _, _, _, _, _):
return .message(message.index)
case let .holeEntry(index, _):
return .hole(index)
}
}
var stableId: CallListNodeEntryId {
switch self {
case .displayTab:
return .setting(0)
case .displayTabInfo:
return .setting(1)
case let .groupCall(_, peer):
return .groupCall(peer.id)
case let .messageEntry(message, _, _, _, _, _, _):
return .message(message.index)
case let .holeEntry(index, _):
return .hole(index)
}
}
static func <(lhs: CallListNodeEntry, rhs: CallListNodeEntry) -> Bool {
return lhs.sortIndex < rhs.sortIndex
}
static func ==(lhs: CallListNodeEntry, rhs: CallListNodeEntry) -> Bool {
switch lhs {
@ -136,6 +130,18 @@ enum CallListNodeEntry: Comparable, Identifiable {
} else {
return false
}
case let .groupCall(lhsIndex, lhsPeer):
if case let .groupCall(rhsIndex, rhsPeer) = rhs {
if lhsIndex != rhsIndex {
return false
}
if !lhsPeer.isEqual(rhsPeer) {
return false
}
return true
} else {
return false
}
case let .messageEntry(lhsMessage, lhsMessages, lhsTheme, lhsStrings, lhsDateTimeFormat, lhsEditing, lhsHasRevealControls):
if case let .messageEntry(rhsMessage, rhsMessages, rhsTheme, rhsStrings, rhsDateTimeFormat, rhsEditing, rhsHasRevealControls) = rhs {
if lhsTheme !== rhsTheme {

View File

@ -139,20 +139,24 @@ func preparedCallListNodeViewTransition(from fromView: CallListNodeView?, to toV
case let .index(scrollIndex, position, directionHint, animated):
var index = toView.filteredEntries.count - 1
for entry in toView.filteredEntries {
if entry.index >= scrollIndex {
if case let .message(messageIndex) = entry.sortIndex {
if messageIndex >= scrollIndex {
scrollToItem = ListViewScrollToItem(index: index, position: position, animated: animated, curve: .Default(duration: nil), directionHint: directionHint)
break
}
}
index -= 1
}
if scrollToItem == nil {
var index = 0
for entry in toView.filteredEntries.reversed() {
if entry.index < scrollIndex {
if case let .message(messageIndex) = entry.sortIndex {
if messageIndex < scrollIndex {
scrollToItem = ListViewScrollToItem(index: index, position: position, animated: animated, curve: .Default(duration: nil), directionHint: directionHint)
break
}
}
index += 1
}
}

View File

@ -702,9 +702,8 @@ public final class VoiceChatController: ViewController {
if let callState = strongSelf.callState, (callState.canManageCall && !callState.adminIds.contains(peer.id)) {
items.append(.action(ContextMenuActionItem(text: strongSelf.presentationData.strings.VoiceChat_RemovePeer, textColor: .destructive, icon: { theme in
return generateTintedImage(image: UIImage(bundleImageName: "Chat/Context Menu/Clear"), color: theme.actionSheet.destructiveActionTextColor)
}, action: { [weak self] _, f in
f(.dismissWithoutContent)
}, action: { [weak self] c, _ in
c.dismiss(completion: {
guard let strongSelf = self else {
return
}
@ -736,6 +735,7 @@ public final class VoiceChatController: ViewController {
])
])
strongSelf.controller?.present(actionSheet, in: .window(.root))
})
})))
}
}

View File

@ -502,6 +502,10 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
}
}
case let .groupPhoneCall(callId, accessHash, nil), let .inviteToGroupPhoneCall(callId, accessHash, _):
guard strongSelf.presentationInterfaceState.activeGroupCallInfo?.activeCall.id == callId else {
return true
}
let peerId = message.id.peerId
let callResult = strongSelf.context.sharedContext.callManager?.joinGroupCall(context: strongSelf.context, peerId: peerId, initialCall: CachedChannelData.ActiveCall(id: callId, accessHash: accessHash), endCurrentIfAny: false, sourcePanel: nil)
if let callResult = callResult, case let .alreadyInProgress(currentPeerId) = callResult {