Skip to content

Commit

Permalink
MXServerNotices: Add this class to get notices from the user homeserver
Browse files Browse the repository at this point in the history
  • Loading branch information
manuroe committed Oct 2, 2018
1 parent 64431b0 commit 4869f67
Show file tree
Hide file tree
Showing 9 changed files with 393 additions and 11 deletions.
4 changes: 1 addition & 3 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ Changes in Matrix iOS SDK in 0.11.5 (2018-10-)
Improvements:
* MXSession: Add eventWithEventId:inRoom: method.
* MXRoomState: Add pinnedEvents to list pinned events ids.

Bug fix:
*
* MXServerNotices: Add this class to get notices from the user homeserver.

Changes in Matrix iOS SDK in 0.11.4 (2018-09-26)
===============================================
Expand Down
16 changes: 16 additions & 0 deletions MatrixSDK.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@
3291D4D51A68FFEB00C3BA41 /* MXFileRoomStore.m in Sources */ = {isa = PBXBuildFile; fileRef = 3291D4D31A68FFEB00C3BA41 /* MXFileRoomStore.m */; };
3293C700214BBA4F009B3DDB /* MXPeekingRoomSummary.h in Headers */ = {isa = PBXBuildFile; fileRef = 3293C6FE214BBA4F009B3DDB /* MXPeekingRoomSummary.h */; };
3293C701214BBA4F009B3DDB /* MXPeekingRoomSummary.m in Sources */ = {isa = PBXBuildFile; fileRef = 3293C6FF214BBA4F009B3DDB /* MXPeekingRoomSummary.m */; };
32954019216385F100E300FC /* MXServerNoticeContent.h in Headers */ = {isa = PBXBuildFile; fileRef = 32954017216385F100E300FC /* MXServerNoticeContent.h */; settings = {ATTRIBUTES = (Public, ); }; };
3295401A216385F100E300FC /* MXServerNoticeContent.m in Sources */ = {isa = PBXBuildFile; fileRef = 32954018216385F100E300FC /* MXServerNoticeContent.m */; };
329571931B0240CE00ABB3BA /* MXVoIPTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 329571921B0240CE00ABB3BA /* MXVoIPTests.m */; };
329571991B024D2B00ABB3BA /* MXMockCallStack.m in Sources */ = {isa = PBXBuildFile; fileRef = 329571961B024D2B00ABB3BA /* MXMockCallStack.m */; };
3295719A1B024D2B00ABB3BA /* MXMockCallStackCall.m in Sources */ = {isa = PBXBuildFile; fileRef = 329571981B024D2B00ABB3BA /* MXMockCallStackCall.m */; };
Expand Down Expand Up @@ -171,6 +173,8 @@
32A31BC520D3FFB0005916C7 /* MXFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 32A31BC320D3FFB0005916C7 /* MXFilter.m */; };
32A31BC820D401FC005916C7 /* MXRoomFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 32A31BC620D401FC005916C7 /* MXRoomFilter.h */; settings = {ATTRIBUTES = (Public, ); }; };
32A31BC920D401FC005916C7 /* MXRoomFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 32A31BC720D401FC005916C7 /* MXRoomFilter.m */; };
32A9770421626E5C00919CC0 /* MXServerNotices.h in Headers */ = {isa = PBXBuildFile; fileRef = 32A9770221626E5C00919CC0 /* MXServerNotices.h */; settings = {ATTRIBUTES = (Public, ); }; };
32A9770521626E5C00919CC0 /* MXServerNotices.m in Sources */ = {isa = PBXBuildFile; fileRef = 32A9770321626E5C00919CC0 /* MXServerNotices.m */; };
32A9E8241EF4026E0081358A /* MXBackgroundModeHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = 32A9E8211EF4026E0081358A /* MXBackgroundModeHandler.h */; };
32A9E8251EF4026E0081358A /* MXUIKitBackgroundModeHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = 32A9E8221EF4026E0081358A /* MXUIKitBackgroundModeHandler.h */; };
32A9E8261EF4026E0081358A /* MXUIKitBackgroundModeHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = 32A9E8231EF4026E0081358A /* MXUIKitBackgroundModeHandler.m */; };
Expand Down Expand Up @@ -431,6 +435,8 @@
3291D4D31A68FFEB00C3BA41 /* MXFileRoomStore.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MXFileRoomStore.m; sourceTree = "<group>"; };
3293C6FE214BBA4F009B3DDB /* MXPeekingRoomSummary.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MXPeekingRoomSummary.h; sourceTree = "<group>"; };
3293C6FF214BBA4F009B3DDB /* MXPeekingRoomSummary.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MXPeekingRoomSummary.m; sourceTree = "<group>"; };
32954017216385F100E300FC /* MXServerNoticeContent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MXServerNoticeContent.h; sourceTree = "<group>"; };
32954018216385F100E300FC /* MXServerNoticeContent.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MXServerNoticeContent.m; sourceTree = "<group>"; };
329571921B0240CE00ABB3BA /* MXVoIPTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MXVoIPTests.m; sourceTree = "<group>"; };
329571951B024D2B00ABB3BA /* MXMockCallStack.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MXMockCallStack.h; sourceTree = "<group>"; };
329571961B024D2B00ABB3BA /* MXMockCallStack.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MXMockCallStack.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -473,6 +479,8 @@
32A31BC320D3FFB0005916C7 /* MXFilter.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MXFilter.m; sourceTree = "<group>"; };
32A31BC620D401FC005916C7 /* MXRoomFilter.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MXRoomFilter.h; sourceTree = "<group>"; };
32A31BC720D401FC005916C7 /* MXRoomFilter.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MXRoomFilter.m; sourceTree = "<group>"; };
32A9770221626E5C00919CC0 /* MXServerNotices.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MXServerNotices.h; sourceTree = "<group>"; };
32A9770321626E5C00919CC0 /* MXServerNotices.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MXServerNotices.m; sourceTree = "<group>"; };
32A9E8211EF4026E0081358A /* MXBackgroundModeHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MXBackgroundModeHandler.h; sourceTree = "<group>"; };
32A9E8221EF4026E0081358A /* MXUIKitBackgroundModeHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MXUIKitBackgroundModeHandler.h; sourceTree = "<group>"; };
32A9E8231EF4026E0081358A /* MXUIKitBackgroundModeHandler.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MXUIKitBackgroundModeHandler.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -714,6 +722,8 @@
32A9E8211EF4026E0081358A /* MXBackgroundModeHandler.h */,
32A9E8221EF4026E0081358A /* MXUIKitBackgroundModeHandler.h */,
32A9E8231EF4026E0081358A /* MXUIKitBackgroundModeHandler.m */,
32A9770221626E5C00919CC0 /* MXServerNotices.h */,
32A9770321626E5C00919CC0 /* MXServerNotices.m */,
);
path = Utils;
sourceTree = "<group>";
Expand Down Expand Up @@ -870,6 +880,8 @@
B17982F22119E4A1001FD722 /* MXRoomCreateContent.m */,
B17982EF2119E49F001FD722 /* MXRoomPredecessorInfo.h */,
B17982F32119E4A1001FD722 /* MXRoomPredecessorInfo.m */,
32954017216385F100E300FC /* MXServerNoticeContent.h */,
32954018216385F100E300FC /* MXServerNoticeContent.m */,
323F8862212D4E470001C73C /* MXMatrixVersions.h */,
323F8863212D4E470001C73C /* MXMatrixVersions.m */,
);
Expand Down Expand Up @@ -1231,6 +1243,7 @@
321B413F1E09937E009EEEC7 /* MXRoomSummary.h in Headers */,
B17982F52119E4A2001FD722 /* MXRoomCreateContent.h in Headers */,
32DC15CF1A8CF7AE006F9AD3 /* MXPushRuleConditionChecker.h in Headers */,
32954019216385F100E300FC /* MXServerNoticeContent.h in Headers */,
327187851DA7D0220071C818 /* MXOlmDecryption.h in Headers */,
32D7767D1A27860600FC4AA2 /* MXMemoryStore.h in Headers */,
32CE6FB81A409B1F00317F1E /* MXFileStoreMetaData.h in Headers */,
Expand Down Expand Up @@ -1271,6 +1284,7 @@
329FB1791A0A74B100A5E88E /* MXTools.h in Headers */,
322691321E5EF77D00966A6E /* MXDeviceListOperation.h in Headers */,
32481A841C03572900782AD3 /* MXRoomAccountData.h in Headers */,
32A9770421626E5C00919CC0 /* MXServerNotices.h in Headers */,
F08B8D5C1E014711006171A8 /* NSData+MatrixSDK.h in Headers */,
C60165381E3AA57900B92CFA /* MXSDKOptions.h in Headers */,
3281E8B919E42DFE00976E1A /* MXJSONModels.h in Headers */,
Expand Down Expand Up @@ -1501,6 +1515,7 @@
322A51C41D9AC8FE00C8536D /* MXCryptoAlgorithms.m in Sources */,
329FB1761A0A3A1600A5E88E /* MXRoomMember.m in Sources */,
323360701A403A0D0071A488 /* MXFileStore.m in Sources */,
32A9770521626E5C00919CC0 /* MXServerNotices.m in Sources */,
32D7767E1A27860600FC4AA2 /* MXMemoryStore.m in Sources */,
32A151531DAF8A7200400192 /* MXQueuedEncryption.m in Sources */,
C6D5D60A1E4FA74000706C0F /* MXEnumConstants.swift in Sources */,
Expand Down Expand Up @@ -1564,6 +1579,7 @@
320DFDE119DD99B60068622A /* MXSession.m in Sources */,
B17982F62119E4A2001FD722 /* MXRoomTombStoneContent.m in Sources */,
C602B58E1F22A8D700B67D87 /* MXImage.swift in Sources */,
3295401A216385F100E300FC /* MXServerNoticeContent.m in Sources */,
32A151491DAF7C0C00400192 /* MXKey.m in Sources */,
F0C34CBB1C18C93700C36F09 /* MXSDKOptions.m in Sources */,
320BBF441D6C81550079890E /* MXEventsEnumeratorOnArray.m in Sources */,
Expand Down
1 change: 1 addition & 0 deletions MatrixSDK/JSONModels/MXEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ FOUNDATION_EXPORT NSString *const kMXMessageTypeAudio;
FOUNDATION_EXPORT NSString *const kMXMessageTypeVideo;
FOUNDATION_EXPORT NSString *const kMXMessageTypeLocation;
FOUNDATION_EXPORT NSString *const kMXMessageTypeFile;
FOUNDATION_EXPORT NSString *const kMXMessageTypeServerNotice;

