feat(all): Make ConversationType an enhanced enum.
Signed-off-by: Ikjot Singh Dhody <ikjotsd@gmail.com>
This commit is contained in:
parent
008e816d70
commit
06eab1d6f5
@ -88,7 +88,7 @@ class ConversationService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
GroupchatDetails? groupchatDetails;
|
GroupchatDetails? groupchatDetails;
|
||||||
if (c['type'] == 'groupchat') {
|
if (c['type'] == ConversationType.groupchat.value) {
|
||||||
groupchatDetails =
|
groupchatDetails =
|
||||||
await gs.getGroupchatDetailsByJid(c['jid']! as String);
|
await gs.getGroupchatDetailsByJid(c['jid']! as String);
|
||||||
}
|
}
|
||||||
@ -272,7 +272,7 @@ class ConversationService {
|
|||||||
_conversationCache![newConversation.jid] = newConversation;
|
_conversationCache![newConversation.jid] = newConversation;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type == ConversationType.groupchat) {
|
if (type == ConversationType.groupchat && groupchatDetails != null) {
|
||||||
await gs.addGroupchatDetailsFromData(
|
await gs.addGroupchatDetailsFromData(
|
||||||
jid,
|
jid,
|
||||||
groupchatDetails!.nick,
|
groupchatDetails!.nick,
|
||||||
|
@ -10,40 +10,6 @@ bool stringToBool(String s) => s == 'true' ? true : false;
|
|||||||
String intToString(int i) => '$i';
|
String intToString(int i) => '$i';
|
||||||
int stringToInt(String s) => int.parse(s);
|
int stringToInt(String s) => int.parse(s);
|
||||||
|
|
||||||
String conversationTypeToString(ConversationType type) {
|
|
||||||
switch (type) {
|
|
||||||
case ConversationType.chat:
|
|
||||||
{
|
|
||||||
return 'chat';
|
|
||||||
}
|
|
||||||
case ConversationType.note:
|
|
||||||
{
|
|
||||||
return 'note';
|
|
||||||
}
|
|
||||||
case ConversationType.groupchat:
|
|
||||||
{
|
|
||||||
return 'groupchat';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ConversationType stringToConversationType(String type) {
|
|
||||||
switch (type) {
|
|
||||||
case 'chat':
|
|
||||||
{
|
|
||||||
return ConversationType.chat;
|
|
||||||
}
|
|
||||||
case 'note':
|
|
||||||
{
|
|
||||||
return ConversationType.note;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
return ConversationType.groupchat;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Given a map [map], extract all key-value pairs from [map] where the key starts with
|
/// Given a map [map], extract all key-value pairs from [map] where the key starts with
|
||||||
/// [prefix]. Combine those key-value pairs into a new map, where the leading [prefix]
|
/// [prefix]. Combine those key-value pairs into a new map, where the leading [prefix]
|
||||||
/// is removed from all key names.
|
/// is removed from all key names.
|
||||||
|
@ -105,8 +105,8 @@ void setupBackgroundEventHandler() {
|
|||||||
EventTypeMatcher<GetPagedSharedMediaCommand>(performGetPagedSharedMedia),
|
EventTypeMatcher<GetPagedSharedMediaCommand>(performGetPagedSharedMedia),
|
||||||
EventTypeMatcher<GetReactionsForMessageCommand>(performGetReactions),
|
EventTypeMatcher<GetReactionsForMessageCommand>(performGetReactions),
|
||||||
EventTypeMatcher<RequestAvatarForJidCommand>(performRequestAvatarForJid),
|
EventTypeMatcher<RequestAvatarForJidCommand>(performRequestAvatarForJid),
|
||||||
EventTypeMatcher<DebugCommand>(performDebugCommand),
|
|
||||||
EventTypeMatcher<JoinGroupchatCommand>(performJoinGroupchat),
|
EventTypeMatcher<JoinGroupchatCommand>(performJoinGroupchat),
|
||||||
|
EventTypeMatcher<DebugCommand>(performDebugCommand),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
GetIt.I.registerSingleton<EventHandler>(handler);
|
GetIt.I.registerSingleton<EventHandler>(handler);
|
||||||
@ -244,7 +244,7 @@ Future<void> performAddConversation(
|
|||||||
final newConversation = await cs.addConversationFromData(
|
final newConversation = await cs.addConversationFromData(
|
||||||
command.title,
|
command.title,
|
||||||
null,
|
null,
|
||||||
stringToConversationType(command.conversationType),
|
ConversationType.fromString(command.conversationType),
|
||||||
command.avatarUrl,
|
command.avatarUrl,
|
||||||
command.jid,
|
command.jid,
|
||||||
0,
|
0,
|
||||||
@ -255,11 +255,7 @@ Future<void> performAddConversation(
|
|||||||
contactId,
|
contactId,
|
||||||
await css.getProfilePicturePathForJid(command.jid),
|
await css.getProfilePicturePathForJid(command.jid),
|
||||||
await css.getContactDisplayName(contactId),
|
await css.getContactDisplayName(contactId),
|
||||||
GroupchatDetails(
|
null,
|
||||||
command.jid,
|
|
||||||
'',
|
|
||||||
'',
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
sendEvent(
|
sendEvent(
|
||||||
@ -592,11 +588,7 @@ Future<void> performAddContact(
|
|||||||
contactId,
|
contactId,
|
||||||
await css.getProfilePicturePathForJid(jid),
|
await css.getProfilePicturePathForJid(jid),
|
||||||
await css.getContactDisplayName(contactId),
|
await css.getContactDisplayName(contactId),
|
||||||
GroupchatDetails(
|
null,
|
||||||
jid,
|
|
||||||
'',
|
|
||||||
'',
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
sendEvent(
|
sendEvent(
|
||||||
|
@ -40,28 +40,52 @@ class ConversationMessageConverter
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
enum ConversationType {
|
// enum ConversationType {
|
||||||
|
// chat('chat'),
|
||||||
|
// note('note'),
|
||||||
|
// groupchat('groupchat');
|
||||||
|
|
||||||
|
// const ConversationType(this.value);
|
||||||
|
|
||||||
|
// /// The identifier of the enum value.
|
||||||
|
// final String value;
|
||||||
|
|
||||||
|
// static ConversationType? fromInt(String value) {
|
||||||
|
// switch (value) {
|
||||||
|
// case 'chat':
|
||||||
|
// return ConversationType.chat;
|
||||||
|
// case 'note':
|
||||||
|
// return ConversationType.note;
|
||||||
|
// case 'groupchat':
|
||||||
|
// return ConversationType.groupchat;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// return null;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
enum ConversationType implements Comparable<ConversationType> {
|
||||||
chat('chat'),
|
chat('chat'),
|
||||||
note('note'),
|
note('note'),
|
||||||
groupchat('groupchat');
|
groupchat('groupchat');
|
||||||
|
|
||||||
const ConversationType(this.value);
|
const ConversationType(this.value);
|
||||||
|
|
||||||
/// The identifier of the enum value.
|
|
||||||
final String value;
|
final String value;
|
||||||
|
|
||||||
static ConversationType? fromInt(String value) {
|
static ConversationType fromString(String value) {
|
||||||
switch (value) {
|
switch (value) {
|
||||||
case 'chat':
|
|
||||||
return ConversationType.chat;
|
|
||||||
case 'note':
|
|
||||||
return ConversationType.note;
|
|
||||||
case 'groupchat':
|
case 'groupchat':
|
||||||
return ConversationType.groupchat;
|
return ConversationType.groupchat;
|
||||||
|
case 'note':
|
||||||
|
return ConversationType.note;
|
||||||
|
default:
|
||||||
|
return ConversationType.chat;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: What to do here?
|
||||||
|
@override
|
||||||
|
int compareTo(ConversationType other) => 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
class ConversationTypeConverter
|
class ConversationTypeConverter
|
||||||
@ -70,7 +94,7 @@ class ConversationTypeConverter
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
ConversationType fromJson(String json) {
|
ConversationType fromJson(String json) {
|
||||||
return ConversationType.fromInt(json)!;
|
return ConversationType.fromString(json)!;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -65,7 +65,7 @@ class NewConversationBloc
|
|||||||
jid: event.jid,
|
jid: event.jid,
|
||||||
avatarUrl: event.avatarUrl,
|
avatarUrl: event.avatarUrl,
|
||||||
lastMessageBody: '',
|
lastMessageBody: '',
|
||||||
conversationType: conversationTypeToString(event.type),
|
conversationType: event.type.value,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user