Estoy montando un chat con ng-chat y estoy en el proceso de sacar las conversaciones activas del usuario. NG-Chat la demo viene con un array con unas conversaciones de DEMO, pero yo quiero mostrar mi array sacado de la base de datos.
public static mockedParticipants: IChatParticipant[] = [
{
participantType: ChatParticipantType.User,
id: 1,
displayName: "Arya Stark",
avatar: "https://66.media.tumblr.com/avatar_9dd9bb497b75_128.pnj",
status: ChatParticipantStatus.Online
},
{
participantType: ChatParticipantType.User,
id: 2,
displayName: "Cersei Lannister",
avatar: null,
status: ChatParticipantStatus.Online
},
{
participantType: ChatParticipantType.User,
id: 3,
displayName: "Daenerys Targaryen",
avatar: "https://68.media.tumblr.com/avatar_d28d7149f567_128.png",
status: ChatParticipantStatus.Busy
},
{
participantType: ChatParticipantType.User,
id: 4,
displayName: "Eddard Stark",
avatar: "https://pbs.twimg.com/profile_images/600707945911844864/MNogF757_400x400.jpg",
status: ChatParticipantStatus.Offline
},
{
participantType: ChatParticipantType.User,
id: 5,
displayName: "Hodor",
avatar: "https://pbs.twimg.com/profile_images/378800000449071678/27f2e27edd119a7133110f8635f2c130.jpeg",
status: ChatParticipantStatus.Offline
},
{
participantType: ChatParticipantType.User,
id: 6,
displayName: "Jaime Lannister",
avatar: "https://pbs.twimg.com/profile_images/378800000243930208/4fa8efadb63777ead29046d822606a57.jpeg",
status: ChatParticipantStatus.Busy
},
{
participantType: ChatParticipantType.User,
id: 7,
displayName: "John Snow",
avatar: "https://pbs.twimg.com/profile_images/3456602315/aad436e6fab77ef4098c7a5b86cac8e3.jpeg",
status: ChatParticipantStatus.Busy
},
{
participantType: ChatParticipantType.User,
id: 8,
displayName: "Lorde Petyr 'Littlefinger' Baelish",
avatar: "http://68.media.tumblr.com/avatar_ba75cbb26da7_128.png",
status: ChatParticipantStatus.Offline
},
{
participantType: ChatParticipantType.User,
id: 9,
displayName: "Sansa Stark",
avatar: "http://pm1.narvii.com/6201/dfe7ad75cd32130a5c844d58315cbca02fe5b804_128.jpg",
status: ChatParticipantStatus.Online
},
{
participantType: ChatParticipantType.User,
id: 10,
displayName: "Theon Greyjoy",
avatar: "https://thumbnail.myheritageimages.com/502/323/78502323/000/000114_884889c3n33qfe004v5024_C_64x64C.jpg",
status: ChatParticipantStatus.Away
}
];
Este sería el Array DEMO, yo obtengo las conversaciones de la siguiente forma:
getMessages() {
this.profile.id = 184;
this.chatService.getAllMessages(`?conversation_user=${this.profile.id}&limit=100`).subscribe(async (res: any) => {
let msgs = await res.results;
this.allMessages = [];
})
}
En this.allMessages tengo el array con las conversaciones pero ahí es donde me quedo, ya que no me deja hacer lo siguiente
public static mockedParticipants: IChatParticipant[] = this.allMessages;
Y finalmente tiene un observable
listFriends(): Observable<ParticipantResponse[]> {
return of(DemoAdapter.mockedParticipants.map(user => {
let participantResponse = new ParticipantResponse();
participantResponse.participant = user;
participantResponse.metadata = {
totalUnreadMessages: Math.floor(Math.random() * 10)
}
return participantResponse;
}));
}