Code Monkey home page Code Monkey logo

chatexchange's People

Contributors

tunaki avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

chatexchange's Issues

Add User.getProfileLink()

For SOBotics/Guttenberg#123, we need to get a link to a user's profile. As a workaround, we could build it by using the user-ID and Room.getChatHost() (which we had to map manually, because ChatHost.getName() is not public), but having User.getProfileLink() would be much cleaner.

What exactly are we trying to achieve?

In this line, we need to send the link to the user's profile, who has posted the feedback to a plagiarism-report. In the current version of ChatExchange, we only get the strings stack_overflow, stack_exchange or meta_stack_exchange instead of the actual hostname. That's why we had to write this ugly workaround:

public static String getChatHostAsString(ChatHost host) {
	switch (host) {
		case STACK_OVERFLOW:
			return "stackoverflow.com";
		case STACK_EXCHANGE:
			return "stackexchange.com";
		case META_STACK_EXCHANGE:
			return "meta.stackexchange.com";
		default:
			return "stackoverflow.com"; 
	}
}

Listen for UserMentioned and MessagePosted

When I try to listen to the events UserMentionedEvent and MessagePostedEvent, I keep getting the following exception when the UserMentionedEvent is happening:

ERROR [Room:254] 2017-03-18 18:17:19,840 - Couldn't execute task
java.util.concurrent.CompletionException: java.lang.UnsupportedOperationException: JsonNull
	at java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:273)
	at java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:280)
	at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1592)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.UnsupportedOperationException: JsonNull
	at com.google.gson.JsonElement.getAsLong(JsonElement.java:230)
	at fr.tunaki.stackoverflow.chat.Room.lambda$send$11(Room.java:279)
	at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1590)
	... 7 more

You can see my code in Guttenberg's branch feature/81-global-alive-command: https://github.com/SOBotics/Guttenberg/tree/feature/81-global-alive-command

SOBotics/Guttenberg#81

Seems like SO have changed something they need all calls to be https

SO returns

"The openid.return_to parameter... does not match the actual URL ",

Switching all http to https in the StackExchangeClient.siteLogin seems to solve this problem

private void siteLogin(String host) throws IOException {
	Response response = httpClient.get("https://" + host + "/users/login?returnurl=" + URLEncoder.encode("https://" + host + "/", "UTF-8"), cookies);
	String fkey = response.parse().select("input[name='fkey']").val();
	response = httpClient.post("https://" + host + "/users/authenticate", cookies, "fkey", fkey, "openid_identifier", openIdProvider);
	Document document = response.parse();

	// confirmation prompt?
	if (response.url().toString().startsWith("https://openid.stackexchange.com/account/prompt")) {
		LOGGER.trace("Confirmation prompt \n" + document.html());
		String session = document.select("input[name='session']").first().val();
		fkey = document.select("input[name='fkey']").first().val();
		Response promptResponse = httpClient.post("https://openid.stackexchange.com/account/prompt/submit", cookies, "session", session, "fkey", fkey);
		document = promptResponse.parse();
		LOGGER.trace("Confirmation prompt response \n" + document.html());
	}

	// when the account doesn't exist on this site, confirm its creation
	if (!document.select("form[action='/users/openidconfirm']").isEmpty()) {
		LOGGER.debug("Account doesn't exist on target site '{}', confirming new account", host);
		String session = document.select("input[name='s']").first().val();
		fkey = document.select("input[name='fkey']").first().val();
		Response newAccountResponse = httpClient.post("https://" + host + "/users/openidconfirm", cookies, "s", session, "fkey", fkey);
		LOGGER.trace("New account confirmation response \n" + newAccountResponse.parse().html());
	}

	// check logged in
	Response checkResponse = httpClient.get("https://" + host + "/users/current", cookies);
	if (checkResponse.parse().getElementsByClass("js-inbox-button").first() == null) {
		LOGGER.debug(response.parse().html());
		throw new IllegalStateException("Unable to login to Stack Exchange.");
	}
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.