Skip to content

Commit c7fcae4

Browse files
Fingelgnprice
authored andcommitted
streams: Add "Copy link to stream" stream action.
Adds a "Copy link to stream" action to the stream action sheet which copies the full URL to a stream narrow to the system clipboard. Fixes: #5154
1 parent 9854f41 commit c7fcae4

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

src/action-sheets/index.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import { deleteMessagesForTopic } from '../topics/topicActions';
4040
import * as logging from '../utils/logging';
4141
import { getUnreadCountForTopic } from '../unread/unreadModel';
4242
import getIsNotificationEnabled from '../streams/getIsNotificationEnabled';
43-
import { getStreamTopicUrl } from '../utils/internalLinks';
43+
import { getStreamTopicUrl, getStreamUrl } from '../utils/internalLinks';
4444

4545
// TODO really this belongs in a libdef.
4646
export type ShowActionSheetWithOptions = (
@@ -234,6 +234,16 @@ const muteStream = {
234234
},
235235
};
236236

237+
const copyLinkToStream = {
238+
title: 'Copy link to stream',
239+
errorMessage: 'Failed to copy stream link',
240+
action: async ({ auth, streamId, streams, _ }) => {
241+
const streamUrl = getStreamUrl(auth.realm, streamId, streams);
242+
Clipboard.setString(streamUrl.toString());
243+
showToast(_('Link copied'));
244+
},
245+
};
246+
237247
const showStreamSettings = {
238248
title: 'Stream settings',
239249
errorMessage: 'Failed to show stream settings',
@@ -378,6 +388,7 @@ export const constructStreamActionButtons = (args: {|
378388
} else {
379389
buttons.push(muteStream);
380390
}
391+
buttons.push(copyLinkToStream);
381392
if (sub.pin_to_top) {
382393
buttons.push(unpinFromTop);
383394
} else {

src/utils/internalLinks.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,3 +230,13 @@ export const getStreamTopicUrl = (
230230
const path = internal_url.by_stream_topic_url(streamId, topic, maybe_get_stream_name);
231231
return new URL(path, realm);
232232
};
233+
234+
export const getStreamUrl = (
235+
realm: URL,
236+
streamId: number,
237+
streamsById: Map<number, Stream>,
238+
): URL => {
239+
const maybe_get_stream_name = id => streamsById.get(streamId)?.name;
240+
const path = internal_url.by_stream_url(streamId, maybe_get_stream_name);
241+
return new URL(path, realm);
242+
};

static/translations/messages_en.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,5 +292,7 @@
292292
"Remove account": "Remove account",
293293
"Search topics": "Search topics",
294294
"Copy link to topic": "Copy link to topic",
295-
"Failed to copy topic link": "Failed to copy topic link"
295+
"Failed to copy topic link": "Failed to copy topic link",
296+
"Copy link to stream": "Copy link to stream",
297+
"Failed to copy stream link": "Failed to copy stream link"
296298
}

0 commit comments

Comments
 (0)