Skip to content

Commit

Permalink
feat: Image gallery with swiper (#30623)
Browse files Browse the repository at this point in the history
  • Loading branch information
juliajforesti authored Dec 4, 2023
1 parent b90f871 commit 5224eab
Show file tree
Hide file tree
Showing 35 changed files with 559 additions and 751 deletions.
1 change: 0 additions & 1 deletion apps/meteor/.meteor/packages
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,5 @@ [email protected]

# photoswipe

jquery
zodern:types
zodern:standard-minifier-js
1 change: 0 additions & 1 deletion apps/meteor/.meteor/versions
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ [email protected]
[email protected]
[email protected]
[email protected]
[email protected]
kadira:[email protected]
[email protected]
[email protected]
Expand Down
45 changes: 44 additions & 1 deletion apps/meteor/app/api/server/v1/channels.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Team, Room } from '@rocket.chat/core-services';
import type { IRoom, ISubscription, IUser, RoomType } from '@rocket.chat/core-typings';
import type { IRoom, ISubscription, IUser, RoomType, IUpload } from '@rocket.chat/core-typings';
import { Integrations, Messages, Rooms, Subscriptions, Uploads, Users } from '@rocket.chat/models';
import {
isChannelsAddAllProps,
Expand All @@ -18,6 +18,7 @@ import {
isChannelsConvertToTeamProps,
isChannelsSetReadOnlyProps,
isChannelsDeleteProps,
isChannelsImagesProps,
} from '@rocket.chat/rest-typings';
import { Meteor } from 'meteor/meteor';

Expand Down Expand Up @@ -803,6 +804,48 @@ API.v1.addRoute(
},
);

API.v1.addRoute(
'channels.images',
{ authRequired: true, validateParams: isChannelsImagesProps },
{
async get() {
const room = await Rooms.findOneById<Pick<IRoom, '_id' | 't' | 'teamId' | 'prid'>>(this.queryParams.roomId, {
projection: { t: 1, teamId: 1, prid: 1 },
});

if (!room || !(await canAccessRoomAsync(room, { _id: this.userId }))) {
return API.v1.unauthorized();
}

let initialImage: IUpload | null = null;
if (this.queryParams.startingFromId) {
initialImage = await Uploads.findOneById(this.queryParams.startingFromId);
}

const { offset, count } = await getPaginationItems(this.queryParams);

const { cursor, totalCount } = Uploads.findImagesByRoomId(room._id, initialImage?.uploadedAt, {
skip: offset,
limit: count,
});

const [files, total] = await Promise.all([cursor.toArray(), totalCount]);

// If the initial image was not returned in the query, insert it as the first element of the list
if (initialImage && !files.find(({ _id }) => _id === (initialImage as IUpload)._id)) {
files.splice(0, 0, initialImage);
}

return API.v1.success({
files,
count,
offset,
total,
});
},
},
);

API.v1.addRoute(
'channels.getIntegrations',
{ authRequired: true },
Expand Down
46 changes: 0 additions & 46 deletions apps/meteor/app/emoji-custom/client/lib/emojiCustom.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { escapeRegExp } from '@rocket.chat/string-helpers';
import $ from 'jquery';
import { Meteor } from 'meteor/meteor';
import { Session } from 'meteor/session';

import { emoji, updateRecent } from '../../../emoji/client';
import { CachedCollectionManager } from '../../../ui-cached-collection/client';
import { LegacyRoomManager } from '../../../ui-utils/client';
import { getURL } from '../../../utils/client';
import { sdk } from '../../../utils/client/lib/SDKClient';
import { isSetNotNull } from './function-isSet';
Expand Down Expand Up @@ -45,9 +43,6 @@ export const deleteEmojiCustom = function (emojiData) {
};

export const updateEmojiCustom = function (emojiData) {
let key = `emoji_random_${emojiData.name}`;
Session.set(key, Math.round(Math.random() * 1000));

const previousExists = isSetNotNull(() => emojiData.previousName);
const currentAliases = isSetNotNull(() => emojiData.aliases);

Expand Down Expand Up @@ -88,47 +83,6 @@ export const updateEmojiCustom = function (emojiData) {
}
}

const url = getEmojiUrlFromName(emojiData.name, emojiData.extension);

// update in admin interface
if (previousExists && emojiData.name !== emojiData.previousName) {
$(document)
.find(`.emojiAdminPreview-image[data-emoji='${emojiData.previousName}']`)
.css('background-image', `url('${url})'`)
.attr('data-emoji', `${emojiData.name}`);
} else {
$(document).find(`.emojiAdminPreview-image[data-emoji='${emojiData.name}']`).css('background-image', `url('${url}')`);
}

// update in picker
if (previousExists && emojiData.name !== emojiData.previousName) {
$(document)
.find(`li[data-emoji='${emojiData.previousName}'] span`)
.css('background-image', `url('${url}')`)
.attr('data-emoji', `${emojiData.name}`);
$(document)
.find(`li[data-emoji='${emojiData.previousName}']`)
.attr('data-emoji', `${emojiData.name}`)
.attr('class', `emoji-${emojiData.name}`);
} else {
$(document).find(`li[data-emoji='${emojiData.name}'] span`).css('background-image', `url('${url}')`);
}

// update in picker and opened rooms
for (key in LegacyRoomManager.openedRooms) {
if (LegacyRoomManager.openedRooms.hasOwnProperty(key)) {
const room = LegacyRoomManager.openedRooms[key];
if (previousExists && emojiData.name !== emojiData.previousName) {
$(room.dom)
.find(`span[data-emoji='${emojiData.previousName}']`)
.css('background-image', `url('${url}')`)
.attr('data-emoji', `${emojiData.name}`);
} else {
$(room.dom).find(`span[data-emoji='${emojiData.name}']`).css('background-image', `url('${url}')`);
}
}
}

updateRecent('rocket');
};

Expand Down
1 change: 0 additions & 1 deletion apps/meteor/app/theme/client/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

/* Legacy theming */
@import 'imports/general/theme_old.css';
@import './vendor/photoswipe.css';
@import './vendor/fontello/css/fontello.css';
@import './rocketchat.font.css';
@import './mentionLink.css';
Expand Down
Loading

0 comments on commit 5224eab

Please sign in to comment.