Skip to content

Commit

Permalink
Merge pull request #1713 from matrix-org/alfogrillo/fallback_poll_end…
Browse files Browse the repository at this point in the history
…ed_event

Add fallback text for m.poll.end events (PSG-1156)
  • Loading branch information
alfogrillo authored Feb 10, 2023
2 parents 9dd83ea + cdfc9a6 commit f5a4ac9
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 7 deletions.
6 changes: 4 additions & 2 deletions MatrixSDK/Data/MXRoom.m
Original file line number Diff line number Diff line change
Expand Up @@ -2220,7 +2220,7 @@ - (void)getReplyContentBodiesWithEventToReply:(MXEvent*)eventToReply
{
// The "Ended poll" text is not meant to be localized from the sender side.
// This is why here we use a "default localizer" providing the english version of it.
senderMessageBody = MXSendReplyEventDefaultStringLocalizer.new.replyToEndedPoll;
senderMessageBody = MXSendReplyEventDefaultStringLocalizer.new.endedPollMessage;
}
else if (eventToReply.eventType == MXEventTypeBeaconInfo)
{
Expand Down Expand Up @@ -2583,9 +2583,11 @@ - (MXHTTPOperation *)sendPollEndForEvent:(MXEvent *)pollStartEvent
MXEventContentRelatesTo *relatesTo = [[MXEventContentRelatesTo alloc] initWithRelationType:MXEventRelationTypeReference
eventId:pollStartEvent.eventId];

MXSendReplyEventDefaultStringLocalizer* localizer = MXSendReplyEventDefaultStringLocalizer.new;
NSDictionary *content = @{
kMXEventRelationRelatesToKey: relatesTo.JSONDictionary,
kMXMessageContentKeyExtensiblePollEndMSC3381: @{}
kMXMessageContentKeyExtensiblePollEndMSC3381: @{},
kMXMessageContentKeyExtensibleTextMSC1767: localizer.endedPollMessage
};

return [self sendEventOfType:[MXTools eventTypeString:MXEventTypePollEnd] content:content threadId:threadId localEcho:localEcho success:success failure:failure];
Expand Down
4 changes: 2 additions & 2 deletions MatrixSDK/Data/MXSendReplyEventDefaultStringLocalizer.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ @interface MXSendReplyEventDefaultStringLocalizer ()
@property (nonatomic, strong) NSString *senderSentTheirLocation;
@property (nonatomic, strong) NSString *senderSentTheirLiveLocation;
@property (nonatomic, strong) NSString *messageToReplyToPrefix;
@property (nonatomic, strong) NSString *replyToEndedPoll;
@property (nonatomic, strong) NSString *endedPollMessage;

@end

Expand All @@ -44,7 +44,7 @@ - (instancetype)init
_senderSentTheirLocation = @"has shared their location.";
_senderSentTheirLiveLocation = @"Live location.";
_messageToReplyToPrefix = @"In reply to";
_replyToEndedPoll = @"Ended poll";
_endedPollMessage = @"Ended poll";
}
return self;
}
Expand Down
2 changes: 1 addition & 1 deletion MatrixSDK/Data/MXSendReplyEventStringLocalizerProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ NS_ASSUME_NONNULL_BEGIN
- (NSString *)senderSentTheirLocation;
- (NSString *)senderSentTheirLiveLocation;
- (NSString *)messageToReplyToPrefix;
- (NSString *)replyToEndedPoll;
- (NSString *)endedPollMessage;

@end

Expand Down
4 changes: 2 additions & 2 deletions MatrixSDKTests/MXPollRelationTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ - (void)testBobClosesPollWithOneAnswer
[mxSession.aggregations referenceEventsForEvent:pollStartEvent.eventId inRoom:room.roomId from:nil limit:-1 success:^(MXAggregationPaginatedResponse *paginatedResponse) {
XCTAssertNil(paginatedResponse.nextBatch);
XCTAssertEqual(paginatedResponse.chunk.count, 2);
MXEvent* pollEndedEvent = paginatedResponse.chunk.lastObject;
XCTAssertTrue([pollEndedEvent.content[kMXMessageContentKeyExtensibleTextMSC1767] isEqual:@"Ended poll"]);

[expectation fulfill];
} failure:^(NSError *error) {
Expand All @@ -81,8 +83,6 @@ - (void)testBobClosesPollWithOneAnswer
XCTFail(@"The operation should not fail - NSError: %@", error);
[expectation fulfill];
}];

[expectation fulfill];
} failure:^(NSError *error) {
XCTFail(@"The operation should not fail - NSError: %@", error);
[expectation fulfill];
Expand Down
1 change: 1 addition & 0 deletions changelog.d/pr-1713.change
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Polls: add fallback text for poll ended events.

0 comments on commit f5a4ac9

Please sign in to comment.