Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Poll editing and undisclosed polls #5378

Merged
merged 9 commits into from
Jan 18, 2022
Merged
2 changes: 1 addition & 1 deletion Config/BuildSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,6 @@ final class BuildSettings: NSObject {
return false
}

return false
return true
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"filename" : "poll_type_checkbox_default.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"filename" : "poll_type_checkbox_selected.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions Riot/Assets/en.lproj/Vector.strings
Original file line number Diff line number Diff line change
Expand Up @@ -1808,6 +1808,8 @@ Tap the + to start adding people.";

"poll_edit_form_create_poll" = "Create poll";

"poll_edit_form_poll_type" = "Poll type";

"poll_edit_form_poll_question_or_topic" = "Poll question or topic";

"poll_edit_form_question_or_topic" = "Question or topic";
Expand All @@ -1824,6 +1826,18 @@ Tap the + to start adding people.";

"poll_edit_form_post_failure_subtitle" = "Please try again";

"poll_edit_form_update_failure_title" = "Failed to update poll";

"poll_edit_form_update_failure_subtitle" = "Please try again";

"poll_edit_form_poll_type_open" = "Open poll";

"poll_edit_form_poll_type_open_description" = "Voters see results as soon as they have voted";

"poll_edit_form_poll_type_closed" = "Closed poll";

"poll_edit_form_poll_type_closed_description" = "Results are only revealed when you end the poll";

"poll_timeline_one_vote" = "1 vote";

