From 8443ca58289055cde25a3cdaaa3987c6f8cfde4a Mon Sep 17 00:00:00 2001
From: George Goldberg <george@gberg.me>
Date: Mon, 19 Sep 2016 13:21:22 +0100
Subject: PLT-1759 - Auto-complete for !channels when posting messages. (#3890)

* Auto-complete for !channels when posting messages.

This is part 1 of the fix for PLT-1759 to make channels linkable.

Still to do:
- Make the !channels clickable when they appear in messages. This is
  blocked until PR #3865 is resolved as it looks like that refactors
  some of the code that would be touched by making this change.

- Unit tests. Again, I think the above referenced PR should be merged
  before tackling this.

* Fix style problems.

* Highlighting of !channel-names in messages.

This only identifies the !channel-name (not the display name). The
implementation of the auto-complete on channel names now needs to be
modified to convert to the channel handle before sending the message.

* Display !channel-name as !Display Name.

When we encounter !channel-name in a message, display it as a link using
the channel's actual name rather than it's handle (name).

* Match on names and display name, and use name.

* Autocomplete channels matching on both the name and the the display
  name.
* Use the name as the text we fill in instead of the display name. It's
  potentially a bit ugly, but it minimises complexity for now as
  otherwise we'd have to do complicated things to the message box.

* Fix style issues.

* Load more channels everywhere.

Whenever we load the list of channels, we should also load the list of
more channels. This is to enable auto-completing and auto-linking of all
channels whether or not the user is in them currently.

* Include more channels in the map for linking.

* Listen for channel list updates for autolinking.

* Remove accidental console.log.

* Autocomplete on more channels too.

* i18n for channel autocomplete.

* Link directly to channels in !channel mentions.

This currently does not work if you aren't a member of that channel.
Need to decide what the correct behaviour is in that case.

* Fix style issues.

* Show channel name and handle in suggestion.

* Match channels only at start or after space.

* Better matching in text-formatting.

Only match channels after a space-type character or at the start in the
posts list too.

* Move the route construction to make tests work.

Moves route-construction out of text_formatting.jsx and into utils.jsx
so that the unit tests work once again.
---
 webapp/actions/global_actions.jsx | 3 +++
 1 file changed, 3 insertions(+)

(limited to 'webapp/actions/global_actions.jsx')

diff --git a/webapp/actions/global_actions.jsx b/webapp/actions/global_actions.jsx
index 87bd20165..3b38d16b0 100644
--- a/webapp/actions/global_actions.jsx
+++ b/webapp/actions/global_actions.jsx
@@ -42,6 +42,7 @@ export function emitChannelClickEvent(channel) {
     }
     function switchToChannel(chan) {
         AsyncClient.getChannels(true);
+        AsyncClient.getMoreChannels(true);
         AsyncClient.getChannelExtraInfo(chan.id);
         AsyncClient.updateLastViewedAt(chan.id);
         AsyncClient.getPosts(chan.id);
@@ -141,6 +142,7 @@ export function doFocusPost(channelId, postId, data) {
         post_list: data
     });
     AsyncClient.getChannels(true);
+    AsyncClient.getMoreChannels(true);
     AsyncClient.getChannelExtraInfo(channelId);
     AsyncClient.getPostsBefore(postId, 0, Constants.POST_FOCUS_CONTEXT_RADIUS, true);
     AsyncClient.getPostsAfter(postId, 0, Constants.POST_FOCUS_CONTEXT_RADIUS, true);
@@ -435,6 +437,7 @@ export function loadDefaultLocale() {
 
 export function viewLoggedIn() {
     AsyncClient.getChannels();
+    AsyncClient.getMoreChannels();
     AsyncClient.getChannelExtraInfo();
 
     // Clear pending posts (shouldn't have pending posts if we are loading)
-- 
cgit v1.2.3-1-g7c22