/**
Prefix used for id of temporary local event.
Expand Down
17 changes: 9 additions & 8 deletions MatrixSDK/JSONModels/MXEvent.m
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,15 @@
NSString *const kMXEventTypeStringSticker = @"m.sticker";
NSString *const kMXEventTypeStringRoomTombStone = @"m.room.tombstone";

NSString *const kMXMessageTypeText = @"m.text";
NSString *const kMXMessageTypeEmote = @"m.emote";
NSString *const kMXMessageTypeNotice = @"m.notice";
NSString *const kMXMessageTypeImage = @"m.image";
NSString *const kMXMessageTypeAudio = @"m.audio";
NSString *const kMXMessageTypeVideo = @"m.video";
NSString *const kMXMessageTypeLocation = @"m.location";
NSString *const kMXMessageTypeFile = @"m.file";
NSString *const kMXMessageTypeText = @"m.text";
NSString *const kMXMessageTypeEmote = @"m.emote";
NSString *const kMXMessageTypeNotice = @"m.notice";
NSString *const kMXMessageTypeImage = @"m.image";
NSString *const kMXMessageTypeAudio = @"m.audio";
NSString *const kMXMessageTypeVideo = @"m.video";
NSString *const kMXMessageTypeLocation = @"m.location";
NSString *const kMXMessageTypeFile = @"m.file";
NSString *const kMXMessageTypeServerNotice = @"m.server_notice";

NSString *const kMXEventLocalEventIdPrefix = @"kMXEventLocalId_";

Expand Down
50 changes: 50 additions & 0 deletions MatrixSDK/JSONModels/MXServerNoticeContent.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
Copyright 2018 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/Foundation.h>
#import "MXJSONModel.h"


FOUNDATION_EXPORT NSString *const kMXServerNoticeTypeUsageLimitReached;

/**
* Content of a m.server_notice event message.
*/
@interface MXServerNoticeContent : MXJSONModel

