Merge branch 'refactoring-fix-analyse-issues' into 'master'

[Refactoring] Make analyzer happy.

See merge request famedly/famedlysdk!20
This commit is contained in:
Marcel 2019-06-27 10:44:18 +00:00
commit 0bab9c23be
8 changed files with 13 additions and 22 deletions

View file

@ -251,8 +251,6 @@ class Connection {
Future<void> _sync() async { Future<void> _sync() async {
if (client.isLogged() == false) return; if (client.isLogged() == false) return;
dynamic args = {};
String action = "/client/r0/sync?filters=$_firstSyncFilters"; String action = "/client/r0/sync?filters=$_firstSyncFilters";
if (client.prevBatch != null) { if (client.prevBatch != null) {
@ -383,8 +381,6 @@ class Connection {
is Map<String, dynamic> && is Map<String, dynamic> &&
events[i]["content"][e]["m.read"]["ts"] is num)) return; events[i]["content"][e]["m.read"]["ts"] is num)) return;
num timestamp = events[i]["content"][e]["m.read"]["ts"];
_handleEvent(events[i], id, "ephemeral"); _handleEvent(events[i], id, "ephemeral");
}); });
}); });
@ -410,7 +406,8 @@ class Connection {
void _handleGlobalEvents(List<dynamic> events, String type) { void _handleGlobalEvents(List<dynamic> events, String type) {
for (int i = 0; i < events.length; i++) for (int i = 0; i < events.length; i++)
if (events[i]["type"] is String && events[i]["content"] is dynamic) { if (events[i]["type"] is String &&
events[i]["content"] is Map<String, dynamic>) {
UserUpdate update = UserUpdate( UserUpdate update = UserUpdate(
eventType: events[i]["type"], eventType: events[i]["type"],
type: type, type: type,
@ -422,7 +419,7 @@ class Connection {
} }
void _handleEvent(Map<String, dynamic> event, String roomID, String type) { void _handleEvent(Map<String, dynamic> event, String roomID, String type) {
if (event["type"] is String && event["content"] is dynamic) { if (event["type"] is String && event["content"] is Map<String, dynamic>) {
EventUpdate update = EventUpdate( EventUpdate update = EventUpdate(
eventType: event["type"], eventType: event["type"],
roomID: roomID, roomID: roomID,

View file

@ -123,6 +123,7 @@ class Event {
return EventTypes.Location; return EventTypes.Location;
} }
} }
return EventTypes.Text;
} }
/// Generate a new Event object from a json string, mostly a table row. /// Generate a new Event object from a json string, mostly a table row.

View file

@ -82,8 +82,6 @@ class RoomList {
// Does the chat already exist in the list rooms? // Does the chat already exist in the list rooms?
if (!found && chatUpdate.membership != "leave") { if (!found && chatUpdate.membership != "leave") {
num position = chatUpdate.membership == "invite" ? 0 : j; num position = chatUpdate.membership == "invite" ? 0 : j;
ChatTime timestamp =
chatUpdate.membership == "invite" ? ChatTime.now() : ChatTime(0);
// Add the new chat to the list // Add the new chat to the list
Room newRoom = Room( Room newRoom = Room(
id: chatUpdate.id, id: chatUpdate.id,
@ -97,7 +95,7 @@ class RoomList {
} }
// If the membership is "leave" then remove the item and stop here // If the membership is "leave" then remove the item and stop here
else if (found && chatUpdate.membership == "leave") { else if (found && chatUpdate.membership == "leave") {
final Room removed = rooms.removeAt(j); rooms.removeAt(j);
if (onRemove != null) onRemove(j); if (onRemove != null) onRemove(j);
} }
// Update notification and highlight count // Update notification and highlight count
@ -132,7 +130,6 @@ class RoomList {
if (eventUpdate.type == "timeline") { if (eventUpdate.type == "timeline") {
// Update the last message preview // Update the last message preview
String body = eventUpdate.content["content"]["body"] ?? "";
rooms[j].lastEvent = Event( rooms[j].lastEvent = Event(
eventUpdate.content["id"], eventUpdate.content["id"],
User(eventUpdate.content["sender"]), User(eventUpdate.content["sender"]),

View file

@ -144,6 +144,7 @@ class Store {
Future<void> storePrevBatch(dynamic sync) { Future<void> storePrevBatch(dynamic sync) {
txn.rawUpdate("UPDATE Clients SET prev_batch=? WHERE client=?", txn.rawUpdate("UPDATE Clients SET prev_batch=? WHERE client=?",
[client.prevBatch, client.clientName]); [client.prevBatch, client.clientName]);
return null;
} }
/// Stores a RoomUpdate object in the database. Must be called inside of /// Stores a RoomUpdate object in the database. Must be called inside of
@ -172,14 +173,12 @@ class Store {
txn.rawUpdate("UPDATE Rooms SET prev_batch=? WHERE id=?", txn.rawUpdate("UPDATE Rooms SET prev_batch=? WHERE id=?",
[roomUpdate.prev_batch, roomUpdate.id]); [roomUpdate.prev_batch, roomUpdate.id]);
} }
return null;
} }
/// Stores an UserUpdate object in the database. Must be called inside of /// Stores an UserUpdate object in the database. Must be called inside of
/// [transaction]. /// [transaction].
Future<void> storeUserEventUpdate(UserUpdate userUpdate) { Future<void> storeUserEventUpdate(UserUpdate userUpdate) {
dynamic eventContent = userUpdate.content;
String type = userUpdate.type;
switch (userUpdate.eventType) { switch (userUpdate.eventType) {
case "m.direct": case "m.direct":
if (userUpdate.content["content"] is Map<String, dynamic>) { if (userUpdate.content["content"] is Map<String, dynamic>) {
@ -195,6 +194,7 @@ class Store {
} }
break; break;
} }
return null;
} }
/// Stores an EventUpdate object in the database. Must be called inside of /// Stores an EventUpdate object in the database. Must be called inside of
@ -412,6 +412,7 @@ class Store {
} }
break; break;
} }
return null;
} }
/// Returns a User object by a given Matrix ID and a Room. /// Returns a User object by a given Matrix ID and a Room.

View file

@ -22,7 +22,6 @@
*/ */
import 'package:famedlysdk/src/responses/ErrorResponse.dart'; import 'package:famedlysdk/src/responses/ErrorResponse.dart';
import 'package:famedlysdk/src/Client.dart';
import 'package:famedlysdk/src/utils/MxContent.dart'; import 'package:famedlysdk/src/utils/MxContent.dart';
import 'package:famedlysdk/src/Room.dart'; import 'package:famedlysdk/src/Room.dart';
@ -74,7 +73,7 @@ class User {
/// Returns the displayname or the local part of the Matrix ID if the user /// Returns the displayname or the local part of the Matrix ID if the user
/// has no displayname. /// has no displayname.
String calcDisplayname() => displayName.isEmpty String calcDisplayname() => displayName.isEmpty
? mxid.replaceFirst("@", "").split(":")[0] ? id.replaceFirst("@", "").split(":")[0]
: displayName; : displayName;
/// Creates a new User object from a json string like a row from the database. /// Creates a new User object from a json string like a row from the database.
@ -129,7 +128,7 @@ class User {
/// Returns null on error. /// Returns null on error.
Future<String> startDirectChat() async { Future<String> startDirectChat() async {
// Try to find an existing direct chat // Try to find an existing direct chat
String roomID = await room.client?.store.getDirectChatRoomID(id); String roomID = await room.client?.store?.getDirectChatRoomID(id);
if (roomID != null) return roomID; if (roomID != null) return roomID;
// Start a new direct chat // Start a new direct chat

View file

@ -77,9 +77,8 @@ class ChatTime {
} }
} else if (sameYear) { } else if (sameYear) {
return DateFormat('dd.MM').format(dateTime); return DateFormat('dd.MM').format(dateTime);
} else {
return DateFormat('dd.MM.yyyy').format(dateTime);
} }
return DateFormat('dd.MM.yyyy').format(dateTime);
} }
/// Returns the milliseconds since the Unix epoch. /// Returns the milliseconds since the Unix epoch.

View file

@ -249,7 +249,7 @@ void main() {
test('Logout when token is unknown', () async { test('Logout when token is unknown', () async {
Future<LoginState> loginStateFuture = Future<LoginState> loginStateFuture =
matrix.connection.onLoginStateChanged.stream.first; matrix.connection.onLoginStateChanged.stream.first;
final resp = await matrix.connection await matrix.connection
.jsonRequest(type: "DELETE", action: "/unknown/token"); .jsonRequest(type: "DELETE", action: "/unknown/token");
LoginState state = await loginStateFuture; LoginState state = await loginStateFuture;

View file

@ -23,10 +23,7 @@
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:famedlysdk/src/Client.dart'; import 'package:famedlysdk/src/Client.dart';
import 'package:famedlysdk/src/Event.dart';
import 'package:famedlysdk/src/Room.dart';
import 'package:famedlysdk/src/RoomList.dart'; import 'package:famedlysdk/src/RoomList.dart';
import 'package:famedlysdk/src/User.dart';
import 'package:famedlysdk/src/sync/EventUpdate.dart'; import 'package:famedlysdk/src/sync/EventUpdate.dart';
import 'package:famedlysdk/src/sync/RoomUpdate.dart'; import 'package:famedlysdk/src/sync/RoomUpdate.dart';
import 'package:famedlysdk/src/utils/ChatTime.dart'; import 'package:famedlysdk/src/utils/ChatTime.dart';