Skip to content

Commit

Permalink
Merge pull request #374 from bobs4462/main
Browse files Browse the repository at this point in the history
Build 2.2.9+4
  • Loading branch information
bmuddha authored Mar 22, 2021
2 parents 1e7d93a + 07d16cd commit c02575d
Show file tree
Hide file tree
Showing 57 changed files with 1,018 additions and 417 deletions.
9 changes: 9 additions & 0 deletions ios/Runner/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ import Flutter
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
GeneratedPluginRegistrant.register(with: self)

if #available(iOS 10.0, *) {
UNUserNotificationCenter.current().delegate = self
}

return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}

// override func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
// completionHandler([.alert, .badge, .sound])
// }
}
3 changes: 3 additions & 0 deletions ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
<string>????</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>FirebaseAppDelegateProxyEnabled</key>
<false/>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSAppTransportSecurity</key>
Expand All @@ -39,6 +41,7 @@
<string>Uploading pictures to the chat</string>
<key>UIBackgroundModes</key>
<array>
<string>fetch</string>
<string>remote-notification</string>
</array>
<key>UILaunchStoryboardName</key>
Expand Down
2 changes: 1 addition & 1 deletion lib/blocs/auth_bloc/auth_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
runWebView();
} else if (event is ResetAuthentication) {
if (event.message == null) {
repository.logout();
await repository.logout();
} else {
repository.clean();
}
Expand Down
19 changes: 11 additions & 8 deletions lib/blocs/channels_bloc/channels_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class ChannelsBloc extends BaseChannelBloc {
workspaceId: state.data.workspaceId,
));
}
// else if (state is ChannnelUpdateNotification) {
// else if (state is ChannelUpdateNotification) {
// this.add(
// ModifyChannelState(
// channelId: state.data.channelId,
Expand Down Expand Up @@ -107,13 +107,13 @@ class ChannelsBloc extends BaseChannelBloc {
await repository.clean();
yield ChannelsEmpty();
} else if (event is ChangeSelectedChannel) {
repository.logger.w('CHANNEL ${event.channelId} is selected');
// repository.logger.w('CHANNEL ${event.channelId} is selected');
repository.select(event.channelId,
saveToStore: false,
apiEndpoint: Endpoint.channelsRead,
params: {
"company_id": ProfileBloc.selectedCompany,
"workspace_id": ProfileBloc.selectedWorkspace,
"company_id": ProfileBloc.selectedCompanyId,
"workspace_id": ProfileBloc.selectedWorkspaceId,
"channel_id": event.channelId
});

Expand All @@ -125,8 +125,9 @@ class ChannelsBloc extends BaseChannelBloc {
selected: repository.selected,
hasUnread: repository.selected.hasUnread,
);
ProfileBloc.selectedChannel = event.channelId;
ProfileBloc.selectedThread = null;
ProfileBloc.selectedChannelId = event.channelId;
ProfileBloc.selectedThreadId = null;

yield newState;
notificationBloc.add(CancelPendingSubscriptions(event.channelId));
} else if (event is ModifyMessageCount) {
Expand All @@ -138,7 +139,7 @@ class ChannelsBloc extends BaseChannelBloc {
);
}
} else if (event is UpdateSingleChannel) {
repository.logger.d('UPDATING CHANNELS\n${event.data.toJson()}');
// repository.logger.d('UPDATING CHANNELS\n${event.data.toJson()}');
var item = await repository.getItemById(event.data.channelId) as Channel;
if (item != null) {
item.icon = event.data.icon ?? item.icon ?? '👽';
Expand All @@ -147,7 +148,9 @@ class ChannelsBloc extends BaseChannelBloc {
item.visibility = event.data.visibility ?? item.visibility;
item.lastMessage = event.data.lastMessage ?? item.lastMessage;
} else {
item = Channel.fromJson(event.data.toJson());
this.add(
ReloadChannels(workspaceId: selectedParentId, forceFromApi: true));
return;
}
await repository.saveOne(item);
if (event.data.workspaceId == selectedParentId) {
Expand Down
5 changes: 3 additions & 2 deletions lib/blocs/companies_bloc/companies_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ class CompaniesBloc extends Bloc<CompaniesEvent, CompaniesState> {
selected: repository.selected,
)) {
// repository.logger.w('SELECTED COMPANY: ${repository.selected.id}');
ProfileBloc.selectedCompany = repository.selected.id;
ProfileBloc.selectedCompanyId = repository.selected.id;
ProfileBloc.selectedCompany = repository.selected;

_notificationSubscription =
notificationBloc.listen((NotificationState state) {
Expand All @@ -45,7 +46,7 @@ class CompaniesBloc extends Bloc<CompaniesEvent, CompaniesState> {
yield CompaniesEmpty();
} else if (event is ChangeSelectedCompany) {
repository.select(event.companyId);
ProfileBloc.selectedCompany = event.companyId;
ProfileBloc.selectedCompanyId = event.companyId;
yield CompaniesLoaded(
companies: repository.items,
selected: repository.selected,
Expand Down
6 changes: 5 additions & 1 deletion lib/blocs/directs_bloc/directs_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,17 @@ class DirectsBloc extends BaseChannelBloc {
saveToStore: false,
apiEndpoint: Endpoint.channelsRead,
params: {
"company_id": ProfileBloc.selectedCompany,
"company_id": ProfileBloc.selectedCompanyId,
"workspace_id": "direct",
"channel_id": event.channelId
});
repository.selected.messagesUnread = 0;
repository.selected.hasUnread = 0;
repository.saveOne(repository.selected);

ProfileBloc.selectedChannelId = event.channelId;
ProfileBloc.selectedThreadId = null;

yield ChannelPicked(
channels: repository.items,
selected: repository.selected,
Expand Down
22 changes: 11 additions & 11 deletions lib/blocs/messages_bloc/messages_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ class MessagesBloc<T extends BaseChannelBloc>
this.notificationBloc,
}) : super(MessagesEmpty(parentChannel: channelsBloc.repository.selected)) {
_subscription = channelsBloc.listen((ChannelState state) {
if (state is ChannelPicked) {
if (state is ChannelPicked && state.selected != selectedChannel) {
// repository.logger.d('TRIGGERED MESSAGE FETCH');
repository.logger.w(
'FETCHING CHANNEL MESSAGES: ${state.selected.name}(${state.selected.id})');
// repository.logger.w(
// 'FETCHING CHANNEL MESSAGES: ${state.selected.name}(${state.selected.id})');
this.add(LoadMessages());
selectedChannel = state.selected;
}
Expand All @@ -63,14 +63,14 @@ class MessagesBloc<T extends BaseChannelBloc>
this.add(LoadSingleMessage(
messageId: state.data.messageId,
channelId: state.data.channelId,
workspaceId: ProfileBloc.selectedWorkspace,
companyId: ProfileBloc.selectedCompany,
workspaceId: ProfileBloc.selectedWorkspaceId,
companyId: ProfileBloc.selectedCompanyId,
));
} else if (T == DirectsBloc && state is DirectMessageArrived) {
this.add(LoadSingleMessage(
messageId: state.data.messageId,
channelId: state.data.channelId,
companyId: ProfileBloc.selectedCompany,
companyId: ProfileBloc.selectedCompanyId,
));
} else if (state is DirectThreadMessageArrived && T == DirectsBloc) {
this.add(ModifyResponsesCount(
Expand Down Expand Up @@ -309,7 +309,7 @@ class MessagesBloc<T extends BaseChannelBloc>
);
} else if (event is SelectMessage) {
// print('$T MESSAGE SELECTED');
ProfileBloc.selectedThread = event.messageId;
ProfileBloc.selectedThreadId = event.messageId;
repository.select(event.messageId);
yield MessageSelected(
threadMessage: repository.selected,
Expand Down Expand Up @@ -337,17 +337,17 @@ class MessagesBloc<T extends BaseChannelBloc>
Map<String, dynamic> _makeQueryParams(MessagesEvent event) {
Map<String, dynamic> map = event.toMap();
map['channel_id'] = map['channel_id'] ?? selectedChannel.id;
map['company_id'] = map['company_id'] ?? ProfileBloc.selectedCompany;
map['company_id'] = map['company_id'] ?? ProfileBloc.selectedCompanyId;
map['workspace_id'] = map['workspace_id'] ??
(T == DirectsBloc ? 'direct' : ProfileBloc.selectedWorkspace);
(T == DirectsBloc ? 'direct' : ProfileBloc.selectedWorkspaceId);
return map;
}

void _updateParentChannel(String channelId, [int hasUnread = 1]) {
channelsBloc.add(ModifyMessageCount(
workspaceId: ProfileBloc.selectedWorkspace,
workspaceId: ProfileBloc.selectedWorkspaceId,
channelId: channelId ?? selectedChannel.id,
companyId: ProfileBloc.selectedCompany,
companyId: ProfileBloc.selectedCompanyId,
hasUnread: hasUnread,
));
}
Expand Down
34 changes: 24 additions & 10 deletions lib/blocs/notification_bloc/notification_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ class NotificationBloc extends Bloc<NotificationEvent, NotificationState> {
unsubscribe(room);
}
setSubscriptions();
this.add(BadgeUpdateEvent());
}

Future<void> setSubscriptions() async {
Expand All @@ -155,8 +156,8 @@ class NotificationBloc extends Bloc<NotificationEvent, NotificationState> {
subscriptionRooms = await _api.get(
Endpoint.notificationRooms,
params: {
'company_id': ProfileBloc.selectedCompany,
'workspace_id': ProfileBloc.selectedWorkspace,
'company_id': ProfileBloc.selectedCompanyId,
'workspace_id': ProfileBloc.selectedWorkspaceId,
},
);
for (String room in subscriptionRooms.keys) {
Expand All @@ -171,7 +172,7 @@ class NotificationBloc extends Bloc<NotificationEvent, NotificationState> {

void unsubscribe(String path, [String tag = 'twake']) {
socket.emit(SocketIOEvent.LEAVE, {'name': path, 'token': tag});
logger.d('UNSUBSCRIBED FROM $path');
// logger.d('UNSUBSCRIBED FROM $path');
}

@override
Expand Down Expand Up @@ -202,26 +203,33 @@ class NotificationBloc extends Bloc<NotificationEvent, NotificationState> {
reinit();
} else if (event is CancelPendingSubscriptions) {
service.cancelNotificationForChannel(event.channelId);
} else if (event is BadgeUpdateEvent) {
yield BadgesUpdated(DateTime.now().toString());
}
}

bool shouldNotify(MessageNotification data) {
if (data.channelId == ProfileBloc.selectedChannel &&
(ProfileBloc.selectedThread == data.threadId ||
ProfileBloc.selectedThread == null)) return false;
print('Data channel id: ${data.channelId}');
print('ProfileBloc id: ${ProfileBloc.selectedChannelId}');
print('Data thread id: ${data.threadId}');
print('ProfileBloc selected thread id: ${ProfileBloc.selectedThreadId}');

if (data.channelId == ProfileBloc.selectedChannelId &&
(ProfileBloc.selectedThreadId == data.threadId ||
ProfileBloc.selectedThreadId == null)) return false;
return true;
}

void onMessageCallback(NotificationData data) {
if (data is MessageNotification) {
if (data.threadId.isNotEmpty && data.threadId != data.messageId) {
logger.d('adding ThreadMessageEvent');
// logger.d('adding ThreadMessageEvent');
this.add(ThreadMessageEvent(data));
} else if (data.workspaceId == 'direct') {
logger.d('adding DirectMessageEvent');
// logger.d('adding DirectMessageEvent');
this.add(DirectMessageEvent(data));
} else {
logger.d('adding ChannelMessageEvent');
// logger.d('adding ChannelMessageEvent');
this.add(ChannelMessageEvent(data));
}
}
Expand Down Expand Up @@ -287,6 +295,8 @@ class NotificationBloc extends Bloc<NotificationEvent, NotificationState> {
final data =
SocketChannelUpdateNotification.fromJson(resource['resource']);
this.add(ChannelDeleteEvent(data));
} else if (type == SocketResourceType.BadgeUpdate) {
this.add(BadgeUpdateEvent());
}
}

Expand Down Expand Up @@ -362,12 +372,15 @@ class NotificationBloc extends Bloc<NotificationEvent, NotificationState> {
final type = subscriptionRooms[resource['room']]['type'];
if (type == 'CHANNELS_LIST') {
if (resource['type'] == 'channel' ||
resource['type'] == 'channel_activity') {
resource['type'] == 'channel_activity' ||
resource['type'] == 'channel_member') {
if (resource['action'] == 'saved' || resource['action'] == 'updated') {
return SocketResourceType.ChannelUpdate;
} else if (resource['action'] == 'deleted')
return SocketResourceType.ChannelDelete;
}
} else if (type == 'NOTIFICATIONS') {
return SocketResourceType.BadgeUpdate;
}
return SocketResourceType.Unknown;
}
Expand Down Expand Up @@ -416,5 +429,6 @@ enum SocketResourceType {
ChannelUpdate,
ChannelDelete,
DirectUpdate,
BadgeUpdate,
Unknown,
}
7 changes: 7 additions & 0 deletions lib/blocs/notification_bloc/notification_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ class ChannelDeleteEvent extends NotificationEvent {
List<Object> get props => [data];
}

class BadgeUpdateEvent extends NotificationEvent {
const BadgeUpdateEvent();

@override
List<Object> get props => [];
}

class ReinitSubscriptions extends NotificationEvent {
const ReinitSubscriptions();

Expand Down
8 changes: 8 additions & 0 deletions lib/blocs/notification_bloc/notification_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,11 @@ class ThreadMessageNotification extends BaseChannelMessageNotification {
@override
List<Object> get props => [data];
}

class BadgesUpdated extends NotificationState {
final String forceId;
const BadgesUpdated(this.forceId);

@override
List<Object> get props => [forceId];
}
Loading

0 comments on commit c02575d

Please sign in to comment.