[License] Replace 'foobar' with 'famedlysdk' in all Files.

This commit is contained in:
Christian 2019-06-21 12:38:07 +00:00 committed by Marcel
parent 116a644a0e
commit 68ab8b8c8c
20 changed files with 243 additions and 269 deletions

View file

@ -18,7 +18,7 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Foobar. If not, see <http://www.gnu.org/licenses/>.
* along with famedlysdk. If not, see <http://www.gnu.org/licenses/>.
*/
library famedlysdk;

View file

@ -18,7 +18,7 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Foobar. If not, see <http://www.gnu.org/licenses/>.
* along with famedlysdk. If not, see <http://www.gnu.org/licenses/>.
*/
import 'dart:async';

View file

@ -18,7 +18,7 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Foobar. If not, see <http://www.gnu.org/licenses/>.
* along with famedlysdk. If not, see <http://www.gnu.org/licenses/>.
*/
import 'dart:async';

View file

@ -18,7 +18,7 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Foobar. If not, see <http://www.gnu.org/licenses/>.
* along with famedlysdk. If not, see <http://www.gnu.org/licenses/>.
*/
import 'dart:convert';
@ -29,7 +29,6 @@ import './Room.dart';
/// A single Matrix event, e.g. a message in a chat.
class Event {
/// The Matrix ID for this event in the format '$localpart:server.abc'.
final String id;
@ -56,9 +55,12 @@ class Event {
int status;
/// The json payload of the content. The content highly depends on the type.
final Map<String,dynamic> content;
final Map<String, dynamic> content;
Event(this.id, this.sender, this.time,{
Event(
this.id,
this.sender,
this.time, {
this.room,
this.stateKey,
this.status = 2,
@ -73,7 +75,7 @@ class Event {
String get formattedText => content["formatted_body"] ?? "";
/// Use this to get the body.
String getBody () {
String getBody() {
if (text != "") return text;
if (formattedText != "") return formattedText;
return "*** Unable to parse Content ***";
@ -82,36 +84,52 @@ class Event {
/// Get the real type.
EventTypes get type {
switch (environment) {
case "m.room.avatar": return EventTypes.RoomAvatar;
case "m.room.name": return EventTypes.RoomName;
case "m.room.topic": return EventTypes.RoomTopic;
case "m.room.Aliases": return EventTypes.RoomAliases;
case "m.room.canonical_alias": return EventTypes.RoomCanonicalAlias;
case "m.room.create": return EventTypes.RoomCreate;
case "m.room.join_rules": return EventTypes.RoomJoinRules;
case "m.room.member": return EventTypes.RoomMember;
case "m.room.power_levels": return EventTypes.RoomPowerLevels;
case "m.room.avatar":
return EventTypes.RoomAvatar;
case "m.room.name":
return EventTypes.RoomName;
case "m.room.topic":
return EventTypes.RoomTopic;
case "m.room.Aliases":
return EventTypes.RoomAliases;
case "m.room.canonical_alias":
return EventTypes.RoomCanonicalAlias;
case "m.room.create":
return EventTypes.RoomCreate;
case "m.room.join_rules":
return EventTypes.RoomJoinRules;
case "m.room.member":
return EventTypes.RoomMember;
case "m.room.power_levels":
return EventTypes.RoomPowerLevels;
case "m.room.message":
switch(content["msgtype"] ?? "m.text") {
case "m.text": return EventTypes.Text;
case "m.notice": return EventTypes.Notice;
case "m.emote": return EventTypes.Emote;
case "m.image": return EventTypes.Image;
case "m.video": return EventTypes.Video;
case "m.audio": return EventTypes.Audio;
case "m.file": return EventTypes.File;
case "m.location": return EventTypes.Location;
switch (content["msgtype"] ?? "m.text") {
case "m.text":
return EventTypes.Text;
case "m.notice":
return EventTypes.Notice;
case "m.emote":
return EventTypes.Emote;
case "m.image":
return EventTypes.Image;
case "m.video":
return EventTypes.Video;
case "m.audio":
return EventTypes.Audio;
case "m.file":
return EventTypes.File;
case "m.location":
return EventTypes.Location;
}
}
}
/// Generate a new Event object from a json string, mostly a table row.
static Event fromJson(Map<String, dynamic> jsonObj, Room room) {
Map<String,dynamic> content;
Map<String, dynamic> content;
try {
content = json.decode(jsonObj["content_json"]);
} catch(e) {
} catch (e) {
print("jsonObj decode of event content failed: ${e.toString()}");
content = {};
}
@ -128,11 +146,10 @@ class Event {
}
@Deprecated("Use [client.store.getEventList(Room room)] instead!")
static Future<List<Event>> getEventList(Client matrix, Room room) async{
static Future<List<Event>> getEventList(Client matrix, Room room) async {
List<Event> eventList = await matrix.store.getEventList(room);
return eventList;
}
}
enum EventTypes {
@ -155,7 +172,7 @@ enum EventTypes {
RoomAvatar,
}
final Map<String,int> StatusTypes = {
final Map<String, int> StatusTypes = {
"ERROR": -1,
"SENDING": 0,
"SENT": 1,

View file

@ -18,7 +18,7 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Foobar. If not, see <http://www.gnu.org/licenses/>.
* along with famedlysdk. If not, see <http://www.gnu.org/licenses/>.
*/
import 'package:famedlysdk/src/Client.dart';

View file

@ -18,7 +18,7 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Foobar. If not, see <http://www.gnu.org/licenses/>.
* along with famedlysdk. If not, see <http://www.gnu.org/licenses/>.
*/
import 'dart:async';

View file

@ -18,7 +18,7 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Foobar. If not, see <http://www.gnu.org/licenses/>.
* along with famedlysdk. If not, see <http://www.gnu.org/licenses/>.
*/
import 'package:famedlysdk/src/responses/ErrorResponse.dart';

View file

@ -18,14 +18,13 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Foobar. If not, see <http://www.gnu.org/licenses/>.
* along with famedlysdk. If not, see <http://www.gnu.org/licenses/>.
*/
import 'package:http/http.dart' as http;
/// Represents a special response from the Homeserver for errors.
class ErrorResponse {
/// The unique identifier for this error.
String errcode;

View file

@ -18,13 +18,12 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Foobar. If not, see <http://www.gnu.org/licenses/>.
* along with famedlysdk. If not, see <http://www.gnu.org/licenses/>.
*/
/// Represents a new event (e.g. a message in a room) or an update for an
/// already known event.
class EventUpdate {
/// Usually 'timeline', 'state' or whatever.
final String eventType;

View file

@ -18,13 +18,12 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Foobar. If not, see <http://www.gnu.org/licenses/>.
* along with famedlysdk. If not, see <http://www.gnu.org/licenses/>.
*/
/// Represents a new room or an update for an
/// already known room.
class RoomUpdate {
/// All rooms have an idea in the format: !uniqueid:server.abc
final String id;

View file

@ -18,12 +18,11 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Foobar. If not, see <http://www.gnu.org/licenses/>.
* along with famedlysdk. If not, see <http://www.gnu.org/licenses/>.
*/
/// Represents a new global event like presence or account_data.
class UserUpdate {
/// Usually 'presence', 'account_data' or whatever.
final String eventType;

View file

@ -18,7 +18,7 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Foobar. If not, see <http://www.gnu.org/licenses/>.
* along with famedlysdk. If not, see <http://www.gnu.org/licenses/>.
*/
// TODO: localize this!
@ -32,8 +32,7 @@ class ChatTime {
/// Insert with a timestamp [ts] which represents the milliseconds since
/// the Unix epoch.
ChatTime(num ts) {
if (ts != null)
dateTime = DateTime.fromMillisecondsSinceEpoch(ts);
if (ts != null) dateTime = DateTime.fromMillisecondsSinceEpoch(ts);
}
/// Returns a ChatTime object which represents the current time.
@ -51,12 +50,16 @@ class ChatTime {
bool sameDay =
sameYear && now.month == dateTime.month && now.day == dateTime.day;
bool sameWeek = sameYear && !sameDay && now.millisecondsSinceEpoch - dateTime.millisecondsSinceEpoch < 1000*60*60*24*7;
bool sameWeek = sameYear &&
!sameDay &&
now.millisecondsSinceEpoch - dateTime.millisecondsSinceEpoch <
1000 * 60 * 60 * 24 * 7;
if (sameDay) {
return toTimeString();
} else if (sameWeek) {
switch (dateTime.weekday) { // TODO: Needs localization
switch (dateTime.weekday) {
// TODO: Needs localization
case 1:
return "Montag";
case 2:
@ -102,8 +105,9 @@ class ChatTime {
operator ==(dynamic other) {
if (other is ChatTime)
return this.toTimeStamp() == other.toTimeStamp();
else return false;
return this.toTimeStamp() == other.toTimeStamp();
else
return false;
}
/// Two message events can belong to the same environment. That means that they
@ -114,7 +118,8 @@ class ChatTime {
/// Checks if two ChatTimes are close enough to belong to the same
/// environment.
bool sameEnvironment(ChatTime prevTime) {
return toTimeStamp() - prevTime.toTimeStamp() < 1000*60*minutesBetweenEnvironments;
return toTimeStamp() - prevTime.toTimeStamp() <
1000 * 60 * minutesBetweenEnvironments;
}
/// Returns a simple time String.

View file

@ -18,7 +18,7 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Foobar. If not, see <http://www.gnu.org/licenses/>.
* along with famedlysdk. If not, see <http://www.gnu.org/licenses/>.
*/
import 'package:famedlysdk/src/Client.dart';

View file

@ -18,30 +18,29 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Foobar. If not, see <http://www.gnu.org/licenses/>.
* along with famedlysdk. If not, see <http://www.gnu.org/licenses/>.
*/
import 'package:flutter_test/flutter_test.dart';
import 'package:famedlysdk/src/utils/ChatTime.dart';
void main() {
/// All Tests related to the ChatTime
group("ChatTime", () {
test("Comparing", () async {
final int originServerTs = DateTime.now().millisecondsSinceEpoch - (ChatTime.minutesBetweenEnvironments-1)*1000*60;
final int oldOriginServerTs = DateTime.now().millisecondsSinceEpoch - (ChatTime.minutesBetweenEnvironments+1)*1000*60;
final int originServerTs = DateTime.now().millisecondsSinceEpoch -
(ChatTime.minutesBetweenEnvironments - 1) * 1000 * 60;
final int oldOriginServerTs = DateTime.now().millisecondsSinceEpoch -
(ChatTime.minutesBetweenEnvironments + 1) * 1000 * 60;
final ChatTime chatTime = ChatTime(originServerTs);
final ChatTime oldChatTime = ChatTime(oldOriginServerTs);
final ChatTime nowTime = ChatTime.now();
expect(chatTime.toTimeStamp(), originServerTs);
expect(nowTime.toTimeStamp()>chatTime.toTimeStamp(),true);
expect(nowTime.sameEnvironment(chatTime),true);
expect(nowTime.sameEnvironment(oldChatTime),false);
expect(nowTime.toTimeStamp() > chatTime.toTimeStamp(), true);
expect(nowTime.sameEnvironment(chatTime), true);
expect(nowTime.sameEnvironment(oldChatTime), false);
expect(chatTime > oldChatTime, true);
expect(chatTime < oldChatTime, false);
@ -55,10 +54,10 @@ void main() {
final int timestamp = DateTime.now().millisecondsSinceEpoch;
final ChatTime chatTime = ChatTime(timestamp);
//expect(chatTime.toTimeString(),"05:36"); // This depends on the time and your timezone ;)
expect(chatTime.toTimeString(),chatTime.toEventTimeString());
expect(chatTime.toTimeString(), chatTime.toEventTimeString());
final ChatTime oldChatTime = ChatTime(156014498475);
expect(oldChatTime.toString(),"11.12.1974");
expect(oldChatTime.toString(), "11.12.1974");
});
});
}

View file

@ -18,7 +18,7 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Foobar. If not, see <http://www.gnu.org/licenses/>.
* along with famedlysdk. If not, see <http://www.gnu.org/licenses/>.
*/
import 'package:famedlysdk/src/responses/PushrulesResponse.dart';

View file

@ -18,7 +18,7 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Foobar. If not, see <http://www.gnu.org/licenses/>.
* along with famedlysdk. If not, see <http://www.gnu.org/licenses/>.
*/
import 'package:flutter_test/flutter_test.dart';

View file

@ -18,7 +18,7 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Foobar. If not, see <http://www.gnu.org/licenses/>.
* along with famedlysdk. If not, see <http://www.gnu.org/licenses/>.
*/
import 'package:http/testing.dart';
@ -90,193 +90,150 @@ class FakeMatrixApi extends MockClient {
]
},
"/client/r0/pushrules": (var req) => {
"global": {
"content": [
{
"actions": [
"notify",
"global": {
"content": [
{
"set_tweak": "sound",
"value": "default"
},
{
"set_tweak": "highlight"
"actions": [
"notify",
{"set_tweak": "sound", "value": "default"},
{"set_tweak": "highlight"}
],
"default": true,
"enabled": true,
"pattern": "alice",
"rule_id": ".m.rule.contains_user_name"
}
],
"default": true,
"enabled": true,
"pattern": "alice",
"rule_id": ".m.rule.contains_user_name"
"override": [
{
"actions": ["dont_notify"],
"conditions": [],
"default": true,
"enabled": false,
"rule_id": ".m.rule.master"
},
{
"actions": ["dont_notify"],
"conditions": [
{
"key": "content.msgtype",
"kind": "event_match",
"pattern": "m.notice"
}
],
"default": true,
"enabled": true,
"rule_id": ".m.rule.suppress_notices"
}
],
"room": [],
"sender": [],
"underride": [
{
"actions": [
"notify",
{"set_tweak": "sound", "value": "ring"},
{"set_tweak": "highlight", "value": false}
],
"conditions": [
{
"key": "type",
"kind": "event_match",
"pattern": "m.call.invite"
}
],
"default": true,
"enabled": true,
"rule_id": ".m.rule.call"
},
{
"actions": [
"notify",
{"set_tweak": "sound", "value": "default"},
{"set_tweak": "highlight"}
],
"conditions": [
{"kind": "contains_display_name"}
],
"default": true,
"enabled": true,
"rule_id": ".m.rule.contains_display_name"
},
{
"actions": [
"notify",
{"set_tweak": "sound", "value": "default"},
{"set_tweak": "highlight", "value": false}
],
"conditions": [
{"is": "2", "kind": "room_member_count"}
],
"default": true,
"enabled": true,
"rule_id": ".m.rule.room_one_to_one"
},
{
"actions": [
"notify",
{"set_tweak": "sound", "value": "default"},
{"set_tweak": "highlight", "value": false}
],
"conditions": [
{
"key": "type",
"kind": "event_match",
"pattern": "m.room.member"
},
{
"key": "content.membership",
"kind": "event_match",
"pattern": "invite"
},
{
"key": "state_key",
"kind": "event_match",
"pattern": "@alice:example.com"
}
],
"default": true,
"enabled": true,
"rule_id": ".m.rule.invite_for_me"
},
{
"actions": [
"notify",
{"set_tweak": "highlight", "value": false}
],
"conditions": [
{
"key": "type",
"kind": "event_match",
"pattern": "m.room.member"
}
],
"default": true,
"enabled": true,
"rule_id": ".m.rule.member_event"
},
{
"actions": [
"notify",
{"set_tweak": "highlight", "value": false}
],
"conditions": [
{
"key": "type",
"kind": "event_match",
"pattern": "m.room.message"
}
],
"default": true,
"enabled": true,
"rule_id": ".m.rule.message"
}
]
}
],
"override": [
{
"actions": [
"dont_notify"
],
"conditions": [],
"default": true,
"enabled": false,
"rule_id": ".m.rule.master"
},
{
"actions": [
"dont_notify"
],
"conditions": [
{
"key": "content.msgtype",
"kind": "event_match",
"pattern": "m.notice"
}
],
"default": true,
"enabled": true,
"rule_id": ".m.rule.suppress_notices"
}
],
"room": [],
"sender": [],
"underride": [
{
"actions": [
"notify",
{
"set_tweak": "sound",
"value": "ring"
},
{
"set_tweak": "highlight",
"value": false
}
],
"conditions": [
{
"key": "type",
"kind": "event_match",
"pattern": "m.call.invite"
}
],
"default": true,
"enabled": true,
"rule_id": ".m.rule.call"
},
{
"actions": [
"notify",
{
"set_tweak": "sound",
"value": "default"
},
{
"set_tweak": "highlight"
}
],
"conditions": [
{
"kind": "contains_display_name"
}
],
"default": true,
"enabled": true,
"rule_id": ".m.rule.contains_display_name"
},
{
"actions": [
"notify",
{
"set_tweak": "sound",
"value": "default"
},
{
"set_tweak": "highlight",
"value": false
}
],
"conditions": [
{
"is": "2",
"kind": "room_member_count"
}
],
"default": true,
"enabled": true,
"rule_id": ".m.rule.room_one_to_one"
},
{
"actions": [
"notify",
{
"set_tweak": "sound",
"value": "default"
},
{
"set_tweak": "highlight",
"value": false
}
],
"conditions": [
{
"key": "type",
"kind": "event_match",
"pattern": "m.room.member"
},
{
"key": "content.membership",
"kind": "event_match",
"pattern": "invite"
},
{
"key": "state_key",
"kind": "event_match",
"pattern": "@alice:example.com"
}
],
"default": true,
"enabled": true,
"rule_id": ".m.rule.invite_for_me"
},
{
"actions": [
"notify",
{
"set_tweak": "highlight",
"value": false
}
],
"conditions": [
{
"key": "type",
"kind": "event_match",
"pattern": "m.room.member"
}
],
"default": true,
"enabled": true,
"rule_id": ".m.rule.member_event"
},
{
"actions": [
"notify",
{
"set_tweak": "highlight",
"value": false
}
],
"conditions": [
{
"key": "type",
"kind": "event_match",
"pattern": "m.room.message"
}
],
"default": true,
"enabled": true,
"rule_id": ".m.rule.message"
}
]
}
},
},
"/client/r0/sync": (var req) => {
"next_batch": Random().nextDouble().toString(),
"presence": {

View file

@ -18,7 +18,7 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Foobar. If not, see <http://www.gnu.org/licenses/>.
* along with famedlysdk. If not, see <http://www.gnu.org/licenses/>.
*/
import 'package:flutter_test/flutter_test.dart';
@ -26,20 +26,22 @@ import 'package:famedlysdk/src/Client.dart';
import 'package:famedlysdk/src/utils/MxContent.dart';
void main() {
/// All Tests related to the MxContent
group("MxContent", () {
test("Formatting", () async {
Client client = Client("testclient");
client.homeserver = "https://testserver.abc";
final String mxc = "mxc://exampleserver.abc/abcdefghijklmn";
final MxContent content = MxContent(mxc);
expect(content.getDownloadLink(client),"${client.homeserver}/_matrix/media/r0/download/exampleserver.abc/abcdefghijklmn");
expect(content.getThumbnail(client, width: 50, height: 50),"${client.homeserver}/_matrix/media/r0/thumbnail/exampleserver.abc/abcdefghijklmn?width=50&height=50&method=crop");
expect(content.getThumbnail(client, width: 50, height: 50, method: ThumbnailMethod.scale),"${client.homeserver}/_matrix/media/r0/thumbnail/exampleserver.abc/abcdefghijklmn?width=50&height=50&method=scale");
expect(content.getDownloadLink(client),
"${client.homeserver}/_matrix/media/r0/download/exampleserver.abc/abcdefghijklmn");
expect(content.getThumbnail(client, width: 50, height: 50),
"${client.homeserver}/_matrix/media/r0/thumbnail/exampleserver.abc/abcdefghijklmn?width=50&height=50&method=crop");
expect(
content.getThumbnail(client,
width: 50, height: 50, method: ThumbnailMethod.scale),
"${client.homeserver}/_matrix/media/r0/thumbnail/exampleserver.abc/abcdefghijklmn?width=50&height=50&method=scale");
});
});
}

View file

@ -18,7 +18,7 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Foobar. If not, see <http://www.gnu.org/licenses/>.
* along with famedlysdk. If not, see <http://www.gnu.org/licenses/>.
*/
import 'package:flutter_test/flutter_test.dart';

View file

@ -18,7 +18,7 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Foobar. If not, see <http://www.gnu.org/licenses/>.
* along with famedlysdk. If not, see <http://www.gnu.org/licenses/>.
*/
import 'package:flutter_test/flutter_test.dart';
@ -28,14 +28,13 @@ void main() {
/// All Tests related to the Event
group("User", () {
test("Create from json", () async {
final String id = "@alice:server.abc";
final String membership = "join";
final String displayName = "Alice";
final String avatarUrl = "";
final int powerLevel = 50;
final Map<String,dynamic> jsonObj = {
final Map<String, dynamic> jsonObj = {
"matrix_id": id,
"displayname": displayName,
"avatar_url": avatarUrl,
@ -45,13 +44,12 @@ void main() {
User user = User.fromJson(jsonObj, null);
expect(user.id,id);
expect(user.membership,membership);
expect(user.displayName,displayName);
expect(user.avatarUrl.mxc,avatarUrl);
expect(user.powerLevel,powerLevel);
expect(user.calcDisplayname(),displayName);
expect(user.id, id);
expect(user.membership, membership);
expect(user.displayName, displayName);
expect(user.avatarUrl.mxc, avatarUrl);
expect(user.powerLevel, powerLevel);
expect(user.calcDisplayname(), displayName);
});
});
}