widget parole 18
This commit is contained in:
parent
de02d31a5c
commit
2bdd71869a
@ -150,8 +150,8 @@ export async function GET(request: Request) {
|
||||
if (sub.t === 'd') {
|
||||
return sub.rid.includes(currentUser._id);
|
||||
}
|
||||
// For channels (t: 'c'), include if user has unread messages or mentions
|
||||
return sub.t === 'c' && (sub.unread > 0 || sub.userMentions > 0 || sub.alert);
|
||||
// For channels (t: 'c'), include all channels
|
||||
return sub.t === 'c';
|
||||
});
|
||||
|
||||
console.log('Filtered subscriptions:', {
|
||||
@ -202,40 +202,60 @@ export async function GET(request: Request) {
|
||||
const message = messageData.messages[0];
|
||||
const messageUser = message.u || {};
|
||||
const username = messageUser.username || 'unknown';
|
||||
const name = messageUser.name || username;
|
||||
const displayName = subscription.fname || subscription.name || username;
|
||||
|
||||
// Format the timestamp
|
||||
const timestamp = new Date(message.ts);
|
||||
const now = new Date();
|
||||
let formattedTime = '';
|
||||
|
||||
if (isNaN(timestamp.getTime())) {
|
||||
formattedTime = 'Invalid Date';
|
||||
} else if (timestamp.toDateString() === now.toDateString()) {
|
||||
// Today - show time only
|
||||
formattedTime = timestamp.toLocaleTimeString('fr-FR', {
|
||||
hour: '2-digit',
|
||||
minute: '2-digit'
|
||||
});
|
||||
} else {
|
||||
// Not today - show date
|
||||
formattedTime = timestamp.toLocaleDateString('fr-FR', {
|
||||
day: '2-digit',
|
||||
month: 'short'
|
||||
});
|
||||
}
|
||||
|
||||
messages.push({
|
||||
id: message._id,
|
||||
text: message.msg || '',
|
||||
timestamp: message.ts,
|
||||
roomName: subscription.fname || subscription.name || 'Direct Message',
|
||||
timestamp: formattedTime,
|
||||
roomName: displayName,
|
||||
roomType: subscription.t,
|
||||
unread: subscription.unread || 0,
|
||||
userMentions: subscription.userMentions || 0,
|
||||
alert: subscription.alert || false,
|
||||
lastSeen: subscription.ls,
|
||||
u: { // Keep the original u object for backward compatibility
|
||||
username: username,
|
||||
name: name
|
||||
},
|
||||
sender: {
|
||||
username: username,
|
||||
name: name,
|
||||
initials: name
|
||||
name: displayName,
|
||||
initials: displayName
|
||||
.split(' ')
|
||||
.map((n: string) => n[0])
|
||||
.slice(0, 2)
|
||||
.join('')
|
||||
.toUpperCase(),
|
||||
color: username === currentUser.username ? '#E3E3E3' : getAvatarColor(username)
|
||||
color: getAvatarColor(username)
|
||||
},
|
||||
isOwnMessage: username === currentUser.username,
|
||||
room: {
|
||||
id: subscription.rid,
|
||||
type: subscription.t,
|
||||
name: subscription.fname || subscription.name,
|
||||
name: displayName,
|
||||
isChannel: subscription.t === 'c',
|
||||
isDirect: subscription.t === 'd'
|
||||
isDirect: subscription.t === 'd',
|
||||
link: subscription.t === 'c'
|
||||
? `${baseUrl}/channel/${subscription.name}`
|
||||
: `${baseUrl}/direct/${subscription.name}`
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -246,7 +266,12 @@ export async function GET(request: Request) {
|
||||
}
|
||||
|
||||
// Sort messages by timestamp (newest first) and limit to 7
|
||||
messages.sort((a, b) => new Date(b.timestamp).getTime() - new Date(a.timestamp).getTime());
|
||||
messages.sort((a, b) => {
|
||||
const dateA = new Date(a.timestamp);
|
||||
const dateB = new Date(b.timestamp);
|
||||
return dateB.getTime() - dateA.getTime();
|
||||
});
|
||||
|
||||
const limitedMessages = messages.slice(0, 7);
|
||||
|
||||
return NextResponse.json({
|
||||
|
||||
Loading…
Reference in New Issue
Block a user