"poll_timeline_votes_count" = "%lu votes";
Expand Down
2 changes: 2 additions & 0 deletions Riot/Generated/Images.swift
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ internal enum Asset {
internal static let pollDeleteOptionIcon = ImageAsset(name: "poll_delete_option_icon")
internal static let pollEditIcon = ImageAsset(name: "poll_edit_icon")
internal static let pollEndIcon = ImageAsset(name: "poll_end_icon")
internal static let pollTypeCheckboxDefault = ImageAsset(name: "poll_type_checkbox_default")
internal static let pollTypeCheckboxSelected = ImageAsset(name: "poll_type_checkbox_selected")
Comment on lines +158 to +159
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cheeky suggestion, if we were to use circle and record.circle/smallcircle.fill.circle SF symbols instead of custom assets, then they would scale perfectly with dynamic type 😉

Probably a suggestion for @gaelledel rather than you though.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah that would be great but they don't quite match our designs.

Screenshot 2022-01-14 at 16 21 15

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for reference these two as well, but yeah, that's sad :(
Screenshot 2022-01-14 at 4 01 37 pm
Screenshot 2022-01-14 at 4 00 59 pm

internal static let pollWinnerIcon = ImageAsset(name: "poll_winner_icon")
internal static let urlPreviewClose = ImageAsset(name: "url_preview_close")
internal static let urlPreviewCloseDark = ImageAsset(name: "url_preview_close_dark")
Expand Down
28 changes: 28 additions & 0 deletions Riot/Generated/Strings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2495,6 +2495,26 @@ public class VectorL10n: NSObject {
public static var pollEditFormPollQuestionOrTopic: String {
return VectorL10n.tr("Vector", "poll_edit_form_poll_question_or_topic")
}
/// Poll type
public static var pollEditFormPollType: String {
return VectorL10n.tr("Vector", "poll_edit_form_poll_type")
}
/// Closed poll
public static var pollEditFormPollTypeClosed: String {
return VectorL10n.tr("Vector", "poll_edit_form_poll_type_closed")
}
/// Results are only revealed when you end the poll
public static var pollEditFormPollTypeClosedDescription: String {
return VectorL10n.tr("Vector", "poll_edit_form_poll_type_closed_description")
}
/// Open poll
public static var pollEditFormPollTypeOpen: String {
return VectorL10n.tr("Vector", "poll_edit_form_poll_type_open")
}
/// Voters see results as soon as they have voted
public static var pollEditFormPollTypeOpenDescription: String {
return VectorL10n.tr("Vector", "poll_edit_form_poll_type_open_description")
}
/// Please try again
public static var pollEditFormPostFailureSubtitle: String {
return VectorL10n.tr("Vector", "poll_edit_form_post_failure_subtitle")
Expand All @@ -2508,6 +2528,14 @@ public class VectorL10n: NSObject {
return VectorL10n.tr("Vector", "poll_edit_form_question_or_topic")
}
/// Please try again
public static var pollEditFormUpdateFailureSubtitle: String {
return VectorL10n.tr("Vector", "poll_edit_form_update_failure_subtitle")
}
/// Failed to update poll
public static var pollEditFormUpdateFailureTitle: String {
return VectorL10n.tr("Vector", "poll_edit_form_update_failure_title")
}
/// Please try again
public static var pollTimelineNotClosedSubtitle: String {
return VectorL10n.tr("Vector", "poll_timeline_not_closed_subtitle")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1577,6 +1577,11 @@ - (NSAttributedString *)attributedStringFromEvent:(MXEvent *)event withRoomState
}
case MXEventTypePollStart:
{
if (event.isEditEvent)
{
return nil;
}

displayText = [MXEventContentPollStart modelFromJSON:event.content].question;
break;
}
Expand Down
4 changes: 4 additions & 0 deletions Riot/Modules/Room/CellData/RoomBubbleCellData.m
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,10 @@ - (BOOL)hasNoDisplay

if (self.tag == RoomBubbleCellDataTagPoll)
{
if (self.events.lastObject.isEditEvent) {
return YES;
}

return NO;
}

Expand Down
62 changes: 39 additions & 23 deletions Riot/Modules/Room/RoomCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ final class RoomCoordinator: NSObject, RoomCoordinatorProtocol {
self.activityIndicatorPresenter = ActivityIndicatorPresenter()

if #available(iOS 14, *) {
PollTimelineProvider.shared.session = parameters.session
TimelinePollProvider.shared.session = parameters.session
}

super.init()
Expand Down Expand Up @@ -246,6 +246,29 @@ final class RoomCoordinator: NSObject, RoomCoordinatorProtocol {
navigationRouter.present(coordinator, animated: true)
coordinator.start()
}

private func startEditPollCoordinator(startEvent: MXEvent? = nil) {
guard #available(iOS 14.0, *) else {
return
}

let parameters = PollEditFormCoordinatorParameters(room: roomViewController.roomDataSource.room, pollStartEvent: startEvent)
let coordinator = PollEditFormCoordinator(parameters: parameters)

coordinator.completion = { [weak self, weak coordinator] in
guard let self = self, let coordinator = coordinator else {
return
}

self.navigationRouter?.dismissModule(animated: true, completion: nil)
self.remove(childCoordinator: coordinator)
}

add(childCoordinator: coordinator)

navigationRouter?.present(coordinator, animated: true)
coordinator.start()
}
}

// MARK: - RoomIdentifiable
Expand Down Expand Up @@ -305,26 +328,7 @@ extension RoomCoordinator: RoomViewControllerDelegate {
}

func roomViewControllerDidRequestPollCreationFormPresentation(_ roomViewController: RoomViewController) {
guard #available(iOS 14.0, *) else {
return
}

let parameters = PollEditFormCoordinatorParameters(room: roomViewController.roomDataSource.room)
let coordinator = PollEditFormCoordinator(parameters: parameters)

coordinator.completion = { [weak self, weak coordinator] in
guard let self = self, let coordinator = coordinator else {
return
}

self.navigationRouter?.dismissModule(animated: true, completion: nil)
self.remove(childCoordinator: coordinator)
}

add(childCoordinator: coordinator)

navigationRouter?.present(coordinator, animated: true)
coordinator.start()
startEditPollCoordinator()
}

func roomViewControllerDidRequestLocationSharingFormPresentation(_ roomViewController: RoomViewController) {
Expand All @@ -340,14 +344,26 @@ extension RoomCoordinator: RoomViewControllerDelegate {
return false
}

return PollTimelineProvider.shared.pollTimelineCoordinatorForEventIdentifier(eventIdentifier)?.canEndPoll() ?? false
return TimelinePollProvider.shared.timelinePollCoordinatorForEventIdentifier(eventIdentifier)?.canEndPoll() ?? false
}

func roomViewController(_ roomViewController: RoomViewController, endPollWithEventIdentifier eventIdentifier: String) {
guard #available(iOS 14.0, *) else {
return
}

PollTimelineProvider.shared.pollTimelineCoordinatorForEventIdentifier(eventIdentifier)?.endPoll()
TimelinePollProvider.shared.timelinePollCoordinatorForEventIdentifier(eventIdentifier)?.endPoll()
}

func roomViewController(_ roomViewController: RoomViewController, canEditPollWithEventIdentifier eventIdentifier: String) -> Bool {
guard #available(iOS 14.0, *) else {
return false
}

return TimelinePollProvider.shared.timelinePollCoordinatorForEventIdentifier(eventIdentifier)?.canEditPoll() ?? false
}

