Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes null handles #5

Merged
merged 5 commits into from
May 28, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/repository/blocs/setup_bloc.dart
Original file line number Diff line number Diff line change
@@ -92,6 +92,7 @@ class SetupBloc {
Settings _settingsCopy = Singleton().settings;
_settingsCopy.finishedSetup = true;
_finishedSetup = true;
Singleton().saveSettings(_settingsCopy, false);
Singleton().finishSetup();
}

18 changes: 11 additions & 7 deletions lib/repository/database.dart
Original file line number Diff line number Diff line change
@@ -28,16 +28,20 @@ class DBProvider {
return await openDatabase(_path, version: 1, onOpen: (Database db) {
debugPrint("Database Opened");
}, onCreate: (Database db, int version) async {
await createHandleTable(db);
await createChatTable(db);
await createMessageTable(db);
await createAttachmentTable(db);
await createAttachmentMessageJoinTable(db);
await createChatHandleJoinTable(db);
await createChatMessageJoinTable(db);
await this.buildDatabase(db);
});
}

Future<void> buildDatabase(Database db) async {
await createHandleTable(db);
await createChatTable(db);
await createMessageTable(db);
await createAttachmentTable(db);
await createAttachmentMessageJoinTable(db);
await createChatHandleJoinTable(db);
await createChatMessageJoinTable(db);
}

createHandleTable(Database db) async {
await db.execute("CREATE TABLE handle ("
"ROWID INTEGER PRIMARY KEY AUTOINCREMENT,"
20 changes: 10 additions & 10 deletions lib/repository/models/attachment.dart
Original file line number Diff line number Diff line change
@@ -128,14 +128,14 @@ class Attachment {
}

Map<String, dynamic> toMap() => {
"ROWID": id,
"guid": guid,
"uti": uti,
"transferState": transferState,
"isOutgoing": isOutgoing ? 1 : 0,
"transferName": transferName,
"totalBytes": totalBytes,
"isSticker": isSticker ? 1 : 0,
"hideAttachment": hideAttachment ? 1 : 0
};
"ROWID": id,
"guid": guid,
"uti": uti,
"transferState": transferState,
"isOutgoing": isOutgoing ? 1 : 0,
"transferName": transferName,
"totalBytes": totalBytes,
"isSticker": isSticker ? 1 : 0,
"hideAttachment": hideAttachment ? 1 : 0
};
}
5 changes: 5 additions & 0 deletions lib/repository/models/chat.dart
Original file line number Diff line number Diff line change
@@ -296,6 +296,11 @@ class Chat {
return (res.isNotEmpty) ? res.map((c) => Chat.fromMap(c)).toList() : [];
}

static flush() async {
final Database db = await DBProvider.db.database;
await db.delete("chat");
}

Map<String, dynamic> toMap() => {
"ROWID": id,
"guid": guid,
10 changes: 5 additions & 5 deletions lib/repository/models/handle.dart
Original file line number Diff line number Diff line change
@@ -137,9 +137,9 @@ class Handle {
}

Map<String, dynamic> toMap() => {
"ROWID": id,
"address": address,
"country": country,
"uncanonicalizedId": uncanonicalizedId,
};
"ROWID": id,
"address": address,
"country": country,
"uncanonicalizedId": uncanonicalizedId,
};
}
80 changes: 40 additions & 40 deletions lib/repository/models/message.dart
Original file line number Diff line number Diff line change
@@ -219,11 +219,6 @@ class Message {
return this;
}

static flush() async {
final Database db = await DBProvider.db.database;
await db.delete("message");
}

