112 lines
3.8 KiB
TypeScript
112 lines
3.8 KiB
TypeScript
// (C) Copyright 2015 Moodle Pty Ltd.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
import { CoreSiteSchema } from '@services/sites';
|
|
import { AddonMessagesConversation } from '../messages';
|
|
|
|
/**
|
|
* Database variables for AddonMessagesOffline service.
|
|
*/
|
|
export const MESSAGES_TABLE = 'addon_messages_offline_messages'; // When group messaging isn't available or new conversation starts.
|
|
export const CONVERSATION_MESSAGES_TABLE = 'addon_messages_offline_conversation_messages'; // Conversation messages.
|
|
export const MESSAGES_OFFLINE_SITE_SCHEMA: CoreSiteSchema = {
|
|
name: 'AddonMessagesOfflineProvider',
|
|
version: 1,
|
|
tables: [
|
|
{
|
|
name: MESSAGES_TABLE,
|
|
columns: [
|
|
{
|
|
name: 'touserid',
|
|
type: 'INTEGER',
|
|
},
|
|
{
|
|
name: 'useridfrom',
|
|
type: 'INTEGER',
|
|
},
|
|
{
|
|
name: 'smallmessage',
|
|
type: 'TEXT',
|
|
},
|
|
{
|
|
name: 'timecreated',
|
|
type: 'INTEGER',
|
|
},
|
|
{
|
|
name: 'deviceoffline', // If message was stored because device was offline.
|
|
type: 'INTEGER',
|
|
},
|
|
],
|
|
primaryKeys: ['touserid', 'smallmessage', 'timecreated'],
|
|
},
|
|
{
|
|
name: CONVERSATION_MESSAGES_TABLE,
|
|
columns: [
|
|
{
|
|
name: 'conversationid',
|
|
type: 'INTEGER',
|
|
},
|
|
{
|
|
name: 'text',
|
|
type: 'TEXT',
|
|
},
|
|
{
|
|
name: 'timecreated',
|
|
type: 'INTEGER',
|
|
},
|
|
{
|
|
name: 'deviceoffline', // If message was stored because device was offline.
|
|
type: 'INTEGER',
|
|
},
|
|
{
|
|
name: 'conversation', // Data about the conversation.
|
|
type: 'TEXT',
|
|
},
|
|
],
|
|
primaryKeys: ['conversationid', 'text', 'timecreated'],
|
|
},
|
|
],
|
|
};
|
|
|
|
export type AddonMessagesOfflineMessagesDBRecord = {
|
|
touserid: number;
|
|
useridfrom: number;
|
|
smallmessage: string;
|
|
timecreated: number;
|
|
deviceoffline: number; // If message was stored because device was offline.
|
|
};
|
|
|
|
export type AddonMessagesOfflineMessagesDBRecordFormatted = AddonMessagesOfflineMessagesDBRecord & {
|
|
pending?: boolean; // Will be likely true.
|
|
text?: string; // Copy of smallmessage.
|
|
};
|
|
|
|
export type AddonMessagesOfflineConversationMessagesDBRecord = {
|
|
conversationid: number;
|
|
text: string;
|
|
timecreated: number;
|
|
deviceoffline: number; // If message was stored because device was offline.
|
|
conversation: string; // Data about the conversation.
|
|
};
|
|
|
|
export type AddonMessagesOfflineConversationMessagesDBRecordFormatted =
|
|
Omit<AddonMessagesOfflineConversationMessagesDBRecord, 'conversation'> &
|
|
{
|
|
conversation?: AddonMessagesConversation; // Data about the conversation.
|
|
pending: boolean; // Will be always true.
|
|
useridfrom?: number; // User Id who send the message, will be likely us.
|
|
};
|
|
|
|
|