mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-04 01:20:12 +00:00
hide the forward action on live location shares (#6091)
Live location shares have no message event content, so forwarding always failed silently. Exclude them from `isForwardable` matching polls logic
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
//
|
||||
// Copyright 2026 Element Creations Ltd.
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
|
||||
// Please see LICENSE files in the repository root for full details.
|
||||
//
|
||||
|
||||
@testable import ElementX
|
||||
import Testing
|
||||
|
||||
struct TimelineItemMenuActionProviderTests {
|
||||
@Test
|
||||
func liveLocationShareIsNotForwardable() throws {
|
||||
let item = makeLiveLocationItem(isLive: true)
|
||||
let actions = try #require(makeActions(for: item))
|
||||
|
||||
let hasForward = actions.actions.contains(where: \.isForward)
|
||||
#expect(!hasForward)
|
||||
}
|
||||
|
||||
@Test
|
||||
func endedLiveLocationShareIsNotForwardable() throws {
|
||||
let item = makeLiveLocationItem(isLive: false)
|
||||
let actions = try #require(makeActions(for: item))
|
||||
|
||||
let hasForward = actions.actions.contains(where: \.isForward)
|
||||
#expect(!hasForward)
|
||||
}
|
||||
|
||||
@Test
|
||||
func pollIsNotForwardable() throws {
|
||||
let item = PollRoomTimelineItem.mock(poll: .emptyDisclosed)
|
||||
let actions = try #require(makeActions(for: item))
|
||||
|
||||
let hasForward = actions.actions.contains(where: \.isForward)
|
||||
#expect(!hasForward)
|
||||
}
|
||||
|
||||
@Test
|
||||
func textMessageIsForwardable() throws {
|
||||
let item = TextRoomTimelineItem(id: .randomEvent,
|
||||
timestamp: .mock,
|
||||
isOutgoing: false,
|
||||
isEditable: false,
|
||||
canBeRepliedTo: true,
|
||||
sender: .init(id: "@alice:matrix.org"),
|
||||
content: .init(body: "Hello"))
|
||||
let actions = try #require(makeActions(for: item))
|
||||
|
||||
let hasForward = actions.actions.contains(where: \.isForward)
|
||||
#expect(hasForward)
|
||||
}
|
||||
|
||||
// MARK: - Helpers
|
||||
|
||||
private func makeLiveLocationItem(isLive: Bool) -> LiveLocationRoomTimelineItem {
|
||||
.init(id: .randomEvent,
|
||||
timestamp: .mock,
|
||||
isOutgoing: false,
|
||||
isEditable: false,
|
||||
canBeRepliedTo: true,
|
||||
sender: .init(id: "@alice:matrix.org"),
|
||||
content: .init(isLive: isLive, timeoutDate: .mock, lastGeoURI: nil))
|
||||
}
|
||||
|
||||
private func makeActions(for item: RoomTimelineItemProtocol) -> TimelineItemMenuActions? {
|
||||
TimelineItemMenuActionProvider(timelineItem: item,
|
||||
canCurrentUserSendMessage: true,
|
||||
canCurrentUserRedactSelf: true,
|
||||
canCurrentUserRedactOthers: false,
|
||||
canCurrentUserPin: true,
|
||||
pinnedEventIDs: [],
|
||||
isViewSourceEnabled: true,
|
||||
areThreadsEnabled: true,
|
||||
timelineKind: .live,
|
||||
emojiProvider: EmojiProvider(appSettings: .volatile()))
|
||||
.makeActions()
|
||||
}
|
||||
}
|
||||
|
||||
private extension TimelineItemMenuAction {
|
||||
var isForward: Bool {
|
||||
if case .forward = self {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user