com.akaxin.proto.client.ImStcNoticeProto Java Examples

The following examples show how to use com.akaxin.proto.client.ImStcNoticeProto. 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: NoticeHandler.java    From wind-im with Apache License 2.0 6 votes vote down vote up
public Boolean handle(Command command) {
	try {
		ImStcNoticeProto.ImStcNoticeRequest request = ImStcNoticeProto.ImStcNoticeRequest
				.parseFrom(command.getParams());
		String siteUserId = command.getSiteUserId();
		String siteFriendId = command.getSiteFriendId();
		LogUtils.requestDebugLog(logger, command, request.toString());

		List<String> deviceList = SessionDeviceDao.getInstance().getSessionDevices(siteFriendId);
		for (String deviceId : deviceList) {
			CommandResponse commandResponse = new CommandResponse().setVersion(CommandConst.PROTOCOL_VERSION)
					.setAction(CommandConst.IM_NOTICE);
			commandResponse.setParams(request.toByteArray());
			commandResponse.setErrCode2(ErrorCode2.SUCCESS);
			ChannelWriter.writeByDeviceId(deviceId, commandResponse);
			logger.debug("siteUserId={} apply friend to siteFriendId={} deviceId={}", siteUserId, siteFriendId,
					deviceId);
		}

		return true;
	} catch (Exception e) {
		LogUtils.requestErrorLog(logger, command, this.getClass(), e);
	}

	return false;
}
 
Example #2
Source File: User2Notice.java    From wind-im with Apache License 2.0 6 votes vote down vote up
/**
 * A用户添加用户B为好友,发送B有好友添加的申请 <br>
 * 
 * 客户端接收到此通知,会在通讯录的好友申请提示
 * 
 * @param siteUserId
 *            用户B的用户ID
 */
public void applyFriendNotice(String siteUserId, String siteFriendId) {
	try {
		Command command = new Command();
		command.setSiteUserId(siteUserId);
		command.setSiteFriendId(siteFriendId);
		command.setAction(RequestAction.IM_STC_NOTICE.getName());
		ImStcNoticeProto.ImStcNoticeRequest noticeRequest = ImStcNoticeProto.ImStcNoticeRequest.newBuilder()
				.setType(ImStcNoticeProto.NoticeType.APPLY_FRIEND).build();
		command.setParams(noticeRequest.toByteArray());
		// 发送im.stc.notice消息
		boolean result = imService.execute(command);
		logger.debug("siteUserId={} apply friend notice friendId={} result={}", siteUserId, siteFriendId, result);
	} catch (Exception e) {
		logger.error("send apply friend notice error", e);
	}
}
 
Example #3
Source File: User2Notice.java    From openzaly with Apache License 2.0 6 votes vote down vote up
/**
 * A用户添加用户B为好友,发送B有好友添加的申请 <br>
 * 
 * 客户端接收到此通知,会在通讯录的好友申请提示
 * 
 * @param siteUserId
 *            用户B的用户ID
 */
public void applyFriendNotice(String siteUserId, String siteFriendId) {
	try {
		Command command = new Command();
		command.setSiteUserId(siteUserId);
		command.setSiteFriendId(siteFriendId);
		command.setAction(RequestAction.IM_STC_NOTICE.getName());
		ImStcNoticeProto.ImStcNoticeRequest noticeRequest = ImStcNoticeProto.ImStcNoticeRequest.newBuilder()
				.setType(ImStcNoticeProto.NoticeType.APPLY_FRIEND).build();
		command.setParams(noticeRequest.toByteArray());
		// 发送im.stc.notice消息
		boolean result = imService.execute(command);
		logger.debug("siteUserId={} apply friend notice friendId={} result={}", siteUserId, siteFriendId, result);
	} catch (Exception e) {
		logger.error("send apply friend notice error", e);
	}
}
 