static Future<List<Attachment>> getAttachments(Message message) async {
final Database db = await DBProvider.db.database;

@@ -300,40 +295,45 @@ class Message {
return (res.isNotEmpty) ? res.map((c) => Message.fromMap(c)).toList() : [];
}

static flush() async {
final Database db = await DBProvider.db.database;
await db.delete("message");
}

Map<String, dynamic> toMap() => {
"ROWID": id,
"guid": guid,
"handleId": handleId,
"text": text,
"subject": subject,
"country": country,
"error": error ? 1 : 0,
"dateCreated":
(dateCreated == null) ? null : dateCreated.millisecondsSinceEpoch,
"dateRead": (dateRead == null) ? null : dateRead.millisecondsSinceEpoch,
"dateDelivered": (dateDelivered == null)
? null
: dateDelivered.millisecondsSinceEpoch,
"isFromMe": isFromMe ? 1 : 0,
"isDelayed": isDelayed ? 1 : 0,
"isAutoReply": isAutoReply ? 1 : 0,
"isSystemMessage": isSystemMessage ? 1 : 0,
"isServiceMessage": isServiceMessage ? 1 : 0,
"isForward": isForward ? 1 : 0,
"isArchived": isArchived ? 1 : 0,
"cacheRoomnames": cacheRoomnames,
"isAudioMessage": isAudioMessage ? 1 : 0,
"datePlayed":
(datePlayed == null) ? null : datePlayed.millisecondsSinceEpoch,
"itemType": itemType,
"groupTitle": groupTitle,
"isExpired": isExpired ? 1 : 0,
"associatedMessageGuid": associatedMessageGuid,
"associatedMessageType": associatedMessageType,
"expressiveSendStyleId": expressiveSendStyleId,
"timeExpressiveSendStyleId": (timeExpressiveSendStyleId == null)
? null
: timeExpressiveSendStyleId.millisecondsSinceEpoch,
"handle": (handle != null) ? handle.toMap() : null
};
"ROWID": id,
"guid": guid,
"handleId": handleId,
"text": text,
"subject": subject,
"country": country,
"error": error ? 1 : 0,
"dateCreated":
(dateCreated == null) ? null : dateCreated.millisecondsSinceEpoch,
"dateRead": (dateRead == null) ? null : dateRead.millisecondsSinceEpoch,
"dateDelivered": (dateDelivered == null)
? null
: dateDelivered.millisecondsSinceEpoch,
"isFromMe": isFromMe ? 1 : 0,
"isDelayed": isDelayed ? 1 : 0,
"isAutoReply": isAutoReply ? 1 : 0,
"isSystemMessage": isSystemMessage ? 1 : 0,
"isServiceMessage": isServiceMessage ? 1 : 0,
"isForward": isForward ? 1 : 0,
"isArchived": isArchived ? 1 : 0,
"cacheRoomnames": cacheRoomnames,
"isAudioMessage": isAudioMessage ? 1 : 0,
"datePlayed":
(datePlayed == null) ? null : datePlayed.millisecondsSinceEpoch,
"itemType": itemType,
"groupTitle": groupTitle,
"isExpired": isExpired ? 1 : 0,
"associatedMessageGuid": associatedMessageGuid,
"associatedMessageType": associatedMessageType,
"expressiveSendStyleId": expressiveSendStyleId,
"timeExpressiveSendStyleId": (timeExpressiveSendStyleId == null)
? null
: timeExpressiveSendStyleId.millisecondsSinceEpoch,
"handle": (handle != null) ? handle.toMap() : null
};
}
30 changes: 15 additions & 15 deletions lib/singleton.dart
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@ import 'repository/models/message.dart';
import 'settings.dart';
import './repository/blocs/chat_bloc.dart';
import './repository/models/chat.dart';
import './repository/models/handle.dart';

class Singleton {
factory Singleton() {
@@ -157,21 +158,20 @@ class Singleton {

Future<void> deleteDB() async {
Database db = await DBProvider.db.database;
db.execute("DELETE FROM handle");
db.execute("DELETE FROM chat");
db.execute("DELETE FROM message");
db.execute("DELETE FROM attachment");
db.execute("DELETE FROM chat_handle_join");
db.execute("DELETE FROM chat_message_join");
db.execute("DELETE FROM attachment_message_join");

DBProvider.db.createHandleTable(db);
DBProvider.db.createChatTable(db);
DBProvider.db.createMessageTable(db);
DBProvider.db.createAttachmentTable(db);
DBProvider.db.createAttachmentMessageJoinTable(db);
DBProvider.db.createChatHandleJoinTable(db);
DBProvider.db.createChatMessageJoinTable(db);

// Remove base tables
await Handle.flush();
await Chat.flush();
await Attachment.flush();
await Message.flush();

// Remove join tables
await db.execute("DELETE FROM chat_handle_join");
await db.execute("DELETE FROM chat_message_join");
await db.execute("DELETE FROM attachment_message_join");

// Recreate tables
DBProvider.db.buildDatabase(db);
}

startSocketIO([Function connectCb]) async {