/**
The kind of user limit, generally is monthly_active_user.
*/
@property (nonatomic, readonly ) NSString *limitType;

/**
An URI to contact the homeserver administrator
*/
@property (nonatomic, readonly ) NSString *adminContact;

/**
The notice type.
Like kMXServerNoticeTypeUsageLimitReached.
*/
@property (nonatomic, readonly ) NSString *serverNoticeType;

/**
Inidicate if it is a notice for usage limit reached.
*/
@property (nonatomic, readonly ) BOOL isServerNoticeUsageLimit;

@end
42 changes: 42 additions & 0 deletions MatrixSDK/JSONModels/MXServerNoticeContent.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
Copyright 2018 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 "MXServerNoticeContent.h"

NSString *const kMXServerNoticeTypeUsageLimitReached = @"m.server_notice.usage_limit_reached";


@implementation MXServerNoticeContent

+ (id)modelFromJSON:(NSDictionary *)JSONDictionary
{
MXServerNoticeContent* serverNoticeUsageLimitContent = [MXServerNoticeContent new];
if (serverNoticeUsageLimitContent)
{
MXJSONModelSetString(serverNoticeUsageLimitContent->_limitType, JSONDictionary[@"limit_type"]);
MXJSONModelSetString(serverNoticeUsageLimitContent->_adminContact, JSONDictionary[@"admin_contact"]);
MXJSONModelSetString(serverNoticeUsageLimitContent->_serverNoticeType, JSONDictionary[@"server_notice_type"]);
}

return serverNoticeUsageLimitContent;
}

