mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-29 20:56:57 +02:00
Report matrix kit renaming
This commit is contained in:
@@ -25,8 +25,6 @@
|
||||
|
||||
#import <AudioToolbox/AudioToolbox.h>
|
||||
|
||||
NSString *const kMatrixSDKHandlerUnsupportedEventDescriptionPrefix = @"Unsupported event: ";
|
||||
|
||||
static MatrixSDKHandler *sharedHandler = nil;
|
||||
|
||||
@interface MatrixSDKHandler () {
|
||||
@@ -43,6 +41,8 @@ static MatrixSDKHandler *sharedHandler = nil;
|
||||
|
||||
// Used for logging application start up
|
||||
NSDate *openSessionStartDate;
|
||||
|
||||
MXKEventFormatter *eventFormatter;
|
||||
}
|
||||
|
||||
@property (strong, nonatomic) MXFileStore *mxFileStore;
|
||||
@@ -140,6 +140,11 @@ static MatrixSDKHandler *sharedHandler = nil;
|
||||
_mxFileStore = [[MXFileStore alloc] init];
|
||||
|
||||
self.mxSession = [[MXSession alloc] initWithMatrixRestClient:self.mxRestClient];
|
||||
|
||||
// Build MXEvent -> NSString formatter
|
||||
eventFormatter = [[MXKEventFormatter alloc] initWithMatrixSession:self.mxSession];
|
||||
eventFormatter.isForSubtitle = YES;
|
||||
|
||||
__weak typeof(self) weakSelf = self;
|
||||
[self.mxSession setStore:_mxFileStore success:^{
|
||||
typeof(self) self = weakSelf;
|
||||
@@ -403,42 +408,46 @@ static MatrixSDKHandler *sharedHandler = nil;
|
||||
if (![[AppDelegate theDelegate].masterTabBarController.visibleRoomId isEqualToString:event.roomId]
|
||||
&& ![[AppDelegate theDelegate].masterTabBarController isPresentingMediaPicker]
|
||||
&& ([self.unnotifiedRooms indexOfObject:event.roomId] == NSNotFound)) {
|
||||
// Removing existing notification (if any)
|
||||
if (self.mxNotification) {
|
||||
[self.mxNotification dismiss:NO];
|
||||
}
|
||||
|
||||
// Check whether tweak is required
|
||||
for (MXPushRuleAction *ruleAction in rule.actions) {
|
||||
if (ruleAction.actionType == MXPushRuleActionTypeSetTweak) {
|
||||
if ([[ruleAction.parameters valueForKey:@"set_tweak"] isEqualToString:@"sound"]) {
|
||||
// Play system sound (VoicemailReceived)
|
||||
AudioServicesPlaySystemSound (1002);
|
||||
MXKEventFormatterError error;
|
||||
NSString* messageText = [eventFormatter stringFromEvent:event withRoomState:roomState error:&error];
|
||||
if (messageText.length && (error != MXKEventFormatterErrorNone)) {
|
||||
|
||||
// Removing existing notification (if any)
|
||||
if (self.mxNotification) {
|
||||
[self.mxNotification dismiss:NO];
|
||||
}
|
||||
|
||||
// Check whether tweak is required
|
||||
for (MXPushRuleAction *ruleAction in rule.actions) {
|
||||
if (ruleAction.actionType == MXPushRuleActionTypeSetTweak) {
|
||||
if ([[ruleAction.parameters valueForKey:@"set_tweak"] isEqualToString:@"sound"]) {
|
||||
// Play system sound (VoicemailReceived)
|
||||
AudioServicesPlaySystemSound (1002);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
__weak typeof(self) weakSelf = self;
|
||||
self.mxNotification = [[MXKAlert alloc] initWithTitle:roomState.displayname
|
||||
message:messageText
|
||||
style:MXKAlertStyleAlert];
|
||||
self.mxNotification.cancelButtonIndex = [self.mxNotification addActionWithTitle:@"Cancel"
|
||||
style:MXKAlertActionStyleDefault
|
||||
handler:^(MXKAlert *alert) {
|
||||
weakSelf.mxNotification = nil;
|
||||
[weakSelf.unnotifiedRooms addObject:event.roomId];
|
||||
}];
|
||||
[self.mxNotification addActionWithTitle:@"View"
|
||||
style:MXKAlertActionStyleDefault
|
||||
handler:^(MXKAlert *alert) {
|
||||
weakSelf.mxNotification = nil;
|
||||
// Show the room
|
||||
[[AppDelegate theDelegate].masterTabBarController showRoom:event.roomId];
|
||||
}];
|
||||
|
||||
[self.mxNotification showInViewController:[[AppDelegate theDelegate].masterTabBarController selectedViewController]];
|
||||
}
|
||||
|
||||
NSString* messageText = [self displayTextForEvent:event withRoomState:roomState inSubtitleMode:YES];
|
||||
|
||||
__weak typeof(self) weakSelf = self;
|
||||
self.mxNotification = [[MXKAlert alloc] initWithTitle:roomState.displayname
|
||||
message:messageText
|
||||
style:MXKAlertStyleAlert];
|
||||
self.mxNotification.cancelButtonIndex = [self.mxNotification addActionWithTitle:@"Cancel"
|
||||
style:MXKAlertActionStyleDefault
|
||||
handler:^(MXKAlert *alert) {
|
||||
weakSelf.mxNotification = nil;
|
||||
[weakSelf.unnotifiedRooms addObject:event.roomId];
|
||||
}];
|
||||
[self.mxNotification addActionWithTitle:@"View"
|
||||
style:MXKAlertActionStyleDefault
|
||||
handler:^(MXKAlert *alert) {
|
||||
weakSelf.mxNotification = nil;
|
||||
// Show the room
|
||||
[[AppDelegate theDelegate].masterTabBarController showRoom:event.roomId];
|
||||
}];
|
||||
|
||||
[self.mxNotification showInViewController:[[AppDelegate theDelegate].masterTabBarController selectedViewController]];
|
||||
}
|
||||
}];
|
||||
} else {
|
||||
@@ -884,348 +893,6 @@ static MatrixSDKHandler *sharedHandler = nil;
|
||||
return senderAvatarUrl;
|
||||
}
|
||||
|
||||
- (NSString*)displayTextForEvent:(MXEvent*)event withRoomState:(MXRoomState*)roomState inSubtitleMode:(BOOL)isSubtitle {
|
||||
// Check first whether the event has been redacted
|
||||
NSString *redactedInfo = nil;
|
||||
BOOL isRedacted = (event.redactedBecause != nil);
|
||||
if (isRedacted) {
|
||||
NSLog(@"[MatrixSDKHandler] Redacted event %@ (%@)", event.description, event.redactedBecause);
|
||||
// Check whether redacted information is required
|
||||
if (!isSubtitle && ![AppSettings sharedSettings].hideRedactions) {
|
||||
redactedInfo = @"<redacted>";
|
||||
// Consider live room state to resolve redactor name if no roomState is provided
|
||||
MXRoomState *aRoomState = roomState ? roomState : [self.mxSession roomWithRoomId:event.roomId].state;
|
||||
NSString *redactedBy = [aRoomState memberName:event.redactedBecause[@"user_id"]];
|
||||
NSString *redactedReason = (event.redactedBecause[@"content"])[@"reason"];
|
||||
if (redactedReason.length) {
|
||||
if (redactedBy.length) {
|
||||
redactedBy = [NSString stringWithFormat:@"by %@ [reason: %@]", redactedBy, redactedReason];
|
||||
} else {
|
||||
redactedBy = [NSString stringWithFormat:@"[reason: %@]", redactedReason];
|
||||
}
|
||||
} else if (redactedBy.length) {
|
||||
redactedBy = [NSString stringWithFormat:@"by %@", redactedBy];
|
||||
}
|
||||
|
||||
if (redactedBy.length) {
|
||||
redactedInfo = [NSString stringWithFormat:@"<redacted %@>", redactedBy];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Prepare returned description
|
||||
NSString *displayText = nil;
|
||||
// Prepare display name for concerned users
|
||||
NSString *senderDisplayName = roomState ? [self senderDisplayNameForEvent:event withRoomState:roomState] : event.userId;
|
||||
NSString *targetDisplayName = nil;
|
||||
if (event.stateKey) {
|
||||
targetDisplayName = roomState ? [roomState memberName:event.stateKey] : event.stateKey;
|
||||
}
|
||||
|
||||
switch (event.eventType) {
|
||||
case MXEventTypeRoomName: {
|
||||
NSString *roomName = event.content[@"name"];
|
||||
if (isRedacted) {
|
||||
if (!redactedInfo) {
|
||||
// Here the event is ignored (no display)
|
||||
return nil;
|
||||
}
|
||||
roomName = redactedInfo;
|
||||
}
|
||||
|
||||
if (roomName.length) {
|
||||
displayText = [NSString stringWithFormat:@"%@ changed the room name to: %@", senderDisplayName, roomName];
|
||||
} else {
|
||||
displayText = [NSString stringWithFormat:@"%@ removed the room name", senderDisplayName];
|
||||
}
|
||||
break;
|
||||
}
|
||||
case MXEventTypeRoomTopic: {
|
||||
NSString *roomTopic = event.content[@"topic"];
|
||||
if (isRedacted) {
|
||||
if (!redactedInfo) {
|
||||
// Here the event is ignored (no display)
|
||||
return nil;
|
||||
}
|
||||
roomTopic = redactedInfo;
|
||||
}
|
||||
|
||||
if (roomTopic.length) {
|
||||
displayText = [NSString stringWithFormat:@"%@ changed the topic to: %@", senderDisplayName, roomTopic];
|
||||
} else {
|
||||
displayText = [NSString stringWithFormat:@"%@ removed the topic", senderDisplayName];
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case MXEventTypeRoomMember: {
|
||||
// Presently only change on membership, display name and avatar are supported
|
||||
|
||||
// Retrieve membership
|
||||
NSString* membership = event.content[@"membership"];
|
||||
NSString *prevMembership = nil;
|
||||
if (event.prevContent) {
|
||||
prevMembership = event.prevContent[@"membership"];
|
||||
}
|
||||
|
||||
// Check whether the sender has updated his profile (the membership is then unchanged)
|
||||
if (prevMembership && membership && [membership isEqualToString:prevMembership]) {
|
||||
// Is redacted event?
|
||||
if (isRedacted) {
|
||||
if (!redactedInfo) {
|
||||
// Here the event is ignored (no display)
|
||||
return nil;
|
||||
}
|
||||
displayText = [NSString stringWithFormat:@"%@ updated their profile %@", senderDisplayName, redactedInfo];;
|
||||
} else {
|
||||
// Check whether the display name has been changed
|
||||
NSString *displayname = event.content[@"displayname"];
|
||||
NSString *prevDisplayname = event.prevContent[@"displayname"];
|
||||
if (!displayname.length) {
|
||||
displayname = nil;
|
||||
}
|
||||
if (!prevDisplayname.length) {
|
||||
prevDisplayname = nil;
|
||||
}
|
||||
if ((displayname || prevDisplayname) && ([displayname isEqualToString:prevDisplayname] == NO)) {
|
||||
if (!prevDisplayname) {
|
||||
displayText = [NSString stringWithFormat:@"%@ set their display name to %@", event.userId, displayname];
|
||||
} else if (!displayname) {
|
||||
displayText = [NSString stringWithFormat:@"%@ removed their display name (previouly named %@)", event.userId, prevDisplayname];
|
||||
} else {
|
||||
displayText = [NSString stringWithFormat:@"%@ changed their display name from %@ to %@", event.userId, prevDisplayname, displayname];
|
||||
}
|
||||
}
|
||||
|
||||
// Check whether the avatar has been changed
|
||||
NSString *avatar = event.content[@"avatar_url"];
|
||||
NSString *prevAvatar = event.prevContent[@"avatar_url"];
|
||||
if (!avatar.length) {
|
||||
avatar = nil;
|
||||
}
|
||||
if (!prevAvatar.length) {
|
||||
prevAvatar = nil;
|
||||
}
|
||||
if ((prevAvatar || avatar) && ([avatar isEqualToString:prevAvatar] == NO)) {
|
||||
if (displayText) {
|
||||
displayText = [NSString stringWithFormat:@"%@ (picture profile was changed too)", displayText];
|
||||
} else {
|
||||
displayText = [NSString stringWithFormat:@"%@ changed their picture profile", senderDisplayName];
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Consider here a membership change
|
||||
if ([membership isEqualToString:@"invite"]) {
|
||||
displayText = [NSString stringWithFormat:@"%@ invited %@", senderDisplayName, targetDisplayName];
|
||||
} else if ([membership isEqualToString:@"join"]) {
|
||||
displayText = [NSString stringWithFormat:@"%@ joined", senderDisplayName];
|
||||
} else if ([membership isEqualToString:@"leave"]) {
|
||||
if ([event.userId isEqualToString:event.stateKey]) {
|
||||
displayText = [NSString stringWithFormat:@"%@ left", senderDisplayName];
|
||||
} else if (prevMembership) {
|
||||
if ([prevMembership isEqualToString:@"join"] || [prevMembership isEqualToString:@"invite"]) {
|
||||
displayText = [NSString stringWithFormat:@"%@ kicked %@", senderDisplayName, targetDisplayName];
|
||||
if (event.content[@"reason"]) {
|
||||
displayText = [NSString stringWithFormat:@"%@: %@", displayText, event.content[@"reason"]];
|
||||
}
|
||||
} else if ([prevMembership isEqualToString:@"ban"]) {
|
||||
displayText = [NSString stringWithFormat:@"%@ unbanned %@", senderDisplayName, targetDisplayName];
|
||||
}
|
||||
}
|
||||
} else if ([membership isEqualToString:@"ban"]) {
|
||||
displayText = [NSString stringWithFormat:@"%@ banned %@", senderDisplayName, targetDisplayName];
|
||||
if (event.content[@"reason"]) {
|
||||
displayText = [NSString stringWithFormat:@"%@: %@", displayText, event.content[@"reason"]];
|
||||
}
|
||||
}
|
||||
|
||||
// Append redacted info if any
|
||||
if (redactedInfo) {
|
||||
displayText = [NSString stringWithFormat:@"%@ %@", displayText, redactedInfo];
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case MXEventTypeRoomCreate: {
|
||||
NSString *creatorId = event.content[@"creator"];
|
||||
if (creatorId) {
|
||||
displayText = [NSString stringWithFormat:@"%@ created the room", (roomState ? [roomState memberName:creatorId] : creatorId)];
|
||||
// Append redacted info if any
|
||||
if (redactedInfo) {
|
||||
displayText = [NSString stringWithFormat:@"%@ %@", displayText, redactedInfo];
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case MXEventTypeRoomJoinRules: {
|
||||
NSString *joinRule = event.content[@"join_rule"];
|
||||
if (joinRule) {
|
||||
displayText = [NSString stringWithFormat:@"The join rule is: %@", joinRule];
|
||||
// Append redacted info if any
|
||||
if (redactedInfo) {
|
||||
displayText = [NSString stringWithFormat:@"%@ %@", displayText, redactedInfo];
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case MXEventTypeRoomPowerLevels: {
|
||||
displayText = @"The power level of room members are:";
|
||||
NSDictionary *users = event.content[@"users"];
|
||||
for (NSString *key in users.allKeys) {
|
||||
displayText = [NSString stringWithFormat:@"%@\r\n\u2022 %@: %@", displayText, key, [users objectForKey:key]];
|
||||
}
|
||||
if (event.content[@"users_default"]) {
|
||||
displayText = [NSString stringWithFormat:@"%@\r\n\u2022 %@: %@", displayText, @"default", event.content[@"users_default"]];
|
||||
}
|
||||
|
||||
displayText = [NSString stringWithFormat:@"%@\r\nThe minimum power levels that a user must have before acting are:", displayText];
|
||||
if (event.content[@"ban"]) {
|
||||
displayText = [NSString stringWithFormat:@"%@\r\n\u2022 ban: %@", displayText, event.content[@"ban"]];
|
||||
}
|
||||
if (event.content[@"kick"]) {
|
||||
displayText = [NSString stringWithFormat:@"%@\r\n\u2022 kick: %@", displayText, event.content[@"kick"]];
|
||||
}
|
||||
if (event.content[@"redact"]) {
|
||||
displayText = [NSString stringWithFormat:@"%@\r\n\u2022 redact: %@", displayText, event.content[@"redact"]];
|
||||
}
|
||||
if (event.content[@"invite"]) {
|
||||
displayText = [NSString stringWithFormat:@"%@\r\n\u2022 invite: %@", displayText, event.content[@"invite"]];
|
||||
}
|
||||
|
||||
displayText = [NSString stringWithFormat:@"%@\r\nThe minimum power levels related to events are:", displayText];
|
||||
NSDictionary *events = event.content[@"events"];
|
||||
for (NSString *key in events.allKeys) {
|
||||
displayText = [NSString stringWithFormat:@"%@\r\n\u2022 %@: %@", displayText, key, [events objectForKey:key]];
|
||||
}
|
||||
if (event.content[@"events_default"]) {
|
||||
displayText = [NSString stringWithFormat:@"%@\r\n\u2022 %@: %@", displayText, @"events_default", event.content[@"events_default"]];
|
||||
}
|
||||
if (event.content[@"state_default"]) {
|
||||
displayText = [NSString stringWithFormat:@"%@\r\n\u2022 %@: %@", displayText, @"state_default", event.content[@"state_default"]];
|
||||
}
|
||||
|
||||
// Append redacted info if any
|
||||
if (redactedInfo) {
|
||||
displayText = [NSString stringWithFormat:@"%@\r\n %@", displayText, redactedInfo];
|
||||
}
|
||||
break;
|
||||
}
|
||||
case MXEventTypeRoomAliases: {
|
||||
NSArray *aliases = event.content[@"aliases"];
|
||||
if (aliases) {
|
||||
displayText = [NSString stringWithFormat:@"The room aliases are: %@", aliases];
|
||||
// Append redacted info if any
|
||||
if (redactedInfo) {
|
||||
displayText = [NSString stringWithFormat:@"%@\r\n %@", displayText, redactedInfo];
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case MXEventTypeRoomMessage: {
|
||||
// Is redacted?
|
||||
if (isRedacted) {
|
||||
if (!redactedInfo) {
|
||||
// Here the event is ignored (no display)
|
||||
return nil;
|
||||
}
|
||||
displayText = redactedInfo;
|
||||
} else {
|
||||
NSString *msgtype = event.content[@"msgtype"];
|
||||
displayText = [event.content[@"body"] isKindOfClass:[NSString class]] ? event.content[@"body"] : nil;
|
||||
|
||||
if ([msgtype isEqualToString:kMXMessageTypeEmote]) {
|
||||
displayText = [NSString stringWithFormat:@"* %@ %@", senderDisplayName, displayText];
|
||||
} else if ([msgtype isEqualToString:kMXMessageTypeImage]) {
|
||||
displayText = displayText? displayText : @"image attachment";
|
||||
// Check attachment validity
|
||||
if (![self isSupportedAttachment:event]) {
|
||||
NSLog(@"[MatrixSDKHandler] Warning: Unsupported attachment %@", event.description);
|
||||
// Check whether unsupported/unexpected messages should be exposed
|
||||
if (isSubtitle || [AppSettings sharedSettings].hideUnsupportedEvents) {
|
||||
displayText = @"invalid image attachment";
|
||||
} else {
|
||||
// Display event content as unsupported event
|
||||
displayText = [NSString stringWithFormat:@"%@%@", kMatrixSDKHandlerUnsupportedEventDescriptionPrefix, event.description];
|
||||
}
|
||||
}
|
||||
} else if ([msgtype isEqualToString:kMXMessageTypeAudio]) {
|
||||
displayText = displayText? displayText : @"audio attachment";
|
||||
if (![self isSupportedAttachment:event]) {
|
||||
NSLog(@"[MatrixSDKHandler] Warning: Unsupported attachment %@", event.description);
|
||||
if (isSubtitle || [AppSettings sharedSettings].hideUnsupportedEvents) {
|
||||
displayText = @"invalid audio attachment";
|
||||
} else {
|
||||
displayText = [NSString stringWithFormat:@"%@%@", kMatrixSDKHandlerUnsupportedEventDescriptionPrefix, event.description];
|
||||
}
|
||||
}
|
||||
} else if ([msgtype isEqualToString:kMXMessageTypeVideo]) {
|
||||
displayText = displayText? displayText : @"video attachment";
|
||||
if (![self isSupportedAttachment:event]) {
|
||||
NSLog(@"[MatrixSDKHandler] Warning: Unsupported attachment %@", event.description);
|
||||
if (isSubtitle || [AppSettings sharedSettings].hideUnsupportedEvents) {
|
||||
displayText = @"invalid video attachment";
|
||||
} else {
|
||||
displayText = [NSString stringWithFormat:@"%@%@", kMatrixSDKHandlerUnsupportedEventDescriptionPrefix, event.description];
|
||||
}
|
||||
}
|
||||
} else if ([msgtype isEqualToString:kMXMessageTypeLocation]) {
|
||||
displayText = displayText? displayText : @"location attachment";
|
||||
if (![self isSupportedAttachment:event]) {
|
||||
NSLog(@"[MatrixSDKHandler] Warning: Unsupported attachment %@", event.description);
|
||||
if (isSubtitle || [AppSettings sharedSettings].hideUnsupportedEvents) {
|
||||
displayText = @"invalid location attachment";
|
||||
} else {
|
||||
displayText = [NSString stringWithFormat:@"%@%@", kMatrixSDKHandlerUnsupportedEventDescriptionPrefix, event.description];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check whether the sender name has to be added
|
||||
if (displayText && isSubtitle && [msgtype isEqualToString:kMXMessageTypeEmote] == NO) {
|
||||
displayText = [NSString stringWithFormat:@"%@: %@", senderDisplayName, displayText];
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case MXEventTypeRoomMessageFeedback: {
|
||||
NSString *type = event.content[@"type"];
|
||||
NSString *eventId = event.content[@"target_event_id"];
|
||||
if (type && eventId) {
|
||||
displayText = [NSString stringWithFormat:@"Feedback event (id: %@): %@", eventId, type];
|
||||
// Append redacted info if any
|
||||
if (redactedInfo) {
|
||||
displayText = [NSString stringWithFormat:@"%@ %@", displayText, redactedInfo];
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case MXEventTypeRoomRedaction: {
|
||||
if ([self.eventsFilterForMessages indexOfObject:kMXEventTypeStringRoomRedaction] != NSNotFound) {
|
||||
NSString *eventId = event.redacts;
|
||||
displayText = [NSString stringWithFormat:@"%@ redacted an event (id: %@)", senderDisplayName, eventId];
|
||||
} else {
|
||||
// No description
|
||||
return nil;
|
||||
}
|
||||
}
|
||||
case MXEventTypeCustom:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (!displayText) {
|
||||
NSLog(@"[MatrixSDKHandler] Warning: Unsupported event %@)", event.description);
|
||||
if (!isSubtitle && ![AppSettings sharedSettings].hideUnsupportedEvents) {
|
||||
// Return event content as unsupported event
|
||||
displayText = [NSString stringWithFormat:@"%@%@", kMatrixSDKHandlerUnsupportedEventDescriptionPrefix, event.description];
|
||||
}
|
||||
}
|
||||
|
||||
return displayText;
|
||||
}
|
||||
|
||||
#pragma mark - Presence
|
||||
|
||||
// return the presence ring color
|
||||
|
||||
Reference in New Issue
Block a user