Browse Source

Complete Last Message Edition support

pull/183/head
Timothée Jaussoin 10 years ago
parent
commit
ca3766350e
  1. 2
      CHANGELOG.md
  2. 25
      app/models/message/MessageDAO.php
  3. 50
      app/widgets/Chat/Chat.php
  4. 4
      app/widgets/Chat/_chat.tpl
  5. 17
      app/widgets/Chat/chat.js
  6. 3
      composer.json
  7. 75
      composer.lock

2
CHANGELOG.md

@ -4,6 +4,8 @@ Movim Changelog
v0.9.1 (trunk)
---------------------------
* CSS fixes
* Add Last Message Edition support
* Improve Post discovery in the News page
v0.9
---------------------------

25
app/models/message/MessageDAO.php

@ -88,7 +88,30 @@ class MessageDAO extends SQL {
return $this->run('Message');
}
function getContact($jid, $limitf = false, $limitr = false) {
function getLastItem($to)
{
$this->_sql = '
select * from message
where session = :session
and jidto = :jidto
and jidfrom = :jidfrom
order by published desc
limit 1';
$this->prepare(
'Message',
array(
'session' => $this->_user,
'jidto' => $to,
'jidfrom' => $this->_user
)
);
return $this->run('Message', 'item');
}
function getContact($jid, $limitf = false, $limitr = false)
{
$this->_sql = '
select * from message
where session = :session

50
app/widgets/Chat/Chat.php

@ -10,6 +10,8 @@ use Moxl\Xec\Action\Muc\SetSubject;
use Respect\Validation\Validator;
use Ramsey\Uuid\Uuid;
class Chat extends WidgetBase
{
private $_pagination = 30;
@ -223,7 +225,7 @@ class Chat extends WidgetBase
* @param string $message
* @return void
*/
function ajaxSendMessage($to, $message, $muc = false, $resource = false) {
function ajaxSendMessage($to, $message, $muc = false, $resource = false, $replace = false) {
if($message == '')
return;
@ -232,6 +234,14 @@ class Chat extends WidgetBase
$m->jidto = echapJid($to);
$m->jidfrom = $this->user->getLogin();
if($replace != false) {
$m->newid = Uuid::uuid4();
$m->id = $replace;
$m->edited = true;
} else {
$m->id = Uuid::uuid4();
}
$session = \Sessionx::start();
$m->type = 'chat';
@ -265,6 +275,13 @@ class Chat extends WidgetBase
//$p->setHTML($m->html);
$p->setContent($m->body);
if($replace != false) {
$p->setId($m->newid);
$p->setReplace($m->id);
} else {
$p->setId($m->id);
}
if($muc) {
$p->setMuc();
}
@ -284,6 +301,37 @@ class Chat extends WidgetBase
}
}
/**
* @brief Send a correction message
*
* @param string $to
* @param string $message
* @return void
*/
function ajaxCorrect($to, $message)
{
$md = new \Modl\MessageDAO;
$m = $md->getLastItem($to);
if($m) {
$this->ajaxSendMessage($to, $message, false, false, $m->id);
}
}
/**
* @brief Get the last message sent
*
* @param string $to
* @return void
*/
function ajaxLast($to)
{
$md = new \Modl\MessageDAO;
$m = $md->getLastItem($to);
RPC::call('Chat.setTextarea', $m->body);
}
/**
* @brief Send a "composing" message
*

4
app/widgets/Chat/_chat.tpl

@ -111,6 +111,10 @@
state = 0;
Chat.sendMessage(this.dataset.jid, {if="$muc"}true{else}false{/if});
return false;
} else if(event.keyCode == 38) {
Chat_ajaxLast(this.dataset.jid);
} else if(event.keyCode == 40) {
Chat.clearReplace();
} else {
{if="!$muc"}
if(state == 0 || state == 2) {

17
app/widgets/Chat/chat.js

@ -5,6 +5,7 @@ var Chat = {
previous: null,
date: null,
lastScroll: null,
edit: false,
addSmiley: function(element) {
var n = document.querySelector('#chat_textarea');
n.value = n.value + element.dataset.emoji;
@ -18,7 +19,12 @@ var Chat = {
n.value = "";
n.focus();
movim_textarea_autoheight(n);
Chat_ajaxSendMessage(jid, encodeURIComponent(text), muc);
if(Chat.edit) {
Chat.edit = false;
Chat_ajaxCorrect(jid, encodeURIComponent(text));
} else {
Chat_ajaxSendMessage(jid, encodeURIComponent(text), muc);
}
},
focus: function()
{
@ -26,8 +32,15 @@ var Chat = {
document.querySelector('#chat_textarea').focus();
}
},
appendTextarea: function(value)
setTextarea: function(value)
{
Chat.edit = true;
document.querySelector('#chat_textarea').value = value;
},
clearReplace: function()
{
Chat.edit = false;
document.querySelector('#chat_textarea').value = '';
},
notify : function(title, body, image)
{

3
composer.json

@ -23,6 +23,7 @@
"forxer/Gravatar": "~1.2",
"respect/validation": "1.0.*",
"ezyang/htmlpurifier": "^4.7"
"ezyang/htmlpurifier": "^4.7",
"ramsey/uuid": "^3.2"
}
}

75
composer.lock

@ -4,8 +4,8 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"hash": "530ddadaf89e5d672e3b42b8831fee62",
"content-hash": "2a4187ff046018943394d6797b018de3",
"hash": "36f305c1b49f9700c3c90de31d9ad5c6",
"content-hash": "cfb38697ddf63cba689ff1f94487d2b5",
"packages": [
{
"name": "cboden/ratchet",
@ -909,6 +909,77 @@
"homepage": "http://raintpl.com",
"time": "2014-12-23 19:29:46"
},
{
"name": "ramsey/uuid",
"version": "3.2.0",
"source": {
"type": "git",
"url": "https://github.com/ramsey/uuid.git",
"reference": "adee1ba4a6885ed800021a98dd69ae2394d695ec"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/ramsey/uuid/zipball/adee1ba4a6885ed800021a98dd69ae2394d695ec",
"reference": "adee1ba4a6885ed800021a98dd69ae2394d695ec",
"shasum": ""
},
"require": {
"php": ">=5.4"
},
"replace": {
"rhumsaa/uuid": "self.version"
},
"require-dev": {
"apigen/apigen": "^4.1",
"ircmaxell/random-lib": "^1.1",
"jakub-onderka/php-parallel-lint": "^0.9.0",
"moontoast/math": "^1.1",
"phpunit/phpunit": "^4.7|^5.0",
"satooshi/php-coveralls": "^0.6.1",
"squizlabs/php_codesniffer": "^2.3"
},
"suggest": {
"ext-libsodium": "Provides the PECL libsodium extension for use with the SodiumRandomGenerator",
"ext-uuid": "Provides the PECL UUID extension for use with the PeclUuidTimeGenerator and PeclUuidRandomGenerator",
"ircmaxell/random-lib": "Provides RandomLib for use with the RandomLibAdapter",
"moontoast/math": "Provides support for converting UUID to 128-bit integer (in string form).",
"ramsey/uuid-console": "A console application for generating UUIDs with ramsey/uuid",
"ramsey/uuid-doctrine": "Allows the use of Ramsey\\Uuid\\Uuid as Doctrine field type."
},
"type": "library",
"autoload": {
"psr-4": {
"Ramsey\\Uuid\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Marijn Huizendveld",
"email": "marijn.huizendveld@gmail.com"
},
{
"name": "Thibaud Fabre",
"email": "thibaud@aztech.io"
},
{
"name": "Ben Ramsey",
"email": "ben@benramsey.com",
"homepage": "https://benramsey.com"
}
],
"description": "Formerly rhumsaa/uuid. A PHP 5.4+ library for generating RFC 4122 version 1, 3, 4, and 5 universally unique identifiers (UUID).",
"homepage": "https://github.com/ramsey/uuid",
"keywords": [
"guid",
"identifier",
"uuid"
],
"time": "2016-02-17 23:32:34"
},
{
"name": "react/cache",
"version": "v0.4.0",

Loading…
Cancel
Save