- (BOOL)isServerNoticeUsageLimit
{
return [kMXServerNoticeTypeUsageLimitReached isEqualToString:_serverNoticeType];
}

@end
2 changes: 2 additions & 0 deletions MatrixSDK/MatrixSDK.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,5 @@ FOUNDATION_EXPORT NSString *MatrixSDKVersion;
#import "MXCallKitConfiguration.h"

#import "MXGroup.h"

#import "MXServerNotices.h"
74 changes: 74 additions & 0 deletions MatrixSDK/Utils/MXServerNotices.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
Copyright 2018 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/Foundation.h>

#import "MXServerNoticeContent.h"

@class MXSession;

@protocol MXServerNoticesDelegate;

/**
A `MXServerNotices` instance is responsible for listening to messages from the
user homeserver.
It implements https://github.com/matrix-org/matrix-doc/issues/1452.system where
this communication channel is based on system alert rooms and their pinning events.
*/
@interface MXServerNotices : NSObject

/**
Create the `MXServerNotices` instance.
@param mxSession the mxSession to the home server.
@return the newly created MXNotification instance.
*/
- (instancetype)initWithMatrixSession:(MXSession*)mxSession;

/**
Stop checking homeserver notices.
*/
- (void)close;

/**
If not nil, there is an outgoing usage limitation.
*/
@property (nonatomic, readonly) MXServerNoticeContent *usageLimit;

/**
The delegate.
*/
@property (nonatomic, weak) id<MXServerNoticesDelegate> delegate;

@end


#pragma mark - MXServerNoticesDelegate

/**
Delegate for `MXCall` object
*/
@protocol MXServerNoticesDelegate <NSObject>

/**
Tells the delegate that there is a change in server notices
@param serverNotices the instance that changes.
*/
- (void)serverNoticesDidChangeState:(MXServerNotices *)serverNotices;

@end
Loading

0 comments on commit 4869f67

Please sign in to comment.