Update the room description in the rooms list in case of live broadcast (incoming or outgoing) (#7160)

This commit is contained in:
Yoan Pintas
2022-12-19 19:26:55 +01:00
committed by GitHub
parent 5d1b05e961
commit 79e9f8ee40
17 changed files with 119 additions and 10 deletions
@@ -0,0 +1,48 @@
//
// 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 VoiceBroadcastInfo : MXJSONModel
/// The device id from which the broadcast has been started
@property (nonatomic) NSString *deviceId;
/// The voice broadcast state (started - paused - resumed - stopped).
@property (nonatomic) NSString *state;
/// The length of the voice chunks in seconds. Only required on the started state event.
@property (nonatomic) NSInteger chunkLength;
/// The event id of the started voice broadcast info state event.
@property (nonatomic, strong, nullable) NSString* voiceBroadcastId;
/// The voice broadcast last chunk sequence number.
@property (nonatomic) NSInteger lastChunkSequence;
- (instancetype)initWithDeviceId:(NSString *)deviceId
state:(NSString *)state
chunkLength:(NSInteger)chunkLength
voiceBroadcastId:(NSString *)voiceBroadcastId
lastChunkSequence:(NSInteger)lastChunkSequence;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,103 @@
//
// 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 "VoiceBroadcastInfo.h"
#import "GeneratedInterface-Swift.h"
@implementation VoiceBroadcastInfo
- (instancetype)initWithDeviceId:(NSString *)deviceId
state:(NSString *)state
chunkLength:(NSInteger)chunkLength
voiceBroadcastId:(NSString *)voiceBroadcastId
lastChunkSequence:(NSInteger)lastChunkSequence
{
if (self = [super init])
{
_deviceId = deviceId;
_state = state;
_chunkLength = chunkLength;
_voiceBroadcastId = voiceBroadcastId;
_lastChunkSequence = lastChunkSequence;
}
return self;
}
+ (id)modelFromJSON:(NSDictionary *)JSONDictionary
{
// Return nil for redacted state event
if (!JSONDictionary[VoiceBroadcastSettings.voiceBroadcastContentKeyState])
{
return nil;
}
NSString *state;
MXJSONModelSetString(state, JSONDictionary[VoiceBroadcastSettings.voiceBroadcastContentKeyState]);
NSString *deviceId;
MXJSONModelSetString(deviceId, JSONDictionary[VoiceBroadcastSettings.voiceBroadcastContentKeyDeviceId]);
NSInteger chunkLength = BuildSettings.voiceBroadcastChunkLength;
if (JSONDictionary[VoiceBroadcastSettings.voiceBroadcastContentKeyChunkLength])
{
MXJSONModelSetInteger(chunkLength, JSONDictionary[VoiceBroadcastSettings.voiceBroadcastContentKeyChunkLength]);
}
NSString *voiceBroadcastId;
if (JSONDictionary[kMXEventRelationRelatesToKey]) {
MXEventContentRelatesTo *relatesTo;
MXJSONModelSetMXJSONModel(relatesTo, MXEventContentRelatesTo, JSONDictionary[kMXEventRelationRelatesToKey]);
if (relatesTo && [relatesTo.relationType isEqualToString:MXEventRelationTypeReference])
{
voiceBroadcastId = relatesTo.eventId;
}
}
NSInteger lastChunkSequence = 0;
if (JSONDictionary[VoiceBroadcastSettings.voiceBroadcastContentKeyChunkLastSequence]) {
MXJSONModelSetInteger(lastChunkSequence, JSONDictionary[VoiceBroadcastSettings.voiceBroadcastContentKeyChunkLastSequence]);
}
return [[VoiceBroadcastInfo alloc] initWithDeviceId:deviceId state:state chunkLength:chunkLength voiceBroadcastId:voiceBroadcastId lastChunkSequence:lastChunkSequence];
}
- (NSDictionary *)JSONDictionary
{
NSMutableDictionary *JSONDictionary = [NSMutableDictionary dictionary];
JSONDictionary[VoiceBroadcastSettings.voiceBroadcastContentKeyDeviceId] = self.deviceId;
JSONDictionary[VoiceBroadcastSettings.voiceBroadcastContentKeyState] = self.state;
if (_voiceBroadcastId) {
MXEventContentRelatesTo *relatesTo = [[MXEventContentRelatesTo alloc] initWithRelationType:MXEventRelationTypeReference eventId:_voiceBroadcastId];
JSONDictionary[kMXEventRelationRelatesToKey] = relatesTo.JSONDictionary;
} else {
JSONDictionary[VoiceBroadcastSettings.voiceBroadcastContentKeyChunkLength] = @(self.chunkLength);
}
if (self.lastChunkSequence != 0) {
JSONDictionary[VoiceBroadcastSettings.voiceBroadcastContentKeyChunkLastSequence] = @(self.lastChunkSequence);
}
return JSONDictionary;
}
@end
@@ -0,0 +1,47 @@
//
// 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
extension VoiceBroadcastInfo {
// MARK: - Constants
// MARK: - Public
@objc static func isStarted(for name: String) -> Bool {
return name == VoiceBroadcastInfoState.started.rawValue
}
@objc static func isStopped(for name: String) -> Bool {
return name == VoiceBroadcastInfoState.stopped.rawValue
}
@objc static func startedValue() -> String {
return VoiceBroadcastInfoState.started.rawValue
}
@objc static func pausedValue() -> String {
return VoiceBroadcastInfoState.paused.rawValue
}
@objc static func resumedValue() -> String {
return VoiceBroadcastInfoState.resumed.rawValue
}
@objc static func stoppedValue() -> String {
return VoiceBroadcastInfoState.stopped.rawValue
}
}
@@ -0,0 +1,22 @@
//
// 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.
//
public enum VoiceBroadcastInfoState: String {
case started
case paused
case resumed
case stopped
}
@@ -0,0 +1,30 @@
//
// 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
/// Voice Broadcast settings.
@objcMembers
final class VoiceBroadcastSettings: NSObject {
static let voiceBroadcastInfoContentKeyType = "io.element.voice_broadcast_info"
static let voiceBroadcastContentKeyDeviceId = "device_id"
static let voiceBroadcastContentKeyState = "state"
static let voiceBroadcastContentKeyChunkLength = "chunk_length"
static let voiceBroadcastContentKeyChunkType = "io.element.voice_broadcast_chunk"
static let voiceBroadcastContentKeyChunkSequence = "sequence"
static let voiceBroadcastContentKeyChunkLastSequence = "last_chunk_sequence"
}