add apisocket messages to chat history
This commit is contained in:
parent
de83b3e06e
commit
10353c2056
|
@ -30,7 +30,7 @@ const floatStyle = {
|
||||||
top: '50%',
|
top: '50%',
|
||||||
left: '50%',
|
left: '50%',
|
||||||
transform: 'translate(-50%,-50%)',
|
transform: 'translate(-50%,-50%)',
|
||||||
}
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* autoload: Load captcha immediately and autofocus input textbox
|
* autoload: Load captcha immediately and autofocus input textbox
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
import Sequelize from 'sequelize';
|
import Sequelize from 'sequelize';
|
||||||
import logger from './logger';
|
import logger from './logger';
|
||||||
|
|
||||||
import { RegUser, Message, Channel } from '../data/models';
|
import { Message, Channel } from '../data/models';
|
||||||
|
|
||||||
const MAX_BUFFER_TIME = 120000;
|
const MAX_BUFFER_TIME = 120000;
|
||||||
|
|
||||||
|
@ -59,9 +59,11 @@ class ChatMessageBuffer {
|
||||||
flag,
|
flag,
|
||||||
) {
|
) {
|
||||||
Message.create({
|
Message.create({
|
||||||
|
name,
|
||||||
|
flag,
|
||||||
|
message,
|
||||||
cid,
|
cid,
|
||||||
uid,
|
uid,
|
||||||
message,
|
|
||||||
});
|
});
|
||||||
Channel.update({
|
Channel.update({
|
||||||
lastMessage: Sequelize.literal('CURRENT_TIMESTAMP'),
|
lastMessage: Sequelize.literal('CURRENT_TIMESTAMP'),
|
||||||
|
@ -83,20 +85,11 @@ class ChatMessageBuffer {
|
||||||
|
|
||||||
static async getMessagesFromDatabase(cid, limit = 200) {
|
static async getMessagesFromDatabase(cid, limit = 200) {
|
||||||
const messagesModel = await Message.findAll({
|
const messagesModel = await Message.findAll({
|
||||||
include: [
|
|
||||||
{
|
|
||||||
model: RegUser,
|
|
||||||
as: 'user',
|
|
||||||
foreignKey: 'uid',
|
|
||||||
attributes: [
|
|
||||||
'id',
|
|
||||||
'name',
|
|
||||||
'flag',
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
attributes: [
|
attributes: [
|
||||||
'message',
|
'message',
|
||||||
|
'uid',
|
||||||
|
'name',
|
||||||
|
'flag',
|
||||||
],
|
],
|
||||||
where: { cid },
|
where: { cid },
|
||||||
limit,
|
limit,
|
||||||
|
@ -108,10 +101,10 @@ class ChatMessageBuffer {
|
||||||
while (i > 0) {
|
while (i > 0) {
|
||||||
i -= 1;
|
i -= 1;
|
||||||
const {
|
const {
|
||||||
|
name,
|
||||||
message,
|
message,
|
||||||
'user.name': name,
|
flag,
|
||||||
'user.flag': flag,
|
uid,
|
||||||
'user.id': uid,
|
|
||||||
} = messagesModel[i];
|
} = messagesModel[i];
|
||||||
messages.push([
|
messages.push([
|
||||||
name,
|
name,
|
||||||
|
|
|
@ -13,7 +13,12 @@ import { cheapDetector } from './isProxy';
|
||||||
import { DailyCron } from '../utils/cron';
|
import { DailyCron } from '../utils/cron';
|
||||||
import ttags from './ttag';
|
import ttags from './ttag';
|
||||||
|
|
||||||
import { CHAT_CHANNELS, EVENT_USER_NAME, INFO_USER_NAME } from './constants';
|
import {
|
||||||
|
CHAT_CHANNELS,
|
||||||
|
EVENT_USER_NAME,
|
||||||
|
INFO_USER_NAME,
|
||||||
|
APISOCKET_USER_NAME,
|
||||||
|
} from './constants';
|
||||||
|
|
||||||
export class ChatProvider {
|
export class ChatProvider {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
@ -23,6 +28,7 @@ export class ChatProvider {
|
||||||
this.enChannelId = 0;
|
this.enChannelId = 0;
|
||||||
this.infoUserId = 1;
|
this.infoUserId = 1;
|
||||||
this.eventUserId = 1;
|
this.eventUserId = 1;
|
||||||
|
this.apiSocketUserId = 1;
|
||||||
this.caseCheck = /^[A-Z !.]*$/;
|
this.caseCheck = /^[A-Z !.]*$/;
|
||||||
this.cyrillic = /[\u0436-\u043B]'/;
|
this.cyrillic = /[\u0436-\u043B]'/;
|
||||||
this.filters = [
|
this.filters = [
|
||||||
|
@ -156,6 +162,20 @@ export class ChatProvider {
|
||||||
raw: true,
|
raw: true,
|
||||||
});
|
});
|
||||||
this.eventUserId = eventUser[0].id;
|
this.eventUserId = eventUser[0].id;
|
||||||
|
name = APISOCKET_USER_NAME;
|
||||||
|
const apiSocketUser = await RegUser.findOrCreate({
|
||||||
|
attributes: [
|
||||||
|
'id',
|
||||||
|
],
|
||||||
|
where: { name },
|
||||||
|
defaults: {
|
||||||
|
name,
|
||||||
|
verified: 3,
|
||||||
|
email: 'event@example.com',
|
||||||
|
},
|
||||||
|
raw: true,
|
||||||
|
});
|
||||||
|
this.apiSocketUserId = apiSocketUser[0].id;
|
||||||
this.clearOldMessages();
|
this.clearOldMessages();
|
||||||
DailyCron.hook(this.clearOldMessages);
|
DailyCron.hook(this.clearOldMessages);
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,3 +96,4 @@ export const MAX_CHAT_MESSAGES = 100;
|
||||||
|
|
||||||
export const EVENT_USER_NAME = 'event';
|
export const EVENT_USER_NAME = 'event';
|
||||||
export const INFO_USER_NAME = 'info';
|
export const INFO_USER_NAME = 'info';
|
||||||
|
export const APISOCKET_USER_NAME = 'apisocket';
|
||||||
|
|
|
@ -2,8 +2,6 @@
|
||||||
*
|
*
|
||||||
* Database layout for Chat Message History
|
* Database layout for Chat Message History
|
||||||
*
|
*
|
||||||
* @flow
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import DataType from 'sequelize';
|
import DataType from 'sequelize';
|
||||||
|
@ -19,6 +17,18 @@ const Message = Model.define('Message', {
|
||||||
primaryKey: true,
|
primaryKey: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
name: {
|
||||||
|
type: `${DataType.CHAR(32)} CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci`,
|
||||||
|
defaultValue: 'mx',
|
||||||
|
allowNull: false,
|
||||||
|
},
|
||||||
|
|
||||||
|
flag: {
|
||||||
|
type: DataType.CHAR(2),
|
||||||
|
defaultValue: 'xx',
|
||||||
|
allowNull: false,
|
||||||
|
},
|
||||||
|
|
||||||
message: {
|
message: {
|
||||||
type: `${DataType.CHAR(200)} CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci`,
|
type: `${DataType.CHAR(200)} CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci`,
|
||||||
allowNull: false,
|
allowNull: false,
|
||||||
|
|
|
@ -239,11 +239,11 @@ class APISocketServer {
|
||||||
}
|
}
|
||||||
if (command === 'chat') {
|
if (command === 'chat') {
|
||||||
const [name, id, msg, country, channelId] = packet;
|
const [name, id, msg, country, channelId] = packet;
|
||||||
const uid = id || 1;
|
const uid = id || chatProvider.apiSocketUserId;
|
||||||
/*
|
/*
|
||||||
* do not send message back up ws that sent it
|
* do not send message back up ws that sent it
|
||||||
*/
|
*/
|
||||||
socketEvents.broadcastChatMessage(
|
chatProvider.broadcastChatMessage(
|
||||||
name,
|
name,
|
||||||
msg,
|
msg,
|
||||||
channelId,
|
channelId,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user