func roomViewController(_ roomViewController: RoomViewController, didRequestEditForPollWithStart startEvent: MXEvent) {
startEditPollCoordinator(startEvent: startEvent)
}
}
6 changes: 6 additions & 0 deletions Riot/Modules/Room/RoomViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,12 @@ canEndPollWithEventIdentifier:(NSString *)eventIdentifier;
- (void)roomViewController:(RoomViewController *)roomViewController
endPollWithEventIdentifier:(NSString *)eventIdentifier;

- (BOOL)roomViewController:(RoomViewController *)roomViewController
canEditPollWithEventIdentifier:(NSString *)eventIdentifier;

- (void)roomViewController:(RoomViewController *)roomViewController
didRequestEditForPollWithStartEvent:(MXEvent *)startEvent;

@end

NS_ASSUME_NONNULL_END
36 changes: 27 additions & 9 deletions Riot/Modules/Room/RoomViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -6103,16 +6103,34 @@ - (RoomContextualMenuItem *)editMenuItemWithEvent:(MXEvent*)event
MXWeakify(self);

RoomContextualMenuItem *editMenuItem = [[RoomContextualMenuItem alloc] initWithMenuAction:RoomContextualMenuActionEdit];
editMenuItem.action = ^{
MXStrongifyAndReturnIfNil(self);
[self hideContextualMenuAnimated:YES cancelEventSelection:NO completion:nil];
[self editEventContentWithId:event.eventId];

// And display the keyboard
[self.inputToolbarView becomeFirstResponder];
};

editMenuItem.isEnabled = [self.roomDataSource canEditEventWithId:event.eventId];
switch (event.eventType) {
case MXEventTypePollStart: {
editMenuItem.action = ^{
MXStrongifyAndReturnIfNil(self);
[self hideContextualMenuAnimated:YES cancelEventSelection:YES completion:nil];
[self.delegate roomViewController:self didRequestEditForPollWithStartEvent:event];
};

editMenuItem.isEnabled = [self.delegate roomViewController:self canEditPollWithEventIdentifier:event.eventId];

break;
}
default: {
editMenuItem.action = ^{
MXStrongifyAndReturnIfNil(self);
[self hideContextualMenuAnimated:YES cancelEventSelection:NO completion:nil];
[self editEventContentWithId:event.eventId];

// And display the keyboard
[self.inputToolbarView becomeFirstResponder];
};

editMenuItem.isEnabled = [self.roomDataSource canEditEventWithId:event.eventId];

break;
}
}

return editMenuItem;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class PollBubbleCell: SizableBaseBubbleCell, BubbleCellReactionsDisplayable {
let bubbleData = cellData as? RoomBubbleCellData,
let event = bubbleData.events.last,
event.eventType == __MXEventType.pollStart,
let view = PollTimelineProvider.shared.buildPollTimelineViewForEvent(event) else {
let view = TimelinePollProvider.shared.buildTimelinePollViewForEvent(event) else {
return
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// File created from SimpleUserProfileExample
// $ createScreen.sh AnalyticsPrompt AnalyticsPrompt
//
// Copyright 2021 New Vector Ltd
//
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// File created from SimpleUserProfileExample
// $ createScreen.sh AnalyticsPrompt AnalyticsPrompt
//
// Copyright 2021 New Vector Ltd
//
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
// File created from SimpleUserProfileExample
// $ createScreen.sh AnalyticsPrompt AnalyticsPrompt
/*
Copyright 2021 New Vector Ltd

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

import SwiftUI

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// File created from SimpleUserProfileExample
// $ createScreen.sh AnalyticsPrompt AnalyticsPrompt
//
// Copyright 2021 New Vector Ltd
//
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// File created from SimpleUserProfileExample
// $ createScreen.sh AnalyticsPrompt AnalyticsPrompt
//
// Copyright 2021 New Vector Ltd
//
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// File created from SimpleUserProfileExample
// $ createScreen.sh AnalyticsPrompt AnalyticsPrompt
//
// Copyright 2021 New Vector Ltd
//
Expand Down
2 changes: 1 addition & 1 deletion RiotSwiftUI/Modules/Common/Mock/MockAppScreens.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ enum MockAppScreens {
MockAnalyticsPromptScreenState.self,
MockUserSuggestionScreenState.self,
MockPollEditFormScreenState.self,
MockPollTimelineScreenState.self,
MockTimelinePollScreenState.self,
MockTemplateUserProfileScreenState.self,
MockTemplateRoomListScreenState.self,
MockTemplateRoomChatScreenState.self
Expand Down
Loading