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

Add voice broadcast state event #6785

Merged
merged 11 commits into from
Oct 12, 2022
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Config/AppConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ class AppConfiguration: CommonConfiguration {
// Enable CallKit for app
MXKAppSettings.standard()?.isCallKitEnabled = true

// Get modular widget events in rooms histories
// Get additional events (modular widget, voice broadcast...)
MXKAppSettings.standard()?.addSupportedEventTypes([kWidgetMatrixEventTypeString,
kWidgetModularEventTypeString])
kWidgetModularEventTypeString,
giomfo marked this conversation as resolved.
Show resolved Hide resolved
VoiceBroadcastSettings.eventType])

// Hide undecryptable messages that were sent while the user was not in the room
MXKAppSettings.standard()?.hidePreJoinedUndecryptableEvents = true
Expand Down
4 changes: 4 additions & 0 deletions Config/BuildSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,10 @@ final class BuildSettings: NSObject {
static let defaultTileServerMapStyleURL = URL(string: "https://api.maptiler.com/maps/streets/style.json?key=fU3vlMsMn4Jb6dnEIFsx")!

static let locationSharingEnabled = true

// MARK: - Voice Broadcast
static let voiceBroadcastEnabled = false
static let voiceBroadcastChunkLength: Int = 600

// MARK: - MXKAppSettings
static let enableBotCreation: Bool = false
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"filename" : "action_live.png",
yostyle marked this conversation as resolved.
Show resolved Hide resolved
"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.
1 change: 1 addition & 0 deletions Riot/Generated/Images.swift
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ internal class Asset: NSObject {
internal static let peopleFloatingAction = ImageAsset(name: "people_floating_action")
internal static let actionCamera = ImageAsset(name: "action_camera")
internal static let actionFile = ImageAsset(name: "action_file")
internal static let actionLive = ImageAsset(name: "action_live")
internal static let actionLocation = ImageAsset(name: "action_location")
internal static let actionMediaLibrary = ImageAsset(name: "action_media_library")
internal static let actionPoll = ImageAsset(name: "action_poll")
Expand Down
3 changes: 2 additions & 1 deletion Riot/Modules/Room/CellData/RoomBubbleCellData.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ typedef NS_ENUM(NSInteger, RoomBubbleCellDataTag)
RoomBubbleCellDataTagRoomCreationIntro,
RoomBubbleCellDataTagPoll,
RoomBubbleCellDataTagLocation,
RoomBubbleCellDataTagLiveLocation
RoomBubbleCellDataTagLiveLocation,
RoomBubbleCellDataTagVoiceBroadcast
};

/**
Expand Down
78 changes: 46 additions & 32 deletions Riot/Modules/Room/CellData/RoomBubbleCellData.m
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,13 @@ - (instancetype)initWithEvent:(MXEvent *)event andRoomState:(MXRoomState *)roomS
// Show timestamps always on right
self.displayTimestampForSelectedComponentOnLeftWhenPossible = NO;
}
} else if ([event.type isEqualToString:VoiceBroadcastSettings.eventType]) {
self.tag = RoomBubbleCellDataTagVoiceBroadcast;
self.collapsable = NO;
self.collapsed = NO;

MXLogDebug(@"VB incoming initWithEvent")
break;
}

break;
Expand Down Expand Up @@ -271,42 +278,44 @@ - (NSAttributedString*)attributedTextMessageWithoutPositioningSpace

- (BOOL)hasNoDisplay
{
if (self.tag == RoomBubbleCellDataTagKeyVerificationNoDisplay)
{
return YES;
}

if (self.tag == RoomBubbleCellDataTagRoomCreationIntro)
{
return NO;
}

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

return NO;
}

if (self.tag == RoomBubbleCellDataTagLocation)
{
return NO;
}
BOOL hasNoDisplay = YES;

if (self.tag == RoomBubbleCellDataTagLiveLocation)
switch (self.tag)
{
// If the summary does not exist don't show the cell
if (!self.beaconInfoSummary)
{
return YES;
}

return NO;
case RoomBubbleCellDataTagKeyVerificationNoDisplay:
hasNoDisplay = YES;
break;
case RoomBubbleCellDataTagRoomCreationIntro:
hasNoDisplay = NO;
break;
case RoomBubbleCellDataTagPoll:
if (self.events.lastObject.isEditEvent) {
hasNoDisplay = YES;
}

hasNoDisplay = NO;
break;
case RoomBubbleCellDataTagLocation:
hasNoDisplay = NO;
break;
case RoomBubbleCellDataTagLiveLocation:
// If the summary does not exist don't show the cell
if (!self.beaconInfoSummary)
{
hasNoDisplay = YES;
}

hasNoDisplay = NO;
break;
case RoomBubbleCellDataTagVoiceBroadcast:
hasNoDisplay = YES;
giomfo marked this conversation as resolved.
Show resolved Hide resolved
break;
default:
hasNoDisplay = [super hasNoDisplay];
break;
}

return [super hasNoDisplay];
return hasNoDisplay;
}

- (BOOL)hasThreadRoot
Expand Down Expand Up @@ -1050,6 +1059,9 @@ - (BOOL)addEvent:(MXEvent*)event andRoomState:(MXRoomState*)roomState
case RoomBubbleCellDataTagLiveLocation:
shouldAddEvent = NO;
break;
case RoomBubbleCellDataTagVoiceBroadcast:
shouldAddEvent = NO;
break;
default:
break;
}
Expand Down Expand Up @@ -1118,6 +1130,8 @@ - (BOOL)addEvent:(MXEvent*)event andRoomState:(MXRoomState*)roomState
{
shouldAddEvent = NO;
}
} else if ([event.type isEqualToString:VoiceBroadcastSettings.eventType]) {
shouldAddEvent = NO;
}
break;
}
Expand Down
2 changes: 0 additions & 2 deletions Riot/Modules/Room/DataSources/RoomDataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,6 @@ extension RoomDataSource {

return editableTextMessage
}


}

// MARK: - Private Helpers
Expand Down
28 changes: 28 additions & 0 deletions Riot/Modules/Room/RoomViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -2308,6 +2308,34 @@ - (void)setupActions {
[self showCameraControllerAnimated:YES];
}]];
}
if (BuildSettings.voiceBroadcastEnabled && !self.isNewDirectChat)
{
[actionItems addObject:[[RoomActionItem alloc] initWithImage:AssetImages.actionLive.image andAction:^{
MXStrongifyAndReturnIfNil(self);
if ([self.inputToolbarView isKindOfClass:RoomInputToolbarView.class]) {
((RoomInputToolbarView *) self.inputToolbarView).actionMenuOpened = NO;
}

MXSession* session = self.roomDataSource.mxSession;
[session getOrCreateVoiceBroadcastServiceFor:self.roomDataSource.room completion:^(VoiceBroadcastService *voiceBroadcastService) {
if (voiceBroadcastService) {
if ([[voiceBroadcastService getState] isEqualToString:@"stopped"]) {
[session.voiceBroadcastService startVoiceBroadcastWithSuccess:^(NSString * _Nullable success) {

} failure:^(NSError * _Nonnull error) {

}];
} else {
[session.voiceBroadcastService stopVoiceBroadcastWithSuccess:^(NSString * _Nullable success) {

} failure:^(NSError * _Nonnull error) {

}];
Comment on lines +2325 to +2334
Copy link
Member

Choose a reason for hiding this comment

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

Boring housekeeping, could these empty blocks maybe have some // TODO comments just for a bit of clarity?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

Copy link
Contributor

Choose a reason for hiding this comment

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

Why not adding only MXLogs into success and failure blocks for the moment ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This part will change in the next PR.

}
}
}];
}]];
}
roomInputView.actionsBar.actionItems = actionItems;
}

Expand Down
31 changes: 31 additions & 0 deletions Riot/Modules/VoiceBroadcast/MXSession+VoiceBroadcast.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// Copyright 2022 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 Foundation
import MatrixSDK

extension MXSession {

/// Convenient getter to retrieve VoiceBroadcastService associated to the session
@objc var voiceBroadcastService: VoiceBroadcastService? {
return VoiceBroadcastServiceProvider.shared.voiceBroadcastService
}

/// Initialize VoiceBroadcastService
@objc public func getOrCreateVoiceBroadcastService(for room: MXRoom, completion: @escaping (VoiceBroadcastService?) -> Void) {
VoiceBroadcastServiceProvider.shared.getOrCreateVoiceBroadcastService(for: room, completion: completion)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//
// Copyright 2022 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 <MatrixSDK/MatrixSDK.h>

#import "MXJSONModel.h"

NS_ASSUME_NONNULL_BEGIN

@interface VoiceBroadcastEventContent : MXJSONModel

@property (nonatomic) NSString *state;

@property (nonatomic) NSInteger chunkLength;

@property (nonatomic, strong, nullable) NSString* eventId;
Copy link
Member

Choose a reason for hiding this comment

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

Might be nice to have a doc comment with some further explanation about this property as I can see it comes from a relatesTo, but not sure what that means.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added some documentation for the properties.

Copy link
Member

Choose a reason for hiding this comment

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

🙌


- (instancetype)initWithState:(NSString *)state
chunkLength:(NSInteger)chunkLength
eventId:(NSString *)eventId;

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
//
// Copyright 2022 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 "VoiceBroadcastEventContent.h"
#import "GeneratedInterface-Swift.h"

@implementation VoiceBroadcastEventContent

- (instancetype)initWithState:(NSString *)state
chunkLength:(NSInteger)chunkLength
eventId:(NSString *)eventId
{
if (self = [super init])
{
_state = state;
_chunkLength = chunkLength;
_eventId = eventId;
}

return self;
}

+ (id)modelFromJSON:(NSDictionary *)JSONDictionary
{
NSString *state;
MXJSONModelSetString(state, JSONDictionary[VoiceBroadcastSettings.voiceBroadcastContentKeyState]);

NSInteger chunkLength = BuildSettings.voiceBroadcastChunkLength;
if (JSONDictionary[VoiceBroadcastSettings.voiceBroadcastContentKeyChunkLength])
{
MXJSONModelSetInteger(chunkLength, JSONDictionary[VoiceBroadcastSettings.voiceBroadcastContentKeyChunkLength]);
}

NSString *eventId;
if (JSONDictionary[kMXEventRelationRelatesToKey]) {
MXEventContentRelatesTo *relatesTo;

MXJSONModelSetMXJSONModel(relatesTo, MXEventContentRelatesTo, JSONDictionary[kMXEventRelationRelatesToKey]);

if (relatesTo && [relatesTo.relationType isEqualToString:MXEventRelationTypeReference])
{
eventId = relatesTo.eventId;
}
}

return [[VoiceBroadcastEventContent alloc] initWithState:state chunkLength:chunkLength eventId:eventId];
}

- (NSDictionary *)JSONDictionary
{
NSMutableDictionary *JSONDictionary = [NSMutableDictionary dictionary];

JSONDictionary[VoiceBroadcastSettings.voiceBroadcastContentKeyState] = self.state;

if (_eventId) {
MXEventContentRelatesTo *relatesTo = [[MXEventContentRelatesTo alloc] initWithRelationType:MXEventRelationTypeReference eventId:_eventId];

JSONDictionary[kMXEventRelationRelatesToKey] = relatesTo.JSONDictionary;
} else {
JSONDictionary[VoiceBroadcastSettings.voiceBroadcastContentKeyChunkLength] = @(self.chunkLength);
}

return JSONDictionary;
}

@end
Loading