From be2265f2265416bfb311b34042f89232650511ca Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Thu, 27 Jun 2019 12:33:02 +0200 Subject: [PATCH] [Refactoring] Make analyzer happy. --- lib/src/Connection.dart | 9 +++------ lib/src/Event.dart | 1 + lib/src/RoomList.dart | 5 +---- lib/src/Store.dart | 7 ++++--- lib/src/User.dart | 5 ++--- lib/src/utils/ChatTime.dart | 3 +-- test/Client_test.dart | 2 +- test/RoomList_test.dart | 3 --- 8 files changed, 13 insertions(+), 22 deletions(-) diff --git a/lib/src/Connection.dart b/lib/src/Connection.dart index ede7d86a..8a2d45f7 100644 --- a/lib/src/Connection.dart +++ b/lib/src/Connection.dart @@ -251,8 +251,6 @@ class Connection { Future _sync() async { if (client.isLogged() == false) return; - dynamic args = {}; - String action = "/client/r0/sync?filters=$_firstSyncFilters"; if (client.prevBatch != null) { @@ -383,8 +381,6 @@ class Connection { is Map && events[i]["content"][e]["m.read"]["ts"] is num)) return; - num timestamp = events[i]["content"][e]["m.read"]["ts"]; - _handleEvent(events[i], id, "ephemeral"); }); }); @@ -410,7 +406,8 @@ class Connection { void _handleGlobalEvents(List events, String type) { 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) { UserUpdate update = UserUpdate( eventType: events[i]["type"], type: type, @@ -422,7 +419,7 @@ class Connection { } void _handleEvent(Map event, String roomID, String type) { - if (event["type"] is String && event["content"] is dynamic) { + if (event["type"] is String && event["content"] is Map) { EventUpdate update = EventUpdate( eventType: event["type"], roomID: roomID, diff --git a/lib/src/Event.dart b/lib/src/Event.dart index 0470295f..696c5c39 100644 --- a/lib/src/Event.dart +++ b/lib/src/Event.dart @@ -123,6 +123,7 @@ class Event { return EventTypes.Location; } } + return EventTypes.Text; } /// Generate a new Event object from a json string, mostly a table row. diff --git a/lib/src/RoomList.dart b/lib/src/RoomList.dart index b3bc8169..4a5c9289 100644 --- a/lib/src/RoomList.dart +++ b/lib/src/RoomList.dart @@ -82,8 +82,6 @@ class RoomList { // Does the chat already exist in the list rooms? if (!found && chatUpdate.membership != "leave") { num position = chatUpdate.membership == "invite" ? 0 : j; - ChatTime timestamp = - chatUpdate.membership == "invite" ? ChatTime.now() : ChatTime(0); // Add the new chat to the list Room newRoom = Room( id: chatUpdate.id, @@ -97,7 +95,7 @@ class RoomList { } // If the membership is "leave" then remove the item and stop here else if (found && chatUpdate.membership == "leave") { - final Room removed = rooms.removeAt(j); + rooms.removeAt(j); if (onRemove != null) onRemove(j); } // Update notification and highlight count @@ -132,7 +130,6 @@ class RoomList { if (eventUpdate.type == "timeline") { // Update the last message preview - String body = eventUpdate.content["content"]["body"] ?? ""; rooms[j].lastEvent = Event( eventUpdate.content["id"], User(eventUpdate.content["sender"]), diff --git a/lib/src/Store.dart b/lib/src/Store.dart index f4af5846..e108a4c8 100644 --- a/lib/src/Store.dart +++ b/lib/src/Store.dart @@ -144,6 +144,7 @@ class Store { Future storePrevBatch(dynamic sync) { txn.rawUpdate("UPDATE Clients SET prev_batch=? WHERE client=?", [client.prevBatch, client.clientName]); + return null; } /// 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=?", [roomUpdate.prev_batch, roomUpdate.id]); } + return null; } /// Stores an UserUpdate object in the database. Must be called inside of /// [transaction]. Future storeUserEventUpdate(UserUpdate userUpdate) { - dynamic eventContent = userUpdate.content; - String type = userUpdate.type; - switch (userUpdate.eventType) { case "m.direct": if (userUpdate.content["content"] is Map) { @@ -195,6 +194,7 @@ class Store { } break; } + return null; } /// Stores an EventUpdate object in the database. Must be called inside of @@ -412,6 +412,7 @@ class Store { } break; } + return null; } /// Returns a User object by a given Matrix ID and a Room. diff --git a/lib/src/User.dart b/lib/src/User.dart index 9836727f..dedb1ca4 100644 --- a/lib/src/User.dart +++ b/lib/src/User.dart @@ -22,7 +22,6 @@ */ import 'package:famedlysdk/src/responses/ErrorResponse.dart'; -import 'package:famedlysdk/src/Client.dart'; import 'package:famedlysdk/src/utils/MxContent.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 /// has no displayname. String calcDisplayname() => displayName.isEmpty - ? mxid.replaceFirst("@", "").split(":")[0] + ? id.replaceFirst("@", "").split(":")[0] : displayName; /// 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. Future startDirectChat() async { // 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; // Start a new direct chat diff --git a/lib/src/utils/ChatTime.dart b/lib/src/utils/ChatTime.dart index 5b57e81b..bd77d6d1 100644 --- a/lib/src/utils/ChatTime.dart +++ b/lib/src/utils/ChatTime.dart @@ -77,9 +77,8 @@ class ChatTime { } } else if (sameYear) { 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. diff --git a/test/Client_test.dart b/test/Client_test.dart index f71aa35b..f2d0d310 100644 --- a/test/Client_test.dart +++ b/test/Client_test.dart @@ -249,7 +249,7 @@ void main() { test('Logout when token is unknown', () async { Future loginStateFuture = matrix.connection.onLoginStateChanged.stream.first; - final resp = await matrix.connection + await matrix.connection .jsonRequest(type: "DELETE", action: "/unknown/token"); LoginState state = await loginStateFuture; diff --git a/test/RoomList_test.dart b/test/RoomList_test.dart index abd1c4f8..60f32873 100644 --- a/test/RoomList_test.dart +++ b/test/RoomList_test.dart @@ -23,10 +23,7 @@ import 'package:flutter_test/flutter_test.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/User.dart'; import 'package:famedlysdk/src/sync/EventUpdate.dart'; import 'package:famedlysdk/src/sync/RoomUpdate.dart'; import 'package:famedlysdk/src/utils/ChatTime.dart';