Example #4
Source File: NoticeHandler.java    From openzaly with Apache License 2.0 6 votes vote down vote up
public Boolean handle(Command command) {
	try {
		ImStcNoticeProto.ImStcNoticeRequest request = ImStcNoticeProto.ImStcNoticeRequest
				.parseFrom(command.getParams());
		String siteUserId = command.getSiteUserId();
		String siteFriendId = command.getSiteFriendId();
		LogUtils.requestDebugLog(logger, command, request.toString());

		List<String> deviceList = SessionDeviceDao.getInstance().getSessionDevices(siteFriendId);
		for (String deviceId : deviceList) {
			CommandResponse commandResponse = new CommandResponse().setVersion(CommandConst.PROTOCOL_VERSION)
					.setAction(CommandConst.IM_NOTICE);
			commandResponse.setParams(request.toByteArray());
			commandResponse.setErrCode2(ErrorCode2.SUCCESS);
			ChannelWriter.writeByDeviceId(deviceId, commandResponse);
			logger.debug("siteUserId={} apply friend to siteFriendId={} deviceId={}", siteUserId, siteFriendId,
					deviceId);
		}

		return true;
	} catch (Exception e) {
		LogUtils.requestErrorLog(logger, command, this.getClass(), e);
	}

	return false;
}
 
Example #5
Source File: User2Notice.java    From openzaly with Apache License 2.0 6 votes vote down vote up
/**
 * A用户添加用户B为好友,发送B有好友添加的申请 <br>
 * 
 * 客户端接收到此通知,会在通讯录的好友申请提示
 * 
 * @param siteUserId
 *            用户B的用户ID
 */
public void applyFriendNotice(String siteUserId, String siteFriendId) {
	try {
		Command command = new Command();
		command.setSiteUserId(siteUserId);
		command.setSiteFriendId(siteFriendId);
		command.setAction(RequestAction.IM_STC_NOTICE.getName());
		ImStcNoticeProto.ImStcNoticeRequest noticeRequest = ImStcNoticeProto.ImStcNoticeRequest.newBuilder()
				.setType(ImStcNoticeProto.NoticeType.APPLY_FRIEND).build();
		command.setParams(noticeRequest.toByteArray());
		// 发送im.stc.notice消息
		boolean result = imService.execute(command);
		logger.debug("siteUserId={} apply friend notice friendId={} result={}", siteUserId, siteFriendId, result);
	} catch (Exception e) {
		logger.error("send apply friend notice error", e);
	}
}
 
Example #6
Source File: NoticeHandler.java    From openzaly with Apache License 2.0 6 votes vote down vote up
public Boolean handle(Command command) {
	try {
		ImStcNoticeProto.ImStcNoticeRequest request = ImStcNoticeProto.ImStcNoticeRequest
				.parseFrom(command.getParams());
		String siteUserId = command.getSiteUserId();
		String siteFriendId = command.getSiteFriendId();
		LogUtils.requestDebugLog(logger, command, request.toString());

		List<String> deviceList = SessionDeviceDao.getInstance().getSessionDevices(siteFriendId);
		for (String deviceId : deviceList) {
			CommandResponse commandResponse = new CommandResponse().setVersion(CommandConst.PROTOCOL_VERSION)
					.setAction(CommandConst.IM_NOTICE);
			commandResponse.setParams(request.toByteArray());
			commandResponse.setErrCode2(ErrorCode2.SUCCESS);
			ChannelWriter.writeByDeviceId(deviceId, commandResponse);
			logger.debug("siteUserId={} apply friend to siteFriendId={} deviceId={}", siteUserId, siteFriendId,
					deviceId);
		}

		return true;
	} catch (Exception e) {
		LogUtils.requestErrorLog(logger, command, this.getClass(), e);
	}

	return false;
}
 
Example #7
Source File: NoticePushHandler.java    From wind-im with Apache License 2.0 4 votes vote down vote up
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 #8
Source File: NoticePushHandler.java    From openzaly with Apache License 2.0 4 votes vote down vote up
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: NoticePushHandler.java    From openzaly with Apache License 2.0 4 votes vote down vote up
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;
}