ObjMatrix  Diff

Differences From Artifact [bf6cef9450]:

To Artifact [16dc45e5ea]:


37
38
39
40
41
42
43
44
45
46



47
48
49
50
51
52
53
54
55
56
57
58
59

60
61
62
63
64

65
66
67
68
69
70
71
72
73
74
75
76

77
78
79
80

81
82
83
84
85
86
87
88
89
90

91
92

93
94
95
96
97

98
99
100
101
102
103
104
105
106
107
108
109

110
111
112
113
114

115
116
117

118
119

120
121
122
123
124
125
126

127
128
129

130
131
132
133

134
135
136
137
138
139
140
141
142
143

144
145
146
147

148
149
150
151
152
37
38
39
40
41
42
43



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58

59
60
61
62
63

64
65
66
67
68
69
70
71
72
73
74
75

76
77
78
79

80
81
82
83
84
85
86
87
88


89
90

91
92
93
94
95

96
97
98
99
100
101
102
103
104
105
106
107

108
109
110
111
112

113
114


115
116

117

118
119
120
121
122

123

124

125
126
127
128

129
130
131
132
133
134
135
136
137
138

139
140
141
142

143
144
145
146
147
148







-
-
-
+
+
+












-
+




-
+











-
+



-
+








-
-
+

-
+




-
+











-
+




-
+

-
-
+

-
+
-





-
+
-

-
+



-
+









-
+



-
+






- (void)applicationDidFinishLaunching
{
	__auto_type environment = OFApplication.environment;
	if (environment[@"OBJMATRIX_USER"] == nil ||
	    environment[@"OBJMATRIX_PASS"] == nil ||
	    environment[@"OBJMATRIX_HS"] == nil) {
		[of_stderr writeString: @"Please set OBJMATRIX_USER, "
					@"OBJMATRIX_PASS and OBJMATRIX_HS in "
					@"the environment!\n"];
		[OFStdErr writeString: @"Please set OBJMATRIX_USER, "
				       @"OBJMATRIX_PASS and OBJMATRIX_HS in "
				       @"the environment!\n"];
		[OFApplication terminateWithStatus: 1];
	}

	OFURL *homeserver = [OFURL URLWithString: environment[@"OBJMATRIX_HS"]];
	id <MTXStorage> storage =
	    [MTXSQLite3Storage storageWithPath: @"tests.db"];
	[MTXClient logInWithUser: environment[@"OBJMATRIX_USER"]
			password: environment[@"OBJMATRIX_PASS"]
		      homeserver: homeserver
			 storage: storage
			   block: ^ (MTXClient *client, id exception) {
		if (exception != nil) {
			of_log(@"Error logging in: %@", exception);
			OFLog(@"Error logging in: %@", exception);
			[OFApplication terminateWithStatus: 1];
		}

		_client = [client retain];
		of_log(@"Logged in client: %@", _client);
		OFLog(@"Logged in client: %@", _client);

		[_client startSyncLoop];
		[self fetchRoomList];
	}];
}

- (void)fetchRoomList
{
	[_client fetchRoomListWithBlock: ^ (OFArray<OFString *> *rooms,
					     id exception) {
		if (exception != nil) {
			of_log(@"Failed to fetch room list: %@", exception);
			OFLog(@"Failed to fetch room list: %@", exception);
			[OFApplication terminateWithStatus: 1];
		}

		of_log(@"Fetched room list: %@", rooms);
		OFLog(@"Fetched room list: %@", rooms);

		[self joinRoom];
	}];
}

- (void)joinRoom
{
	OFString *room = @"#test:nil.im";
	[_client joinRoom: room
		    block: ^ (OFString *roomID, id exception) {
	[_client joinRoom: room block: ^ (OFString *roomID, id exception) {
		if (exception != nil) {
			of_log(@"Failed to join room %@: %@", room, exception);
			OFLog(@"Failed to join room %@: %@", room, exception);
			[OFApplication terminateWithStatus: 1];
		}

		_roomID = [roomID copy];
		of_log(@"Joined room %@", _roomID);
		OFLog(@"Joined room %@", _roomID);

		[self sendMessage];
	}];
}

- (void)sendMessage
{
	[_client sendMessage: @"ObjMatrix test successful!"
		      roomID: _roomID
		       block: ^ (id exception) {
		if (exception != nil) {
			of_log(@"Failed to send message to room %@: %@",
			OFLog(@"Failed to send message to room %@: %@",
			    _roomID, exception);
			[OFApplication terminateWithStatus: 1];
		}

		of_log(@"Message sent to %@", _roomID);
		OFLog(@"Message sent to %@", _roomID);

		of_log(
		    @"Waiting 5 seconds before leaving room and logging out");
		OFLog(@"Waiting 5 seconds before leaving room and logging out");

		[self performSelector: @selector(leaveRoom)
		[self performSelector: @selector(leaveRoom) afterDelay: 5];
			   afterDelay: 5];
	}];
}

- (void)leaveRoom
{
	[_client leaveRoom: _roomID
	[_client leaveRoom: _roomID block: ^ (id exception) {
		     block: ^ (id exception) {
		if (exception != nil) {
			of_log(@"Failed to leave room %@: %@", exception);
			OFLog(@"Failed to leave room %@: %@", exception);
			[OFApplication terminateWithStatus: 1];
		}

		of_log(@"Left room %@", _roomID);
		OFLog(@"Left room %@", _roomID);

		[self logOut];
	}];
}

- (void)logOut
{
	[_client logOutWithBlock: ^ (id exception) {
		if (exception != nil) {
			of_log(@"Failed to log out: %@\n", exception);
			OFLog(@"Failed to log out: %@\n", exception);
			[OFApplication terminateWithStatus: 1];
		}

		of_log(@"Logged out client");
		OFLog(@"Logged out client");

		[OFApplication terminate];
	}];
}
@end