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" ;
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 ,
on _show : ( ) => {
loading . make _indicator ( $ ( "#read_receipts_modal .loading_indicator" ) ) ;
channel . get ( {
url : ` /json/messages/ ${ message _id } /read_receipts ` ,
success ( data ) {
2022-08-19 02:33:47 +02:00
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 ) ,
} ;
} ) ;
2021-06-16 21:15:47 +02:00
users . sort ( people . compare _by _name ) ;
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 {
2022-09-10 04:23:07 +02:00
$ ( "#read_receipts_modal .read_receipts_info" ) . html (
$t _html (
2021-06-16 21:15:47 +02:00
{
defaultMessage :
2022-09-11 21:47:27 +02:00
"{num_of_people, plural, one {This message has been <z-link>read</z-link> by one person:} other {This message has been <z-link>read</z-link> by {num_of_people} people:}}" ,
2022-09-10 04:23:07 +02:00
} ,
{
num _of _people : users . length ,
"z-link" : ( content _html ) =>
` <a href="/help/read-receipts"> ${ content _html } </a> ` ,
2021-06-16 21:15:47 +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" ) ) ;
} ,
} ) ;
} ,
on _hide : ( ) => {
// Ensure any user info popovers are closed
popovers . hide _all ( ) ;
} ,
} ) ;
}