Conversation Colors

This commit is contained in:
Josh Perez 2021-05-28 12:15:17 -04:00 committed by GitHub
parent b63d8e908c
commit 28f016ce48
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
128 changed files with 3997 additions and 1207 deletions

View file

@ -29,6 +29,7 @@ import { createBatcher } from '../util/batcher';
import { assert } from '../util/assert';
import { cleanDataForIpc } from './cleanDataForIpc';
import { ReactionType } from '../types/Reactions';
import { ConversationColorType, CustomColorType } from '../types/Colors';
import {
ConversationModelCollectionType,
@ -157,6 +158,7 @@ const dataInterface: ClientInterface = {
updateConversation,
updateConversations,
removeConversation,
updateAllConversationColors,
eraseStorageServiceStateFromConversations,
getAllConversations,
@ -1549,3 +1551,16 @@ function insertJob(job: Readonly<StoredJob>): Promise<void> {
function deleteJob(id: string): Promise<void> {
return channels.deleteJob(id);
}
async function updateAllConversationColors(
conversationColor?: ConversationColorType,
customColorData?: {
id: string;
value: CustomColorType;
}
): Promise<void> {
return channels.updateAllConversationColors(
conversationColor,
customColorData
);
}

View file

@ -14,6 +14,7 @@ import { MessageModel } from '../models/messages';
import { ConversationModel } from '../models/conversations';
import { StoredJob } from '../jobs/types';
import { ReactionType } from '../types/Reactions';
import { ConversationColorType, CustomColorType } from '../types/Colors';
export type AttachmentDownloadJobType = {
id: string;
@ -310,6 +311,14 @@ export type DataInterface = {
getJobsInQueue(queueType: string): Promise<Array<StoredJob>>;
insertJob(job: Readonly<StoredJob>): Promise<void>;
deleteJob(id: string): Promise<void>;
updateAllConversationColors: (
conversationColor?: ConversationColorType,
customColorData?: {
id: string;
value: CustomColorType;
}
) => Promise<void>;
};
// The reason for client/server divergence is the need to inject Backbone models and

View file

@ -36,6 +36,7 @@ import { combineNames } from '../util/combineNames';
import { getExpiresAt } from '../services/MessageUpdater';
import { isNormalNumber } from '../util/isNormalNumber';
import { isNotNil } from '../util/isNotNil';
import { ConversationColorType, CustomColorType } from '../types/Colors';
import {
AttachmentDownloadJobType,
@ -153,6 +154,7 @@ const dataInterface: ServerInterface = {
getAllConversationIds,
getAllPrivateConversations,
getAllGroupsInvolvingId,
updateAllConversationColors,
searchConversations,
searchMessages,
@ -5328,3 +5330,26 @@ async function deleteJob(id: string): Promise<void> {
db.prepare<Query>('DELETE FROM jobs WHERE id = $id').run({ id });
}
async function updateAllConversationColors(
conversationColor?: ConversationColorType,
customColorData?: {
id: string;
value: CustomColorType;
}
): Promise<void> {
const db = getInstance();
db.prepare<Query>(
`
UPDATE conversations
SET json = JSON_PATCH(json, $patch);
`
).run({
patch: JSON.stringify({
conversationColor: conversationColor || null,
customColor: customColorData?.value || null,
customColorId: customColorData?.id || null,
}),
});
}