2021-06-16 21:15:47 +02:00
import $ from "jquery" ;
import SimpleBar from "simplebar" ;
import render _read _receipts from "../templates/read_receipts.hbs" ;
import render _read _receipts _modal from "../templates/read_receipts_modal.hbs" ;
import * as channel from "./channel" ;
2022-09-10 04:23:07 +02:00
import { $t , $t _html } from "./i18n" ;
2021-06-16 21:15:47 +02:00
import * as loading from "./loading" ;
2022-09-09 20:22:28 +02:00
import * as message _store from "./message_store" ;
2021-06-16 21:15:47 +02:00
import * as overlays from "./overlays" ;
import * as people from "./people" ;
import * as popovers from "./popovers" ;
import * as ui _report from "./ui_report" ;
export function show _user _list ( message _id ) {
$ ( "body" ) . append ( render _read _receipts _modal ( ) ) ;
overlays . open _modal ( "read_receipts_modal" , {
autoremove : true ,
2022-11-17 23:33:43 +01:00
on _show ( ) {
2022-09-09 20:22:28 +02:00
const message = message _store . get ( message _id ) ;
if ( message . sender _email === "notification-bot@zulip.com" ) {
$ ( "#read_receipts_modal .read_receipts_info" ) . text (
$t ( {
defaultMessage :
"Read receipts are not available for Notification Bot messages." ,
} ) ,
) ;
$ ( "#read_receipts_modal .modal__content" ) . addClass ( "compact" ) ;
} else {
loading . make _indicator ( $ ( "#read_receipts_modal .loading_indicator" ) ) ;
channel . get ( {
url : ` /json/messages/ ${ message _id } /read_receipts ` ,
success ( data ) {
const users = data . user _ids . map ( ( id ) => {
const user = people . get _by _user _id ( id ) ;
return {
user _id : user . user _id ,
full _name : user . full _name ,
avatar _url : people . small _avatar _url _for _person ( user ) ,
} ;
} ) ;
users . sort ( people . compare _by _name ) ;
2021-06-16 21:15:47 +02:00
2022-09-09 20:22:28 +02:00
loading . destroy _indicator ( $ ( "#read_receipts_modal .loading_indicator" ) ) ;
if ( users . length === 0 ) {
$ ( "#read_receipts_modal .read_receipts_info" ) . text (
$t ( { defaultMessage : "No one has read this message yet." } ) ,
) ;
} else {
$ ( "#read_receipts_modal .read_receipts_info" ) . html (
$t _html (
{
defaultMessage :
"{num_of_people, plural, one {This message has been <z-link>read</z-link> by {num_of_people} person:} other {This message has been <z-link>read</z-link> by {num_of_people} people:}}" ,
} ,
{
num _of _people : users . length ,
"z-link" : ( content _html ) =>
2022-11-03 20:14:03 +01:00
` <a href="/help/read-receipts"> ${ content _html . join (
"" ,
) } < / a > ` ,
2022-09-09 20:22:28 +02:00
} ,
) ,
) ;
$ ( "#read_receipts_modal .modal__container" ) . addClass (
"showing_read_receipts_list" ,
) ;
$ ( "#read_receipts_modal .modal__content" ) . append (
render _read _receipts ( { users } ) ,
) ;
new SimpleBar ( $ ( "#read_receipts_modal .modal__content" ) [ 0 ] ) ;
}
} ,
error ( xhr ) {
ui _report . error ( "" , xhr , $ ( "#read_receipts_error" ) ) ;
loading . destroy _indicator ( $ ( "#read_receipts_modal .loading_indicator" ) ) ;
} ,
} ) ;
}
2021-06-16 21:15:47 +02:00
} ,
2022-11-17 23:33:43 +01:00
on _hide ( ) {
2021-06-16 21:15:47 +02:00
// Ensure any user info popovers are closed
popovers . hide _all ( ) ;
} ,
} ) ;
}