public static object fetchChannelMentionSuggestions(string channelId) { return(new ThunkAction <AppState>((dispatcher, getState) => { return ChannelApi.FetchChannelMemberSuggestions(channelId: channelId) .Then(channelMemberResponse => { dispatcher.dispatch(new FollowMapAction { followMap = channelMemberResponse.followeeMap }); var userMap = new Dictionary <string, User>(); var channelMemberMap = new Dictionary <string, ChannelMember>(); (channelMemberResponse.list ?? new List <ChannelMember>()).ForEach(member => { channelMemberMap[key: member.user.id] = member; userMap[key: member.user.id] = member.user; }); dispatcher.dispatch(new UserMapAction { userMap = userMap }); dispatcher.dispatch(new FetchChannelMentionSuggestionsSuccessAction { channelId = channelId, channelMemberMap = channelMemberMap }); }) .Catch(error => { dispatcher.dispatch(new FetchChannelMentionSuggestionsFailureAction()); Debuger.LogError(message: error); }); })); }
public static object leaveChannel(string channelId, string memberId = null, string groupId = null) { if (HttpManager.isNetWorkError()) { CustomDialogUtils.showToast("请检查网络", iconData: Icons.sentiment_dissatisfied); return(null); } CustomDialogUtils.showCustomDialog(child: new CustomLoadingDialog(message: "正在退出群聊")); return(new ThunkAction <AppState>((dispatcher, getState) => { return ChannelApi.LeaveChannel(channelId: channelId, memberId: memberId, groupId: groupId) .Then(leaveChannelResponse => { dispatcher.dispatch(new LeaveChannelSuccessAction { channelId = channelId }); CustomDialogUtils.hiddenCustomDialog(); dispatcher.dispatch(new MainNavigatorPopAction()); dispatcher.dispatch(new MainNavigatorPopAction()); }) .Catch(error => { dispatcher.dispatch(new LeaveChannelFailureAction()); CustomDialogUtils.hiddenCustomDialog(); Debuger.LogError(message: error); }); })); }
public static object fetchChannels(int page, bool fetchMessagesAfterSuccess = false, bool joined = true, bool discoverAll = false) { return(new ThunkAction <AppState>((dispatcher, getState) => { dispatcher.dispatch(new StartFetchChannelsAction()); return ChannelApi.FetchChannels(page: page, joined: joined, discoverAll: discoverAll) .Then(channelResponse => { dispatcher.dispatch(new FetchChannelsSuccessAction { discoverList = channelResponse.discoverList ?? new List <string>(), joinedList = channelResponse.joinedList ?? new List <string>(), discoverPage = channelResponse.discoverPage, channelMap = channelResponse.channelMap ?? new Dictionary <string, Channel>(), joinedMemberMap = channelResponse.joinedMemberMap ?? new Dictionary <string, ChannelMember>(), groupMap = channelResponse.groupFullMap ?? new Dictionary <string, Group>(), groupMemberMap = channelResponse.groupMemberMap ?? new Dictionary <string, GroupMember>(), updateJoined = joined, discoverHasMore = channelResponse.discoverHasMore }); if (fetchMessagesAfterSuccess) { channelResponse.joinedList.ForEach(joinedChannelId => { dispatcher.dispatch(fetchChannelMessages(channelId: joinedChannelId)); dispatcher.dispatch(fetchChannelMembers(channelId: joinedChannelId)); }); } }) .Catch(error => { dispatcher.dispatch(new FetchChannelsFailureAction()); Debuger.LogError(message: error); dispatcher.dispatch(loadReadyStateFromDB()); }); })); }
public static object fetchChannelInfo(string channelId, bool isInfoPage = false) { return(new ThunkAction <AppState>((dispatcher, getState) => { dispatcher.dispatch(new StartFetchChannelInfoAction { channelId = channelId, isInfoPage = isInfoPage }); return ChannelApi.FetchChannelInfo(channelId: channelId) .Then(channelInfoResponse => { dispatcher.dispatch(new FetchChannelInfoSuccessAction { channel = channelInfoResponse.channel, isInfoPage = isInfoPage }); }) .Catch(error => { var errorResponse = JsonConvert.DeserializeObject <ErrorResponse>(value: error.Message); var errorCode = errorResponse.errorCode; dispatcher.dispatch(new FetchChannelInfoErrorAction { isInfoPage = isInfoPage, channelId = channelId, errorCode = errorCode }); Debuger.LogError(message: error); }); })); }
public static object ackChannelMessage(string messageId) { return(new ThunkAction <AppState>((dispatcher, getState) => { return ChannelApi.AckChannelMessage(messageId: messageId) .Then(ackMessageResponse => { dispatcher.dispatch(new AckChannelMessageSuccessAction()); }) .Catch(error => { dispatcher.dispatch(new AckChannelMessageFailureAction()); Debuger.LogError(message: error); }); })); }
public static object fetchChannelMessages(string channelId, string before = null, string after = null) { return(new ThunkAction <AppState>((dispatcher, getState) => { dispatcher.dispatch(new StartFetchChannelMessageAction { channelId = channelId }); return ChannelApi.FetchChannelMessages(channelId: channelId, before: before, after: after) .Then(channelMessagesResponse => { dispatcher.dispatch(new UserLicenseMapAction { userLicenseMap = channelMessagesResponse.userLicenseMap }); var userMap = new Dictionary <string, User>(); (channelMessagesResponse.items ?? new List <ChannelMessage>()).ForEach(channelMessage => { userMap[key: channelMessage.author.id] = channelMessage.author; (channelMessage.mentions ?? new List <User>()).ForEach(mention => { userMap[key: mention.id] = mention; }); (channelMessage.replyUsers ?? new List <User>()).ForEach(replyUser => { userMap[key: replyUser.id] = replyUser; }); }); dispatcher.dispatch(new UserMapAction { userMap = userMap }); dispatcher.dispatch(new FetchChannelMessagesSuccessAction { channelId = channelId, messages = channelMessagesResponse.items ?? new List <ChannelMessage>(), before = before, after = after, hasMore = channelMessagesResponse.hasMore, hasMoreNew = channelMessagesResponse.hasMoreNew }); try { dispatcher.dispatch(channelMessagesResponse.items?.isNotEmpty() ?? false ? saveMessagesToDB(channelMessagesResponse.items) : loadMessagesFromDB(channelId, before.hexToLong())); } catch (Exception e) { Debuger.LogWarning(message: e); } }) .Catch(error => { dispatcher.dispatch(new FetchChannelMessagesFailureAction { channelId = channelId }); Debuger.LogError(message: error); dispatcher.dispatch(loadMessagesFromDB(channelId, before.hexToLong())); }); })); }
public static object cancelReaction(string messageId, string type) { return(new ThunkAction <AppState>((dispatcher, getState) => { return ChannelApi.UpdateReaction(messageId: messageId, likeEmoji: type, true) .Then(ackMessageResponse => { dispatcher.dispatch( new CancelChannelMessageReactionSuccessAction()); }) .Catch(error => { dispatcher.dispatch(new CancelChannelMessageReactionFailureAction()); Debuger.LogError(message: error); }); })); }
public static object fetchCreateChannelFilter() { return(new ThunkAction <AppState>((dispatcher, getState) => { return ChannelApi.FetchChannels(page: 1, joined: false, discoverAll: true) .Then(channelResponse => { dispatcher.dispatch(new FetchDiscoverChannelFilterSuccessAction { discoverList = channelResponse.discoverList ?? new List <string>() }); }) .Catch(error => { dispatcher.dispatch(new FetchDiscoverChannelFilterFailureAction()); Debuger.LogError(message: error); }); })); }
public static object fetchChannelMember(string channelId, string userId) { return(new ThunkAction <AppState>((dispatcher, getState) => { return ChannelApi.FetchChannelMember(channelId: channelId, userId: userId) .Then(channelMemberResponse => { dispatcher.dispatch(new FetchChannelMemberSuccessAction { channelId = channelId, member = channelMemberResponse.member }); }) .Catch(error => { dispatcher.dispatch(new FetchChannelMemberFailureAction()); Debuger.LogError(message: error); }); })); }
public static object fetchChannelInfo(string channelId, bool ignoreError = false) { return(new ThunkAction <AppState>((dispatcher, getState) => { return ChannelApi.FetchChannelInfo(channelId: channelId) .Then(channelInfoResponse => { if (channelInfoResponse.channelMember == null && !ignoreError) { dispatcher.dispatch(new FetchChannelInfoErrorAction()); } dispatcher.dispatch(new FetchChannelInfoSuccessAction { channel = channelInfoResponse.channel }); }) .Catch(onRejected: Debuger.LogError); })); }
public static object queryChannelMentionSuggestions(string channelId, string query) { return(new ThunkAction <AppState>((dispatcher, getState) => { return ChannelApi.FetchChannelMemberQuery(channelId: channelId, query: query) .Then(channelMemberResponse => { var searchMembers = channelMemberResponse.searchMembers ?? new List <ChannelMember>(); dispatcher.dispatch(new FetchChannelMentionQuerySuccessAction { channelId = channelId, members = searchMembers }); }) .Catch(error => { dispatcher.dispatch(new FetchChannelMentionQueryFailureAction()); Debuger.LogError(message: error); }); })); }
public static object joinChannel(string channelId, string groupId = null, bool loading = false) { if (HttpManager.isNetWorkError()) { CustomDialogUtils.showToast("请检查网络", iconData: Icons.sentiment_dissatisfied); return(null); } if (loading) { CustomDialogUtils.showCustomDialog(child: new CustomLoadingDialog(message: "正在加入群聊")); } return(new ThunkAction <AppState>((dispatcher, getState) => { return ChannelApi.JoinChannel(channelId: channelId, groupId: groupId) .Then(joinChannelResponse => { if (loading) { CustomDialogUtils.hiddenCustomDialog(); } dispatcher.dispatch(new JoinChannelSuccessAction { channelId = channelId, member = joinChannelResponse.member }); dispatcher.dispatch(fetchChannelMessages(channelId: channelId)); dispatcher.dispatch(new FetchChannelMemberSuccessAction { channelId = channelId, member = joinChannelResponse.member }); }) .Catch(error => { if (loading) { CustomDialogUtils.hiddenCustomDialog(); } dispatcher.dispatch(new JoinChannelFailureAction { channelId = channelId }); Debuger.LogError(message: error); }); })); }
public static object sendImage(string channelId, string nonce, byte[] imageData) { return(new ThunkAction <AppState>((dispatcher, getState) => { return ChannelApi.SendImage(channelId, "", nonce, imageData) .Then(responseText => { dispatcher.dispatch(new SendChannelMessageSuccessAction { channelId = channelId, content = "", nonce = nonce, isImage = false }); }) .Catch(error => { dispatcher.dispatch(new SendChannelMessageFailureAction { channelId = channelId, messageId = nonce }); Debuger.LogError(message: error); }); })); }
static object sendAttachment(string channelId, string nonce, byte[] attachmentData, string filename, string fileType) { return(new ThunkAction <AppState>((dispatcher, getState) => { return ChannelApi.SendAttachment(channelId: channelId, "", nonce: nonce, attachmentData: attachmentData, filename: filename, fileType: fileType) .Then(responseText => { dispatcher.dispatch(new SendChannelMessageSuccessAction { channelId = channelId, content = "", nonce = nonce, isImage = false }); }) .Catch(error => { dispatcher.dispatch(new SendChannelMessageFailureAction { channelId = channelId, messageId = nonce }); Debuger.LogError(message: error); }); })); }
public static object fetchChannelMembers(string channelId, int offset = 0) { return(new ThunkAction <AppState>((dispatcher, getState) => { var channel = getState().channelState.channelDict.ContainsKey(key: channelId) ? getState().channelState.channelDict[key: channelId] : new ChannelView(); var memberOffset = (channel.memberIds ?? new List <string>()).Count; if (offset != 0 && offset != memberOffset) { offset = memberOffset; } return ChannelApi.FetchChannelMembers(channelId: channelId, offset: offset) .Then(channelMemberResponse => { dispatcher.dispatch(new FollowMapAction { followMap = channelMemberResponse.followeeMap }); var userMap = new Dictionary <string, User>(); (channelMemberResponse.list ?? new List <ChannelMember>()).ForEach(member => { userMap[key: member.user.id] = member.user; }); dispatcher.dispatch(new UserMapAction { userMap = userMap }); dispatcher.dispatch(new FetchChannelMembersSuccessAction { channelId = channelId, offset = channelMemberResponse.offset, total = channelMemberResponse.total, members = channelMemberResponse.list }); }) .Catch(error => { dispatcher.dispatch(new FetchChannelMembersFailureAction()); Debuger.LogError(message: error); }); })); }
public static object fetchUnStickChannel(string channelId) { if (HttpManager.isNetWorkError()) { CustomDialogUtils.showToast("请检查网络", iconData: Icons.sentiment_dissatisfied); return(null); } CustomDialogUtils.showCustomDialog(child: new CustomLoadingDialog(message: "取消置顶中")); return(new ThunkAction <AppState>((dispatcher, getState) => { return ChannelApi.FetchUnStickChannel(channelId: channelId) .Then(unStickChannelResponse => { CustomDialogUtils.hiddenCustomDialog(); dispatcher.dispatch(new FetchUnStickChannelSuccessAction { channelId = channelId }); }) .Catch(error => { CustomDialogUtils.hiddenCustomDialog(); Debuger.LogError(message: error); }); })); }
public static TApi GetStaticApi(string key, string accessToken) { TApi apiClass = null; switch (key) { case "TeamApi": if (_cacheManager.Get <TApi>(key) != null) { return(_cacheManager.Get <TApi>(key)); } else { apiClass = new TeamApi(accessToken); } break; case "BucketApi": if (_cacheManager.Get <TApi>(key) != null) { return(_cacheManager.Get <TApi>(key)); } else { apiClass = new BucketApi(accessToken); } break; case "ChannelApi": if (_cacheManager.Get <TApi>(key) != null) { return(_cacheManager.Get <TApi>(key)); } else { apiClass = new ChannelApi(accessToken); } break; case "PlannerApi": if (_cacheManager.Get <TApi>(key) != null) { return(_cacheManager.Get <TApi>(key)); } else { apiClass = new PlannerApi(accessToken); } break; case "TaskApi": if (_cacheManager.Get <TApi>(key) != null) { return(_cacheManager.Get <TApi>(key)); } else { apiClass = new TaskApi(accessToken); } break; default: break; } _cacheManager.Add(key, apiClass); return(apiClass); }