Browse Source

fixed crons and save of partials channels

master
nicolas-arnaud 2 years ago
parent
commit
b9474f4a7c
  1. 19
      back/volume/src/chat/chat.service.ts

19
back/volume/src/chat/chat.service.ts

@ -40,10 +40,10 @@ export class ChatService {
const channels = await this.getChannelsForUser(user.id) const channels = await this.getChannelsForUser(user.id)
const dmAlreadyExists = channels.find((channel: Channel) => { const dmAlreadyExists = channels.find((channel: Channel) => {
return ( return (
(channel.name === user.ftId + '&' + otherUser.ftId || (channel.name === `${user.ftId}&${otherUser.ftId}` ||
channel.name === otherUser.ftId + '&' + user.ftId) && channel.name === `${otherUser.ftId}&${user.ftId}`) &&
channel.isPrivate && (channel.password === undefined || channel.password === '') &&
(channel.password === undefined || channel.password === '') channel.isPrivate
) )
}) })
if (dmAlreadyExists !== undefined) { if (dmAlreadyExists !== undefined) {
@ -70,7 +70,7 @@ export class ChatService {
newDM.owner = user newDM.owner = user
newDM.users = [user, otherUser] newDM.users = [user, otherUser]
newDM.admins = [] newDM.admins = []
newDM.name = user.ftId + '&' + otherUser.ftId newDM.name = `${user.ftId}&${otherUser.ftId}`
return newDM return newDM
} }
@ -82,7 +82,7 @@ export class ChatService {
throw new BadRequestException(`Channel #${id} not found`) throw new BadRequestException(`Channel #${id} not found`)
} }
channel.password = password channel.password = password
await this.ChannelRepository.save(channel) await this.update(channel)
} }
async getChannelsForUser (ftId: number): Promise<Channel[]> { async getChannelsForUser (ftId: number): Promise<Channel[]> {
@ -110,9 +110,9 @@ export class ChatService {
const channels = await this.ChannelRepository.find({}) const channels = await this.ChannelRepository.find({})
channels.forEach((channel) => { channels.forEach((channel) => {
channel.muted = channel.muted.filter((data) => { channel.muted = channel.muted.filter((data) => {
return data[1] - Date.now() > 0 return Date.now() - data[1] > 0
}) })
void this.ChannelRepository.save(channel) void this.update(channel)
}) })
} }
@ -123,8 +123,9 @@ export class ChatService {
for (const channel of channels) { for (const channel of channels) {
console.log((channel.banned.length) > 0) console.log((channel.banned.length) > 0)
channel.banned = channel.banned.filter((data) => { channel.banned = channel.banned.filter((data) => {
return data[1] - Date.now() > 0 return Date.now() - data[1] > 0
}) })
void this.update( channel)
} }
} }

Loading…
Cancel
Save