com.akaxin.proto.core.PushProto Java Examples
The following examples show how to use
com.akaxin.proto.core.PushProto.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UserPushHandler.java From wind-im with Apache License 2.0 | 4 votes |
public Boolean handle(Command command) { // 1.判断站点是否开启PUSH发送功能 ConfigProto.PushClientStatus pcs = SiteConfigHelper.getPushClientStatus(); if (ConfigProto.PushClientStatus.PUSH_NO == pcs) { logger.warn("push to client error. cause: pushClientStatus={}", ConfigProto.PushClientStatus.PUSH_NO); return true; } // 多线程处理push MultiPushThreadExecutor.getExecutor().execute(new Runnable() { @Override public void run() { try { ImCtsMessageProto.ImCtsMessageRequest request = ImCtsMessageProto.ImCtsMessageRequest .parseFrom(command.getParams()); // String siteUserId = command.getSiteUserId();// 发送者 String fromSiteUserId = command.isProxy() ? command.getProxySiteUserId() : command.getSiteUserId(); // String toSiteUserId = command.getSiteFriendId();// 接受者 这里是用户生成的站点ID String toGlobalUserId = ImUserProfileDao.getInstance().getGlobalUserId(toSiteUserId); LogUtils.requestDebugLog(logger, command, request.toString()); // 一、用户对站点是否消息免打扰 // 二、用户对该好友是否消息免打扰 if (StringUtils.isEmpty(toGlobalUserId) || ImUserProfileDao.getInstance().isMute(toSiteUserId) || ImUserFriendDao.getInstance().isMesageMute(toSiteUserId, fromSiteUserId)) { return; } ApiPushNotificationProto.ApiPushNotificationRequest.Builder requestBuilder = ApiPushNotificationProto.ApiPushNotificationRequest .newBuilder(); PushProto.Notification.Builder notification = PushProto.Notification.newBuilder(); notification.setUserId(toGlobalUserId); notification.setPushBadge(1); String siteName = SiteConfigHelper.getConfig(ConfigProto.ConfigKey.SITE_NAME); if (StringUtils.isNotBlank(siteName)) { notification.setPushTitle(siteName); } String address = SiteConfigHelper.getConfig(ConfigProto.ConfigKey.SITE_ADDRESS); String port = SiteConfigHelper.getConfig(ConfigProto.ConfigKey.SITE_PORT); notification.setSiteServer(address + ":" + port); notification.setPushFromId(fromSiteUserId); // 条件1:站点是否支持push展示消息内容 // 条件2:站点只支持文本消息展示消息内容 if (ConfigProto.PushClientStatus.PUSH_DISPLAY_TEXT == pcs && CoreProto.MsgType.TEXT == request.getType()) { ByteString byteStr = request.getText().getText(); notification.setPushAlert(byteStr.toString(Charset.forName("UTF-8"))); SimpleUserBean bean = ImUserProfileDao.getInstance().getSimpleUserProfile(fromSiteUserId); if (bean != null && StringUtils.isNotEmpty(bean.getUserName())) { notification.setPushFromName(bean.getUserName()); } } List<String> userTokens = ImUserProfileDao.getInstance().getUserToken(toSiteUserId); if (userTokens != null && userTokens.size() > 0) { notification.addAllUserTokens(userTokens); requestBuilder.setNotification(notification.build()); requestBuilder.setPushTypeValue(request.getType().getNumber()); PushClient.asyncWrite(CommandConst.API_PUSH_NOTIFICATION, requestBuilder.build().toByteArray()); logger.debug("client={} siteUserId={} push to siteFriend={} content={}", command.getClientIp(), command.getSiteUserId(), command.getSiteFriendId(), requestBuilder.toString()); } else { logger.warn("client={} siteUserId={} push to siteFriend={} error as userToken={}", command.getClientIp(), command.getSiteUserId(), command.getSiteFriendId(), userTokens); } } catch (Exception e) { LogUtils.requestErrorLog(logger, command, UserPushHandler.class, e); } } }); return true; }
Example #2
Source File: GroupPushHandler.java From wind-im with Apache License 2.0 | 4 votes |
public Boolean handle(Command command) { // 1.检测当前站点是否开启PUSH开关,开启才支持PUSH功能 ConfigProto.PushClientStatus pcs = SiteConfigHelper.getPushClientStatus(); if (ConfigProto.PushClientStatus.PUSH_NO == pcs) { logger.warn("push to client error. cause: pushClientStatus={}", ConfigProto.PushClientStatus.PUSH_NO); return true; } // 多线程处理push MultiPushThreadExecutor.getExecutor().execute(new Runnable() { @Override public void run() { try { ImCtsMessageProto.ImCtsMessageRequest request = ImCtsMessageProto.ImCtsMessageRequest .parseFrom(command.getParams()); // String siteUserId = command.getSiteUserId(); String fromSiteUserId = command.isProxy() ? command.getProxySiteUserId() : command.getSiteUserId(); // String siteGroupId = command.getSiteGroupId(); GroupProfileBean groupBean = ImUserGroupDao.getInstance().getSimpleGroupProfile(siteGroupId); if (groupBean == null || groupBean.getGroupId() == null) { logger.error("send message with push to group={} error", groupBean); return; } String fromGlobalUserId = ImUserProfileDao.getInstance().getGlobalUserId(fromSiteUserId); // Push Request ApiPushNotificationsProto.ApiPushNotificationsRequest.Builder requestBuilder = ApiPushNotificationsProto.ApiPushNotificationsRequest .newBuilder(); // 1.set pushType requestBuilder.setPushTypeValue(request.getType().getNumber()); // 2.set notification PushProto.Notifications.Builder notifications = PushProto.Notifications.newBuilder(); String siteName = SiteConfigHelper.getConfig(ConfigProto.ConfigKey.SITE_NAME); if (StringUtils.isNotBlank(siteName)) { notifications.setPushTitle(siteName); } String address = SiteConfigHelper.getConfig(ConfigProto.ConfigKey.SITE_ADDRESS); String port = SiteConfigHelper.getConfig(ConfigProto.ConfigKey.SITE_PORT); notifications.setSiteServer(address + ":" + port); // 条件1:站点是否支持push展示消息内容 // 条件2:站点只支持文本消息展示消息内容 if (ConfigProto.PushClientStatus.PUSH_DISPLAY_TEXT == pcs) { if (CoreProto.MsgType.GROUP_TEXT == request.getType()) { ByteString byteStr = request.getGroupText().getText(); notifications.setPushAlert(byteStr.toString(Charset.forName("UTF-8"))); } } requestBuilder.setNotifications(notifications.build()); // 3.set pushFromUser PushProto.PushFromUser pushFromUser = PushProto.PushFromUser.newBuilder() .setGlobalUserId(fromGlobalUserId).setSiteUserId(fromSiteUserId) .setPushFromName(groupBean.getGroupName()).build(); requestBuilder.setPushFromUser(pushFromUser); // 4.set pushToUser List<String> groupMembers = groupDao.getGroupMembersId(siteGroupId); for (String memberUserId : groupMembers) { if (StringUtils.isNotBlank(memberUserId) && !memberUserId.equals(fromSiteUserId)) { // 一、用户是否对站点消息免打扰 // 二、用户是否对该群消息免打扰 if (ImUserProfileDao.getInstance().isMute(memberUserId) || ImUserGroupDao.getInstance().isMesageMute(memberUserId, siteGroupId)) { continue; } String globalUserId = ImUserProfileDao.getInstance().getGlobalUserId(memberUserId); logger.debug("push from groupid={} to siteUserId={} globalUserId={}.", siteGroupId, memberUserId, globalUserId); PushProto.PushToUser.Builder pushToUser = PushProto.PushToUser.newBuilder(); pushToUser.setGlobalUserId(globalUserId); List<String> userTokens = ImUserProfileDao.getInstance().getUserToken(memberUserId); if (userTokens != null && userTokens.size() > 0) { pushToUser.addAllUserTokens(userTokens); requestBuilder.addPushToUser(pushToUser.build()); } else { logger.error("siteUserId={} with no userToken", memberUserId); } } } logger.debug("client={} siteUserId={} push to groupId={} siteFriend={} content={}", command.getClientIp(), command.getSiteUserId(), command.getSiteGroupId(), command.getSiteFriendId(), requestBuilder.toString()); PushClient.asyncWrite(CommandConst.API_PUSH_NOTIFICATIONS, requestBuilder.build().toByteArray()); } catch (Exception e) { LogUtils.requestErrorLog(logger, command, GroupPushHandler.class, e); } } }); return true; }
Example #3
Source File: NoticePushHandler.java From wind-im with Apache License 2.0 | 4 votes |
public Boolean handle(Command command) { // 1.判断站点是否开启PUSH发送功能 ConfigProto.PushClientStatus pcs = SiteConfigHelper.getPushClientStatus(); if (ConfigProto.PushClientStatus.PUSH_NO == pcs) { logger.warn("push to client error. cause: pushClientStatus={}", ConfigProto.PushClientStatus.PUSH_NO); return true; } // 多线程处理push MultiPushThreadExecutor.getExecutor().execute(new Runnable() { @Override public void run() { try { ImStcNoticeProto.ImStcNoticeRequest request = ImStcNoticeProto.ImStcNoticeRequest .parseFrom(command.getParams()); String siteUserId = command.getSiteUserId();// 发送者 String siteFriendId = command.getSiteFriendId();// 接受者 这里是用户生成的站点ID String globalUserId = ImUserProfileDao.getInstance().getGlobalUserId(siteFriendId); ImStcNoticeProto.NoticeType noticeType = request.getType(); LogUtils.requestDebugLog(logger, command, request.toString()); // 一、用户对站点是否消息免打扰 // 二、用户对该好友是否消息免打扰 if (ImUserProfileDao.getInstance().isMute(siteFriendId) || ImUserFriendDao.getInstance().isMesageMute(siteFriendId, siteUserId)) { return; } ApiPushNotificationProto.ApiPushNotificationRequest.Builder requestBuilder = ApiPushNotificationProto.ApiPushNotificationRequest .newBuilder(); PushProto.Notification.Builder notification = PushProto.Notification.newBuilder(); notification.setUserId(globalUserId); notification.setPushBadge(1); String siteName = SiteConfigHelper.getConfig(ConfigProto.ConfigKey.SITE_NAME); if (StringUtils.isNotBlank(siteName)) { notification.setPushTitle(siteName); } String address = SiteConfigHelper.getConfig(ConfigProto.ConfigKey.SITE_ADDRESS); String port = SiteConfigHelper.getConfig(ConfigProto.ConfigKey.SITE_PORT); notification.setSiteServer(address + ":" + port); notification.setPushFromId(siteUserId); // 条件1:站点是否支持push展示消息内容 if (ConfigProto.PushClientStatus.PUSH_DISPLAY_TEXT == pcs) { if (NoticeType.APPLY_FRIEND == noticeType) { notification.setPushAlert("你收到一条好友添加请求"); } } List<String> userTokens = ImUserProfileDao.getInstance().getUserToken(siteFriendId); if (userTokens != null && userTokens.size() > 0) { notification.addAllUserTokens(userTokens); requestBuilder.setNotification(notification.build()); requestBuilder.setPushType(PushProto.PushType.PUSH_APPLY_FRIEND_NOTICE); PushClient.asyncWrite(CommandConst.API_PUSH_NOTIFICATION, requestBuilder.build().toByteArray()); logger.debug("client={} siteUserId={} push to siteFriend={} content={}", command.getClientIp(), command.getSiteUserId(), command.getSiteFriendId(), requestBuilder.toString()); } else { logger.warn("client={} siteUserId={} push to siteFriend={} error as userToken={}", command.getClientIp(), command.getSiteUserId(), command.getSiteFriendId(), userTokens); } } catch (Exception e) { LogUtils.requestErrorLog(logger, command, NoticePushHandler.class, e); } } }); return true; }
Example #4
Source File: PushNotification.java From wind-im with Apache License 2.0 | 4 votes |
public static void send(String siteUserId, String siteFriendId, String subTitle, String pushContent, String pushGoto) { MultiPushThreadExecutor.getExecutor().execute(new Runnable() { @Override public void run() { try { String globalUserId = ImUserProfileDao.getInstance().getGlobalUserId(siteFriendId); // 一、用户对站点是否消息免打扰 if (ImUserProfileDao.getInstance().isMute(siteFriendId)) { return; } ApiPushNotificationProto.ApiPushNotificationRequest.Builder requestBuilder = ApiPushNotificationProto.ApiPushNotificationRequest .newBuilder(); PushProto.Notification.Builder notification = PushProto.Notification.newBuilder(); notification.setUserId(globalUserId); notification.setPushBadge(1); String siteName = SiteConfigHelper.getConfig(ConfigProto.ConfigKey.SITE_NAME); if (StringUtils.isNotBlank(siteName)) { notification.setPushTitle(siteName); } String address = SiteConfigHelper.getConfig(ConfigProto.ConfigKey.SITE_ADDRESS); String port = SiteConfigHelper.getConfig(ConfigProto.ConfigKey.SITE_PORT); notification.setSiteServer(address + ":" + port); notification.setPushFromId(siteUserId); if (StringUtils.isNotEmpty(subTitle)) { notification.setPushFromName(subTitle); } notification.setPushAlert(pushContent); notification.setPushGoto(pushGoto); List<String> userTokens = ImUserProfileDao.getInstance().getUserToken(siteFriendId); if (userTokens != null && userTokens.size() > 0) { notification.addAllUserTokens(userTokens); requestBuilder.setNotification(notification.build()); requestBuilder.setPushType(PushProto.PushType.PUSH_NOTICE); PushClient.asyncWrite(CommandConst.API_PUSH_NOTIFICATION, requestBuilder.build().toByteArray()); } } catch (Exception e) { logger.error(StringHelper.format("siteUserId={} siteFriendId={} subtitle={} content={}", siteUserId, siteFriendId, subTitle, pushContent), e); } } }); }
Example #5
Source File: PushNotification.java From openzaly with Apache License 2.0 | 4 votes |
public static void send(String siteUserId, String siteFriendId, String subTitle, String pushContent, String pushGoto) { MultiPushThreadExecutor.getExecutor().execute(new Runnable() { @Override public void run() { try { String globalUserId = ImUserProfileDao.getInstance().getGlobalUserId(siteFriendId); // 一、用户对站点是否消息免打扰 if (ImUserProfileDao.getInstance().isMute(siteFriendId)) { return; } ApiPushNotificationProto.ApiPushNotificationRequest.Builder requestBuilder = ApiPushNotificationProto.ApiPushNotificationRequest .newBuilder(); PushProto.Notification.Builder notification = PushProto.Notification.newBuilder(); notification.setUserId(globalUserId); notification.setPushBadge(1); String siteName = SiteConfigHelper.getConfig(ConfigProto.ConfigKey.SITE_NAME); if (StringUtils.isNotBlank(siteName)) { notification.setPushTitle(siteName); } String address = SiteConfigHelper.getConfig(ConfigProto.ConfigKey.SITE_ADDRESS); String port = SiteConfigHelper.getConfig(ConfigProto.ConfigKey.SITE_PORT); notification.setSiteServer(address + ":" + port); notification.setPushFromId(siteUserId); if (StringUtils.isNotEmpty(subTitle)) { notification.setPushFromName(subTitle); } notification.setPushAlert(pushContent); notification.setPushGoto(pushGoto); List<String> userTokens = ImUserProfileDao.getInstance().getUserToken(siteFriendId); if (userTokens != null && userTokens.size() > 0) { notification.addAllUserTokens(userTokens); requestBuilder.setNotification(notification.build()); requestBuilder.setPushType(PushProto.PushType.PUSH_NOTICE); PushClient.asyncWrite(CommandConst.API_PUSH_NOTIFICATION, requestBuilder.build().toByteArray()); } } catch (Exception e) { logger.error(StringHelper.format("siteUserId={} siteFriendId={} subtitle={} content={}", siteUserId, siteFriendId, subTitle, pushContent), e); } } }); }
Example #6
Source File: UserPushHandler.java From openzaly with Apache License 2.0 | 4 votes |
public Boolean handle(Command command) { // 1.判断站点是否开启PUSH发送功能 ConfigProto.PushClientStatus pcs = SiteConfigHelper.getPushClientStatus(); if (ConfigProto.PushClientStatus.PUSH_NO == pcs) { logger.warn("push to client error. cause: pushClientStatus={}", ConfigProto.PushClientStatus.PUSH_NO); return true; } // 多线程处理push MultiPushThreadExecutor.getExecutor().execute(new Runnable() { @Override public void run() { try { ImCtsMessageProto.ImCtsMessageRequest request = ImCtsMessageProto.ImCtsMessageRequest .parseFrom(command.getParams()); // String siteUserId = command.getSiteUserId();// 发送者 String fromSiteUserId = command.isProxy() ? command.getProxySiteUserId() : command.getSiteUserId(); // String toSiteUserId = command.getSiteFriendId();// 接受者 这里是用户生成的站点ID String toGlobalUserId = ImUserProfileDao.getInstance().getGlobalUserId(toSiteUserId); LogUtils.requestDebugLog(logger, command, request.toString()); // 一、用户对站点是否消息免打扰 // 二、用户对该好友是否消息免打扰 if (StringUtils.isEmpty(toGlobalUserId) || ImUserProfileDao.getInstance().isMute(toSiteUserId) || ImUserFriendDao.getInstance().isMesageMute(toSiteUserId, fromSiteUserId)) { return; } ApiPushNotificationProto.ApiPushNotificationRequest.Builder requestBuilder = ApiPushNotificationProto.ApiPushNotificationRequest .newBuilder(); PushProto.Notification.Builder notification = PushProto.Notification.newBuilder(); notification.setUserId(toGlobalUserId); notification.setPushBadge(1); String siteName = SiteConfigHelper.getConfig(ConfigProto.ConfigKey.SITE_NAME); if (StringUtils.isNotBlank(siteName)) { notification.setPushTitle(siteName); } String address = SiteConfigHelper.getConfig(ConfigProto.ConfigKey.SITE_ADDRESS); String port = SiteConfigHelper.getConfig(ConfigProto.ConfigKey.SITE_PORT); notification.setSiteServer(address + ":" + port); notification.setPushFromId(fromSiteUserId); // 条件1:站点是否支持push展示消息内容 // 条件2:站点只支持文本消息展示消息内容 if (ConfigProto.PushClientStatus.PUSH_DISPLAY_TEXT == pcs && CoreProto.MsgType.TEXT == request.getType()) { ByteString byteStr = request.getText().getText(); notification.setPushAlert(byteStr.toString(Charset.forName("UTF-8"))); SimpleUserBean bean = ImUserProfileDao.getInstance().getSimpleUserProfile(fromSiteUserId); if (bean != null && StringUtils.isNotEmpty(bean.getUserName())) { notification.setPushFromName(bean.getUserName()); } } List<String> userTokens = ImUserProfileDao.getInstance().getUserToken(toSiteUserId); if (userTokens != null && userTokens.size() > 0) { notification.addAllUserTokens(userTokens); requestBuilder.setNotification(notification.build()); requestBuilder.setPushTypeValue(request.getType().getNumber()); PushClient.asyncWrite(CommandConst.API_PUSH_NOTIFICATION, requestBuilder.build().toByteArray()); logger.debug("client={} siteUserId={} push to siteFriend={} content={}", command.getClientIp(), command.getSiteUserId(), command.getSiteFriendId(), requestBuilder.toString()); } else { logger.warn("client={} siteUserId={} push to siteFriend={} error as userToken={}", command.getClientIp(), command.getSiteUserId(), command.getSiteFriendId(), userTokens); } } catch (Exception e) { LogUtils.requestErrorLog(logger, command, UserPushHandler.class, e); } } }); return true; }
Example #7
Source File: GroupPushHandler.java From openzaly with Apache License 2.0 | 4 votes |
public Boolean handle(Command command) { // 1.检测当前站点是否开启PUSH开关,开启才支持PUSH功能 ConfigProto.PushClientStatus pcs = SiteConfigHelper.getPushClientStatus(); if (ConfigProto.PushClientStatus.PUSH_NO == pcs) { logger.warn("push to client error. cause: pushClientStatus={}", ConfigProto.PushClientStatus.PUSH_NO); return true; } // 多线程处理push MultiPushThreadExecutor.getExecutor().execute(new Runnable() { @Override public void run() { try { ImCtsMessageProto.ImCtsMessageRequest request = ImCtsMessageProto.ImCtsMessageRequest .parseFrom(command.getParams()); // String siteUserId = command.getSiteUserId(); String fromSiteUserId = command.isProxy() ? command.getProxySiteUserId() : command.getSiteUserId(); // String siteGroupId = command.getSiteGroupId(); GroupProfileBean groupBean = ImUserGroupDao.getInstance().getSimpleGroupProfile(siteGroupId); if (groupBean == null || groupBean.getGroupId() == null) { logger.error("send message with push to group={} error", groupBean); return; } String fromGlobalUserId = ImUserProfileDao.getInstance().getGlobalUserId(fromSiteUserId); // Push Request ApiPushNotificationsProto.ApiPushNotificationsRequest.Builder requestBuilder = ApiPushNotificationsProto.ApiPushNotificationsRequest .newBuilder(); // 1.set pushType requestBuilder.setPushTypeValue(request.getType().getNumber()); // 2.set notification PushProto.Notifications.Builder notifications = PushProto.Notifications.newBuilder(); String siteName = SiteConfigHelper.getConfig(ConfigProto.ConfigKey.SITE_NAME); if (StringUtils.isNotBlank(siteName)) { notifications.setPushTitle(siteName); } String address = SiteConfigHelper.getConfig(ConfigProto.ConfigKey.SITE_ADDRESS); String port = SiteConfigHelper.getConfig(ConfigProto.ConfigKey.SITE_PORT); notifications.setSiteServer(address + ":" + port); // 条件1:站点是否支持push展示消息内容 // 条件2:站点只支持文本消息展示消息内容 if (ConfigProto.PushClientStatus.PUSH_DISPLAY_TEXT == pcs) { if (CoreProto.MsgType.GROUP_TEXT == request.getType()) { ByteString byteStr = request.getGroupText().getText(); notifications.setPushAlert(byteStr.toString(Charset.forName("UTF-8"))); } } requestBuilder.setNotifications(notifications.build()); // 3.set pushFromUser PushProto.PushFromUser pushFromUser = PushProto.PushFromUser.newBuilder() .setGlobalUserId(fromGlobalUserId).setSiteUserId(fromSiteUserId) .setPushFromName(groupBean.getGroupName()).build(); requestBuilder.setPushFromUser(pushFromUser); // 4.set pushToUser List<String> groupMembers = groupDao.getGroupMembersId(siteGroupId); for (String memberUserId : groupMembers) { if (StringUtils.isNotBlank(memberUserId) && !memberUserId.equals(fromSiteUserId)) { // 一、用户是否对站点消息免打扰 // 二、用户是否对该群消息免打扰 if (ImUserProfileDao.getInstance().isMute(memberUserId) || ImUserGroupDao.getInstance().isMesageMute(memberUserId, siteGroupId)) { continue; } String globalUserId = ImUserProfileDao.getInstance().getGlobalUserId(memberUserId); logger.debug("push from groupid={} to siteUserId={} globalUserId={}.", siteGroupId, memberUserId, globalUserId); PushProto.PushToUser.Builder pushToUser = PushProto.PushToUser.newBuilder(); pushToUser.setGlobalUserId(globalUserId); List<String> userTokens = ImUserProfileDao.getInstance().getUserToken(memberUserId); if (userTokens != null && userTokens.size() > 0) { pushToUser.addAllUserTokens(userTokens); requestBuilder.addPushToUser(pushToUser.build()); } else { logger.error("siteUserId={} with no userToken", memberUserId); } } } logger.debug("client={} siteUserId={} push to groupId={} siteFriend={} content={}", command.getClientIp(), command.getSiteUserId(), command.getSiteGroupId(), command.getSiteFriendId(), requestBuilder.toString()); PushClient.asyncWrite(CommandConst.API_PUSH_NOTIFICATIONS, requestBuilder.build().toByteArray()); } catch (Exception e) { LogUtils.requestErrorLog(logger, command, GroupPushHandler.class, e); } } }); return true; }
Example #8
Source File: NoticePushHandler.java From openzaly with Apache License 2.0 | 4 votes |
public Boolean handle(Command command) { // 1.判断站点是否开启PUSH发送功能 ConfigProto.PushClientStatus pcs = SiteConfigHelper.getPushClientStatus(); if (ConfigProto.PushClientStatus.PUSH_NO == pcs) { logger.warn("push to client error. cause: pushClientStatus={}", ConfigProto.PushClientStatus.PUSH_NO); return true; } // 多线程处理push MultiPushThreadExecutor.getExecutor().execute(new Runnable() { @Override public void run() { try { ImStcNoticeProto.ImStcNoticeRequest request = ImStcNoticeProto.ImStcNoticeRequest .parseFrom(command.getParams()); String siteUserId = command.getSiteUserId();// 发送者 String siteFriendId = command.getSiteFriendId();// 接受者 这里是用户生成的站点ID String globalUserId = ImUserProfileDao.getInstance().getGlobalUserId(siteFriendId); ImStcNoticeProto.NoticeType noticeType = request.getType(); LogUtils.requestDebugLog(logger, command, request.toString()); // 一、用户对站点是否消息免打扰 // 二、用户对该好友是否消息免打扰 if (ImUserProfileDao.getInstance().isMute(siteFriendId) || ImUserFriendDao.getInstance().isMesageMute(siteFriendId, siteUserId)) { return; } ApiPushNotificationProto.ApiPushNotificationRequest.Builder requestBuilder = ApiPushNotificationProto.ApiPushNotificationRequest .newBuilder(); PushProto.Notification.Builder notification = PushProto.Notification.newBuilder(); notification.setUserId(globalUserId); notification.setPushBadge(1); String siteName = SiteConfigHelper.getConfig(ConfigProto.ConfigKey.SITE_NAME); if (StringUtils.isNotBlank(siteName)) { notification.setPushTitle(siteName); } String address = SiteConfigHelper.getConfig(ConfigProto.ConfigKey.SITE_ADDRESS); String port = SiteConfigHelper.getConfig(ConfigProto.ConfigKey.SITE_PORT); notification.setSiteServer(address + ":" + port); notification.setPushFromId(siteUserId); // 条件1:站点是否支持push展示消息内容 if (ConfigProto.PushClientStatus.PUSH_DISPLAY_TEXT == pcs) { if (NoticeType.APPLY_FRIEND == noticeType) { notification.setPushAlert("你收到一条好友添加请求"); } } List<String> userTokens = ImUserProfileDao.getInstance().getUserToken(siteFriendId); if (userTokens != null && userTokens.size() > 0) { notification.addAllUserTokens(userTokens); requestBuilder.setNotification(notification.build()); requestBuilder.setPushType(PushProto.PushType.PUSH_APPLY_FRIEND_NOTICE); PushClient.asyncWrite(CommandConst.API_PUSH_NOTIFICATION, requestBuilder.build().toByteArray()); logger.debug("client={} siteUserId={} push to siteFriend={} content={}", command.getClientIp(), command.getSiteUserId(), command.getSiteFriendId(), requestBuilder.toString()); } else { logger.warn("client={} siteUserId={} push to siteFriend={} error as userToken={}", command.getClientIp(), command.getSiteUserId(), command.getSiteFriendId(), userTokens); } } catch (Exception e) { LogUtils.requestErrorLog(logger, command, NoticePushHandler.class, e); } } }); return true; }
Example #9
Source File: PushNotification.java From openzaly with Apache License 2.0 | 4 votes |
public static void send(String siteUserId, String siteFriendId, String subTitle, String pushContent, String pushGoto) { MultiPushThreadExecutor.getExecutor().execute(new Runnable() { @Override public void run() { try { String globalUserId = ImUserProfileDao.getInstance().getGlobalUserId(siteFriendId); // 一、用户对站点是否消息免打扰 if (ImUserProfileDao.getInstance().isMute(siteFriendId)) { return; } ApiPushNotificationProto.ApiPushNotificationRequest.Builder requestBuilder = ApiPushNotificationProto.ApiPushNotificationRequest .newBuilder(); PushProto.Notification.Builder notification = PushProto.Notification.newBuilder(); notification.setUserId(globalUserId); notification.setPushBadge(1); String siteName = SiteConfigHelper.getConfig(ConfigProto.ConfigKey.SITE_NAME); if (StringUtils.isNotBlank(siteName)) { notification.setPushTitle(siteName); } String address = SiteConfigHelper.getConfig(ConfigProto.ConfigKey.SITE_ADDRESS); String port = SiteConfigHelper.getConfig(ConfigProto.ConfigKey.SITE_PORT); notification.setSiteServer(address + ":" + port); notification.setPushFromId(siteUserId); if (StringUtils.isNotEmpty(subTitle)) { notification.setPushFromName(subTitle); } notification.setPushAlert(pushContent); notification.setPushGoto(pushGoto); List<String> userTokens = ImUserProfileDao.getInstance().getUserToken(siteFriendId); if (userTokens != null && userTokens.size() > 0) { notification.addAllUserTokens(userTokens); requestBuilder.setNotification(notification.build()); requestBuilder.setPushType(PushProto.PushType.PUSH_NOTICE); PushClient.asyncWrite(CommandConst.API_PUSH_NOTIFICATION, requestBuilder.build().toByteArray()); } } catch (Exception e) { logger.error(StringHelper.format("siteUserId={} siteFriendId={} subtitle={} content={}", siteUserId, siteFriendId, subTitle, pushContent), e); } } }); }
Example #10
Source File: UserPushHandler.java From openzaly with Apache License 2.0 | 4 votes |
public Boolean handle(Command command) { // 1.判断站点是否开启PUSH发送功能 ConfigProto.PushClientStatus pcs = SiteConfigHelper.getPushClientStatus(); if (ConfigProto.PushClientStatus.PUSH_NO == pcs) { logger.warn("push to client error. cause: pushClientStatus={}", ConfigProto.PushClientStatus.PUSH_NO); return true; } // 多线程处理push MultiPushThreadExecutor.getExecutor().execute(new Runnable() { @Override public void run() { try { ImCtsMessageProto.ImCtsMessageRequest request = ImCtsMessageProto.ImCtsMessageRequest .parseFrom(command.getParams()); // String siteUserId = command.getSiteUserId();// 发送者 String fromSiteUserId = command.isProxy() ? command.getProxySiteUserId() : command.getSiteUserId(); // String toSiteUserId = command.getSiteFriendId();// 接受者 这里是用户生成的站点ID String toGlobalUserId = ImUserProfileDao.getInstance().getGlobalUserId(toSiteUserId); LogUtils.requestDebugLog(logger, command, request.toString()); // 一、用户对站点是否消息免打扰 // 二、用户对该好友是否消息免打扰 if (StringUtils.isEmpty(toGlobalUserId) || ImUserProfileDao.getInstance().isMute(toSiteUserId) || ImUserFriendDao.getInstance().isMesageMute(toSiteUserId, fromSiteUserId)) { return; } ApiPushNotificationProto.ApiPushNotificationRequest.Builder requestBuilder = ApiPushNotificationProto.ApiPushNotificationRequest .newBuilder(); PushProto.Notification.Builder notification = PushProto.Notification.newBuilder(); notification.setUserId(toGlobalUserId); notification.setPushBadge(1); String siteName = SiteConfigHelper.getConfig(ConfigProto.ConfigKey.SITE_NAME); if (StringUtils.isNotBlank(siteName)) { notification.setPushTitle(siteName); } String address = SiteConfigHelper.getConfig(ConfigProto.ConfigKey.SITE_ADDRESS); String port = SiteConfigHelper.getConfig(ConfigProto.ConfigKey.SITE_PORT); notification.setSiteServer(address + ":" + port); notification.setPushFromId(fromSiteUserId); // 条件1:站点是否支持push展示消息内容 // 条件2:站点只支持文本消息展示消息内容 if (ConfigProto.PushClientStatus.PUSH_DISPLAY_TEXT == pcs && CoreProto.MsgType.TEXT == request.getType()) { ByteString byteStr = request.getText().getText(); notification.setPushAlert(byteStr.toString(Charset.forName("UTF-8"))); SimpleUserBean bean = ImUserProfileDao.getInstance().getSimpleUserProfile(fromSiteUserId); if (bean != null && StringUtils.isNotEmpty(bean.getUserName())) { notification.setPushFromName(bean.getUserName()); } } List<String> userTokens = ImUserProfileDao.getInstance().getUserToken(toSiteUserId); if (userTokens != null && userTokens.size() > 0) { notification.addAllUserTokens(userTokens); requestBuilder.setNotification(notification.build()); requestBuilder.setPushTypeValue(request.getType().getNumber()); PushClient.asyncWrite(CommandConst.API_PUSH_NOTIFICATION, requestBuilder.build().toByteArray()); logger.debug("client={} siteUserId={} push to siteFriend={} content={}", command.getClientIp(), command.getSiteUserId(), command.getSiteFriendId(), requestBuilder.toString()); } else { logger.warn("client={} siteUserId={} push to siteFriend={} error as userToken={}", command.getClientIp(), command.getSiteUserId(), command.getSiteFriendId(), userTokens); } } catch (Exception e) { LogUtils.requestErrorLog(logger, command, UserPushHandler.class, e); } } }); return true; }
Example #11
Source File: GroupPushHandler.java From openzaly with Apache License 2.0 | 4 votes |
public Boolean handle(Command command) { // 1.检测当前站点是否开启PUSH开关,开启才支持PUSH功能 ConfigProto.PushClientStatus pcs = SiteConfigHelper.getPushClientStatus(); if (ConfigProto.PushClientStatus.PUSH_NO == pcs) { logger.warn("push to client error. cause: pushClientStatus={}", ConfigProto.PushClientStatus.PUSH_NO); return true; } // 多线程处理push MultiPushThreadExecutor.getExecutor().execute(new Runnable() { @Override public void run() { try { ImCtsMessageProto.ImCtsMessageRequest request = ImCtsMessageProto.ImCtsMessageRequest .parseFrom(command.getParams()); // String siteUserId = command.getSiteUserId(); String fromSiteUserId = command.isProxy() ? command.getProxySiteUserId() : command.getSiteUserId(); // String siteGroupId = command.getSiteGroupId(); GroupProfileBean groupBean = ImUserGroupDao.getInstance().getSimpleGroupProfile(siteGroupId); if (groupBean == null || groupBean.getGroupId() == null) { logger.error("send message with push to group={} error", groupBean); return; } String fromGlobalUserId = ImUserProfileDao.getInstance().getGlobalUserId(fromSiteUserId); // Push Request ApiPushNotificationsProto.ApiPushNotificationsRequest.Builder requestBuilder = ApiPushNotificationsProto.ApiPushNotificationsRequest .newBuilder(); // 1.set pushType requestBuilder.setPushTypeValue(request.getType().getNumber()); // 2.set notification PushProto.Notifications.Builder notifications = PushProto.Notifications.newBuilder(); String siteName = SiteConfigHelper.getConfig(ConfigProto.ConfigKey.SITE_NAME); if (StringUtils.isNotBlank(siteName)) { notifications.setPushTitle(siteName); } String address = SiteConfigHelper.getConfig(ConfigProto.ConfigKey.SITE_ADDRESS); String port = SiteConfigHelper.getConfig(ConfigProto.ConfigKey.SITE_PORT); notifications.setSiteServer(address + ":" + port); // 条件1:站点是否支持push展示消息内容 // 条件2:站点只支持文本消息展示消息内容 if (ConfigProto.PushClientStatus.PUSH_DISPLAY_TEXT == pcs) { if (CoreProto.MsgType.GROUP_TEXT == request.getType()) { ByteString byteStr = request.getGroupText().getText(); notifications.setPushAlert(byteStr.toString(Charset.forName("UTF-8"))); } } requestBuilder.setNotifications(notifications.build()); // 3.set pushFromUser PushProto.PushFromUser pushFromUser = PushProto.PushFromUser.newBuilder() .setGlobalUserId(fromGlobalUserId).setSiteUserId(fromSiteUserId) .setPushFromName(groupBean.getGroupName()).build(); requestBuilder.setPushFromUser(pushFromUser); // 4.set pushToUser List<String> groupMembers = groupDao.getGroupMembersId(siteGroupId); for (String memberUserId : groupMembers) { if (StringUtils.isNotBlank(memberUserId) && !memberUserId.equals(fromSiteUserId)) { // 一、用户是否对站点消息免打扰 // 二、用户是否对该群消息免打扰 if (ImUserProfileDao.getInstance().isMute(memberUserId) || ImUserGroupDao.getInstance().isMesageMute(memberUserId, siteGroupId)) { continue; } String globalUserId = ImUserProfileDao.getInstance().getGlobalUserId(memberUserId); logger.debug("push from groupid={} to siteUserId={} globalUserId={}.", siteGroupId, memberUserId, globalUserId); PushProto.PushToUser.Builder pushToUser = PushProto.PushToUser.newBuilder(); pushToUser.setGlobalUserId(globalUserId); List<String> userTokens = ImUserProfileDao.getInstance().getUserToken(memberUserId); if (userTokens != null && userTokens.size() > 0) { pushToUser.addAllUserTokens(userTokens); requestBuilder.addPushToUser(pushToUser.build()); } else { logger.error("siteUserId={} with no userToken", memberUserId); } } } logger.debug("client={} siteUserId={} push to groupId={} siteFriend={} content={}", command.getClientIp(), command.getSiteUserId(), command.getSiteGroupId(), command.getSiteFriendId(), requestBuilder.toString()); PushClient.asyncWrite(CommandConst.API_PUSH_NOTIFICATIONS, requestBuilder.build().toByteArray()); } catch (Exception e) { LogUtils.requestErrorLog(logger, command, GroupPushHandler.class, e); } } }); return true; }
Example #12
Source File: NoticePushHandler.java From openzaly with Apache License 2.0 | 4 votes |
public Boolean handle(Command command) { // 1.判断站点是否开启PUSH发送功能 ConfigProto.PushClientStatus pcs = SiteConfigHelper.getPushClientStatus(); if (ConfigProto.PushClientStatus.PUSH_NO == pcs) { logger.warn("push to client error. cause: pushClientStatus={}", ConfigProto.PushClientStatus.PUSH_NO); return true; } // 多线程处理push MultiPushThreadExecutor.getExecutor().execute(new Runnable() { @Override public void run() { try { ImStcNoticeProto.ImStcNoticeRequest request = ImStcNoticeProto.ImStcNoticeRequest .parseFrom(command.getParams()); String siteUserId = command.getSiteUserId();// 发送者 String siteFriendId = command.getSiteFriendId();// 接受者 这里是用户生成的站点ID String globalUserId = ImUserProfileDao.getInstance().getGlobalUserId(siteFriendId); ImStcNoticeProto.NoticeType noticeType = request.getType(); LogUtils.requestDebugLog(logger, command, request.toString()); // 一、用户对站点是否消息免打扰 // 二、用户对该好友是否消息免打扰 if (ImUserProfileDao.getInstance().isMute(siteFriendId) || ImUserFriendDao.getInstance().isMesageMute(siteFriendId, siteUserId)) { return; } ApiPushNotificationProto.ApiPushNotificationRequest.Builder requestBuilder = ApiPushNotificationProto.ApiPushNotificationRequest .newBuilder(); PushProto.Notification.Builder notification = PushProto.Notification.newBuilder(); notification.setUserId(globalUserId); notification.setPushBadge(1); String siteName = SiteConfigHelper.getConfig(ConfigProto.ConfigKey.SITE_NAME); if (StringUtils.isNotBlank(siteName)) { notification.setPushTitle(siteName); } String address = SiteConfigHelper.getConfig(ConfigProto.ConfigKey.SITE_ADDRESS); String port = SiteConfigHelper.getConfig(ConfigProto.ConfigKey.SITE_PORT); notification.setSiteServer(address + ":" + port); notification.setPushFromId(siteUserId); // 条件1:站点是否支持push展示消息内容 if (ConfigProto.PushClientStatus.PUSH_DISPLAY_TEXT == pcs) { if (NoticeType.APPLY_FRIEND == noticeType) { notification.setPushAlert("你收到一条好友添加请求"); } } List<String> userTokens = ImUserProfileDao.getInstance().getUserToken(siteFriendId); if (userTokens != null && userTokens.size() > 0) { notification.addAllUserTokens(userTokens); requestBuilder.setNotification(notification.build()); requestBuilder.setPushType(PushProto.PushType.PUSH_APPLY_FRIEND_NOTICE); PushClient.asyncWrite(CommandConst.API_PUSH_NOTIFICATION, requestBuilder.build().toByteArray()); logger.debug("client={} siteUserId={} push to siteFriend={} content={}", command.getClientIp(), command.getSiteUserId(), command.getSiteFriendId(), requestBuilder.toString()); } else { logger.warn("client={} siteUserId={} push to siteFriend={} error as userToken={}", command.getClientIp(), command.getSiteUserId(), command.getSiteFriendId(), userTokens); } } catch (Exception e) { LogUtils.requestErrorLog(logger, command, NoticePushHandler.class, e); } } }); return true; }