Browse Source

chat username colored

master
Eduard Kuzmenko 5 years ago
parent
commit
34c6c5a5c0
  1. 19
      src/lib/appManagers/appDialogsManager.ts
  2. 5
      src/lib/appManagers/appImManager.ts
  3. 22
      src/lib/appManagers/appPeersManager.ts

19
src/lib/appManagers/appDialogsManager.ts

@ -20,9 +20,6 @@ type DialogDom = {
listEl: HTMLLIElement listEl: HTMLLIElement
}; };
const DialogColors = ['#c03d33', '#4fad2d', '#d09306', '#168acd', '#8544d6', '#cd4073', '#2996ad', '#ce671b'];
const DialogColorsMap = [0, 7, 4, 1, 6, 3, 5];
export class AppDialogsManager { export class AppDialogsManager {
public chatList = document.getElementById('dialogs') as HTMLUListElement; public chatList = document.getElementById('dialogs') as HTMLUListElement;
public pinnedDelimiter: HTMLDivElement; public pinnedDelimiter: HTMLDivElement;
@ -76,17 +73,6 @@ export class AppDialogsManager {
}); });
} }
/*
HTML-color IRC-color Description
#c03d33 4 red
#4fad2d 3 green
#d09306 7 yellow
#168acd 10 blue
#8544d6 6 purple
#cd4073 13 pink
#2996ad 11 sea
#ce671b 5 orange
*/
public async loadDialogPhoto(div: HTMLDivElement, peerID: number | string, isDialog = false): Promise<boolean> { public async loadDialogPhoto(div: HTMLDivElement, peerID: number | string, isDialog = false): Promise<boolean> {
let inputPeer: any; let inputPeer: any;
let location: any; let location: any;
@ -102,6 +88,7 @@ export class AppDialogsManager {
div.firstChild.remove(); div.firstChild.remove();
} }
div.style.backgroundColor = '';
div.style.fontSize = ''; div.style.fontSize = '';
div.classList.add('tgico-savedmessages'); div.classList.add('tgico-savedmessages');
return true; return true;
@ -113,8 +100,8 @@ export class AppDialogsManager {
} }
let color = ''; let color = '';
if(typeof(peerID) != 'string') { if(typeof(peerID) != 'string' && peerID != this.myID) {
color = DialogColors[DialogColorsMap[(peerID < 0 ? -peerID : peerID) % 7]]; color = appPeersManager.getPeerColorByID(peerID);
} }
div.classList.remove('tgico-savedmessages'); div.classList.remove('tgico-savedmessages');

5
src/lib/appManagers/appImManager.ts

@ -356,6 +356,7 @@ export class AppImManager {
public contextMenu = document.getElementById('bubble-contextmenu') as HTMLDivElement; public contextMenu = document.getElementById('bubble-contextmenu') as HTMLDivElement;
private contextMenuPin = this.contextMenu.querySelector('.menu-pin') as HTMLDivElement; private contextMenuPin = this.contextMenu.querySelector('.menu-pin') as HTMLDivElement;
private contextMenuEdit = this.contextMenu.querySelector('.menu-edit') as HTMLDivElement;
private contextMenuMsgID: number; private contextMenuMsgID: number;
public replyElements: { public replyElements: {
@ -569,6 +570,8 @@ export class AppImManager {
let side = bubble.parentElement.classList.contains('in') ? 'left' : 'right'; let side = bubble.parentElement.classList.contains('in') ? 'left' : 'right';
this.contextMenuEdit.style.display = side == 'right' ? '' : 'none';
this.contextMenu.classList.remove('bottom-left', 'bottom-right'); this.contextMenu.classList.remove('bottom-left', 'bottom-right');
this.contextMenu.classList.add(side == 'left' ? 'bottom-right' : 'bottom-left'); this.contextMenu.classList.add(side == 'left' ? 'bottom-right' : 'bottom-left');
@ -1475,6 +1478,7 @@ export class AppImManager {
let nameDiv = document.createElement('div'); let nameDiv = document.createElement('div');
nameDiv.classList.add('name'); nameDiv.classList.add('name');
nameDiv.innerHTML = 'Forwarded from ' + title; nameDiv.innerHTML = 'Forwarded from ' + title;
nameDiv.style.color = appPeersManager.getPeerColorByID(message.fromID);
bubble.append(nameDiv); bubble.append(nameDiv);
} }
} else { } else {
@ -1545,6 +1549,7 @@ export class AppImManager {
let nameDiv = document.createElement('div'); let nameDiv = document.createElement('div');
nameDiv.classList.add('name'); nameDiv.classList.add('name');
nameDiv.innerHTML = title; nameDiv.innerHTML = title;
nameDiv.style.color = appPeersManager.getPeerColorByID(message.fromID);
bubble.append(nameDiv); bubble.append(nameDiv);
} else if(!message.reply_to_mid) { } else if(!message.reply_to_mid) {
bubble.classList.add('hide-name'); bubble.classList.add('hide-name');

22
src/lib/appManagers/appPeersManager.ts

@ -3,6 +3,22 @@ import appChatsManager from "./appChatsManager";
import { isObject } from "../utils"; import { isObject } from "../utils";
import { RichTextProcessor } from "../richtextprocessor"; import { RichTextProcessor } from "../richtextprocessor";
// https://github.com/eelcohn/Telegram-API/wiki/Calculating-color-for-a-Telegram-user-on-IRC
/*
HTML-color IRC-color Description
#c03d33 4 red
#4fad2d 3 green
#d09306 7 yellow
#168acd 10 blue
#8544d6 6 purple
#cd4073 13 pink
#2996ad 11 sea
#ce671b 5 orange
*/
const DialogColorsFg = ['#c03d33', '#4fad2d', '#d09306', '#168acd', '#8544d6', '#cd4073', '#2996ad', '#ce671b'];
const DialogColors = ['#e17076', '#7bc862', '#e5ca77', '#65AADD', '#a695e7', '#ee7aae', '#6ec9cb', '#faa774'];
const DialogColorsMap = [0, 7, 4, 1, 6, 3, 5];
const AppPeersManager = { const AppPeersManager = {
getPeerPhoto: (peerID: number) => { getPeerPhoto: (peerID: number) => {
return peerID > 0 return peerID > 0
@ -115,6 +131,12 @@ const AppPeersManager = {
}; };
}, },
getPeerColorByID: (peerID: number, pic = true) => {
let idx = DialogColorsMap[(peerID < 0 ? -peerID : peerID) % 7];
let color = (pic ? DialogColors : DialogColorsFg)[idx];
return color;
},
isMegagroup: (peerID: number) => { isMegagroup: (peerID: number) => {
return (peerID < 0) && appChatsManager.isMegagroup(-peerID); return (peerID < 0) && appChatsManager.isMegagroup(-peerID);
}, },

Loading…
Cancel
Save